mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 724513 - Part 1 - Add StartupCache method for disregarding disk file. r=mwu
This commit is contained in:
parent
04d3a8ad36
commit
d7d3e8b34a
@ -122,6 +122,7 @@ StartupCache::InitSingleton()
|
|||||||
|
|
||||||
StartupCache* StartupCache::gStartupCache;
|
StartupCache* StartupCache::gStartupCache;
|
||||||
bool StartupCache::gShutdownInitiated;
|
bool StartupCache::gShutdownInitiated;
|
||||||
|
bool StartupCache::gIgnoreDiskCache;
|
||||||
enum StartupCache::TelemetrifyAge StartupCache::gPostFlushAgeAction = StartupCache::IGNORE_AGE;
|
enum StartupCache::TelemetrifyAge StartupCache::gPostFlushAgeAction = StartupCache::IGNORE_AGE;
|
||||||
|
|
||||||
StartupCache::StartupCache()
|
StartupCache::StartupCache()
|
||||||
@ -208,7 +209,7 @@ StartupCache::Init()
|
|||||||
|
|
||||||
// Sometimes we don't have a cache yet, that's ok.
|
// Sometimes we don't have a cache yet, that's ok.
|
||||||
// If it's corrupted, just remove it and start over.
|
// 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!");
|
NS_WARNING("Failed to load startupcache file correctly, removing!");
|
||||||
InvalidateCache();
|
InvalidateCache();
|
||||||
}
|
}
|
||||||
@ -227,6 +228,9 @@ StartupCache::Init()
|
|||||||
nsresult
|
nsresult
|
||||||
StartupCache::LoadArchive(enum TelemetrifyAge flag)
|
StartupCache::LoadArchive(enum TelemetrifyAge flag)
|
||||||
{
|
{
|
||||||
|
if (gIgnoreDiskCache)
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
bool exists;
|
bool exists;
|
||||||
mArchive = NULL;
|
mArchive = NULL;
|
||||||
nsresult rv = mFile->Exists(&exists);
|
nsresult rv = mFile->Exists(&exists);
|
||||||
@ -458,6 +462,9 @@ StartupCache::WriteToDisk()
|
|||||||
mArchive = NULL;
|
mArchive = NULL;
|
||||||
zipW->Close();
|
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.
|
// Our reader's view of the archive is outdated now, reload it.
|
||||||
LoadArchive(gPostFlushAgeAction);
|
LoadArchive(gPostFlushAgeAction);
|
||||||
|
|
||||||
@ -470,10 +477,24 @@ StartupCache::InvalidateCache()
|
|||||||
WaitOnWriteThread();
|
WaitOnWriteThread();
|
||||||
mTable.Clear();
|
mTable.Clear();
|
||||||
mArchive = NULL;
|
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);
|
LoadArchive(gPostFlushAgeAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
StartupCache::IgnoreDiskCache()
|
||||||
|
{
|
||||||
|
gIgnoreDiskCache = true;
|
||||||
|
if (gStartupCache)
|
||||||
|
gStartupCache->InvalidateCache();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* WaitOnWriteThread() is called from a main thread to wait for the worker
|
* 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
|
* thread to finish. However since the same code is used in the worker thread and
|
||||||
@ -713,6 +734,13 @@ StartupCacheWrapper::InvalidateCache()
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
StartupCacheWrapper::IgnoreDiskCache()
|
||||||
|
{
|
||||||
|
StartupCache::IgnoreDiskCache();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
StartupCacheWrapper::GetDebugObjectOutputStream(nsIObjectOutputStream* stream,
|
StartupCacheWrapper::GetDebugObjectOutputStream(nsIObjectOutputStream* stream,
|
||||||
nsIObjectOutputStream** outStream)
|
nsIObjectOutputStream** outStream)
|
||||||
|
@ -44,6 +44,12 @@
|
|||||||
*
|
*
|
||||||
* InvalidateCache() may be called if a client suspects data corruption
|
* InvalidateCache() may be called if a client suspects data corruption
|
||||||
* or wishes to invalidate for any other reason. This will remove all existing cache data.
|
* or wishes to invalidate for any other reason. This will remove all existing cache data.
|
||||||
|
* Additionally, the static method IgnoreDiskCache() can be called if it is
|
||||||
|
* believed that the on-disk cache file is itself corrupt. This call implicitly
|
||||||
|
* calls InvalidateCache (if the singleton has been initialized) to ensure any
|
||||||
|
* data already read from disk is discarded. The cache will not load data from
|
||||||
|
* the disk file until a successful write occurs.
|
||||||
|
*
|
||||||
* Finally, getDebugObjectOutputStream() allows debug code to wrap an objectstream
|
* Finally, getDebugObjectOutputStream() allows debug code to wrap an objectstream
|
||||||
* with a debug objectstream, to check for multiply-referenced objects. These will
|
* with a debug objectstream, to check for multiply-referenced objects. These will
|
||||||
* generally fail to deserialize correctly, unless they are stateless singletons or the
|
* generally fail to deserialize correctly, unless they are stateless singletons or the
|
||||||
@ -114,6 +120,9 @@ public:
|
|||||||
// Removes the cache file.
|
// Removes the cache file.
|
||||||
void InvalidateCache();
|
void InvalidateCache();
|
||||||
|
|
||||||
|
// Signal that data should not be loaded from the cache file
|
||||||
|
static void IgnoreDiskCache();
|
||||||
|
|
||||||
// In DEBUG builds, returns a stream that will attempt to check for
|
// In DEBUG builds, returns a stream that will attempt to check for
|
||||||
// and disallow multiple writes of the same object.
|
// and disallow multiple writes of the same object.
|
||||||
nsresult GetDebugObjectOutputStream(nsIObjectOutputStream* aStream,
|
nsresult GetDebugObjectOutputStream(nsIObjectOutputStream* aStream,
|
||||||
@ -167,6 +176,7 @@ private:
|
|||||||
|
|
||||||
static StartupCache *gStartupCache;
|
static StartupCache *gStartupCache;
|
||||||
static bool gShutdownInitiated;
|
static bool gShutdownInitiated;
|
||||||
|
static bool gIgnoreDiskCache;
|
||||||
PRThread *mWriteThread;
|
PRThread *mWriteThread;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
nsTHashtable<nsISupportsHashKey> mWriteObjectMap;
|
nsTHashtable<nsISupportsHashKey> mWriteObjectMap;
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include "nsIObserver.idl"
|
#include "nsIObserver.idl"
|
||||||
#include "nsIObjectOutputStream.idl"
|
#include "nsIObjectOutputStream.idl"
|
||||||
|
|
||||||
[uuid(c1b3796b-33af-4ff0-b83d-8eb0ca2c080f)]
|
[uuid(25957820-90a1-428c-8739-b0845d3cc534)]
|
||||||
interface nsIStartupCache : nsISupports
|
interface nsIStartupCache : nsISupports
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -24,6 +24,8 @@ interface nsIStartupCache : nsISupports
|
|||||||
|
|
||||||
void invalidateCache();
|
void invalidateCache();
|
||||||
|
|
||||||
|
void ignoreDiskCache();
|
||||||
|
|
||||||
/** In debug builds, wraps this object output stream with a stream that will
|
/** In debug builds, wraps this object output stream with a stream that will
|
||||||
* detect and prevent the write of a multiply-referenced non-singleton object
|
* detect and prevent the write of a multiply-referenced non-singleton object
|
||||||
* during serialization. In non-debug, returns an add-ref'd pointer to
|
* during serialization. In non-debug, returns an add-ref'd pointer to
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "nsIPrefService.h"
|
#include "nsIPrefService.h"
|
||||||
#include "nsITelemetry.h"
|
#include "nsITelemetry.h"
|
||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
|
#include "prio.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace scache {
|
namespace scache {
|
||||||
@ -247,6 +248,106 @@ TestWriteObject() {
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
LockCacheFile(bool protect, nsIFile* profileDir) {
|
||||||
|
NS_ENSURE_ARG(profileDir);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIFile> startupCache;
|
||||||
|
profileDir->Clone(getter_AddRefs(startupCache));
|
||||||
|
NS_ENSURE_STATE(startupCache);
|
||||||
|
startupCache->AppendNative(NS_LITERAL_CSTRING("startupCache"));
|
||||||
|
|
||||||
|
nsresult rv;
|
||||||
|
#ifndef XP_WIN
|
||||||
|
static uint32_t oldPermissions;
|
||||||
|
#else
|
||||||
|
static PRFileDesc* fd = nullptr;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// To prevent deletion of the startupcache file, we change the containing
|
||||||
|
// directory's permissions on Linux/Mac, and hold the file open on Windows
|
||||||
|
if (protect) {
|
||||||
|
#ifndef XP_WIN
|
||||||
|
rv = startupCache->GetPermissions(&oldPermissions);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
rv = startupCache->SetPermissions(0555);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
#else
|
||||||
|
// Filename logic from StartupCache.cpp
|
||||||
|
#ifdef IS_BIG_ENDIAN
|
||||||
|
#define SC_ENDIAN "big"
|
||||||
|
#else
|
||||||
|
#define SC_ENDIAN "little"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if PR_BYTES_PER_WORD == 4
|
||||||
|
#define SC_WORDSIZE "4"
|
||||||
|
#else
|
||||||
|
#define SC_WORDSIZE "8"
|
||||||
|
#endif
|
||||||
|
char sStartupCacheName[] = "startupCache." SC_WORDSIZE "." SC_ENDIAN;
|
||||||
|
startupCache->AppendNative(NS_LITERAL_CSTRING(sStartupCacheName));
|
||||||
|
|
||||||
|
rv = startupCache->OpenNSPRFileDesc(PR_RDONLY, 0, &fd);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
#ifndef XP_WIN
|
||||||
|
rv = startupCache->SetPermissions(oldPermissions);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
#else
|
||||||
|
PR_Close(fd);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
TestIgnoreDiskCache(nsIFile* profileDir) {
|
||||||
|
nsresult rv;
|
||||||
|
nsCOMPtr<nsIStartupCache> sc
|
||||||
|
= do_GetService("@mozilla.org/startupcache/cache;1", &rv);
|
||||||
|
sc->InvalidateCache();
|
||||||
|
|
||||||
|
const char* buf = "Get a Beardbook app for your smartphone";
|
||||||
|
const char* id = "id";
|
||||||
|
char* outbuf = NULL;
|
||||||
|
PRUint32 len;
|
||||||
|
|
||||||
|
rv = sc->PutBuffer(id, buf, strlen(buf) + 1);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
rv = sc->ResetStartupWriteTimer();
|
||||||
|
rv = WaitForStartupTimer();
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
// Prevent StartupCache::InvalidateCache from deleting the disk file
|
||||||
|
rv = LockCacheFile(true, profileDir);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
sc->IgnoreDiskCache();
|
||||||
|
|
||||||
|
rv = sc->GetBuffer(id, &outbuf, &len);
|
||||||
|
|
||||||
|
nsresult r = LockCacheFile(false, profileDir);
|
||||||
|
NS_ENSURE_SUCCESS(r, r);
|
||||||
|
|
||||||
|
delete[] outbuf;
|
||||||
|
|
||||||
|
if (rv == NS_ERROR_NOT_AVAILABLE) {
|
||||||
|
passed("buffer not available after ignoring disk cache");
|
||||||
|
} else if (NS_SUCCEEDED(rv)) {
|
||||||
|
fail("GetBuffer succeeded unexpectedly after ignoring disk cache");
|
||||||
|
return NS_ERROR_UNEXPECTED;
|
||||||
|
} else {
|
||||||
|
fail("GetBuffer gave an unexpected failure, expected NOT_AVAILABLE");
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
sc->InvalidateCache();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
TestEarlyShutdown() {
|
TestEarlyShutdown() {
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
@ -416,6 +517,9 @@ int main(int argc, char** argv)
|
|||||||
rv = 1;
|
rv = 1;
|
||||||
if (NS_FAILED(TestWriteObject()))
|
if (NS_FAILED(TestWriteObject()))
|
||||||
rv = 1;
|
rv = 1;
|
||||||
|
nsCOMPtr<nsIFile> profileDir = xpcom.GetProfileDirectory();
|
||||||
|
if (NS_FAILED(TestIgnoreDiskCache(profileDir)))
|
||||||
|
rv = 1;
|
||||||
if (NS_FAILED(TestEarlyShutdown()))
|
if (NS_FAILED(TestEarlyShutdown()))
|
||||||
rv = 1;
|
rv = 1;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user