michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef CacheObserver__h__ michael@0: #define CacheObserver__h__ michael@0: michael@0: #include "nsIObserver.h" michael@0: #include "nsIFile.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsWeakReference.h" michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace net { michael@0: michael@0: class CacheObserver : public nsIObserver michael@0: , public nsSupportsWeakReference michael@0: { michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIOBSERVER michael@0: michael@0: virtual ~CacheObserver() {} michael@0: michael@0: static nsresult Init(); michael@0: static nsresult Shutdown(); michael@0: static CacheObserver* Self() { return sSelf; } michael@0: michael@0: // Access to preferences michael@0: static bool const UseNewCache(); michael@0: static bool const UseDiskCache() michael@0: { return sUseDiskCache; } michael@0: static bool const UseMemoryCache() michael@0: { return sUseMemoryCache; } michael@0: static uint32_t const MetadataMemoryLimit() // result in bytes. michael@0: { return sMetadataMemoryLimit << 10; } michael@0: static uint32_t const MemoryCacheCapacity(); // result in bytes. michael@0: static uint32_t const DiskCacheCapacity() // result in bytes. michael@0: { return sDiskCacheCapacity << 10; } michael@0: static void SetDiskCacheCapacity(uint32_t); // parameter in bytes. michael@0: static bool const SmartCacheSizeEnabled() michael@0: { return sSmartCacheSizeEnabled; } michael@0: static uint32_t const MaxMemoryEntrySize() // result in bytes. michael@0: { return sMaxMemoryEntrySize << 10; } michael@0: static uint32_t const MaxDiskEntrySize() // result in bytes. michael@0: { return sMaxDiskEntrySize << 10; } michael@0: static uint32_t const CompressionLevel() michael@0: { return sCompressionLevel; } michael@0: static uint32_t const HalfLifeSeconds() michael@0: { return sHalfLifeHours * 60 * 60; } michael@0: static int32_t const HalfLifeExperiment() michael@0: { return sHalfLifeExperiment; } michael@0: static bool const ClearCacheOnShutdown() michael@0: { return sSanitizeOnShutdown && sClearCacheOnShutdown; } michael@0: static void ParentDirOverride(nsIFile ** aDir); michael@0: michael@0: static bool const EntryIsTooBig(int64_t aSize, bool aUsingDisk); michael@0: michael@0: private: michael@0: static CacheObserver* sSelf; michael@0: michael@0: void StoreDiskCacheCapacity(); michael@0: void AttachToPreferences(); michael@0: void SchduleAutoDelete(); michael@0: michael@0: static uint32_t sUseNewCache; michael@0: static bool sUseMemoryCache; michael@0: static bool sUseDiskCache; michael@0: static uint32_t sMetadataMemoryLimit; michael@0: static int32_t sMemoryCacheCapacity; michael@0: static int32_t sAutoMemoryCacheCapacity; michael@0: static uint32_t sDiskCacheCapacity; michael@0: static bool sSmartCacheSizeEnabled; michael@0: static uint32_t sMaxMemoryEntrySize; michael@0: static uint32_t sMaxDiskEntrySize; michael@0: static uint32_t sCompressionLevel; michael@0: static uint32_t sHalfLifeHours; michael@0: static int32_t sHalfLifeExperiment; michael@0: static bool sSanitizeOnShutdown; michael@0: static bool sClearCacheOnShutdown; michael@0: michael@0: // Non static properties, accessible via sSelf michael@0: nsCOMPtr mCacheParentDirectoryOverride; michael@0: }; michael@0: michael@0: } // net michael@0: } // mozilla michael@0: michael@0: #endif