2013-09-20 13:11:25 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef CacheObserver__h__
|
|
|
|
#define CacheObserver__h__
|
|
|
|
|
|
|
|
#include "nsIObserver.h"
|
2014-02-27 03:11:38 +04:00
|
|
|
#include "nsIFile.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2013-09-20 13:11:25 +04:00
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
class CacheObserver : public nsIObserver
|
|
|
|
, public nsSupportsWeakReference
|
|
|
|
{
|
2014-04-22 13:21:00 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2013-09-20 13:11:25 +04:00
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
virtual ~CacheObserver() {}
|
|
|
|
|
|
|
|
static nsresult Init();
|
|
|
|
static nsresult Shutdown();
|
|
|
|
static CacheObserver* Self() { return sSelf; }
|
|
|
|
|
|
|
|
// Access to preferences
|
2014-02-04 04:53:00 +04:00
|
|
|
static bool const UseNewCache();
|
|
|
|
static bool const UseDiskCache()
|
|
|
|
{ return sUseDiskCache; }
|
|
|
|
static bool const UseMemoryCache()
|
|
|
|
{ return sUseMemoryCache; }
|
2014-04-06 22:45:18 +04:00
|
|
|
static uint32_t const MetadataMemoryLimit() // result in bytes.
|
|
|
|
{ return sMetadataMemoryLimit << 10; }
|
|
|
|
static uint32_t const MemoryCacheCapacity(); // result in bytes.
|
2014-02-04 04:53:00 +04:00
|
|
|
static uint32_t const DiskCacheCapacity() // result in bytes.
|
|
|
|
{ return sDiskCacheCapacity << 10; }
|
2014-04-22 13:21:00 +04:00
|
|
|
static void SetDiskCacheCapacity(uint32_t); // parameter in bytes.
|
|
|
|
static bool const SmartCacheSizeEnabled()
|
|
|
|
{ return sSmartCacheSizeEnabled; }
|
2014-05-02 22:15:14 +04:00
|
|
|
static uint32_t const PreloadChunkCount()
|
|
|
|
{ return sPreloadChunkCount; }
|
2014-02-04 04:53:00 +04:00
|
|
|
static uint32_t const MaxMemoryEntrySize() // result in bytes.
|
|
|
|
{ return sMaxMemoryEntrySize << 10; }
|
|
|
|
static uint32_t const MaxDiskEntrySize() // result in bytes.
|
|
|
|
{ return sMaxDiskEntrySize << 10; }
|
|
|
|
static uint32_t const CompressionLevel()
|
|
|
|
{ return sCompressionLevel; }
|
2014-01-09 03:27:33 +04:00
|
|
|
static uint32_t const HalfLifeSeconds()
|
|
|
|
{ return sHalfLifeHours * 60 * 60; }
|
|
|
|
static int32_t const HalfLifeExperiment()
|
|
|
|
{ return sHalfLifeExperiment; }
|
2014-04-09 12:06:59 +04:00
|
|
|
static bool const ClearCacheOnShutdown()
|
|
|
|
{ return sSanitizeOnShutdown && sClearCacheOnShutdown; }
|
2014-02-27 03:11:38 +04:00
|
|
|
static void ParentDirOverride(nsIFile ** aDir);
|
2013-09-20 13:11:25 +04:00
|
|
|
|
2014-02-04 04:53:00 +04:00
|
|
|
static bool const EntryIsTooBig(int64_t aSize, bool aUsingDisk);
|
|
|
|
|
2013-09-20 13:11:25 +04:00
|
|
|
private:
|
|
|
|
static CacheObserver* sSelf;
|
|
|
|
|
2014-04-22 13:21:00 +04:00
|
|
|
void StoreDiskCacheCapacity();
|
2013-09-20 13:11:25 +04:00
|
|
|
void AttachToPreferences();
|
|
|
|
|
|
|
|
static uint32_t sUseNewCache;
|
2014-02-04 04:53:00 +04:00
|
|
|
static bool sUseMemoryCache;
|
2014-04-06 22:45:18 +04:00
|
|
|
static bool sUseDiskCache;
|
|
|
|
static uint32_t sMetadataMemoryLimit;
|
|
|
|
static int32_t sMemoryCacheCapacity;
|
|
|
|
static int32_t sAutoMemoryCacheCapacity;
|
2014-02-04 04:53:00 +04:00
|
|
|
static uint32_t sDiskCacheCapacity;
|
2014-04-22 13:21:00 +04:00
|
|
|
static bool sSmartCacheSizeEnabled;
|
2014-05-02 22:15:14 +04:00
|
|
|
static uint32_t sPreloadChunkCount;
|
2014-02-04 04:53:00 +04:00
|
|
|
static uint32_t sMaxMemoryEntrySize;
|
|
|
|
static uint32_t sMaxDiskEntrySize;
|
|
|
|
static uint32_t sCompressionLevel;
|
2014-01-09 03:27:33 +04:00
|
|
|
static uint32_t sHalfLifeHours;
|
|
|
|
static int32_t sHalfLifeExperiment;
|
2014-04-09 12:06:59 +04:00
|
|
|
static bool sSanitizeOnShutdown;
|
|
|
|
static bool sClearCacheOnShutdown;
|
2014-02-27 03:11:38 +04:00
|
|
|
|
|
|
|
// Non static properties, accessible via sSelf
|
|
|
|
nsCOMPtr<nsIFile> mCacheParentDirectoryOverride;
|
2013-09-20 13:11:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // net
|
|
|
|
} // mozilla
|
|
|
|
|
|
|
|
#endif
|