netwerk/cache2/CacheFileContextEvictor.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef CacheFileContextEvictor__h__
michael@0 6 #define CacheFileContextEvictor__h__
michael@0 7
michael@0 8 #include "nsTArray.h"
michael@0 9 #include "nsCOMPtr.h"
michael@0 10 #include "nsAutoPtr.h"
michael@0 11
michael@0 12 class nsIFile;
michael@0 13 class nsILoadContextInfo;
michael@0 14
michael@0 15 namespace mozilla {
michael@0 16 namespace net {
michael@0 17
michael@0 18 class CacheIndexIterator;
michael@0 19
michael@0 20 struct CacheFileContextEvictorEntry
michael@0 21 {
michael@0 22 nsCOMPtr<nsILoadContextInfo> mInfo;
michael@0 23 PRTime mTimeStamp; // in milliseconds
michael@0 24 nsRefPtr<CacheIndexIterator> mIterator;
michael@0 25 };
michael@0 26
michael@0 27 class CacheFileContextEvictor
michael@0 28 {
michael@0 29 public:
michael@0 30 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CacheFileContextEvictor)
michael@0 31
michael@0 32 CacheFileContextEvictor();
michael@0 33 virtual ~CacheFileContextEvictor();
michael@0 34
michael@0 35 nsresult Init(nsIFile *aCacheDirectory);
michael@0 36
michael@0 37 // Returns number of contexts that are being evicted.
michael@0 38 uint32_t ContextsCount();
michael@0 39 // Start evicting given context.
michael@0 40 nsresult AddContext(nsILoadContextInfo *aLoadContextInfo);
michael@0 41 // CacheFileIOManager calls this method when CacheIndex's state changes. We
michael@0 42 // check whether the index is up to date and start or stop evicting according
michael@0 43 // to index's state.
michael@0 44 nsresult CacheIndexStateChanged();
michael@0 45 // CacheFileIOManager calls this method to check whether an entry file should
michael@0 46 // be considered as evicted. It returns true when there is a matching context
michael@0 47 // info to the given key and the last modified time of the entry file is
michael@0 48 // earlier than the time stamp of the time when the context was added to the
michael@0 49 // evictor.
michael@0 50 nsresult WasEvicted(const nsACString &aKey, nsIFile *aFile, bool *_retval);
michael@0 51
michael@0 52 private:
michael@0 53 // Writes information about eviction of the given context to the disk. This is
michael@0 54 // done for every context added to the evictor to be able to recover eviction
michael@0 55 // after a shutdown or crash. When the context file is found after startup, we
michael@0 56 // restore mTimeStamp from the last modified time of the file.
michael@0 57 nsresult PersistEvictionInfoToDisk(nsILoadContextInfo *aLoadContextInfo);
michael@0 58 // Once we are done with eviction for the given context, the eviction info is
michael@0 59 // removed from the disk.
michael@0 60 nsresult RemoveEvictInfoFromDisk(nsILoadContextInfo *aLoadContextInfo);
michael@0 61 // Tries to load all contexts from the disk. This method is called just once
michael@0 62 // after startup.
michael@0 63 nsresult LoadEvictInfoFromDisk();
michael@0 64 nsresult GetContextFile(nsILoadContextInfo *aLoadContextInfo,
michael@0 65 nsIFile **_retval);
michael@0 66
michael@0 67 void CreateIterators();
michael@0 68 void CloseIterators();
michael@0 69 void StartEvicting();
michael@0 70 nsresult EvictEntries();
michael@0 71
michael@0 72 // Whether eviction is in progress
michael@0 73 bool mEvicting;
michael@0 74 // Whether index is up to date. We wait with eviction until the index finishes
michael@0 75 // update process when it is outdated. NOTE: We also stop eviction in progress
michael@0 76 // when the index is found outdated, the eviction is restarted again once the
michael@0 77 // update process finishes.
michael@0 78 bool mIndexIsUpToDate;
michael@0 79 // Whether we already tried to restore unfinished jobs from previous run after
michael@0 80 // startup.
michael@0 81 static bool sDiskAlreadySearched;
michael@0 82 // Array of contexts being evicted.
michael@0 83 nsTArray<nsAutoPtr<CacheFileContextEvictorEntry> > mEntries;
michael@0 84 nsCOMPtr<nsIFile> mCacheDirectory;
michael@0 85 nsCOMPtr<nsIFile> mEntriesDir;
michael@0 86 };
michael@0 87
michael@0 88 } // net
michael@0 89 } // mozilla
michael@0 90
michael@0 91 #endif

mercurial