CacheStorage.h (1665B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef CacheStorage__h__ 6 #define CacheStorage__h__ 7 8 #include "nsICacheStorage.h" 9 #include "CacheEntry.h" 10 #include "LoadContextInfo.h" 11 12 #include "nsILoadContextInfo.h" 13 14 class nsIURI; 15 16 namespace mozilla { 17 namespace net { 18 19 // This dance is needed to make CacheEntryTable declarable-only in headers 20 // w/o exporting CacheEntry.h file to make nsNetModule.cpp compilable. 21 using TCacheEntryTable = nsRefPtrHashtable<nsCStringHashKey, CacheEntry>; 22 class CacheEntryTable : public TCacheEntryTable { 23 public: 24 enum EType { MEMORY_ONLY, ALL_ENTRIES }; 25 26 explicit CacheEntryTable(EType aType) : mType(aType) {} 27 EType Type() const { return mType; } 28 29 private: 30 EType const mType; 31 CacheEntryTable() = delete; 32 }; 33 34 class CacheStorage : public nsICacheStorage { 35 NS_DECL_THREADSAFE_ISUPPORTS 36 NS_DECL_NSICACHESTORAGE 37 38 public: 39 CacheStorage(nsILoadContextInfo* aInfo, bool aAllowDisk, bool aSkipSizeCheck, 40 bool aPinning); 41 42 protected: 43 virtual ~CacheStorage() = default; 44 45 RefPtr<LoadContextInfo> mLoadContextInfo; 46 bool mWriteToDisk : 1; 47 bool mSkipSizeCheck : 1; 48 bool mPinning : 1; 49 50 public: 51 nsILoadContextInfo* LoadInfo() const { return mLoadContextInfo; } 52 bool WriteToDisk() const { 53 return mWriteToDisk && 54 (!mLoadContextInfo || !mLoadContextInfo->IsPrivate()); 55 } 56 bool SkipSizeCheck() const { return mSkipSizeCheck; } 57 bool Pinning() const { return mPinning; } 58 }; 59 60 } // namespace net 61 } // namespace mozilla 62 63 #endif