Bug 1371882 - Make gMediaCache private inside MediaCache, to avoid misuse - r=cpearce
MozReview-Commit-ID: 6MyKmG7DNaG
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -57,21 +57,16 @@ static const uint32_t REPLAY_PENALTY_FAC
// can.
static const uint32_t FREE_BLOCK_SCAN_LIMIT = 16;
#ifdef DEBUG
// Turn this on to do very expensive cache state validation
// #define DEBUG_VERIFY_CACHE
#endif
-// There is at most one media cache (although that could quite easily be
-// relaxed if we wanted to manage multiple caches with independent
-// size limits).
-static MediaCache* gMediaCache;
-
class MediaCacheFlusher final : public nsIObserver,
public nsSupportsWeakReference
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
static void RegisterMediaCache(MediaCache* aMediaCache);
@@ -388,16 +383,19 @@ protected:
// end
void Truncate();
// Shutdown this MediaCache, and reset gMediaCache if we are the global one.
// If there is no queued update, destroy the MediaCache immediately.
// Otherwise when the update is processed, it will destroy the MediaCache.
void ShutdownAndDestroyThis();
+ // There is at most one file-backed media cache.
+ static MediaCache* gMediaCache;
+
// This member is main-thread only. It's used to allocate unique
// resource IDs to streams.
int64_t mNextResourceID;
// The monitor protects all the data members here. Also, off-main-thread
// readers that need to block will Wait() on this monitor. When new
// data becomes available in the cache, we NotifyAll() on this monitor.
ReentrantMonitor mReentrantMonitor;
@@ -421,16 +419,19 @@ protected:
bool mShutdownInsteadOfUpdating;
#ifdef DEBUG
bool mInUpdate;
#endif
// A list of resource IDs to notify about the change in suspended status.
nsTArray<int64_t> mSuspendedStatusToNotify;
};
+// Initialized to nullptr by non-local static initialization.
+/* static */ MediaCache* MediaCache::gMediaCache;
+
NS_IMETHODIMP
MediaCacheFlusher::Observe(nsISupports *aSubject, char const *aTopic, char16_t const *aData)
{
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
if (strcmp(aTopic, "last-pb-context-exited") == 0) {
for (MediaCache* mc : mMediaCaches) {
mc->CloseStreamsForPrivateBrowsing();