netwerk/cache2/CacheObserver.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:d3890e98ff7a
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 NS_DECL_THREADSAFE_ISUPPORTS
21 NS_DECL_NSIOBSERVER
22
23 virtual ~CacheObserver() {}
24
25 static nsresult Init();
26 static nsresult Shutdown();
27 static CacheObserver* Self() { return sSelf; }
28
29 // Access to preferences
30 static bool const UseNewCache();
31 static bool const UseDiskCache()
32 { return sUseDiskCache; }
33 static bool const UseMemoryCache()
34 { return sUseMemoryCache; }
35 static uint32_t const MetadataMemoryLimit() // result in bytes.
36 { return sMetadataMemoryLimit << 10; }
37 static uint32_t const MemoryCacheCapacity(); // result in bytes.
38 static uint32_t const DiskCacheCapacity() // result in bytes.
39 { return sDiskCacheCapacity << 10; }
40 static void SetDiskCacheCapacity(uint32_t); // parameter in bytes.
41 static bool const SmartCacheSizeEnabled()
42 { return sSmartCacheSizeEnabled; }
43 static uint32_t const MaxMemoryEntrySize() // result in bytes.
44 { return sMaxMemoryEntrySize << 10; }
45 static uint32_t const MaxDiskEntrySize() // result in bytes.
46 { return sMaxDiskEntrySize << 10; }
47 static uint32_t const CompressionLevel()
48 { return sCompressionLevel; }
49 static uint32_t const HalfLifeSeconds()
50 { return sHalfLifeHours * 60 * 60; }
51 static int32_t const HalfLifeExperiment()
52 { return sHalfLifeExperiment; }
53 static bool const ClearCacheOnShutdown()
54 { return sSanitizeOnShutdown && sClearCacheOnShutdown; }
55 static void ParentDirOverride(nsIFile ** aDir);
56
57 static bool const EntryIsTooBig(int64_t aSize, bool aUsingDisk);
58
59 private:
60 static CacheObserver* sSelf;
61
62 void StoreDiskCacheCapacity();
63 void AttachToPreferences();
64 void SchduleAutoDelete();
65
66 static uint32_t sUseNewCache;
67 static bool sUseMemoryCache;
68 static bool sUseDiskCache;
69 static uint32_t sMetadataMemoryLimit;
70 static int32_t sMemoryCacheCapacity;
71 static int32_t sAutoMemoryCacheCapacity;
72 static uint32_t sDiskCacheCapacity;
73 static bool sSmartCacheSizeEnabled;
74 static uint32_t sMaxMemoryEntrySize;
75 static uint32_t sMaxDiskEntrySize;
76 static uint32_t sCompressionLevel;
77 static uint32_t sHalfLifeHours;
78 static int32_t sHalfLifeExperiment;
79 static bool sSanitizeOnShutdown;
80 static bool sClearCacheOnShutdown;
81
82 // Non static properties, accessible via sSelf
83 nsCOMPtr<nsIFile> mCacheParentDirectoryOverride;
84 };
85
86 } // net
87 } // mozilla
88
89 #endif

mercurial