Bug 1875866 [wpt PR 44121] - Update wpt metadata, a=testonly
[gecko.git] / netwerk / cache2 / CacheObserver.h
blob633af7eec575ebe2851adb302fd7b0d647a535f0
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"
9 #include "nsIFile.h"
10 #include "nsCOMPtr.h"
11 #include "nsWeakReference.h"
12 #include "mozilla/StaticPrefs_browser.h"
13 #include "mozilla/StaticPrefs_privacy.h"
14 #include "mozilla/StaticPtr.h"
15 #include <algorithm>
17 namespace mozilla {
18 namespace net {
20 class CacheObserver : public nsIObserver, public nsSupportsWeakReference {
21 virtual ~CacheObserver() = default;
23 NS_DECL_THREADSAFE_ISUPPORTS
24 NS_DECL_NSIOBSERVER
26 static nsresult Init();
27 static nsresult Shutdown();
28 static CacheObserver* Self() { return sSelf; }
30 // Access to preferences
31 static bool UseDiskCache() {
32 return StaticPrefs::browser_cache_disk_enable();
34 static bool UseMemoryCache() {
35 return StaticPrefs::browser_cache_memory_enable();
37 static uint32_t MetadataMemoryLimit() // result in kilobytes.
39 return StaticPrefs::browser_cache_disk_metadata_memory_limit();
41 static uint32_t MemoryCacheCapacity(); // result in kilobytes.
42 static uint32_t DiskCacheCapacity(); // result in kilobytes.
43 static void SetSmartDiskCacheCapacity(uint32_t); // parameter in kilobytes.
44 static uint32_t DiskFreeSpaceSoftLimit() // result in kilobytes.
46 return StaticPrefs::browser_cache_disk_free_space_soft_limit();
48 static uint32_t DiskFreeSpaceHardLimit() // result in kilobytes.
50 return StaticPrefs::browser_cache_disk_free_space_hard_limit();
52 static bool SmartCacheSizeEnabled() {
53 return StaticPrefs::browser_cache_disk_smart_size_enabled();
55 static uint32_t PreloadChunkCount() {
56 return StaticPrefs::browser_cache_disk_preload_chunk_count();
58 static uint32_t MaxMemoryEntrySize() // result in kilobytes.
60 return StaticPrefs::browser_cache_memory_max_entry_size();
62 static uint32_t MaxDiskEntrySize() // result in kilobytes.
64 return StaticPrefs::browser_cache_disk_max_entry_size();
66 static uint32_t MaxDiskChunksMemoryUsage(
67 bool aPriority) // result in kilobytes.
69 return aPriority
70 ? StaticPrefs::
71 browser_cache_disk_max_priority_chunks_memory_usage()
72 : StaticPrefs::browser_cache_disk_max_chunks_memory_usage();
74 static uint32_t HalfLifeSeconds() { return sHalfLifeHours * 60.0F * 60.0F; }
75 static bool ClearCacheOnShutdown() {
76 return StaticPrefs::privacy_sanitize_sanitizeOnShutdown() &&
77 StaticPrefs::privacy_clearOnShutdown_cache();
79 static void ParentDirOverride(nsIFile** aDir);
81 static bool EntryIsTooBig(int64_t aSize, bool aUsingDisk);
83 static uint32_t MaxShutdownIOLag() {
84 return StaticPrefs::browser_cache_max_shutdown_io_lag();
86 static bool IsPastShutdownIOLag();
88 static bool ShuttingDown() {
89 return sShutdownDemandedTime != PR_INTERVAL_NO_TIMEOUT;
92 private:
93 static StaticRefPtr<CacheObserver> sSelf;
95 void AttachToPreferences();
97 static int32_t sAutoMemoryCacheCapacity;
98 static Atomic<uint32_t, Relaxed> sSmartDiskCacheCapacity;
99 static float sHalfLifeHours;
100 static Atomic<PRIntervalTime> sShutdownDemandedTime;
102 // Non static properties, accessible via sSelf
103 nsCOMPtr<nsIFile> mCacheParentDirectoryOverride;
106 } // namespace net
107 } // namespace mozilla
109 #endif