Bug 1371882 - Make gMediaCache private inside MediaCache, to avoid misuse - r=cpearce draft
authorGerald Squelart <gsquelart@mozilla.com>
Thu, 08 Jun 2017 17:12:13 +1200
changeset 595153 b567a13c9621a8a2e3302e1844fe9be21dbf193e
parent 595152 08553aded67b2954d2ba369fbffc056f7f1497d8
child 595154 09c1f126c7da491ed7db18c76fb397f7673e431c
push id64265
push usergsquelart@mozilla.com
push dateFri, 16 Jun 2017 03:37:56 +0000
reviewerscpearce
bugs1371882
milestone56.0a1
Bug 1371882 - Make gMediaCache private inside MediaCache, to avoid misuse - r=cpearce MozReview-Commit-ID: 6MyKmG7DNaG
dom/media/MediaCache.cpp
--- 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();