mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
fe3519e975
- Bug 1257611 - Fix wrong CondVar::Wait() and Monitor::Wait() usage in netwerk/cache2, r=honzab (54f1a79f43) - Bug 1239687 - Leak invalid/doomed file handles immediately after HTTP cache shutdown. r=michal (a20bcf662b) - Bug 996836 - Merge CLOSE and WRITE priority in cache2 I/O thread. r=michal (8b0af50593) - Bug 1265243 - Do not initialize CacheObserver in the child process, r=honzab (87f69529d2) - Bug 1247432 - Don't do any unnecessary I/O in cache2 after shutdown. r=michal (7c5a2b89ac) - Bug 1220272 - Fix signalling in HTTP cache test code suspender. r=michal (293a16731d) - Bug 1160368 - Part 2: Clean up some cruft in nsCookie.h from PRBool/bool conversions. r=jdm (aa873f2dcc) - Bug 1160368 - Part 5: Clean up some confusing browser_storage_listings.js checks. r=jdm (b27f5930a9) - Bug 866380 - Null check for amlogic libc implementation. r=valentin (c3a487af9c) - Bug 1257320 - Disable C4577 to unblock compilation on VS2015; r=mayhemer (2f800ca85c) - Bug 1229726 - fix the data copy from sockaddr to NetAddr on OSX/FreeBSD. r=mcmanus. (fde11e004e) - Bug 1241368 - provide JS implemented MDNS service as a fallback. r=nwgh,nalexander. (afe1445eb8) - Bug 571126: Remove NECKO_SEPARATE_STACKS support, r=jduell (fb5b87bb3a) - Bug 1057689 - Add xpcshell test checking correct notifications and app-offline state r=jduell (89946b44ba) - Bug 1259459 - h2 0 length options puts end-stream on headers r=hurley (618480a609) - Bug 1234251 - Remove HttpChannelChild::mSynthesizedResponseHead; r=jdm (20981affea) - Bug 904559 - Veto redirect when target channel doesn't implement nsIParentRedirectingChannel. r=jduell (b3da2fae91) - Bug 1261784 Make sure InterceptedChannel body streams are always closed. r=jdm (cd50b1a52b) - Bug 1224508 - Use URI path without reference as the callback key. r=valentin. (b8a953f23a) - Bug 1226760 - ViewSource doesn't work for packaged app resources r=mcmanus (ec9b0297de) - Bug 1254061 - Rewrite nsHttp::ParseInt64 using strtoll r=mcmanus (2125b8ae6f) - Bug 1241565 - nsIHttpChannelInternal should be a builtinclass, r=honzab.moz (d24da6a95a) - Bug 1252386 - Removed debugging printf,r=me (c5d89f353c) - bug 277813 - autogenerated expires needs max r=mayhemer (6aa7c255a5) - Bug 1225384 - Change how the default resource "host names" are handled. r=michal (868732baab) - Bug 719905: Fix resolution of resource: URLs containing : and / characters. r=valentin (f60f4baacf) - Bug 1195173 - Convert ExtensionProtocolHandler to use channel->Open2() (r=maglione) (063f5d5d10) - Bug 1226909 followup to fix bustage. Make sure that the channel returned by NS_NewChannel doesn't have a loadinfo that indicates that the channel has already been opened (42ebe0f44e) - Bug 241698 - Fixed init and use of nsDirIndex::mLastModified (-1LL) + built in nullptr checks where they were missing. r=dragana (e9c2277a3d) - Bug 1261318 - make sure brotli context is created in onstoprequest r=bagder (6646fed64d) - Bug 1212223 - Update |bufLen| as well when we probed the multipart preamble. r=valentin. (ec878c5b0f) - Bug 1259561: Increase CRAZY_COORD (threshold for debug build layout warnings) by an order of magnitude. r=mats (c05c16dd85) - Bug 1261698. Make ReparentFrameViewTo return void because it always returns NS_OK. r=mats (e806d6abcb) - Bug 1261698. Remove comment that is not relevant in nsContainerFrame.cpp. (f570189d15) - Bug 1261698. Don't descend into child frames looking for views in ReparentFrameViewTo if the frame doesn't have the NS_FRAME_HAS_CHILD_WITH_VIEW bit set. r=mats (0d42befd46) - Bug 1265154 - Fix compile error in MSVC 2013 caused by ArrayLength; r=heycam (1c962f2840) - Bug 1260351 - Image: Enable ConvolveVertically/Horizontally in LS3 MMI. r=tnikkel (576b6bbdb3) - Bug 1209780 (Part 1) - Mark DrawResult MOZ_MUST_USE. r=tn (e6c113bef2) - Bug 1253753 - Remove unnecessary switch fallthrough to avoid -Wimplicit-fallthrough warning. r=karlt (96bd93fc5c) - bug 1260178 null check pattern from -unico-border-gradient r=acomminos (f63c9c7ffb) - Bug 1247796. Use keyboardFocusIndicatorColor for ActiveBorder system color keyword. r=mstange (7ed133de97) - Bug 1248675 - Update the cached mBounds in nsChildView when its backing scale factor (display DPI) changes. r=mstange (8197274118) - Bug 1256576 - Make sure texture is (re)initialized if the size changed. r=snorp (2c56790ca9) - Bug 1242449 - Fix confusion among CSS, desktop and device pixel units in nsXULWindow position/size and window staggering so as to work consistently across mixed resolution displays. r=emk (f73d2fd41d) - Bug 1255645 - Ensure nsXULWindow constrains the window to the bounds of its screen after applying intrinsic sizing (if appropriate), by re-doing positioning after the window has been sized properly. r=emk (e87e0cea81) - Bug 1259492 - Ensure window position is constrained to the screen after it has been sized properly in nsXULWindow::OnChromeLoaded. r=emk (7cf599b39b) - Bug 1832708 - Disable std::__throw_* wrapping on libc++ >= 14.0. r=firefox-build-system-reviewers,andi (29e0cc9319)
481 lines
18 KiB
C++
481 lines
18 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 CacheFileIOManager__h__
|
|
#define CacheFileIOManager__h__
|
|
|
|
#include "CacheIOThread.h"
|
|
#include "CacheStorageService.h"
|
|
#include "nsIEventTarget.h"
|
|
#include "nsITimer.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "mozilla/Atomics.h"
|
|
#include "mozilla/SHA1.h"
|
|
#include "mozilla/TimeStamp.h"
|
|
#include "nsTArray.h"
|
|
#include "nsString.h"
|
|
#include "nsTHashtable.h"
|
|
#include "prio.h"
|
|
|
|
//#define DEBUG_HANDLES 1
|
|
|
|
class nsIFile;
|
|
class nsITimer;
|
|
class nsIDirectoryEnumerator;
|
|
class nsILoadContextInfo;
|
|
|
|
namespace mozilla {
|
|
namespace net {
|
|
|
|
class CacheFile;
|
|
class CacheFileIOListener;
|
|
|
|
#ifdef DEBUG_HANDLES
|
|
class CacheFileHandlesEntry;
|
|
#endif
|
|
|
|
#define ENTRIES_DIR "entries"
|
|
#define DOOMED_DIR "doomed"
|
|
#define TRASH_DIR "trash"
|
|
|
|
|
|
class CacheFileHandle : public nsISupports
|
|
{
|
|
public:
|
|
enum class PinningStatus : uint32_t {
|
|
UNKNOWN,
|
|
NON_PINNED,
|
|
PINNED
|
|
};
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
bool DispatchRelease();
|
|
|
|
CacheFileHandle(const SHA1Sum::Hash *aHash, bool aPriority, PinningStatus aPinning);
|
|
CacheFileHandle(const nsACString &aKey, bool aPriority, PinningStatus aPinning);
|
|
void Log();
|
|
bool IsDoomed() const { return mIsDoomed; }
|
|
const SHA1Sum::Hash *Hash() const { return mHash; }
|
|
int64_t FileSize() const { return mFileSize; }
|
|
uint32_t FileSizeInK() const;
|
|
bool IsPriority() const { return mPriority; }
|
|
bool FileExists() const { return mFileExists; }
|
|
bool IsClosed() const { return mClosed; }
|
|
bool IsSpecialFile() const { return mSpecialFile; }
|
|
nsCString & Key() { return mKey; }
|
|
|
|
// Returns false when this handle has been doomed based on the pinning state update.
|
|
bool SetPinned(bool aPinned);
|
|
|
|
// Memory reporting
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
|
|
|
|
private:
|
|
friend class CacheFileIOManager;
|
|
friend class CacheFileHandles;
|
|
friend class ReleaseNSPRHandleEvent;
|
|
|
|
virtual ~CacheFileHandle();
|
|
|
|
const SHA1Sum::Hash *mHash;
|
|
mozilla::Atomic<bool,ReleaseAcquire> mIsDoomed;
|
|
bool mPriority;
|
|
bool mClosed;
|
|
bool mSpecialFile;
|
|
bool mInvalid;
|
|
bool mFileExists; // This means that the file should exists,
|
|
// but it can be still deleted by OS/user
|
|
// and then a subsequent OpenNSPRFileDesc()
|
|
// will fail.
|
|
|
|
// For existing files this is always pre-set to UNKNOWN. The status is udpated accordingly
|
|
// after the matadata has been parsed.
|
|
// For new files the flag is set according to which storage kind is opening
|
|
// the cache entry and remains so for the handle's lifetime.
|
|
// The status can only change from UNKNOWN (if set so initially) to one of PINNED or NON_PINNED
|
|
// and it stays unchanged afterwards.
|
|
// This status is only accessed on the IO thread.
|
|
PinningStatus mPinning;
|
|
// Both initially false. Can be raised to true only when this handle is to be doomed
|
|
// during the period when the pinning status is unknown. After the pinning status
|
|
// determination we check these flags and possibly doom.
|
|
// These flags are only accessed on the IO thread.
|
|
bool mDoomWhenFoundPinned : 1;
|
|
bool mDoomWhenFoundNonPinned : 1;
|
|
|
|
nsCOMPtr<nsIFile> mFile;
|
|
int64_t mFileSize;
|
|
PRFileDesc *mFD; // if null then the file doesn't exists on the disk
|
|
nsCString mKey;
|
|
};
|
|
|
|
class CacheFileHandles {
|
|
public:
|
|
CacheFileHandles();
|
|
~CacheFileHandles();
|
|
|
|
nsresult GetHandle(const SHA1Sum::Hash *aHash, CacheFileHandle **_retval);
|
|
nsresult NewHandle(const SHA1Sum::Hash *aHash, bool aPriority,
|
|
CacheFileHandle::PinningStatus aPinning, CacheFileHandle **_retval);
|
|
void RemoveHandle(CacheFileHandle *aHandlle);
|
|
void GetAllHandles(nsTArray<RefPtr<CacheFileHandle> > *_retval);
|
|
void GetActiveHandles(nsTArray<RefPtr<CacheFileHandle> > *_retval);
|
|
void ClearAll();
|
|
uint32_t HandleCount();
|
|
|
|
#ifdef DEBUG_HANDLES
|
|
void Log(CacheFileHandlesEntry *entry);
|
|
#endif
|
|
|
|
// Memory reporting
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
|
|
|
|
class HandleHashKey : public PLDHashEntryHdr
|
|
{
|
|
public:
|
|
typedef const SHA1Sum::Hash& KeyType;
|
|
typedef const SHA1Sum::Hash* KeyTypePointer;
|
|
|
|
explicit HandleHashKey(KeyTypePointer aKey)
|
|
{
|
|
MOZ_COUNT_CTOR(HandleHashKey);
|
|
mHash = MakeUnique<uint8_t[]>(SHA1Sum::kHashSize);
|
|
memcpy(mHash.get(), aKey, sizeof(SHA1Sum::Hash));
|
|
}
|
|
HandleHashKey(const HandleHashKey& aOther)
|
|
{
|
|
NS_NOTREACHED("HandleHashKey copy constructor is forbidden!");
|
|
}
|
|
~HandleHashKey()
|
|
{
|
|
MOZ_COUNT_DTOR(HandleHashKey);
|
|
}
|
|
|
|
bool KeyEquals(KeyTypePointer aKey) const
|
|
{
|
|
return memcmp(mHash.get(), aKey, sizeof(SHA1Sum::Hash)) == 0;
|
|
}
|
|
static KeyTypePointer KeyToPointer(KeyType aKey)
|
|
{
|
|
return &aKey;
|
|
}
|
|
static PLDHashNumber HashKey(KeyTypePointer aKey)
|
|
{
|
|
return (reinterpret_cast<const uint32_t *>(aKey))[0];
|
|
}
|
|
|
|
void AddHandle(CacheFileHandle* aHandle);
|
|
void RemoveHandle(CacheFileHandle* aHandle);
|
|
already_AddRefed<CacheFileHandle> GetNewestHandle();
|
|
void GetHandles(nsTArray<RefPtr<CacheFileHandle> > &aResult);
|
|
|
|
SHA1Sum::Hash *Hash() const
|
|
{
|
|
return reinterpret_cast<SHA1Sum::Hash*>(mHash.get());
|
|
}
|
|
bool IsEmpty() const { return mHandles.Length() == 0; }
|
|
|
|
enum { ALLOW_MEMMOVE = true };
|
|
|
|
#ifdef DEBUG
|
|
void AssertHandlesState();
|
|
#endif
|
|
|
|
// Memory reporting
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
|
|
|
|
private:
|
|
// We can't make this UniquePtr<SHA1Sum::Hash>, because you can't have
|
|
// UniquePtrs with known bounds. So we settle for this representation
|
|
// and using appropriate casts when we need to access it as a
|
|
// SHA1Sum::Hash.
|
|
UniquePtr<uint8_t[]> mHash;
|
|
// Use weak pointers since the hash table access is on a single thread
|
|
// only and CacheFileHandle removes itself from this table in its dtor
|
|
// that may only be called on the same thread as we work with the hashtable
|
|
// since we dispatch its Release() to this thread.
|
|
nsTArray<CacheFileHandle*> mHandles;
|
|
};
|
|
|
|
private:
|
|
nsTHashtable<HandleHashKey> mTable;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
class OpenFileEvent;
|
|
class ReadEvent;
|
|
class WriteEvent;
|
|
class MetadataWriteScheduleEvent;
|
|
class CacheFileContextEvictor;
|
|
|
|
#define CACHEFILEIOLISTENER_IID \
|
|
{ /* dcaf2ddc-17cf-4242-bca1-8c86936375a5 */ \
|
|
0xdcaf2ddc, \
|
|
0x17cf, \
|
|
0x4242, \
|
|
{0xbc, 0xa1, 0x8c, 0x86, 0x93, 0x63, 0x75, 0xa5} \
|
|
}
|
|
|
|
class CacheFileIOListener : public nsISupports
|
|
{
|
|
public:
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(CACHEFILEIOLISTENER_IID)
|
|
|
|
NS_IMETHOD OnFileOpened(CacheFileHandle *aHandle, nsresult aResult) = 0;
|
|
NS_IMETHOD OnDataWritten(CacheFileHandle *aHandle, const char *aBuf,
|
|
nsresult aResult) = 0;
|
|
NS_IMETHOD OnDataRead(CacheFileHandle *aHandle, char *aBuf,
|
|
nsresult aResult) = 0;
|
|
NS_IMETHOD OnFileDoomed(CacheFileHandle *aHandle, nsresult aResult) = 0;
|
|
NS_IMETHOD OnEOFSet(CacheFileHandle *aHandle, nsresult aResult) = 0;
|
|
NS_IMETHOD OnFileRenamed(CacheFileHandle *aHandle, nsresult aResult) = 0;
|
|
|
|
virtual bool IsKilled() { return false; }
|
|
};
|
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(CacheFileIOListener, CACHEFILEIOLISTENER_IID)
|
|
|
|
|
|
class CacheFileIOManager : public nsITimerCallback
|
|
{
|
|
public:
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
NS_DECL_NSITIMERCALLBACK
|
|
|
|
enum {
|
|
OPEN = 0U,
|
|
CREATE = 1U,
|
|
CREATE_NEW = 2U,
|
|
PRIORITY = 4U,
|
|
SPECIAL_FILE = 8U,
|
|
PINNED = 16U
|
|
};
|
|
|
|
CacheFileIOManager();
|
|
|
|
static nsresult Init();
|
|
static nsresult Shutdown();
|
|
static nsresult OnProfile();
|
|
static already_AddRefed<nsIEventTarget> IOTarget();
|
|
static already_AddRefed<CacheIOThread> IOThread();
|
|
static bool IsOnIOThread();
|
|
static bool IsOnIOThreadOrCeased();
|
|
static bool IsShutdown();
|
|
|
|
// Make aFile's WriteMetadataIfNeeded be called automatically after
|
|
// a short interval.
|
|
static nsresult ScheduleMetadataWrite(CacheFile * aFile);
|
|
// Remove aFile from the scheduling registry array.
|
|
// WriteMetadataIfNeeded will not be automatically called.
|
|
static nsresult UnscheduleMetadataWrite(CacheFile * aFile);
|
|
// Shuts the scheduling off and flushes all pending metadata writes.
|
|
static nsresult ShutdownMetadataWriteScheduling();
|
|
|
|
static nsresult OpenFile(const nsACString &aKey,
|
|
uint32_t aFlags, CacheFileIOListener *aCallback);
|
|
static nsresult Read(CacheFileHandle *aHandle, int64_t aOffset,
|
|
char *aBuf, int32_t aCount,
|
|
CacheFileIOListener *aCallback);
|
|
static nsresult Write(CacheFileHandle *aHandle, int64_t aOffset,
|
|
const char *aBuf, int32_t aCount, bool aValidate,
|
|
bool aTruncate, CacheFileIOListener *aCallback);
|
|
// PinningDoomRestriction:
|
|
// NO_RESTRICTION
|
|
// no restriction is checked, the file is simply always doomed
|
|
// DOOM_WHEN_(NON)_PINNED, we branch based on the pinning status of the handle:
|
|
// UNKNOWN: the handle is marked to be doomed when later found (non)pinned
|
|
// PINNED/NON_PINNED: doom only when the restriction matches the pin status
|
|
// and the handle has not yet been required to doom during the UNKNOWN
|
|
// period
|
|
enum PinningDoomRestriction {
|
|
NO_RESTRICTION,
|
|
DOOM_WHEN_NON_PINNED,
|
|
DOOM_WHEN_PINNED
|
|
};
|
|
static nsresult DoomFile(CacheFileHandle *aHandle,
|
|
CacheFileIOListener *aCallback);
|
|
static nsresult DoomFileByKey(const nsACString &aKey,
|
|
CacheFileIOListener *aCallback);
|
|
static nsresult ReleaseNSPRHandle(CacheFileHandle *aHandle);
|
|
static nsresult TruncateSeekSetEOF(CacheFileHandle *aHandle,
|
|
int64_t aTruncatePos, int64_t aEOFPos,
|
|
CacheFileIOListener *aCallback);
|
|
static nsresult RenameFile(CacheFileHandle *aHandle,
|
|
const nsACString &aNewName,
|
|
CacheFileIOListener *aCallback);
|
|
static nsresult EvictIfOverLimit();
|
|
static nsresult EvictAll();
|
|
static nsresult EvictByContext(nsILoadContextInfo *aLoadContextInfo,
|
|
bool aPinning);
|
|
|
|
static nsresult InitIndexEntry(CacheFileHandle *aHandle,
|
|
uint32_t aAppId,
|
|
bool aAnonymous,
|
|
bool aInBrowser,
|
|
bool aPinning);
|
|
static nsresult UpdateIndexEntry(CacheFileHandle *aHandle,
|
|
const uint32_t *aFrecency,
|
|
const uint32_t *aExpirationTime);
|
|
|
|
static nsresult UpdateIndexEntry();
|
|
|
|
enum EEnumerateMode {
|
|
ENTRIES,
|
|
DOOMED
|
|
};
|
|
|
|
static void GetCacheDirectory(nsIFile** result);
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
static void GetProfilelessCacheDirectory(nsIFile** result);
|
|
#endif
|
|
|
|
// Calls synchronously OnEntryInfo for an entry with the given hash.
|
|
// Tries to find an existing entry in the service hashtables first, if not
|
|
// found, loads synchronously from disk file.
|
|
// Callable on the IO thread only.
|
|
static nsresult GetEntryInfo(const SHA1Sum::Hash *aHash,
|
|
CacheStorageService::EntryInfoCallback *aCallback);
|
|
|
|
// Memory reporting
|
|
static size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf);
|
|
static size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
|
|
|
|
private:
|
|
friend class CacheFileHandle;
|
|
friend class CacheFileChunk;
|
|
friend class CacheFile;
|
|
friend class ShutdownEvent;
|
|
friend class OpenFileEvent;
|
|
friend class CloseHandleEvent;
|
|
friend class ReadEvent;
|
|
friend class WriteEvent;
|
|
friend class DoomFileEvent;
|
|
friend class DoomFileByKeyEvent;
|
|
friend class ReleaseNSPRHandleEvent;
|
|
friend class TruncateSeekSetEOFEvent;
|
|
friend class RenameFileEvent;
|
|
friend class CacheIndex;
|
|
friend class MetadataWriteScheduleEvent;
|
|
friend class CacheFileContextEvictor;
|
|
|
|
virtual ~CacheFileIOManager();
|
|
|
|
nsresult InitInternal();
|
|
nsresult ShutdownInternal();
|
|
|
|
nsresult OpenFileInternal(const SHA1Sum::Hash *aHash,
|
|
const nsACString &aKey,
|
|
uint32_t aFlags,
|
|
CacheFileHandle **_retval);
|
|
nsresult OpenSpecialFileInternal(const nsACString &aKey,
|
|
uint32_t aFlags,
|
|
CacheFileHandle **_retval);
|
|
nsresult CloseHandleInternal(CacheFileHandle *aHandle);
|
|
nsresult ReadInternal(CacheFileHandle *aHandle, int64_t aOffset,
|
|
char *aBuf, int32_t aCount);
|
|
nsresult WriteInternal(CacheFileHandle *aHandle, int64_t aOffset,
|
|
const char *aBuf, int32_t aCount, bool aValidate,
|
|
bool aTruncate);
|
|
nsresult DoomFileInternal(CacheFileHandle *aHandle,
|
|
PinningDoomRestriction aPinningStatusRestriction = NO_RESTRICTION);
|
|
nsresult DoomFileByKeyInternal(const SHA1Sum::Hash *aHash);
|
|
nsresult ReleaseNSPRHandleInternal(CacheFileHandle *aHandle,
|
|
bool aIgnoreShutdownLag = false);
|
|
nsresult TruncateSeekSetEOFInternal(CacheFileHandle *aHandle,
|
|
int64_t aTruncatePos, int64_t aEOFPos);
|
|
nsresult RenameFileInternal(CacheFileHandle *aHandle,
|
|
const nsACString &aNewName);
|
|
nsresult EvictIfOverLimitInternal();
|
|
nsresult OverLimitEvictionInternal();
|
|
nsresult EvictAllInternal();
|
|
nsresult EvictByContextInternal(nsILoadContextInfo *aLoadContextInfo,
|
|
bool aPinning);
|
|
|
|
nsresult TrashDirectory(nsIFile *aFile);
|
|
static void OnTrashTimer(nsITimer *aTimer, void *aClosure);
|
|
nsresult StartRemovingTrash();
|
|
nsresult RemoveTrashInternal();
|
|
nsresult FindTrashDirToRemove();
|
|
|
|
nsresult CreateFile(CacheFileHandle *aHandle);
|
|
static void HashToStr(const SHA1Sum::Hash *aHash, nsACString &_retval);
|
|
static nsresult StrToHash(const nsACString &aHash, SHA1Sum::Hash *_retval);
|
|
nsresult GetFile(const SHA1Sum::Hash *aHash, nsIFile **_retval);
|
|
nsresult GetSpecialFile(const nsACString &aKey, nsIFile **_retval);
|
|
nsresult GetDoomedFile(nsIFile **_retval);
|
|
nsresult IsEmptyDirectory(nsIFile *aFile, bool *_retval);
|
|
nsresult CheckAndCreateDir(nsIFile *aFile, const char *aDir,
|
|
bool aEnsureEmptyDir);
|
|
nsresult CreateCacheTree();
|
|
nsresult OpenNSPRHandle(CacheFileHandle *aHandle, bool aCreate = false);
|
|
void NSPRHandleUsed(CacheFileHandle *aHandle);
|
|
|
|
// Removing all cache files during shutdown
|
|
nsresult SyncRemoveDir(nsIFile *aFile, const char *aDir);
|
|
void SyncRemoveAllCacheFiles();
|
|
|
|
nsresult ScheduleMetadataWriteInternal(CacheFile * aFile);
|
|
nsresult UnscheduleMetadataWriteInternal(CacheFile * aFile);
|
|
nsresult ShutdownMetadataWriteSchedulingInternal();
|
|
|
|
static nsresult CacheIndexStateChanged();
|
|
nsresult CacheIndexStateChangedInternal();
|
|
|
|
// Smart size calculation. UpdateSmartCacheSize() must be called on IO thread.
|
|
// It is called in EvictIfOverLimitInternal() just before we decide whether to
|
|
// start overlimit eviction or not and also in OverLimitEvictionInternal()
|
|
// before we start an eviction loop.
|
|
nsresult UpdateSmartCacheSize(int64_t aFreeSpace);
|
|
|
|
// May return true after shutdown only when time for flushing all data
|
|
// has already passed.
|
|
bool IsPastShutdownIOLag();
|
|
|
|
// Memory reporting (private part)
|
|
size_t SizeOfExcludingThisInternal(mozilla::MallocSizeOf mallocSizeOf) const;
|
|
|
|
static CacheFileIOManager *gInstance;
|
|
TimeStamp mStartTime;
|
|
// Shutdown time stamp, accessed only on the I/O thread. Used to bypass
|
|
// I/O after a certain time pass the shutdown has been demanded.
|
|
TimeStamp mShutdownDemandedTime;
|
|
// Set true on the main thread when cache shutdown is first demanded.
|
|
Atomic<bool, Relaxed> mShutdownDemanded;
|
|
// Set true on the IO thread, CLOSE level as part of the internal shutdown
|
|
// procedure.
|
|
bool mShuttingDown;
|
|
RefPtr<CacheIOThread> mIOThread;
|
|
nsCOMPtr<nsIFile> mCacheDirectory;
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
// On Android we add the active profile directory name between the path
|
|
// and the 'cache2' leaf name. However, to delete any leftover data from
|
|
// times before we were doing it, we still need to access the directory
|
|
// w/o the profile name in the path. Here it is stored.
|
|
nsCOMPtr<nsIFile> mCacheProfilelessDirectory;
|
|
#endif
|
|
bool mTreeCreated;
|
|
CacheFileHandles mHandles;
|
|
nsTArray<CacheFileHandle *> mHandlesByLastUsed;
|
|
nsTArray<CacheFileHandle *> mSpecialHandles;
|
|
nsTArray<RefPtr<CacheFile> > mScheduledMetadataWrites;
|
|
nsCOMPtr<nsITimer> mMetadataWritesTimer;
|
|
bool mOverLimitEvicting;
|
|
bool mRemovingTrashDirs;
|
|
nsCOMPtr<nsITimer> mTrashTimer;
|
|
nsCOMPtr<nsIFile> mTrashDir;
|
|
nsCOMPtr<nsIDirectoryEnumerator> mTrashDirEnumerator;
|
|
nsTArray<nsCString> mFailedTrashDirs;
|
|
RefPtr<CacheFileContextEvictor> mContextEvictor;
|
|
TimeStamp mLastSmartSizeTime;
|
|
};
|
|
|
|
} // namespace net
|
|
} // namespace mozilla
|
|
|
|
#endif
|