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 CacheObserver__h__
6 #define CacheObserver__h__
8 #include "nsIObserver.h"
11 #include "nsWeakReference.h"
17 class CacheObserver
: public nsIObserver
18 , public nsSupportsWeakReference
20 virtual ~CacheObserver() = default;
22 NS_DECL_THREADSAFE_ISUPPORTS
25 static nsresult
Init();
26 static nsresult
Shutdown();
27 static CacheObserver
* Self() { return sSelf
; }
29 // Access to preferences
30 static bool UseDiskCache()
31 { return sUseDiskCache
; }
32 static bool UseMemoryCache()
33 { return sUseMemoryCache
; }
34 static uint32_t MetadataMemoryLimit() // result in bytes.
35 { return sMetadataMemoryLimit
<< 10; }
36 static uint32_t MemoryCacheCapacity(); // result in bytes.
37 static uint32_t DiskCacheCapacity() // result in bytes.
38 { return sDiskCacheCapacity
<< 10; }
39 static void SetDiskCacheCapacity(uint32_t); // parameter in bytes.
40 static uint32_t DiskFreeSpaceSoftLimit() // result in bytes.
41 { return sDiskFreeSpaceSoftLimit
<< 10; }
42 static uint32_t DiskFreeSpaceHardLimit() // result in bytes.
43 { return sDiskFreeSpaceHardLimit
<< 10; }
44 static bool SmartCacheSizeEnabled()
45 { return sSmartCacheSizeEnabled
; }
46 static uint32_t PreloadChunkCount()
47 { return sPreloadChunkCount
; }
48 static uint32_t MaxMemoryEntrySize() // result in bytes.
49 { return sMaxMemoryEntrySize
<< 10; }
50 static uint32_t MaxDiskEntrySize() // result in bytes.
51 { return sMaxDiskEntrySize
<< 10; }
52 static uint32_t MaxDiskChunksMemoryUsage(bool aPriority
) // result in bytes.
53 { return aPriority
? sMaxDiskPriorityChunksMemoryUsage
<< 10
54 : sMaxDiskChunksMemoryUsage
<< 10; }
55 static uint32_t CompressionLevel()
56 { return sCompressionLevel
; }
57 static uint32_t HalfLifeSeconds()
58 { return sHalfLifeHours
* 60.0F
* 60.0F
; }
59 static bool ClearCacheOnShutdown()
60 { return sSanitizeOnShutdown
&& sClearCacheOnShutdown
; }
61 static bool CacheFSReported()
62 { return sCacheFSReported
; }
63 static void SetCacheFSReported();
64 static bool HashStatsReported()
65 { return sHashStatsReported
; }
66 static void SetHashStatsReported();
67 static void ParentDirOverride(nsIFile
** aDir
);
69 static bool EntryIsTooBig(int64_t aSize
, bool aUsingDisk
);
71 static uint32_t MaxShutdownIOLag()
72 { return sMaxShutdownIOLag
; }
73 static bool IsPastShutdownIOLag();
75 static bool ShuttingDown()
76 { return sShutdownDemandedTime
!= PR_INTERVAL_NO_TIMEOUT
; }
79 static CacheObserver
* sSelf
;
81 void StoreDiskCacheCapacity();
82 void StoreCacheFSReported();
83 void StoreHashStatsReported();
84 void AttachToPreferences();
86 static bool sUseMemoryCache
;
87 static bool sUseDiskCache
;
88 static uint32_t sMetadataMemoryLimit
;
89 static int32_t sMemoryCacheCapacity
;
90 static int32_t sAutoMemoryCacheCapacity
;
91 static Atomic
<uint32_t, Relaxed
> sDiskCacheCapacity
;
92 static uint32_t sDiskFreeSpaceSoftLimit
;
93 static uint32_t sDiskFreeSpaceHardLimit
;
94 static bool sSmartCacheSizeEnabled
;
95 static uint32_t sPreloadChunkCount
;
96 static int32_t sMaxMemoryEntrySize
;
97 static int32_t sMaxDiskEntrySize
;
98 static uint32_t sMaxDiskChunksMemoryUsage
;
99 static uint32_t sMaxDiskPriorityChunksMemoryUsage
;
100 static uint32_t sCompressionLevel
;
101 static float sHalfLifeHours
;
102 static bool sSanitizeOnShutdown
;
103 static bool sClearCacheOnShutdown
;
104 static bool sCacheFSReported
;
105 static bool sHashStatsReported
;
106 static Atomic
<uint32_t, Relaxed
> sMaxShutdownIOLag
;
107 static Atomic
<PRIntervalTime
> sShutdownDemandedTime
;
109 // Non static properties, accessible via sSelf
110 nsCOMPtr
<nsIFile
> mCacheParentDirectoryOverride
;
114 } // namespace mozilla