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

--HG--
extra : rebase_source : 8693264a4347938dde6532730a5bc730384edf51
This commit is contained in:
Nicholas Nethercote 2013-11-25 15:57:40 -08:00
parent e5c372ab44
commit 965e0bfae1
2 changed files with 14 additions and 12 deletions

View File

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

View File

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