netwerk/cache2/CacheObserver.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/cache2/CacheObserver.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef CacheObserver__h__
     1.9 +#define CacheObserver__h__
    1.10 +
    1.11 +#include "nsIObserver.h"
    1.12 +#include "nsIFile.h"
    1.13 +#include "nsCOMPtr.h"
    1.14 +#include "nsWeakReference.h"
    1.15 +#include <algorithm>
    1.16 +
    1.17 +namespace mozilla {
    1.18 +namespace net {
    1.19 +
    1.20 +class CacheObserver : public nsIObserver
    1.21 +                    , public nsSupportsWeakReference
    1.22 +{
    1.23 +  NS_DECL_THREADSAFE_ISUPPORTS
    1.24 +  NS_DECL_NSIOBSERVER
    1.25 +
    1.26 +  virtual ~CacheObserver() {}
    1.27 +
    1.28 +  static nsresult Init();
    1.29 +  static nsresult Shutdown();
    1.30 +  static CacheObserver* Self() { return sSelf; }
    1.31 +
    1.32 +  // Access to preferences
    1.33 +  static bool const UseNewCache();
    1.34 +  static bool const UseDiskCache()
    1.35 +    { return sUseDiskCache; }
    1.36 +  static bool const UseMemoryCache()
    1.37 +    { return sUseMemoryCache; }
    1.38 +  static uint32_t const MetadataMemoryLimit() // result in bytes.
    1.39 +    { return sMetadataMemoryLimit << 10; }
    1.40 +  static uint32_t const MemoryCacheCapacity(); // result in bytes.
    1.41 +  static uint32_t const DiskCacheCapacity() // result in bytes.
    1.42 +    { return sDiskCacheCapacity << 10; }
    1.43 +  static void SetDiskCacheCapacity(uint32_t); // parameter in bytes.
    1.44 +  static bool const SmartCacheSizeEnabled()
    1.45 +    { return sSmartCacheSizeEnabled; }
    1.46 +  static uint32_t const MaxMemoryEntrySize() // result in bytes.
    1.47 +    { return sMaxMemoryEntrySize << 10; }
    1.48 +  static uint32_t const MaxDiskEntrySize() // result in bytes.
    1.49 +    { return sMaxDiskEntrySize << 10; }
    1.50 +  static uint32_t const CompressionLevel()
    1.51 +    { return sCompressionLevel; }
    1.52 +  static uint32_t const HalfLifeSeconds()
    1.53 +    { return sHalfLifeHours * 60 * 60; }
    1.54 +  static int32_t const HalfLifeExperiment()
    1.55 +    { return sHalfLifeExperiment; }
    1.56 +  static bool const ClearCacheOnShutdown()
    1.57 +    { return sSanitizeOnShutdown && sClearCacheOnShutdown; }
    1.58 +  static void ParentDirOverride(nsIFile ** aDir);
    1.59 +
    1.60 +  static bool const EntryIsTooBig(int64_t aSize, bool aUsingDisk);
    1.61 +
    1.62 +private:
    1.63 +  static CacheObserver* sSelf;
    1.64 +
    1.65 +  void StoreDiskCacheCapacity();
    1.66 +  void AttachToPreferences();
    1.67 +  void SchduleAutoDelete();
    1.68 +
    1.69 +  static uint32_t sUseNewCache;
    1.70 +  static bool sUseMemoryCache;
    1.71 +  static bool sUseDiskCache;
    1.72 +  static uint32_t sMetadataMemoryLimit;
    1.73 +  static int32_t sMemoryCacheCapacity;
    1.74 +  static int32_t sAutoMemoryCacheCapacity;
    1.75 +  static uint32_t sDiskCacheCapacity;
    1.76 +  static bool sSmartCacheSizeEnabled;
    1.77 +  static uint32_t sMaxMemoryEntrySize;
    1.78 +  static uint32_t sMaxDiskEntrySize;
    1.79 +  static uint32_t sCompressionLevel;
    1.80 +  static uint32_t sHalfLifeHours;
    1.81 +  static int32_t sHalfLifeExperiment;
    1.82 +  static bool sSanitizeOnShutdown;
    1.83 +  static bool sClearCacheOnShutdown;
    1.84 +
    1.85 +  // Non static properties, accessible via sSelf
    1.86 +  nsCOMPtr<nsIFile> mCacheParentDirectoryOverride;
    1.87 +};
    1.88 +
    1.89 +} // net
    1.90 +} // mozilla
    1.91 +
    1.92 +#endif

mercurial