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
|
|
|
|
{
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
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; }
|
|
|
|
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;
|
|
|
|
|
|
|
|
void AttachToPreferences();
|
2014-02-05 23:29:54 +04:00
|
|
|
void SchduleAutoDelete();
|
2013-09-20 13:11:25 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
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
|