1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/cache/nsDiskCacheDevice.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,116 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * 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 _nsDiskCacheDevice_h_ 1.11 +#define _nsDiskCacheDevice_h_ 1.12 + 1.13 +#include "mozilla/MemoryReporting.h" 1.14 +#include "nsCacheDevice.h" 1.15 +#include "nsDiskCacheBinding.h" 1.16 +#include "nsDiskCacheBlockFile.h" 1.17 +#include "nsDiskCacheEntry.h" 1.18 + 1.19 +#include "nsIFile.h" 1.20 +#include "nsIObserver.h" 1.21 +#include "nsCOMArray.h" 1.22 + 1.23 +class nsDiskCacheMap; 1.24 + 1.25 + 1.26 +class nsDiskCacheDevice : public nsCacheDevice { 1.27 +public: 1.28 + nsDiskCacheDevice(); 1.29 + virtual ~nsDiskCacheDevice(); 1.30 + 1.31 + virtual nsresult Init(); 1.32 + virtual nsresult Shutdown(); 1.33 + 1.34 + virtual const char * GetDeviceID(void); 1.35 + virtual nsCacheEntry * FindEntry(nsCString * key, bool *collision); 1.36 + virtual nsresult DeactivateEntry(nsCacheEntry * entry); 1.37 + virtual nsresult BindEntry(nsCacheEntry * entry); 1.38 + virtual void DoomEntry( nsCacheEntry * entry ); 1.39 + 1.40 + virtual nsresult OpenInputStreamForEntry(nsCacheEntry * entry, 1.41 + nsCacheAccessMode mode, 1.42 + uint32_t offset, 1.43 + nsIInputStream ** result); 1.44 + 1.45 + virtual nsresult OpenOutputStreamForEntry(nsCacheEntry * entry, 1.46 + nsCacheAccessMode mode, 1.47 + uint32_t offset, 1.48 + nsIOutputStream ** result); 1.49 + 1.50 + virtual nsresult GetFileForEntry(nsCacheEntry * entry, 1.51 + nsIFile ** result); 1.52 + 1.53 + virtual nsresult OnDataSizeChange(nsCacheEntry * entry, int32_t deltaSize); 1.54 + 1.55 + virtual nsresult Visit(nsICacheVisitor * visitor); 1.56 + 1.57 + virtual nsresult EvictEntries(const char * clientID); 1.58 + 1.59 + bool EntryIsTooBig(int64_t entrySize); 1.60 + 1.61 + size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf); 1.62 + 1.63 + /** 1.64 + * Preference accessors 1.65 + */ 1.66 + void SetCacheParentDirectory(nsIFile * parentDir); 1.67 + void SetCapacity(uint32_t capacity); 1.68 + void SetMaxEntrySize(int32_t maxSizeInKilobytes); 1.69 + 1.70 +/* private: */ 1.71 + 1.72 + void getCacheDirectory(nsIFile ** result); 1.73 + uint32_t getCacheCapacity(); 1.74 + uint32_t getCacheSize(); 1.75 + uint32_t getEntryCount(); 1.76 + 1.77 + nsDiskCacheMap * CacheMap() { return &mCacheMap; } 1.78 + 1.79 +private: 1.80 + friend class nsDiskCacheDeviceDeactivateEntryEvent; 1.81 + friend class nsEvictDiskCacheEntriesEvent; 1.82 + friend class nsDiskCacheMap; 1.83 + /** 1.84 + * Private methods 1.85 + */ 1.86 + 1.87 + inline bool IsValidBinding(nsDiskCacheBinding *binding) 1.88 + { 1.89 + NS_ASSERTION(binding, " binding == nullptr"); 1.90 + NS_ASSERTION(binding->mDeactivateEvent == nullptr, 1.91 + " entry in process of deactivation"); 1.92 + return (binding && !binding->mDeactivateEvent); 1.93 + } 1.94 + 1.95 + bool Initialized() { return mInitialized; } 1.96 + 1.97 + nsresult Shutdown_Private(bool flush); 1.98 + nsresult DeactivateEntry_Private(nsCacheEntry * entry, 1.99 + nsDiskCacheBinding * binding); 1.100 + 1.101 + nsresult OpenDiskCache(); 1.102 + nsresult ClearDiskCache(); 1.103 + 1.104 + nsresult EvictDiskCacheEntries(uint32_t targetCapacity); 1.105 + 1.106 + /** 1.107 + * Member variables 1.108 + */ 1.109 + nsCOMPtr<nsIFile> mCacheDirectory; 1.110 + nsDiskCacheBindery mBindery; 1.111 + uint32_t mCacheCapacity; // Unit is KiB's 1.112 + int32_t mMaxEntrySize; // Unit is bytes internally 1.113 + // XXX need soft/hard limits, currentTotal 1.114 + nsDiskCacheMap mCacheMap; 1.115 + bool mInitialized; 1.116 + bool mClearingDiskCache; 1.117 +}; 1.118 + 1.119 +#endif // _nsDiskCacheDevice_h_