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 {
|
2018-04-30 19:46:04 +03:00
|
|
|
virtual ~CacheObserver() = default;
|
2014-06-24 20:36:44 +04:00
|
|
|
|
2014-04-22 13:21:00 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2013-09-20 13:11:25 +04:00
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
static nsresult Init();
|
|
|
|
static nsresult Shutdown();
|
|
|
|
static CacheObserver* Self() { return sSelf; }
|
|
|
|
|
|
|
|
// Access to preferences
|
2016-01-06 04:08:45 +03:00
|
|
|
static bool UseDiskCache() { return sUseDiskCache; }
|
|
|
|
static bool UseMemoryCache() { return sUseMemoryCache; }
|
|
|
|
static uint32_t MetadataMemoryLimit() // result in bytes.
|
2014-04-06 22:45:18 +04:00
|
|
|
{
|
|
|
|
return sMetadataMemoryLimit << 10;
|
|
|
|
}
|
2016-01-06 04:08:45 +03:00
|
|
|
static uint32_t MemoryCacheCapacity(); // result in bytes.
|
|
|
|
static uint32_t DiskCacheCapacity() // result in bytes.
|
2014-02-04 04:53:00 +04:00
|
|
|
{
|
|
|
|
return sDiskCacheCapacity << 10;
|
|
|
|
}
|
2014-04-22 13:21:00 +04:00
|
|
|
static void SetDiskCacheCapacity(uint32_t); // parameter in bytes.
|
2016-01-06 04:08:45 +03:00
|
|
|
static uint32_t DiskFreeSpaceSoftLimit() // result in bytes.
|
2014-07-11 10:25:55 +04:00
|
|
|
{
|
|
|
|
return sDiskFreeSpaceSoftLimit << 10;
|
|
|
|
}
|
2016-01-06 04:08:45 +03:00
|
|
|
static uint32_t DiskFreeSpaceHardLimit() // result in bytes.
|
2014-07-11 10:25:55 +04:00
|
|
|
{
|
|
|
|
return sDiskFreeSpaceHardLimit << 10;
|
|
|
|
}
|
2016-01-06 04:08:45 +03:00
|
|
|
static bool SmartCacheSizeEnabled() { return sSmartCacheSizeEnabled; }
|
|
|
|
static uint32_t PreloadChunkCount() { return sPreloadChunkCount; }
|
|
|
|
static uint32_t MaxMemoryEntrySize() // result in bytes.
|
2014-02-04 04:53:00 +04:00
|
|
|
{
|
|
|
|
return sMaxMemoryEntrySize << 10;
|
|
|
|
}
|
2016-01-06 04:08:45 +03:00
|
|
|
static uint32_t MaxDiskEntrySize() // result in bytes.
|
2014-02-04 04:53:00 +04:00
|
|
|
{
|
|
|
|
return sMaxDiskEntrySize << 10;
|
|
|
|
}
|
2016-01-06 04:08:45 +03:00
|
|
|
static uint32_t MaxDiskChunksMemoryUsage(bool aPriority) // result in bytes.
|
2014-07-10 09:59:29 +04:00
|
|
|
{
|
|
|
|
return aPriority ? sMaxDiskPriorityChunksMemoryUsage << 10
|
|
|
|
: sMaxDiskChunksMemoryUsage << 10;
|
|
|
|
}
|
2016-01-06 04:08:45 +03:00
|
|
|
static uint32_t CompressionLevel() { return sCompressionLevel; }
|
2015-02-27 18:17:00 +03:00
|
|
|
static uint32_t HalfLifeSeconds() { return sHalfLifeHours * 60.0F * 60.0F; }
|
2016-01-06 04:08:45 +03:00
|
|
|
static bool ClearCacheOnShutdown() {
|
2014-04-09 12:06:59 +04:00
|
|
|
return sSanitizeOnShutdown && sClearCacheOnShutdown;
|
|
|
|
}
|
2016-01-06 04:08:45 +03:00
|
|
|
static bool CacheFSReported() { return sCacheFSReported; }
|
2015-02-23 14:24:35 +03:00
|
|
|
static void SetCacheFSReported();
|
2016-01-06 04:08:45 +03:00
|
|
|
static bool HashStatsReported() { return sHashStatsReported; }
|
2015-06-14 15:13:18 +03:00
|
|
|
static void SetHashStatsReported();
|
2014-02-27 03:11:38 +04:00
|
|
|
static void ParentDirOverride(nsIFile** aDir);
|
2013-09-20 13:11:25 +04:00
|
|
|
|
2016-01-06 04:08:45 +03:00
|
|
|
static bool EntryIsTooBig(int64_t aSize, bool aUsingDisk);
|
2014-02-04 04:53:00 +04:00
|
|
|
|
2016-08-10 17:50:00 +03:00
|
|
|
static uint32_t MaxShutdownIOLag() { return sMaxShutdownIOLag; }
|
2016-05-11 12:46:54 +03:00
|
|
|
static bool IsPastShutdownIOLag();
|
|
|
|
|
|
|
|
static bool ShuttingDown() {
|
|
|
|
return sShutdownDemandedTime != PR_INTERVAL_NO_TIMEOUT;
|
|
|
|
}
|
2016-01-14 00:11:00 +03:00
|
|
|
|
2013-09-20 13:11:25 +04:00
|
|
|
private:
|
|
|
|
static CacheObserver* sSelf;
|
|
|
|
|
2014-04-22 13:21:00 +04:00
|
|
|
void StoreDiskCacheCapacity();
|
2015-02-23 14:24:35 +03:00
|
|
|
void StoreCacheFSReported();
|
2015-06-14 15:13:18 +03:00
|
|
|
void StoreHashStatsReported();
|
2013-09-20 13:11:25 +04:00
|
|
|
void AttachToPreferences();
|
|
|
|
|
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;
|
2016-03-20 12:08:57 +03:00
|
|
|
static Atomic<uint32_t, Relaxed> sDiskCacheCapacity;
|
2014-07-11 10:25:55 +04:00
|
|
|
static uint32_t sDiskFreeSpaceSoftLimit;
|
|
|
|
static uint32_t sDiskFreeSpaceHardLimit;
|
2014-04-22 13:21:00 +04:00
|
|
|
static bool sSmartCacheSizeEnabled;
|
2014-05-02 22:15:14 +04:00
|
|
|
static uint32_t sPreloadChunkCount;
|
2015-07-22 16:23:16 +03:00
|
|
|
static int32_t sMaxMemoryEntrySize;
|
|
|
|
static int32_t sMaxDiskEntrySize;
|
2014-07-10 09:59:29 +04:00
|
|
|
static uint32_t sMaxDiskChunksMemoryUsage;
|
|
|
|
static uint32_t sMaxDiskPriorityChunksMemoryUsage;
|
2014-02-04 04:53:00 +04:00
|
|
|
static uint32_t sCompressionLevel;
|
2015-02-27 18:17:00 +03:00
|
|
|
static float sHalfLifeHours;
|
2014-04-09 12:06:59 +04:00
|
|
|
static bool sSanitizeOnShutdown;
|
|
|
|
static bool sClearCacheOnShutdown;
|
2015-02-23 14:24:35 +03:00
|
|
|
static bool sCacheFSReported;
|
2015-06-14 15:13:18 +03:00
|
|
|
static bool sHashStatsReported;
|
2016-05-11 12:46:54 +03:00
|
|
|
static Atomic<uint32_t, Relaxed> sMaxShutdownIOLag;
|
2016-06-23 02:18:01 +03:00
|
|
|
static Atomic<PRIntervalTime> sShutdownDemandedTime;
|
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
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
2013-09-20 13:11:25 +04:00
|
|
|
|
|
|
|
#endif
|