netwerk/cache/nsDiskCacheDevice.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  *
     3  * This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #ifndef _nsDiskCacheDevice_h_
     8 #define _nsDiskCacheDevice_h_
    10 #include "mozilla/MemoryReporting.h"
    11 #include "nsCacheDevice.h"
    12 #include "nsDiskCacheBinding.h"
    13 #include "nsDiskCacheBlockFile.h"
    14 #include "nsDiskCacheEntry.h"
    16 #include "nsIFile.h"
    17 #include "nsIObserver.h"
    18 #include "nsCOMArray.h"
    20 class nsDiskCacheMap;
    23 class nsDiskCacheDevice : public nsCacheDevice {
    24 public:
    25     nsDiskCacheDevice();
    26     virtual ~nsDiskCacheDevice();
    28     virtual nsresult        Init();
    29     virtual nsresult        Shutdown();
    31     virtual const char *    GetDeviceID(void);
    32     virtual nsCacheEntry *  FindEntry(nsCString * key, bool *collision);
    33     virtual nsresult        DeactivateEntry(nsCacheEntry * entry);
    34     virtual nsresult        BindEntry(nsCacheEntry * entry);
    35     virtual void            DoomEntry( nsCacheEntry * entry );
    37     virtual nsresult OpenInputStreamForEntry(nsCacheEntry *    entry,
    38                                              nsCacheAccessMode mode,
    39                                              uint32_t          offset,
    40                                              nsIInputStream ** result);
    42     virtual nsresult OpenOutputStreamForEntry(nsCacheEntry *     entry,
    43                                               nsCacheAccessMode  mode,
    44                                               uint32_t           offset,
    45                                               nsIOutputStream ** result);
    47     virtual nsresult        GetFileForEntry(nsCacheEntry *    entry,
    48                                             nsIFile **        result);
    50     virtual nsresult        OnDataSizeChange(nsCacheEntry * entry, int32_t deltaSize);
    52     virtual nsresult        Visit(nsICacheVisitor * visitor);
    54     virtual nsresult        EvictEntries(const char * clientID);
    56     bool                    EntryIsTooBig(int64_t entrySize);
    58     size_t                 SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
    60     /**
    61      * Preference accessors
    62      */
    63     void                    SetCacheParentDirectory(nsIFile * parentDir);
    64     void                    SetCapacity(uint32_t  capacity);
    65     void                    SetMaxEntrySize(int32_t  maxSizeInKilobytes);
    67 /* private: */
    69     void                    getCacheDirectory(nsIFile ** result);
    70     uint32_t                getCacheCapacity();
    71     uint32_t                getCacheSize();
    72     uint32_t                getEntryCount();
    74     nsDiskCacheMap *        CacheMap()    { return &mCacheMap; }
    76 private:    
    77     friend class nsDiskCacheDeviceDeactivateEntryEvent;
    78     friend class nsEvictDiskCacheEntriesEvent;
    79     friend class nsDiskCacheMap;
    80     /**
    81      *  Private methods
    82      */
    84     inline bool IsValidBinding(nsDiskCacheBinding *binding)
    85     {
    86         NS_ASSERTION(binding, "  binding == nullptr");
    87         NS_ASSERTION(binding->mDeactivateEvent == nullptr,
    88                      "  entry in process of deactivation");
    89         return (binding && !binding->mDeactivateEvent);
    90     }
    92     bool                    Initialized() { return mInitialized; }
    94     nsresult                Shutdown_Private(bool flush);
    95     nsresult                DeactivateEntry_Private(nsCacheEntry * entry,
    96                                                     nsDiskCacheBinding * binding);
    98     nsresult                OpenDiskCache();
    99     nsresult                ClearDiskCache();
   101     nsresult                EvictDiskCacheEntries(uint32_t  targetCapacity);
   103     /**
   104      *  Member variables
   105      */
   106     nsCOMPtr<nsIFile>       mCacheDirectory;
   107     nsDiskCacheBindery      mBindery;
   108     uint32_t                mCacheCapacity;     // Unit is KiB's
   109     int32_t                 mMaxEntrySize;      // Unit is bytes internally
   110     // XXX need soft/hard limits, currentTotal
   111     nsDiskCacheMap          mCacheMap;
   112     bool                    mInitialized;
   113     bool                    mClearingDiskCache;
   114 };
   116 #endif // _nsDiskCacheDevice_h_

mercurial