2013-01-18 00:45:11 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2010-08-12 19:37:44 +00:00
|
|
|
|
|
|
|
#include "prio.h"
|
|
|
|
#include "pldhash.h"
|
2012-02-22 19:03:52 +00:00
|
|
|
#include "nsXPCOMStrings.h"
|
2014-04-09 04:57:52 +00:00
|
|
|
#include "mozilla/IOInterposer.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2010-08-12 19:37:44 +00:00
|
|
|
#include "mozilla/scache/StartupCache.h"
|
|
|
|
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsDirectoryServiceUtils.h"
|
|
|
|
#include "nsIClassInfo.h"
|
|
|
|
#include "nsIFile.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIOutputStream.h"
|
|
|
|
#include "nsIStartupCache.h"
|
|
|
|
#include "nsIStorageStream.h"
|
|
|
|
#include "nsIStreamBufferAccess.h"
|
|
|
|
#include "nsIStringStream.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsIZipWriter.h"
|
|
|
|
#include "nsIZipReader.h"
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsZipArchive.h"
|
2011-01-07 19:04:33 +00:00
|
|
|
#include "mozilla/Omnijar.h"
|
|
|
|
#include "prenv.h"
|
2012-02-22 19:03:52 +00:00
|
|
|
#include "mozilla/Telemetry.h"
|
2011-04-01 05:24:16 +00:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
2011-06-30 21:58:03 +00:00
|
|
|
#include "nsIProtocolHandler.h"
|
2011-04-01 05:24:16 +00:00
|
|
|
|
2010-08-12 19:37:44 +00:00
|
|
|
#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
|
|
|
|
|
2011-12-19 00:20:36 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace scache {
|
|
|
|
|
2013-12-08 05:39:47 +00:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(StartupCacheMallocSizeOf)
|
|
|
|
|
2013-11-07 05:35:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
StartupCache::CollectReports(nsIHandleReportCallback* aHandleReport,
|
2014-05-21 06:06:54 +00:00
|
|
|
nsISupports* aData, bool aAnonymize)
|
2011-10-25 00:50:47 +00:00
|
|
|
{
|
2013-11-07 05:35:30 +00:00
|
|
|
#define REPORT(_path, _kind, _amount, _desc) \
|
|
|
|
do { \
|
|
|
|
nsresult rv = \
|
|
|
|
aHandleReport->Callback(EmptyCString(), \
|
|
|
|
NS_LITERAL_CSTRING(_path), \
|
|
|
|
_kind, UNITS_BYTES, _amount, \
|
|
|
|
NS_LITERAL_CSTRING(_desc), aData); \
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
REPORT("explicit/startup-cache/mapping", KIND_NONHEAP,
|
|
|
|
SizeOfMapping(),
|
|
|
|
"Memory used to hold the mapping of the startup cache from file. "
|
|
|
|
"This memory is likely to be swapped out shortly after start-up.");
|
|
|
|
|
|
|
|
REPORT("explicit/startup-cache/data", KIND_HEAP,
|
2013-12-08 05:39:47 +00:00
|
|
|
HeapSizeOfIncludingThis(StartupCacheMallocSizeOf),
|
2013-11-07 05:35:30 +00:00
|
|
|
"Memory used by the startup cache for things other than the file "
|
|
|
|
"mapping.");
|
2011-12-19 00:20:36 +00:00
|
|
|
|
2013-11-07 05:35:30 +00:00
|
|
|
return NS_OK;
|
2014-04-15 07:28:21 +00:00
|
|
|
}
|
2010-08-12 19:37:44 +00:00
|
|
|
|
|
|
|
static const char sStartupCacheName[] = "startupCache." SC_WORDSIZE "." SC_ENDIAN;
|
2013-11-01 23:21:33 +00:00
|
|
|
#if defined(XP_WIN) && defined(MOZ_METRO)
|
|
|
|
static const char sMetroStartupCacheName[] = "metroStartupCache." SC_WORDSIZE "." SC_ENDIAN;
|
|
|
|
#endif
|
|
|
|
|
2010-08-12 19:37:44 +00:00
|
|
|
StartupCache*
|
2013-01-18 00:45:11 +00:00
|
|
|
StartupCache::GetSingleton()
|
2010-08-12 19:37:44 +00:00
|
|
|
{
|
2012-10-26 22:27:53 +00:00
|
|
|
if (!gStartupCache) {
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-04-23 08:57:00 +00:00
|
|
|
#ifdef MOZ_DISABLE_STARTUP_CACHE
|
2014-04-21 17:20:49 +00:00
|
|
|
return nullptr;
|
|
|
|
#endif
|
2012-10-26 22:27:53 +00:00
|
|
|
|
2010-08-12 19:37:44 +00:00
|
|
|
StartupCache::InitSingleton();
|
2012-10-26 22:27:53 +00:00
|
|
|
}
|
2010-08-12 19:37:44 +00:00
|
|
|
|
|
|
|
return StartupCache::gStartupCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StartupCache::DeleteSingleton()
|
|
|
|
{
|
2013-01-18 00:45:11 +00:00
|
|
|
StartupCache::gStartupCache = nullptr;
|
2010-08-12 19:37:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-01-18 00:45:11 +00:00
|
|
|
StartupCache::InitSingleton()
|
2010-08-12 19:37:44 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
StartupCache::gStartupCache = new StartupCache();
|
|
|
|
|
|
|
|
rv = StartupCache::gStartupCache->Init();
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-07-30 14:20:58 +00:00
|
|
|
StartupCache::gStartupCache = nullptr;
|
2010-08-12 19:37:44 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-11-25 23:57:40 +00:00
|
|
|
StaticRefPtr<StartupCache> StartupCache::gStartupCache;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool StartupCache::gShutdownInitiated;
|
2012-10-11 08:17:15 +00:00
|
|
|
bool StartupCache::gIgnoreDiskCache;
|
2012-02-22 19:07:18 +00:00
|
|
|
enum StartupCache::TelemetrifyAge StartupCache::gPostFlushAgeAction = StartupCache::IGNORE_AGE;
|
2010-08-12 19:37:44 +00:00
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(StartupCache, nsIMemoryReporter)
|
2013-11-25 23:57:40 +00:00
|
|
|
|
2013-01-18 00:45:11 +00:00
|
|
|
StartupCache::StartupCache()
|
2013-12-04 04:01:24 +00:00
|
|
|
: mArchive(nullptr), mStartupWriteInitiated(false), mWriteThread(nullptr)
|
2013-01-18 00:45:11 +00:00
|
|
|
{ }
|
2010-08-12 19:37:44 +00:00
|
|
|
|
2013-01-18 00:45:11 +00:00
|
|
|
StartupCache::~StartupCache()
|
2010-08-12 19:37:44 +00:00
|
|
|
{
|
2010-09-23 21:45:26 +00:00
|
|
|
if (mTimer) {
|
|
|
|
mTimer->Cancel();
|
|
|
|
}
|
|
|
|
|
2010-08-12 19:37:44 +00:00
|
|
|
// Generally, the in-memory table should be empty here,
|
2013-01-18 00:45:11 +00:00
|
|
|
// but an early shutdown means either mTimer didn't run
|
2011-04-01 05:24:16 +00:00
|
|
|
// or the write thread is still running.
|
|
|
|
WaitOnWriteThread();
|
2012-12-05 19:09:30 +00:00
|
|
|
|
|
|
|
// If we shutdown quickly timer wont have fired. Instead of writing
|
|
|
|
// it on the main thread and block the shutdown we simply wont update
|
|
|
|
// the startup cache. Always do this if the file doesn't exist since
|
2014-01-11 00:16:25 +00:00
|
|
|
// we use it part of the package step.
|
2012-12-05 19:09:30 +00:00
|
|
|
if (!mArchive) {
|
|
|
|
WriteToDisk();
|
|
|
|
}
|
|
|
|
|
2013-11-07 05:35:30 +00:00
|
|
|
UnregisterWeakMemoryReporter(this);
|
2010-08-12 19:37:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-01-18 00:45:11 +00:00
|
|
|
StartupCache::Init()
|
2010-08-12 19:37:44 +00:00
|
|
|
{
|
2011-06-30 21:58:03 +00:00
|
|
|
// workaround for bug 653936
|
|
|
|
nsCOMPtr<nsIProtocolHandler> jarInitializer(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "jar"));
|
2013-01-18 00:45:11 +00:00
|
|
|
|
2010-08-12 19:37:44 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2011-01-07 19:04:33 +00:00
|
|
|
// This allows to override the startup cache filename
|
|
|
|
// which is useful from xpcshell, when there is no ProfLDS directory to keep cache in.
|
|
|
|
char *env = PR_GetEnv("MOZ_STARTUP_CACHE");
|
|
|
|
if (env) {
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(env), false, getter_AddRefs(mFile));
|
2011-01-07 19:04:33 +00:00
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
rv = NS_GetSpecialDirectory("ProfLDS",
|
|
|
|
getter_AddRefs(file));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// return silently, this will fail in mochitests's xpcshell process.
|
|
|
|
return rv;
|
|
|
|
}
|
2010-08-12 19:37:44 +00:00
|
|
|
|
2013-02-11 14:47:21 +00:00
|
|
|
nsCOMPtr<nsIFile> profDir;
|
|
|
|
NS_GetSpecialDirectory("ProfDS", getter_AddRefs(profDir));
|
|
|
|
if (profDir) {
|
|
|
|
bool same;
|
|
|
|
if (NS_SUCCEEDED(profDir->Equals(file, &same)) && !same) {
|
|
|
|
// We no longer store the startup cache in the main profile
|
|
|
|
// directory, so we should cleanup the old one.
|
|
|
|
if (NS_SUCCEEDED(
|
|
|
|
profDir->AppendNative(NS_LITERAL_CSTRING("startupCache")))) {
|
|
|
|
profDir->Remove(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-07 19:04:33 +00:00
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING("startupCache"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-12 19:37:44 +00:00
|
|
|
|
2011-01-07 19:04:33 +00:00
|
|
|
// Try to create the directory if it's not there yet
|
|
|
|
rv = file->Create(nsIFile::DIRECTORY_TYPE, 0777);
|
|
|
|
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_ALREADY_EXISTS)
|
|
|
|
return rv;
|
|
|
|
|
2013-11-01 23:21:33 +00:00
|
|
|
#if defined(XP_WIN) && defined(MOZ_METRO)
|
|
|
|
if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) {
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING(sMetroStartupCacheName));
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
rv = file->AppendNative(NS_LITERAL_CSTRING(sStartupCacheName));
|
|
|
|
}
|
2011-01-07 19:04:33 +00:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-01-18 00:45:11 +00:00
|
|
|
|
2011-01-07 19:04:33 +00:00
|
|
|
mFile = do_QueryInterface(file);
|
|
|
|
}
|
2010-08-12 19:37:44 +00:00
|
|
|
|
|
|
|
NS_ENSURE_TRUE(mFile, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
mObserverService = do_GetService("@mozilla.org/observer-service;1");
|
2013-01-18 00:45:11 +00:00
|
|
|
|
2010-08-12 19:37:44 +00:00
|
|
|
if (!mObserverService) {
|
|
|
|
NS_WARNING("Could not get observerService.");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2013-01-18 00:45:11 +00:00
|
|
|
|
|
|
|
mListener = new StartupCacheListener();
|
2010-08-12 19:37:44 +00:00
|
|
|
rv = mObserverService->AddObserver(mListener, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
|
2011-10-17 14:59:28 +00:00
|
|
|
false);
|
2010-08-12 19:37:44 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-09-15 00:39:07 +00:00
|
|
|
rv = mObserverService->AddObserver(mListener, "startupcache-invalidate",
|
2011-10-17 14:59:28 +00:00
|
|
|
false);
|
2010-09-15 00:39:07 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-10-11 08:17:15 +00:00
|
|
|
|
2012-02-22 19:03:52 +00:00
|
|
|
rv = LoadArchive(RECORD_AGE);
|
2013-01-18 00:45:11 +00:00
|
|
|
|
2010-08-12 19:37:44 +00:00
|
|
|
// Sometimes we don't have a cache yet, that's ok.
|
|
|
|
// If it's corrupted, just remove it and start over.
|
2012-10-11 08:17:15 +00:00
|
|
|
if (gIgnoreDiskCache || (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND)) {
|
2010-08-12 19:37:44 +00:00
|
|
|
NS_WARNING("Failed to load startupcache file correctly, removing!");
|
|
|
|
InvalidateCache();
|
|
|
|
}
|
2011-10-25 00:50:47 +00:00
|
|
|
|
2013-11-07 05:35:30 +00:00
|
|
|
RegisterWeakMemoryReporter(this);
|
2011-10-25 00:50:47 +00:00
|
|
|
|
2011-01-07 18:55:14 +00:00
|
|
|
return NS_OK;
|
2010-08-12 19:37:44 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 00:45:11 +00:00
|
|
|
/**
|
2011-04-01 05:24:16 +00:00
|
|
|
* LoadArchive can be called from the main thread or while reloading cache on write thread.
|
|
|
|
*/
|
2010-08-12 19:37:44 +00:00
|
|
|
nsresult
|
2012-02-22 19:03:52 +00:00
|
|
|
StartupCache::LoadArchive(enum TelemetrifyAge flag)
|
2010-08-12 19:37:44 +00:00
|
|
|
{
|
2012-10-11 08:17:15 +00:00
|
|
|
if (gIgnoreDiskCache)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool exists;
|
2013-07-31 15:44:43 +00:00
|
|
|
mArchive = nullptr;
|
2010-08-12 19:37:44 +00:00
|
|
|
nsresult rv = mFile->Exists(&exists);
|
|
|
|
if (NS_FAILED(rv) || !exists)
|
|
|
|
return NS_ERROR_FILE_NOT_FOUND;
|
|
|
|
|
|
|
|
mArchive = new nsZipArchive();
|
2012-02-22 19:03:52 +00:00
|
|
|
rv = mArchive->OpenArchive(mFile);
|
|
|
|
if (NS_FAILED(rv) || flag == IGNORE_AGE)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCString comment;
|
|
|
|
if (!mArchive->GetComment(comment)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *data;
|
|
|
|
size_t len = NS_CStringGetData(comment, &data);
|
|
|
|
PRTime creationStamp;
|
|
|
|
// We might not have a comment if the startup cache file was created
|
|
|
|
// before we started recording creation times in the comment.
|
|
|
|
if (len == sizeof(creationStamp)) {
|
|
|
|
memcpy(&creationStamp, data, len);
|
|
|
|
PRTime current = PR_Now();
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t diff = current - creationStamp;
|
2012-02-22 19:03:52 +00:00
|
|
|
|
|
|
|
// We can't use AccumulateTimeDelta here because we have no way of
|
|
|
|
// reifying a TimeStamp from creationStamp.
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t usec_per_hour = PR_USEC_PER_SEC * int64_t(3600);
|
|
|
|
int64_t hour_diff = (diff + usec_per_hour - 1) / usec_per_hour;
|
2012-02-22 19:03:52 +00:00
|
|
|
mozilla::Telemetry::Accumulate(Telemetry::STARTUP_CACHE_AGE_HOURS,
|
|
|
|
hour_diff);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2010-08-12 19:37:44 +00:00
|
|
|
}
|
|
|
|
|
2011-12-08 10:03:36 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetBufferFromZipArchive(nsZipArchive *zip, bool doCRC, const char* id,
|
2012-08-22 15:56:38 +00:00
|
|
|
char** outbuf, uint32_t* length)
|
2011-12-08 10:03:36 +00:00
|
|
|
{
|
|
|
|
if (!zip)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
nsZipItemPtr<char> zipItem(zip, id, doCRC);
|
|
|
|
if (!zipItem)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
*outbuf = zipItem.Forget();
|
|
|
|
*length = zipItem.Length();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* anonymous namespace */
|
|
|
|
|
2010-08-12 19:37:44 +00:00
|
|
|
// NOTE: this will not find a new entry until it has been written to disk!
|
|
|
|
// Consumer should take ownership of the resulting buffer.
|
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
StartupCache::GetBuffer(const char* id, char** outbuf, uint32_t* length)
|
2010-08-12 19:37:44 +00:00
|
|
|
{
|
2011-04-01 05:24:16 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Startup cache only available on main thread");
|
2011-01-20 21:40:45 +00:00
|
|
|
WaitOnWriteThread();
|
2010-08-12 19:37:44 +00:00
|
|
|
if (!mStartupWriteInitiated) {
|
|
|
|
CacheEntry* entry;
|
|
|
|
nsDependentCString idStr(id);
|
|
|
|
mTable.Get(idStr, &entry);
|
|
|
|
if (entry) {
|
2010-11-11 20:13:57 +00:00
|
|
|
*outbuf = new char[entry->size];
|
|
|
|
memcpy(*outbuf, entry->data, entry->size);
|
|
|
|
*length = entry->size;
|
|
|
|
return NS_OK;
|
2010-08-12 19:37:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-08 10:03:36 +00:00
|
|
|
nsresult rv = GetBufferFromZipArchive(mArchive, true, id, outbuf, length);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return rv;
|
2010-08-12 19:37:44 +00:00
|
|
|
|
2011-12-08 10:03:36 +00:00
|
|
|
nsRefPtr<nsZipArchive> omnijar = mozilla::Omnijar::GetReader(mozilla::Omnijar::APP);
|
|
|
|
// no need to checksum omnijarred entries
|
|
|
|
rv = GetBufferFromZipArchive(omnijar, false, id, outbuf, length);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return rv;
|
2011-02-25 11:53:36 +00:00
|
|
|
|
2011-12-08 10:03:36 +00:00
|
|
|
omnijar = mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE);
|
|
|
|
// no need to checksum omnijarred entries
|
|
|
|
return GetBufferFromZipArchive(omnijar, false, id, outbuf, length);
|
2010-08-12 19:37:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Makes a copy of the buffer, client retains ownership of inbuf.
|
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
StartupCache::PutBuffer(const char* id, const char* inbuf, uint32_t len)
|
2010-08-12 19:37:44 +00:00
|
|
|
{
|
2011-04-01 05:24:16 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Startup cache only available on main thread");
|
2011-01-20 21:40:45 +00:00
|
|
|
WaitOnWriteThread();
|
2010-08-12 19:37:44 +00:00
|
|
|
if (StartupCache::gShutdownInitiated) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoArrayPtr<char> data(new char[len]);
|
|
|
|
memcpy(data, inbuf, len);
|
|
|
|
|
|
|
|
nsDependentCString idStr(id);
|
2011-01-07 18:55:14 +00:00
|
|
|
// Cache it for now, we'll write all together later.
|
|
|
|
CacheEntry* entry;
|
2010-08-12 19:37:44 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-01-07 18:55:14 +00:00
|
|
|
mTable.Get(idStr, &entry);
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_ASSERTION(entry == nullptr, "Existing entry in StartupCache.");
|
2011-01-07 18:55:14 +00:00
|
|
|
|
|
|
|
if (mArchive) {
|
|
|
|
nsZipItem* zipItem = mArchive->GetItem(id);
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_ASSERTION(zipItem == nullptr, "Existing entry in disk StartupCache.");
|
2011-01-07 18:55:14 +00:00
|
|
|
}
|
2010-08-12 19:37:44 +00:00
|
|
|
#endif
|
|
|
|
|
2011-01-07 18:55:14 +00:00
|
|
|
entry = new CacheEntry(data.forget(), len);
|
|
|
|
mTable.Put(idStr, entry);
|
|
|
|
return ResetStartupWriteTimer();
|
2010-08-12 19:37:44 +00:00
|
|
|
}
|
|
|
|
|
2011-12-19 00:20:36 +00:00
|
|
|
size_t
|
2013-11-07 05:35:30 +00:00
|
|
|
StartupCache::SizeOfMapping()
|
2011-10-25 00:50:47 +00:00
|
|
|
{
|
|
|
|
return mArchive ? mArchive->SizeOfMapping() : 0;
|
|
|
|
}
|
|
|
|
|
2011-12-19 00:20:36 +00:00
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
StartupCache::HeapSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
2011-12-19 00:20:36 +00:00
|
|
|
{
|
|
|
|
// This function could measure more members, but they haven't been found by
|
|
|
|
// DMD to be significant. They can be added later if necessary.
|
2012-01-25 08:52:51 +00:00
|
|
|
return aMallocSizeOf(this) +
|
2011-12-19 00:20:36 +00:00
|
|
|
mTable.SizeOfExcludingThis(SizeOfEntryExcludingThis, aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ size_t
|
|
|
|
StartupCache::SizeOfEntryExcludingThis(const nsACString& key, const nsAutoPtr<CacheEntry>& data,
|
2013-06-23 12:03:39 +00:00
|
|
|
mozilla::MallocSizeOf mallocSizeOf, void *)
|
2011-12-19 00:20:36 +00:00
|
|
|
{
|
|
|
|
return data->SizeOfExcludingThis(mallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2010-08-12 19:37:44 +00:00
|
|
|
struct CacheWriteHolder
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIZipWriter> writer;
|
|
|
|
nsCOMPtr<nsIStringInputStream> stream;
|
2011-01-07 18:55:14 +00:00
|
|
|
PRTime time;
|
2010-08-12 19:37:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
CacheCloseHelper(const nsACString& key, nsAutoPtr<CacheEntry>& data,
|
|
|
|
void* closure)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
CacheWriteHolder* holder = (CacheWriteHolder*) closure;
|
|
|
|
nsIStringInputStream* stream = holder->stream;
|
|
|
|
nsIZipWriter* writer = holder->writer;
|
|
|
|
|
|
|
|
stream->ShareData(data->data, data->size);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-29 06:19:26 +00:00
|
|
|
bool hasEntry;
|
2010-08-12 19:37:44 +00:00
|
|
|
rv = writer->HasEntry(key, &hasEntry);
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv) && hasEntry == false,
|
2010-08-12 19:37:44 +00:00
|
|
|
"Existing entry in disk StartupCache.");
|
|
|
|
#endif
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = writer->AddEntryStream(key, holder->time, true, stream, false);
|
2010-08-12 19:37:44 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("cache entry deleted but not written to disk.");
|
|
|
|
}
|
|
|
|
return PL_DHASH_REMOVE;
|
|
|
|
}
|
|
|
|
|
2011-04-01 05:24:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* WriteToDisk writes the cache out to disk. Callers of WriteToDisk need to call WaitOnWriteThread
|
|
|
|
* to make sure there isn't a write happening on another thread
|
|
|
|
*/
|
2010-08-12 19:37:44 +00:00
|
|
|
void
|
|
|
|
StartupCache::WriteToDisk()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2011-10-17 14:59:28 +00:00
|
|
|
mStartupWriteInitiated = true;
|
2010-08-12 19:37:44 +00:00
|
|
|
|
2013-09-02 08:41:57 +00:00
|
|
|
if (mTable.Count() == 0)
|
2010-08-12 19:37:44 +00:00
|
|
|
return;
|
|
|
|
|
2011-01-07 18:55:14 +00:00
|
|
|
nsCOMPtr<nsIZipWriter> zipW = do_CreateInstance("@mozilla.org/zipwriter;1");
|
|
|
|
if (!zipW)
|
|
|
|
return;
|
|
|
|
|
|
|
|
rv = zipW->Open(mFile, PR_RDWR | PR_CREATE_FILE);
|
2010-08-12 19:37:44 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("could not open zipfile for write");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-22 19:03:52 +00:00
|
|
|
// If we didn't have an mArchive member, that means that we failed to
|
|
|
|
// open the startup cache for reading. Therefore, we need to record
|
|
|
|
// the time of creation in a zipfile comment; this will be useful for
|
|
|
|
// Telemetry statistics.
|
|
|
|
PRTime now = PR_Now();
|
|
|
|
if (!mArchive) {
|
|
|
|
nsCString comment;
|
|
|
|
comment.Assign((char *)&now, sizeof(now));
|
|
|
|
zipW->SetComment(comment);
|
|
|
|
}
|
|
|
|
|
2010-08-12 19:37:44 +00:00
|
|
|
nsCOMPtr<nsIStringInputStream> stream
|
|
|
|
= do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Couldn't create string input stream.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CacheWriteHolder holder;
|
|
|
|
holder.stream = stream;
|
2011-01-07 18:55:14 +00:00
|
|
|
holder.writer = zipW;
|
2012-02-22 19:03:52 +00:00
|
|
|
holder.time = now;
|
2010-08-12 19:37:44 +00:00
|
|
|
|
|
|
|
mTable.Enumerate(CacheCloseHelper, &holder);
|
|
|
|
|
|
|
|
// Close the archive so Windows doesn't choke.
|
2013-07-31 15:44:43 +00:00
|
|
|
mArchive = nullptr;
|
2011-01-07 18:55:14 +00:00
|
|
|
zipW->Close();
|
2011-01-20 21:40:45 +00:00
|
|
|
|
2012-10-11 08:17:15 +00:00
|
|
|
// We succesfully wrote the archive to disk; mark the disk file as trusted
|
|
|
|
gIgnoreDiskCache = false;
|
|
|
|
|
2012-02-22 19:03:52 +00:00
|
|
|
// Our reader's view of the archive is outdated now, reload it.
|
2012-02-22 19:07:18 +00:00
|
|
|
LoadArchive(gPostFlushAgeAction);
|
2010-08-12 19:37:44 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StartupCache::InvalidateCache()
|
|
|
|
{
|
2011-01-20 21:40:45 +00:00
|
|
|
WaitOnWriteThread();
|
2010-08-12 19:37:44 +00:00
|
|
|
mTable.Clear();
|
2013-07-31 15:44:43 +00:00
|
|
|
mArchive = nullptr;
|
2012-10-11 08:17:15 +00:00
|
|
|
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;
|
2012-10-11 08:50:41 +00:00
|
|
|
mozilla::Telemetry::Accumulate(Telemetry::STARTUP_CACHE_INVALID, true);
|
2012-10-11 08:17:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
gIgnoreDiskCache = false;
|
2012-02-22 19:07:18 +00:00
|
|
|
LoadArchive(gPostFlushAgeAction);
|
2010-08-12 19:37:44 +00:00
|
|
|
}
|
|
|
|
|
2012-10-11 08:17:15 +00:00
|
|
|
void
|
|
|
|
StartupCache::IgnoreDiskCache()
|
|
|
|
{
|
|
|
|
gIgnoreDiskCache = true;
|
|
|
|
if (gStartupCache)
|
|
|
|
gStartupCache->InvalidateCache();
|
|
|
|
}
|
|
|
|
|
2011-01-20 21:40:45 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* main thread, the worker thread can also call WaitOnWriteThread() which is a no-op.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
StartupCache::WaitOnWriteThread()
|
|
|
|
{
|
2011-04-01 05:24:16 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Startup cache should only wait for io thread on main thread");
|
|
|
|
if (!mWriteThread || mWriteThread == PR_GetCurrentThread())
|
2011-01-20 21:40:45 +00:00
|
|
|
return;
|
|
|
|
|
2011-04-01 05:24:16 +00:00
|
|
|
PR_JoinThread(mWriteThread);
|
2013-07-31 15:44:43 +00:00
|
|
|
mWriteThread = nullptr;
|
2011-01-20 21:40:45 +00:00
|
|
|
}
|
|
|
|
|
2013-11-25 23:57:40 +00:00
|
|
|
void
|
2011-01-20 21:40:45 +00:00
|
|
|
StartupCache::ThreadedWrite(void *aClosure)
|
|
|
|
{
|
2012-06-12 17:06:20 +00:00
|
|
|
PR_SetCurrentThreadName("StartupCache");
|
2014-04-09 04:57:52 +00:00
|
|
|
mozilla::IOInterposer::RegisterCurrentThread();
|
2014-01-11 00:16:25 +00:00
|
|
|
/*
|
|
|
|
* It is safe to use the pointer passed in aClosure to reference the
|
|
|
|
* StartupCache object because the thread's lifetime is tightly coupled to
|
|
|
|
* the lifetime of the StartupCache object; this thread is joined in the
|
|
|
|
* StartupCache destructor, guaranteeing that this function runs if and only
|
|
|
|
* if the StartupCache object is valid.
|
|
|
|
*/
|
|
|
|
StartupCache* startupCacheObj = static_cast<StartupCache*>(aClosure);
|
|
|
|
startupCacheObj->WriteToDisk();
|
2014-04-09 04:57:52 +00:00
|
|
|
mozilla::IOInterposer::UnregisterCurrentThread();
|
2011-01-20 21:40:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The write-thread is spawned on a timeout(which is reset with every write). This
|
|
|
|
* can avoid a slow shutdown. After writing out the cache, the zipreader is
|
|
|
|
* reloaded on the worker thread.
|
|
|
|
*/
|
2010-08-12 19:37:44 +00:00
|
|
|
void
|
|
|
|
StartupCache::WriteTimeout(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
2014-01-11 00:16:25 +00:00
|
|
|
/*
|
|
|
|
* It is safe to use the pointer passed in aClosure to reference the
|
|
|
|
* StartupCache object because the timer's lifetime is tightly coupled to
|
|
|
|
* the lifetime of the StartupCache object; this timer is canceled in the
|
|
|
|
* StartupCache destructor, guaranteeing that this function runs if and only
|
|
|
|
* if the StartupCache object is valid.
|
|
|
|
*/
|
|
|
|
StartupCache* startupCacheObj = static_cast<StartupCache*>(aClosure);
|
|
|
|
startupCacheObj->mWriteThread = PR_CreateThread(PR_USER_THREAD,
|
|
|
|
StartupCache::ThreadedWrite,
|
|
|
|
startupCacheObj,
|
|
|
|
PR_PRIORITY_NORMAL,
|
2014-04-04 02:29:40 +00:00
|
|
|
PR_GLOBAL_THREAD,
|
2014-01-11 00:16:25 +00:00
|
|
|
PR_JOINABLE_THREAD,
|
|
|
|
0);
|
2010-08-12 19:37:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We don't want to refcount StartupCache, so we'll just
|
|
|
|
// hold a ref to this and pass it to observerService instead.
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(StartupCacheListener, nsIObserver)
|
2010-08-12 19:37:44 +00:00
|
|
|
|
|
|
|
nsresult
|
2014-01-04 15:02:17 +00:00
|
|
|
StartupCacheListener::Observe(nsISupports *subject, const char* topic, const char16_t* data)
|
2010-08-12 19:37:44 +00:00
|
|
|
{
|
2011-01-20 21:40:45 +00:00
|
|
|
StartupCache* sc = StartupCache::GetSingleton();
|
|
|
|
if (!sc)
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-08-12 19:37:44 +00:00
|
|
|
if (strcmp(topic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
|
2011-01-20 21:40:45 +00:00
|
|
|
// Do not leave the thread running past xpcom shutdown
|
|
|
|
sc->WaitOnWriteThread();
|
2011-10-17 14:59:28 +00:00
|
|
|
StartupCache::gShutdownInitiated = true;
|
2010-09-15 00:39:07 +00:00
|
|
|
} else if (strcmp(topic, "startupcache-invalidate") == 0) {
|
2011-01-20 21:40:45 +00:00
|
|
|
sc->InvalidateCache();
|
2010-08-12 19:37:44 +00:00
|
|
|
}
|
2011-01-20 21:40:45 +00:00
|
|
|
return NS_OK;
|
2010-08-12 19:37:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
StartupCache::GetDebugObjectOutputStream(nsIObjectOutputStream* aStream,
|
|
|
|
nsIObjectOutputStream** aOutStream)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aStream);
|
|
|
|
#ifdef DEBUG
|
|
|
|
StartupCacheDebugOutputStream* stream
|
|
|
|
= new StartupCacheDebugOutputStream(aStream, &mWriteObjectMap);
|
|
|
|
NS_ADDREF(*aOutStream = stream);
|
|
|
|
#else
|
|
|
|
NS_ADDREF(*aOutStream = aStream);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-07 18:55:14 +00:00
|
|
|
nsresult
|
|
|
|
StartupCache::ResetStartupWriteTimer()
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
mStartupWriteInitiated = false;
|
2011-01-07 18:55:14 +00:00
|
|
|
nsresult rv;
|
|
|
|
if (!mTimer)
|
|
|
|
mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
|
|
|
|
else
|
|
|
|
rv = mTimer->Cancel();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// Wait for 10 seconds, then write out the cache.
|
|
|
|
mTimer->InitWithFuncCallback(StartupCache::WriteTimeout, this, 60000,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-22 19:07:18 +00:00
|
|
|
nsresult
|
|
|
|
StartupCache::RecordAgesAlways()
|
|
|
|
{
|
|
|
|
gPostFlushAgeAction = RECORD_AGE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-12 19:37:44 +00:00
|
|
|
// StartupCacheDebugOutputStream implementation
|
|
|
|
#ifdef DEBUG
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(StartupCacheDebugOutputStream, nsIObjectOutputStream,
|
|
|
|
nsIBinaryOutputStream, nsIOutputStream)
|
2010-08-12 19:37:44 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-08-12 19:37:44 +00:00
|
|
|
StartupCacheDebugOutputStream::CheckReferences(nsISupports* aObject)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIClassInfo> classInfo = do_QueryInterface(aObject);
|
|
|
|
if (!classInfo) {
|
|
|
|
NS_ERROR("aObject must implement nsIClassInfo");
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-08-12 19:37:44 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t flags;
|
2010-08-12 19:37:44 +00:00
|
|
|
rv = classInfo->GetFlags(&flags);
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2010-08-12 19:37:44 +00:00
|
|
|
if (flags & nsIClassInfo::SINGLETON)
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-08-12 19:37:44 +00:00
|
|
|
|
|
|
|
nsISupportsHashKey* key = mObjectMap->GetEntry(aObject);
|
|
|
|
if (key) {
|
|
|
|
NS_ERROR("non-singleton aObject is referenced multiple times in this"
|
|
|
|
"serialization, we don't support that.");
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-08-12 19:37:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mObjectMap->PutEntry(aObject);
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-08-12 19:37:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIObjectOutputStream implementation
|
|
|
|
nsresult
|
2011-09-29 06:19:26 +00:00
|
|
|
StartupCacheDebugOutputStream::WriteObject(nsISupports* aObject, bool aIsStrongRef)
|
2010-08-12 19:37:44 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> rootObject(do_QueryInterface(aObject));
|
|
|
|
|
|
|
|
NS_ASSERTION(rootObject.get() == aObject,
|
|
|
|
"bad call to WriteObject -- call WriteCompoundObject!");
|
2011-09-29 06:19:26 +00:00
|
|
|
bool check = CheckReferences(aObject);
|
2010-08-12 19:37:44 +00:00
|
|
|
NS_ENSURE_TRUE(check, NS_ERROR_FAILURE);
|
|
|
|
return mBinaryStream->WriteObject(aObject, aIsStrongRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
StartupCacheDebugOutputStream::WriteSingleRefObject(nsISupports* aObject)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> rootObject(do_QueryInterface(aObject));
|
|
|
|
|
|
|
|
NS_ASSERTION(rootObject.get() == aObject,
|
|
|
|
"bad call to WriteSingleRefObject -- call WriteCompoundObject!");
|
2011-09-29 06:19:26 +00:00
|
|
|
bool check = CheckReferences(aObject);
|
2010-08-12 19:37:44 +00:00
|
|
|
NS_ENSURE_TRUE(check, NS_ERROR_FAILURE);
|
|
|
|
return mBinaryStream->WriteSingleRefObject(aObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
StartupCacheDebugOutputStream::WriteCompoundObject(nsISupports* aObject,
|
|
|
|
const nsIID& aIID,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aIsStrongRef)
|
2010-08-12 19:37:44 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> rootObject(do_QueryInterface(aObject));
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> roundtrip;
|
|
|
|
rootObject->QueryInterface(aIID, getter_AddRefs(roundtrip));
|
|
|
|
NS_ASSERTION(roundtrip.get() == aObject,
|
|
|
|
"bad aggregation or multiple inheritance detected by call to "
|
|
|
|
"WriteCompoundObject!");
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool check = CheckReferences(aObject);
|
2010-08-12 19:37:44 +00:00
|
|
|
NS_ENSURE_TRUE(check, NS_ERROR_FAILURE);
|
|
|
|
return mBinaryStream->WriteCompoundObject(aObject, aIID, aIsStrongRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
StartupCacheDebugOutputStream::WriteID(nsID const& aID)
|
|
|
|
{
|
|
|
|
return mBinaryStream->WriteID(aID);
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
2012-08-22 15:56:38 +00:00
|
|
|
StartupCacheDebugOutputStream::GetBuffer(uint32_t aLength, uint32_t aAlignMask)
|
2010-08-12 19:37:44 +00:00
|
|
|
{
|
|
|
|
return mBinaryStream->GetBuffer(aLength, aAlignMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
StartupCacheDebugOutputStream::PutBuffer(char* aBuffer, uint32_t aLength)
|
2010-08-12 19:37:44 +00:00
|
|
|
{
|
|
|
|
mBinaryStream->PutBuffer(aBuffer, aLength);
|
|
|
|
}
|
|
|
|
#endif //DEBUG
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
StartupCacheWrapper* StartupCacheWrapper::gStartupCacheWrapper = nullptr;
|
2010-08-12 19:37:44 +00:00
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(StartupCacheWrapper, nsIStartupCache)
|
2010-08-12 19:37:44 +00:00
|
|
|
|
|
|
|
StartupCacheWrapper* StartupCacheWrapper::GetSingleton()
|
|
|
|
{
|
|
|
|
if (!gStartupCacheWrapper)
|
|
|
|
gStartupCacheWrapper = new StartupCacheWrapper();
|
|
|
|
|
|
|
|
NS_ADDREF(gStartupCacheWrapper);
|
|
|
|
return gStartupCacheWrapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
StartupCacheWrapper::GetBuffer(const char* id, char** outbuf, uint32_t* length)
|
2010-08-12 19:37:44 +00:00
|
|
|
{
|
|
|
|
StartupCache* sc = StartupCache::GetSingleton();
|
|
|
|
if (!sc) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
return sc->GetBuffer(id, outbuf, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
StartupCacheWrapper::PutBuffer(const char* id, const char* inbuf, uint32_t length)
|
2010-08-12 19:37:44 +00:00
|
|
|
{
|
|
|
|
StartupCache* sc = StartupCache::GetSingleton();
|
|
|
|
if (!sc) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
return sc->PutBuffer(id, inbuf, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
StartupCacheWrapper::InvalidateCache()
|
|
|
|
{
|
|
|
|
StartupCache* sc = StartupCache::GetSingleton();
|
|
|
|
if (!sc) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
sc->InvalidateCache();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-11 08:17:15 +00:00
|
|
|
nsresult
|
|
|
|
StartupCacheWrapper::IgnoreDiskCache()
|
|
|
|
{
|
|
|
|
StartupCache::IgnoreDiskCache();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-12 19:37:44 +00:00
|
|
|
nsresult
|
|
|
|
StartupCacheWrapper::GetDebugObjectOutputStream(nsIObjectOutputStream* stream,
|
|
|
|
nsIObjectOutputStream** outStream)
|
|
|
|
{
|
|
|
|
StartupCache* sc = StartupCache::GetSingleton();
|
|
|
|
if (!sc) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
return sc->GetDebugObjectOutputStream(stream, outStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-29 06:19:26 +00:00
|
|
|
StartupCacheWrapper::StartupWriteComplete(bool *complete)
|
2011-01-07 18:55:14 +00:00
|
|
|
{
|
2010-08-12 19:37:44 +00:00
|
|
|
StartupCache* sc = StartupCache::GetSingleton();
|
|
|
|
if (!sc) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
2011-01-20 21:40:45 +00:00
|
|
|
sc->WaitOnWriteThread();
|
2010-08-12 19:37:44 +00:00
|
|
|
*complete = sc->mStartupWriteInitiated && sc->mTable.Count() == 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
StartupCacheWrapper::ResetStartupWriteTimer()
|
|
|
|
{
|
|
|
|
StartupCache* sc = StartupCache::GetSingleton();
|
2011-01-07 18:55:14 +00:00
|
|
|
return sc ? sc->ResetStartupWriteTimer() : NS_ERROR_NOT_INITIALIZED;
|
2010-08-12 19:37:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
StartupCacheWrapper::GetObserver(nsIObserver** obv) {
|
|
|
|
StartupCache* sc = StartupCache::GetSingleton();
|
|
|
|
if (!sc) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
NS_ADDREF(*obv = sc->mListener);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-22 19:07:18 +00:00
|
|
|
nsresult
|
|
|
|
StartupCacheWrapper::RecordAgesAlways() {
|
|
|
|
StartupCache *sc = StartupCache::GetSingleton();
|
|
|
|
return sc ? sc->RecordAgesAlways() : NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2010-08-12 19:37:44 +00:00
|
|
|
} // namespace scache
|
|
|
|
} // namespace mozilla
|