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/. */
5 #ifndef CacheStorage__h__
6 #define CacheStorage__h__
8 #include "nsICacheStorage.h"
9 #include "CacheEntry.h"
10 #include "LoadContextInfo.h"
12 #include "nsRefPtrHashtable.h"
13 #include "nsThreadUtils.h"
15 #include "nsILoadContextInfo.h"
22 // This dance is needed to make CacheEntryTable declarable-only in headers
23 // w/o exporting CacheEntry.h file to make nsNetModule.cpp compilable.
24 using TCacheEntryTable
= nsRefPtrHashtable
<nsCStringHashKey
, CacheEntry
>;
25 class CacheEntryTable
: public TCacheEntryTable
{
27 enum EType
{ MEMORY_ONLY
, ALL_ENTRIES
};
29 explicit CacheEntryTable(EType aType
) : mType(aType
) {}
30 EType
Type() const { return mType
; }
34 CacheEntryTable() = delete;
37 class CacheStorage
: public nsICacheStorage
{
38 NS_DECL_THREADSAFE_ISUPPORTS
39 NS_DECL_NSICACHESTORAGE
42 CacheStorage(nsILoadContextInfo
* aInfo
, bool aAllowDisk
, bool aSkipSizeCheck
,
46 virtual ~CacheStorage() = default;
48 RefPtr
<LoadContextInfo
> mLoadContextInfo
;
49 bool mWriteToDisk
: 1;
50 bool mSkipSizeCheck
: 1;
54 nsILoadContextInfo
* LoadInfo() const { return mLoadContextInfo
; }
55 bool WriteToDisk() const {
56 return mWriteToDisk
&&
57 (!mLoadContextInfo
|| !mLoadContextInfo
->IsPrivate());
59 bool SkipSizeCheck() const { return mSkipSizeCheck
; }
60 bool Pinning() const { return mPinning
; }
64 } // namespace mozilla