/src/mozilla-central/netwerk/cache2/CacheObserver.h
Line | Count | Source (jump to first uncovered line) |
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 | | class CacheObserver : public nsIObserver |
18 | | , public nsSupportsWeakReference |
19 | | { |
20 | 0 | virtual ~CacheObserver() = default; |
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 UseDiskCache() |
31 | 0 | { return sUseDiskCache; } |
32 | | static bool UseMemoryCache() |
33 | 0 | { return sUseMemoryCache; } |
34 | | static uint32_t MetadataMemoryLimit() // result in bytes. |
35 | 0 | { return sMetadataMemoryLimit << 10; } |
36 | | static uint32_t MemoryCacheCapacity(); // result in bytes. |
37 | | static uint32_t DiskCacheCapacity() // result in bytes. |
38 | 0 | { return sDiskCacheCapacity << 10; } |
39 | | static void SetDiskCacheCapacity(uint32_t); // parameter in bytes. |
40 | | static uint32_t DiskFreeSpaceSoftLimit() // result in bytes. |
41 | 0 | { return sDiskFreeSpaceSoftLimit << 10; } |
42 | | static uint32_t DiskFreeSpaceHardLimit() // result in bytes. |
43 | 0 | { return sDiskFreeSpaceHardLimit << 10; } |
44 | | static bool SmartCacheSizeEnabled() |
45 | 0 | { return sSmartCacheSizeEnabled; } |
46 | | static uint32_t PreloadChunkCount() |
47 | 0 | { 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 | 0 | { return aPriority ? sMaxDiskPriorityChunksMemoryUsage << 10 |
54 | 0 | : sMaxDiskChunksMemoryUsage << 10; } |
55 | | static uint32_t CompressionLevel() |
56 | | { return sCompressionLevel; } |
57 | | static uint32_t HalfLifeSeconds() |
58 | 0 | { return sHalfLifeHours * 60.0F * 60.0F; } |
59 | | static bool ClearCacheOnShutdown() |
60 | 0 | { return sSanitizeOnShutdown && sClearCacheOnShutdown; } |
61 | | static bool CacheFSReported() |
62 | 0 | { return sCacheFSReported; } |
63 | | static void SetCacheFSReported(); |
64 | | static bool HashStatsReported() |
65 | 0 | { return sHashStatsReported; } |
66 | | static void SetHashStatsReported(); |
67 | | static void ParentDirOverride(nsIFile ** aDir); |
68 | | |
69 | | static bool EntryIsTooBig(int64_t aSize, bool aUsingDisk); |
70 | | |
71 | | static uint32_t MaxShutdownIOLag() |
72 | | { return sMaxShutdownIOLag; } |
73 | | static bool IsPastShutdownIOLag(); |
74 | | |
75 | | static bool ShuttingDown() |
76 | 0 | { return sShutdownDemandedTime != PR_INTERVAL_NO_TIMEOUT; } |
77 | | |
78 | | private: |
79 | | static CacheObserver* sSelf; |
80 | | |
81 | | void StoreDiskCacheCapacity(); |
82 | | void StoreCacheFSReported(); |
83 | | void StoreHashStatsReported(); |
84 | | void AttachToPreferences(); |
85 | | |
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; |
108 | | |
109 | | // Non static properties, accessible via sSelf |
110 | | nsCOMPtr<nsIFile> mCacheParentDirectoryOverride; |
111 | | }; |
112 | | |
113 | | } // namespace net |
114 | | } // namespace mozilla |
115 | | |
116 | | #endif |