Bug 724513 - Part 1 - Add StartupCache method for disregarding disk file. r=mwu

This commit is contained in:
Graeme McCutcheon
2012-10-11 09:17:15 +01:00
parent 0d964a26b1
commit 093e8b91b5
4 changed files with 152 additions and 8 deletions

View File

@@ -122,6 +122,7 @@ StartupCache::InitSingleton()
StartupCache* StartupCache::gStartupCache;
bool StartupCache::gShutdownInitiated;
bool StartupCache::gIgnoreDiskCache;
enum StartupCache::TelemetrifyAge StartupCache::gPostFlushAgeAction = StartupCache::IGNORE_AGE;
StartupCache::StartupCache()
@@ -203,12 +204,12 @@ StartupCache::Init()
rv = mObserverService->AddObserver(mListener, "startupcache-invalidate",
false);
NS_ENSURE_SUCCESS(rv, rv);
rv = LoadArchive(RECORD_AGE);
// Sometimes we don't have a cache yet, that's ok.
// If it's corrupted, just remove it and start over.
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND) {
if (gIgnoreDiskCache || (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND)) {
NS_WARNING("Failed to load startupcache file correctly, removing!");
InvalidateCache();
}
@@ -227,6 +228,9 @@ StartupCache::Init()
nsresult
StartupCache::LoadArchive(enum TelemetrifyAge flag)
{
if (gIgnoreDiskCache)
return NS_ERROR_FAILURE;
bool exists;
mArchive = NULL;
nsresult rv = mFile->Exists(&exists);
@@ -458,6 +462,9 @@ StartupCache::WriteToDisk()
mArchive = NULL;
zipW->Close();
// We succesfully wrote the archive to disk; mark the disk file as trusted
gIgnoreDiskCache = false;
// Our reader's view of the archive is outdated now, reload it.
LoadArchive(gPostFlushAgeAction);
@@ -470,10 +477,24 @@ StartupCache::InvalidateCache()
WaitOnWriteThread();
mTable.Clear();
mArchive = NULL;
mFile->Remove(false);
nsresult rv = mFile->Remove(false);
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_TARGET_DOES_NOT_EXIST &&
rv != NS_ERROR_FILE_NOT_FOUND) {
gIgnoreDiskCache = true;
return;
}
gIgnoreDiskCache = false;
LoadArchive(gPostFlushAgeAction);
}
void
StartupCache::IgnoreDiskCache()
{
gIgnoreDiskCache = true;
if (gStartupCache)
gStartupCache->InvalidateCache();
}
/*
* WaitOnWriteThread() is called from a main thread to wait for the worker
* thread to finish. However since the same code is used in the worker thread and
@@ -713,6 +734,13 @@ StartupCacheWrapper::InvalidateCache()
return NS_OK;
}
nsresult
StartupCacheWrapper::IgnoreDiskCache()
{
StartupCache::IgnoreDiskCache();
return NS_OK;
}
nsresult
StartupCacheWrapper::GetDebugObjectOutputStream(nsIObjectOutputStream* stream,
nsIObjectOutputStream** outStream)