Bug 1925561 - Use a quicker radius calculation for ArcParams. r=aosmond
[gecko.git] / netwerk / cache2 / CacheObserver.h
blobc004d0db806a9ac2ab3caa741afc18ffd7ec7863
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 if (!StaticPrefs::privacy_sanitize_sanitizeOnShutdown()) {
77 return false;
79 if (StaticPrefs::privacy_sanitize_useOldClearHistoryDialog()) {
80 return StaticPrefs::privacy_clearOnShutdown_cache();
82 // use the new cache clearing pref for the new clear history dialog
83 return StaticPrefs::privacy_clearOnShutdown_v2_cache();
85 static void ParentDirOverride(nsIFile** aDir);
87 static bool EntryIsTooBig(int64_t aSize, bool aUsingDisk);
89 static uint32_t MaxShutdownIOLag() {
90 return StaticPrefs::browser_cache_max_shutdown_io_lag();
92 static bool IsPastShutdownIOLag();
94 static bool ShuttingDown() {
95 return sShutdownDemandedTime != PR_INTERVAL_NO_TIMEOUT;
98 private:
99 static StaticRefPtr<CacheObserver> sSelf;
101 void AttachToPreferences();
103 static int32_t sAutoMemoryCacheCapacity;
104 static Atomic<uint32_t, Relaxed> sSmartDiskCacheCapacity;
105 static float sHalfLifeHours;
106 static Atomic<PRIntervalTime> sShutdownDemandedTime;
108 // Non static properties, accessible via sSelf
109 nsCOMPtr<nsIFile> mCacheParentDirectoryOverride;
112 } // namespace net
113 } // namespace mozilla
115 #endif