Bug 936964 (part 1, attempt 2) - Make StartupCache ref-counted. r=aklotz.

--HG--
extra : rebase_source : d04b799a861c155b89b8dcf9f328ef7a9bfef097
This commit is contained in:
Nicholas Nethercote 2013-11-25 15:57:40 -08:00
parent 374aa9dfb5
commit 2e64f44ecb
2 changed files with 14 additions and 12 deletions

View File

@ -110,7 +110,6 @@ StartupCache::GetSingleton()
void
StartupCache::DeleteSingleton()
{
delete StartupCache::gStartupCache;
StartupCache::gStartupCache = nullptr;
}
@ -122,17 +121,18 @@ StartupCache::InitSingleton()
rv = StartupCache::gStartupCache->Init();
if (NS_FAILED(rv)) {
delete StartupCache::gStartupCache;
StartupCache::gStartupCache = nullptr;
}
return rv;
}
StartupCache* StartupCache::gStartupCache;
StaticRefPtr<StartupCache> StartupCache::gStartupCache;
bool StartupCache::gShutdownInitiated;
bool StartupCache::gIgnoreDiskCache;
enum StartupCache::TelemetrifyAge StartupCache::gPostFlushAgeAction = StartupCache::IGNORE_AGE;
NS_IMPL_ISUPPORTS1(StartupCache, nsISupports)
StartupCache::StartupCache()
: mArchive(nullptr), mStartupWriteInitiated(false), mWriteThread(nullptr)
{ }
@ -156,7 +156,6 @@ StartupCache::~StartupCache()
WriteToDisk();
}
gStartupCache = nullptr;
NS_UnregisterMemoryReporter(mMappingReporter);
NS_UnregisterMemoryReporter(mDataReporter);
}
@ -543,7 +542,7 @@ StartupCache::WaitOnWriteThread()
mWriteThread = nullptr;
}
void
void
StartupCache::ThreadedWrite(void *aClosure)
{
PR_SetCurrentThreadName("StartupCache");

View File

@ -17,6 +17,7 @@
#include "nsIFile.h"
#include "mozilla/Attributes.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/StaticPtr.h"
class nsIMemoryReporter;
@ -67,9 +68,10 @@ class nsIMemoryReporter;
*/
namespace mozilla {
namespace scache {
struct CacheEntry
struct CacheEntry
{
nsAutoArrayPtr<char> data;
uint32_t size;
@ -96,17 +98,18 @@ class StartupCacheListener MOZ_FINAL : public nsIObserver
NS_DECL_NSIOBSERVER
};
class StartupCache
class StartupCache : public nsISupports
{
friend class StartupCacheListener;
friend class StartupCacheWrapper;
public:
NS_DECL_ISUPPORTS
// StartupCache methods. See above comments for a more detailed description.
// Returns a buffer that was previously stored, caller takes ownership.
// Returns a buffer that was previously stored, caller takes ownership.
nsresult GetBuffer(const char* id, char** outbuf, uint32_t* length);
// Stores a buffer. Caller keeps ownership, we make a copy.
@ -136,7 +139,7 @@ public:
private:
StartupCache();
~StartupCache();
virtual ~StartupCache();
enum TelemetrifyAge {
IGNORE_AGE = 0,
@ -162,14 +165,14 @@ private:
nsClassHashtable<nsCStringHashKey, CacheEntry> mTable;
nsRefPtr<nsZipArchive> mArchive;
nsCOMPtr<nsIFile> mFile;
nsCOMPtr<nsIObserverService> mObserverService;
nsRefPtr<StartupCacheListener> mListener;
nsCOMPtr<nsITimer> mTimer;
bool mStartupWriteInitiated;
static StartupCache *gStartupCache;
static StaticRefPtr<StartupCache> gStartupCache;
static bool gShutdownInitiated;
static bool gIgnoreDiskCache;
PRThread *mWriteThread;