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