gecko-dev/netwerk/cache2/CacheFileContextEvictor.h

97 строки
3.4 KiB
C
Исходник Обычный вид История

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef CacheFileContextEvictor__h__
#define CacheFileContextEvictor__h__
#include "nsTArray.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
class nsIFile;
class nsILoadContextInfo;
namespace mozilla {
namespace net {
class CacheIndexIterator;
struct CacheFileContextEvictorEntry
{
nsCOMPtr<nsILoadContextInfo> mInfo;
bool mPinned;
PRTime mTimeStamp; // in milliseconds
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<CacheIndexIterator> mIterator;
};
class CacheFileContextEvictor
{
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CacheFileContextEvictor)
CacheFileContextEvictor();
private:
virtual ~CacheFileContextEvictor();
public:
nsresult Init(nsIFile *aCacheDirectory);
// Returns number of contexts that are being evicted.
uint32_t ContextsCount();
// Start evicting given context.
nsresult AddContext(nsILoadContextInfo *aLoadContextInfo, bool aPinned);
// CacheFileIOManager calls this method when CacheIndex's state changes. We
// check whether the index is up to date and start or stop evicting according
// to index's state.
nsresult CacheIndexStateChanged();
// CacheFileIOManager calls this method to check whether an entry file should
// be considered as evicted. It returns true when there is a matching context
// info to the given key and the last modified time of the entry file is
// earlier than the time stamp of the time when the context was added to the
// evictor.
nsresult WasEvicted(const nsACString &aKey, nsIFile *aFile,
bool *aEvictedAsPinned, bool *aEvictedAsNonPinned);
private:
// Writes information about eviction of the given context to the disk. This is
// done for every context added to the evictor to be able to recover eviction
// after a shutdown or crash. When the context file is found after startup, we
// restore mTimeStamp from the last modified time of the file.
nsresult PersistEvictionInfoToDisk(nsILoadContextInfo *aLoadContextInfo, bool aPinned);
// Once we are done with eviction for the given context, the eviction info is
// removed from the disk.
nsresult RemoveEvictInfoFromDisk(nsILoadContextInfo *aLoadContextInfo, bool aPinned);
// Tries to load all contexts from the disk. This method is called just once
// after startup.
nsresult LoadEvictInfoFromDisk();
nsresult GetContextFile(nsILoadContextInfo *aLoadContextInfo, bool aPinned,
nsIFile **_retval);
void CreateIterators();
void CloseIterators();
void StartEvicting();
nsresult EvictEntries();
// Whether eviction is in progress
bool mEvicting;
// Whether index is up to date. We wait with eviction until the index finishes
// update process when it is outdated. NOTE: We also stop eviction in progress
// when the index is found outdated, the eviction is restarted again once the
// update process finishes.
bool mIndexIsUpToDate;
// Whether we already tried to restore unfinished jobs from previous run after
// startup.
static bool sDiskAlreadySearched;
// Array of contexts being evicted.
nsTArray<nsAutoPtr<CacheFileContextEvictorEntry> > mEntries;
nsCOMPtr<nsIFile> mCacheDirectory;
nsCOMPtr<nsIFile> mEntriesDir;
};
} // namespace net
} // namespace mozilla
#endif