1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/cache/nsMemoryCacheDevice.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,125 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* vim: set ts=8 sts=4 et sw=4 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef _nsMemoryCacheDevice_h_ 1.11 +#define _nsMemoryCacheDevice_h_ 1.12 + 1.13 +#include "nsCacheDevice.h" 1.14 +#include "pldhash.h" 1.15 +#include "nsCacheEntry.h" 1.16 + 1.17 + 1.18 +class nsMemoryCacheDeviceInfo; 1.19 + 1.20 +/****************************************************************************** 1.21 + * nsMemoryCacheDevice 1.22 + ******************************************************************************/ 1.23 +class nsMemoryCacheDevice : public nsCacheDevice 1.24 +{ 1.25 +public: 1.26 + nsMemoryCacheDevice(); 1.27 + virtual ~nsMemoryCacheDevice(); 1.28 + 1.29 + virtual nsresult Init(); 1.30 + virtual nsresult Shutdown(); 1.31 + 1.32 + virtual const char * GetDeviceID(void); 1.33 + 1.34 + virtual nsresult BindEntry( nsCacheEntry * entry ); 1.35 + virtual nsCacheEntry * FindEntry( nsCString * key, bool *collision ); 1.36 + virtual void DoomEntry( nsCacheEntry * entry ); 1.37 + virtual nsresult DeactivateEntry( nsCacheEntry * entry ); 1.38 + 1.39 + virtual nsresult OpenInputStreamForEntry(nsCacheEntry * entry, 1.40 + nsCacheAccessMode mode, 1.41 + uint32_t offset, 1.42 + nsIInputStream ** result); 1.43 + 1.44 + virtual nsresult OpenOutputStreamForEntry(nsCacheEntry * entry, 1.45 + nsCacheAccessMode mode, 1.46 + uint32_t offset, 1.47 + nsIOutputStream ** result); 1.48 + 1.49 + virtual nsresult GetFileForEntry( nsCacheEntry * entry, 1.50 + nsIFile ** result ); 1.51 + 1.52 + virtual nsresult OnDataSizeChange( nsCacheEntry * entry, int32_t deltaSize ); 1.53 + 1.54 + virtual nsresult Visit( nsICacheVisitor * visitor ); 1.55 + 1.56 + virtual nsresult EvictEntries(const char * clientID); 1.57 + nsresult EvictPrivateEntries(); 1.58 + 1.59 + void SetCapacity(int32_t capacity); 1.60 + void SetMaxEntrySize(int32_t maxSizeInKilobytes); 1.61 + 1.62 + bool EntryIsTooBig(int64_t entrySize); 1.63 + 1.64 + size_t TotalSize(); 1.65 + 1.66 +private: 1.67 + friend class nsMemoryCacheDeviceInfo; 1.68 + enum { DELETE_ENTRY = true, 1.69 + DO_NOT_DELETE_ENTRY = false }; 1.70 + 1.71 + void AdjustMemoryLimits( int32_t softLimit, int32_t hardLimit); 1.72 + void EvictEntry( nsCacheEntry * entry , bool deleteEntry); 1.73 + void EvictEntriesIfNecessary(); 1.74 + int EvictionList(nsCacheEntry * entry, int32_t deltaSize); 1.75 + 1.76 + typedef bool (*EvictionMatcherFn)(nsCacheEntry* entry, void* args); 1.77 + nsresult DoEvictEntries(EvictionMatcherFn matchFn, void* args); 1.78 + 1.79 +#ifdef DEBUG 1.80 + void CheckEntryCount(); 1.81 +#endif 1.82 + /* 1.83 + * Data members 1.84 + */ 1.85 + enum { 1.86 + kQueueCount = 24 // entries > 2^23 (8Mb) start in last queue 1.87 + }; 1.88 + 1.89 + nsCacheEntryHashTable mMemCacheEntries; 1.90 + bool mInitialized; 1.91 + 1.92 + PRCList mEvictionList[kQueueCount]; 1.93 + 1.94 + int32_t mHardLimit; 1.95 + int32_t mSoftLimit; 1.96 + 1.97 + int32_t mTotalSize; 1.98 + int32_t mInactiveSize; 1.99 + 1.100 + int32_t mEntryCount; 1.101 + int32_t mMaxEntryCount; 1.102 + int32_t mMaxEntrySize; // internal unit is bytes 1.103 + 1.104 + // XXX what other stats do we want to keep? 1.105 +}; 1.106 + 1.107 + 1.108 +/****************************************************************************** 1.109 + * nsMemoryCacheDeviceInfo - used to call nsIVisitor for about:cache 1.110 + ******************************************************************************/ 1.111 +class nsMemoryCacheDeviceInfo : public nsICacheDeviceInfo { 1.112 +public: 1.113 + NS_DECL_ISUPPORTS 1.114 + NS_DECL_NSICACHEDEVICEINFO 1.115 + 1.116 + nsMemoryCacheDeviceInfo(nsMemoryCacheDevice* device) 1.117 + : mDevice(device) 1.118 + { 1.119 + } 1.120 + 1.121 + virtual ~nsMemoryCacheDeviceInfo() {} 1.122 + 1.123 +private: 1.124 + nsMemoryCacheDevice* mDevice; 1.125 +}; 1.126 + 1.127 + 1.128 +#endif // _nsMemoryCacheDevice_h_