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