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 593027 a52e16c02b50e12772ae3f9b2685e565471f6b1b
parent 593026 2b5f8fd564b585d8910e31e9ae01ee80b8eec820
child 593028 25bb88fe1875c48e03dde44c5ae16eec93fdbbc0
child 593062 3f9a29cafcb18ca18af5a23feae05b8fc3b98d52
push id63579
push usergsquelart@mozilla.com
push dateTue, 13 Jun 2017 05:16:04 +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);
@@ -378,16 +373,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 shared 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;
@@ -411,16 +409,18 @@ 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;
 };
 
+/* 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();