netwerk/cache/nsMemoryCacheDevice.h

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* vim: set ts=8 sts=4 et sw=4 tw=80: */
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 _nsMemoryCacheDevice_h_
michael@0 8 #define _nsMemoryCacheDevice_h_
michael@0 9
michael@0 10 #include "nsCacheDevice.h"
michael@0 11 #include "pldhash.h"
michael@0 12 #include "nsCacheEntry.h"
michael@0 13
michael@0 14
michael@0 15 class nsMemoryCacheDeviceInfo;
michael@0 16
michael@0 17 /******************************************************************************
michael@0 18 * nsMemoryCacheDevice
michael@0 19 ******************************************************************************/
michael@0 20 class nsMemoryCacheDevice : public nsCacheDevice
michael@0 21 {
michael@0 22 public:
michael@0 23 nsMemoryCacheDevice();
michael@0 24 virtual ~nsMemoryCacheDevice();
michael@0 25
michael@0 26 virtual nsresult Init();
michael@0 27 virtual nsresult Shutdown();
michael@0 28
michael@0 29 virtual const char * GetDeviceID(void);
michael@0 30
michael@0 31 virtual nsresult BindEntry( nsCacheEntry * entry );
michael@0 32 virtual nsCacheEntry * FindEntry( nsCString * key, bool *collision );
michael@0 33 virtual void DoomEntry( nsCacheEntry * entry );
michael@0 34 virtual nsresult DeactivateEntry( nsCacheEntry * entry );
michael@0 35
michael@0 36 virtual nsresult OpenInputStreamForEntry(nsCacheEntry * entry,
michael@0 37 nsCacheAccessMode mode,
michael@0 38 uint32_t offset,
michael@0 39 nsIInputStream ** result);
michael@0 40
michael@0 41 virtual nsresult OpenOutputStreamForEntry(nsCacheEntry * entry,
michael@0 42 nsCacheAccessMode mode,
michael@0 43 uint32_t offset,
michael@0 44 nsIOutputStream ** result);
michael@0 45
michael@0 46 virtual nsresult GetFileForEntry( nsCacheEntry * entry,
michael@0 47 nsIFile ** result );
michael@0 48
michael@0 49 virtual nsresult OnDataSizeChange( nsCacheEntry * entry, int32_t deltaSize );
michael@0 50
michael@0 51 virtual nsresult Visit( nsICacheVisitor * visitor );
michael@0 52
michael@0 53 virtual nsresult EvictEntries(const char * clientID);
michael@0 54 nsresult EvictPrivateEntries();
michael@0 55
michael@0 56 void SetCapacity(int32_t capacity);
michael@0 57 void SetMaxEntrySize(int32_t maxSizeInKilobytes);
michael@0 58
michael@0 59 bool EntryIsTooBig(int64_t entrySize);
michael@0 60
michael@0 61 size_t TotalSize();
michael@0 62
michael@0 63 private:
michael@0 64 friend class nsMemoryCacheDeviceInfo;
michael@0 65 enum { DELETE_ENTRY = true,
michael@0 66 DO_NOT_DELETE_ENTRY = false };
michael@0 67
michael@0 68 void AdjustMemoryLimits( int32_t softLimit, int32_t hardLimit);
michael@0 69 void EvictEntry( nsCacheEntry * entry , bool deleteEntry);
michael@0 70 void EvictEntriesIfNecessary();
michael@0 71 int EvictionList(nsCacheEntry * entry, int32_t deltaSize);
michael@0 72
michael@0 73 typedef bool (*EvictionMatcherFn)(nsCacheEntry* entry, void* args);
michael@0 74 nsresult DoEvictEntries(EvictionMatcherFn matchFn, void* args);
michael@0 75
michael@0 76 #ifdef DEBUG
michael@0 77 void CheckEntryCount();
michael@0 78 #endif
michael@0 79 /*
michael@0 80 * Data members
michael@0 81 */
michael@0 82 enum {
michael@0 83 kQueueCount = 24 // entries > 2^23 (8Mb) start in last queue
michael@0 84 };
michael@0 85
michael@0 86 nsCacheEntryHashTable mMemCacheEntries;
michael@0 87 bool mInitialized;
michael@0 88
michael@0 89 PRCList mEvictionList[kQueueCount];
michael@0 90
michael@0 91 int32_t mHardLimit;
michael@0 92 int32_t mSoftLimit;
michael@0 93
michael@0 94 int32_t mTotalSize;
michael@0 95 int32_t mInactiveSize;
michael@0 96
michael@0 97 int32_t mEntryCount;
michael@0 98 int32_t mMaxEntryCount;
michael@0 99 int32_t mMaxEntrySize; // internal unit is bytes
michael@0 100
michael@0 101 // XXX what other stats do we want to keep?
michael@0 102 };
michael@0 103
michael@0 104
michael@0 105 /******************************************************************************
michael@0 106 * nsMemoryCacheDeviceInfo - used to call nsIVisitor for about:cache
michael@0 107 ******************************************************************************/
michael@0 108 class nsMemoryCacheDeviceInfo : public nsICacheDeviceInfo {
michael@0 109 public:
michael@0 110 NS_DECL_ISUPPORTS
michael@0 111 NS_DECL_NSICACHEDEVICEINFO
michael@0 112
michael@0 113 nsMemoryCacheDeviceInfo(nsMemoryCacheDevice* device)
michael@0 114 : mDevice(device)
michael@0 115 {
michael@0 116 }
michael@0 117
michael@0 118 virtual ~nsMemoryCacheDeviceInfo() {}
michael@0 119
michael@0 120 private:
michael@0 121 nsMemoryCacheDevice* mDevice;
michael@0 122 };
michael@0 123
michael@0 124
michael@0 125 #endif // _nsMemoryCacheDevice_h_

mercurial