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.

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

mercurial