netwerk/cache2/CacheObserver.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef CacheObserver__h__
     6 #define CacheObserver__h__
     8 #include "nsIObserver.h"
     9 #include "nsIFile.h"
    10 #include "nsCOMPtr.h"
    11 #include "nsWeakReference.h"
    12 #include <algorithm>
    14 namespace mozilla {
    15 namespace net {
    17 class CacheObserver : public nsIObserver
    18                     , public nsSupportsWeakReference
    19 {
    20   NS_DECL_THREADSAFE_ISUPPORTS
    21   NS_DECL_NSIOBSERVER
    23   virtual ~CacheObserver() {}
    25   static nsresult Init();
    26   static nsresult Shutdown();
    27   static CacheObserver* Self() { return sSelf; }
    29   // Access to preferences
    30   static bool const UseNewCache();
    31   static bool const UseDiskCache()
    32     { return sUseDiskCache; }
    33   static bool const UseMemoryCache()
    34     { return sUseMemoryCache; }
    35   static uint32_t const MetadataMemoryLimit() // result in bytes.
    36     { return sMetadataMemoryLimit << 10; }
    37   static uint32_t const MemoryCacheCapacity(); // result in bytes.
    38   static uint32_t const DiskCacheCapacity() // result in bytes.
    39     { return sDiskCacheCapacity << 10; }
    40   static void SetDiskCacheCapacity(uint32_t); // parameter in bytes.
    41   static bool const SmartCacheSizeEnabled()
    42     { return sSmartCacheSizeEnabled; }
    43   static uint32_t const MaxMemoryEntrySize() // result in bytes.
    44     { return sMaxMemoryEntrySize << 10; }
    45   static uint32_t const MaxDiskEntrySize() // result in bytes.
    46     { return sMaxDiskEntrySize << 10; }
    47   static uint32_t const CompressionLevel()
    48     { return sCompressionLevel; }
    49   static uint32_t const HalfLifeSeconds()
    50     { return sHalfLifeHours * 60 * 60; }
    51   static int32_t const HalfLifeExperiment()
    52     { return sHalfLifeExperiment; }
    53   static bool const ClearCacheOnShutdown()
    54     { return sSanitizeOnShutdown && sClearCacheOnShutdown; }
    55   static void ParentDirOverride(nsIFile ** aDir);
    57   static bool const EntryIsTooBig(int64_t aSize, bool aUsingDisk);
    59 private:
    60   static CacheObserver* sSelf;
    62   void StoreDiskCacheCapacity();
    63   void AttachToPreferences();
    64   void SchduleAutoDelete();
    66   static uint32_t sUseNewCache;
    67   static bool sUseMemoryCache;
    68   static bool sUseDiskCache;
    69   static uint32_t sMetadataMemoryLimit;
    70   static int32_t sMemoryCacheCapacity;
    71   static int32_t sAutoMemoryCacheCapacity;
    72   static uint32_t sDiskCacheCapacity;
    73   static bool sSmartCacheSizeEnabled;
    74   static uint32_t sMaxMemoryEntrySize;
    75   static uint32_t sMaxDiskEntrySize;
    76   static uint32_t sCompressionLevel;
    77   static uint32_t sHalfLifeHours;
    78   static int32_t sHalfLifeExperiment;
    79   static bool sSanitizeOnShutdown;
    80   static bool sClearCacheOnShutdown;
    82   // Non static properties, accessible via sSelf
    83   nsCOMPtr<nsIFile> mCacheParentDirectoryOverride;
    84 };
    86 } // net
    87 } // mozilla
    89 #endif

mercurial