netwerk/cache2/CacheObserver.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef CacheObserver__h__
michael@0 6 #define CacheObserver__h__
michael@0 7
michael@0 8 #include "nsIObserver.h"
michael@0 9 #include "nsIFile.h"
michael@0 10 #include "nsCOMPtr.h"
michael@0 11 #include "nsWeakReference.h"
michael@0 12 #include <algorithm>
michael@0 13
michael@0 14 namespace mozilla {
michael@0 15 namespace net {
michael@0 16
michael@0 17 class CacheObserver : public nsIObserver
michael@0 18 , public nsSupportsWeakReference
michael@0 19 {
michael@0 20 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 21 NS_DECL_NSIOBSERVER
michael@0 22
michael@0 23 virtual ~CacheObserver() {}
michael@0 24
michael@0 25 static nsresult Init();
michael@0 26 static nsresult Shutdown();
michael@0 27 static CacheObserver* Self() { return sSelf; }
michael@0 28
michael@0 29 // Access to preferences
michael@0 30 static bool const UseNewCache();
michael@0 31 static bool const UseDiskCache()
michael@0 32 { return sUseDiskCache; }
michael@0 33 static bool const UseMemoryCache()
michael@0 34 { return sUseMemoryCache; }
michael@0 35 static uint32_t const MetadataMemoryLimit() // result in bytes.
michael@0 36 { return sMetadataMemoryLimit << 10; }
michael@0 37 static uint32_t const MemoryCacheCapacity(); // result in bytes.
michael@0 38 static uint32_t const DiskCacheCapacity() // result in bytes.
michael@0 39 { return sDiskCacheCapacity << 10; }
michael@0 40 static void SetDiskCacheCapacity(uint32_t); // parameter in bytes.
michael@0 41 static bool const SmartCacheSizeEnabled()
michael@0 42 { return sSmartCacheSizeEnabled; }
michael@0 43 static uint32_t const MaxMemoryEntrySize() // result in bytes.
michael@0 44 { return sMaxMemoryEntrySize << 10; }
michael@0 45 static uint32_t const MaxDiskEntrySize() // result in bytes.
michael@0 46 { return sMaxDiskEntrySize << 10; }
michael@0 47 static uint32_t const CompressionLevel()
michael@0 48 { return sCompressionLevel; }
michael@0 49 static uint32_t const HalfLifeSeconds()
michael@0 50 { return sHalfLifeHours * 60 * 60; }
michael@0 51 static int32_t const HalfLifeExperiment()
michael@0 52 { return sHalfLifeExperiment; }
michael@0 53 static bool const ClearCacheOnShutdown()
michael@0 54 { return sSanitizeOnShutdown && sClearCacheOnShutdown; }
michael@0 55 static void ParentDirOverride(nsIFile ** aDir);
michael@0 56
michael@0 57 static bool const EntryIsTooBig(int64_t aSize, bool aUsingDisk);
michael@0 58
michael@0 59 private:
michael@0 60 static CacheObserver* sSelf;
michael@0 61
michael@0 62 void StoreDiskCacheCapacity();
michael@0 63 void AttachToPreferences();
michael@0 64 void SchduleAutoDelete();
michael@0 65
michael@0 66 static uint32_t sUseNewCache;
michael@0 67 static bool sUseMemoryCache;
michael@0 68 static bool sUseDiskCache;
michael@0 69 static uint32_t sMetadataMemoryLimit;
michael@0 70 static int32_t sMemoryCacheCapacity;
michael@0 71 static int32_t sAutoMemoryCacheCapacity;
michael@0 72 static uint32_t sDiskCacheCapacity;
michael@0 73 static bool sSmartCacheSizeEnabled;
michael@0 74 static uint32_t sMaxMemoryEntrySize;
michael@0 75 static uint32_t sMaxDiskEntrySize;
michael@0 76 static uint32_t sCompressionLevel;
michael@0 77 static uint32_t sHalfLifeHours;
michael@0 78 static int32_t sHalfLifeExperiment;
michael@0 79 static bool sSanitizeOnShutdown;
michael@0 80 static bool sClearCacheOnShutdown;
michael@0 81
michael@0 82 // Non static properties, accessible via sSelf
michael@0 83 nsCOMPtr<nsIFile> mCacheParentDirectoryOverride;
michael@0 84 };
michael@0 85
michael@0 86 } // net
michael@0 87 } // mozilla
michael@0 88
michael@0 89 #endif

mercurial