Bug 711297 - add recordAgesAlways method to nsIStartupCache; r=mwu
--- a/startupcache/StartupCache.cpp
+++ b/startupcache/StartupCache.cpp
@@ -149,16 +149,17 @@ StartupCache::InitSingleton()
delete StartupCache::gStartupCache;
StartupCache::gStartupCache = nsnull;
}
return rv;
}
StartupCache* StartupCache::gStartupCache;
bool StartupCache::gShutdownInitiated;
+enum StartupCache::TelemetrifyAge StartupCache::gPostFlushAgeAction = StartupCache::IGNORE_AGE;
StartupCache::StartupCache()
: mArchive(NULL), mStartupWriteInitiated(false), mWriteThread(NULL),
mMappingMemoryReporter(nsnull), mDataMemoryReporter(nsnull) { }
StartupCache::~StartupCache()
{
if (mTimer) {
@@ -489,29 +490,29 @@ StartupCache::WriteToDisk()
mTable.Enumerate(CacheCloseHelper, &holder);
// Close the archive so Windows doesn't choke.
mArchive = NULL;
zipW->Close();
// Our reader's view of the archive is outdated now, reload it.
- LoadArchive(IGNORE_AGE);
+ LoadArchive(gPostFlushAgeAction);
return;
}
void
StartupCache::InvalidateCache()
{
WaitOnWriteThread();
mTable.Clear();
mArchive = NULL;
mFile->Remove(false);
- LoadArchive(IGNORE_AGE);
+ LoadArchive(gPostFlushAgeAction);
}
/*
* 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
@@ -597,16 +598,23 @@ StartupCache::ResetStartupWriteTimer()
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;
}
+nsresult
+StartupCache::RecordAgesAlways()
+{
+ gPostFlushAgeAction = RECORD_AGE;
+ return NS_OK;
+}
+
// StartupCacheDebugOutputStream implementation
#ifdef DEBUG
NS_IMPL_ISUPPORTS3(StartupCacheDebugOutputStream, nsIObjectOutputStream,
nsIBinaryOutputStream, nsIOutputStream)
bool
StartupCacheDebugOutputStream::CheckReferences(nsISupports* aObject)
{
@@ -776,10 +784,16 @@ StartupCacheWrapper::GetObserver(nsIObse
StartupCache* sc = StartupCache::GetSingleton();
if (!sc) {
return NS_ERROR_NOT_INITIALIZED;
}
NS_ADDREF(*obv = sc->mListener);
return NS_OK;
}
+nsresult
+StartupCacheWrapper::RecordAgesAlways() {
+ StartupCache *sc = StartupCache::GetSingleton();
+ return sc ? sc->RecordAgesAlways() : NS_ERROR_NOT_INITIALIZED;
+}
+
} // namespace scache
} // namespace mozilla
--- a/startupcache/StartupCache.h
+++ b/startupcache/StartupCache.h
@@ -146,16 +146,18 @@ public:
// Removes the cache file.
void InvalidateCache();
// In DEBUG builds, returns a stream that will attempt to check for
// and disallow multiple writes of the same object.
nsresult GetDebugObjectOutputStream(nsIObjectOutputStream* aStream,
nsIObjectOutputStream** outStream);
+ nsresult RecordAgesAlways();
+
static StartupCache* GetSingleton();
static void DeleteSingleton();
// This measures all the heap memory used by the StartupCache, i.e. it
// excludes the mapping.
size_t HeapSizeOfIncludingThis(nsMallocSizeOfFun mallocSizeOf);
size_t SizeOfMapping();
@@ -163,16 +165,17 @@ public:
private:
StartupCache();
~StartupCache();
enum TelemetrifyAge {
IGNORE_AGE = 0,
RECORD_AGE = 1
};
+ static enum TelemetrifyAge gPostFlushAgeAction;
nsresult LoadArchive(enum TelemetrifyAge flag);
nsresult Init();
void WriteToDisk();
nsresult ResetStartupWriteTimer();
void WaitOnWriteThread();
static nsresult InitSingleton();
--- a/startupcache/nsIStartupCache.idl
+++ b/startupcache/nsIStartupCache.idl
@@ -37,17 +37,17 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsIInputStream.idl"
#include "nsISupports.idl"
#include "nsIObserver.idl"
#include "nsIObjectOutputStream.idl"
-[uuid(8c2a360b-e337-455b-8c1b-04265ef9c5a3)]
+[uuid(c1b3796b-33af-4ff0-b83d-8eb0ca2c080f)]
interface nsIStartupCache : nsISupports
{
/** This interface is provided for testing purposes only, basically
* just to solve link vagaries. See docs in StartupCache.h
* GetBuffer, PutBuffer, and InvalidateCache act as described
* in that file. */
@@ -65,12 +65,16 @@ interface nsIStartupCache : nsISupports
/* Allows clients to check whether the one-time writeout after startup
* has finished yet, and also to set this variable as needed (so test
* code can fire mulitple startup writes if needed).
*/
boolean startupWriteComplete();
void resetStartupWriteTimer();
+ /* Instruct clients to always post cache ages to Telemetry, even in
+ cases where it would not normally make sense. */
+ void recordAgesAlways();
+
/* Allows clients to simulate the behavior of ObserverService. */
readonly attribute nsIObserver observer;
};