Bug 1371882 - MediaCache::constructor/destructor/Init() don't need to be public - r=cpearce draft
authorGerald Squelart <gsquelart@mozilla.com>
Fri, 09 Jun 2017 12:53:11 +1200
changeset 595148 d1116e03d4bbef1c6bd1a6be676eb89605a78494
parent 595147 0b3e6fae71207076812b5cb9172d4497d3e68ea2
child 595149 a4eaadb9c4bd40034e16a811878cf7663b6a66ce
push id64265
push usergsquelart@mozilla.com
push dateFri, 16 Jun 2017 03:37:56 +0000
reviewerscpearce
bugs1371882
milestone56.0a1
Bug 1371882 - MediaCache::constructor/destructor/Init() don't need to be public - r=cpearce MozReview-Commit-ID: 9naYvPbGn14
dom/media/MediaCache.cpp
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -128,57 +128,20 @@ MediaCacheFlusher::UnregisterMediaCache(
 }
 
 class MediaCache {
 public:
   friend class MediaCacheStream::BlockList;
   typedef MediaCacheStream::BlockList BlockList;
   static const int64_t BLOCK_SIZE = MediaCacheStream::BLOCK_SIZE;
 
-  MediaCache() : mNextResourceID(1),
-    mReentrantMonitor("MediaCache.mReentrantMonitor"),
-    mUpdateQueued(false)
-#ifdef DEBUG
-    , mInUpdate(false)
-#endif
-  {
-    MOZ_COUNT_CTOR(MediaCache);
-    MediaCacheFlusher::RegisterMediaCache(this);
-  }
-  ~MediaCache() {
-    MediaCacheFlusher::UnregisterMediaCache(this);
-    NS_ASSERTION(mStreams.IsEmpty(), "Stream(s) still open!");
-    Truncate();
-    NS_ASSERTION(mIndex.Length() == 0, "Blocks leaked?");
-    if (mFileCache) {
-      mFileCache->Close();
-      mFileCache = nullptr;
-    }
-    LOG("MediaCache::~MediaCache(this=%p) MEDIACACHE_WATERMARK_KB=%u",
-        this, unsigned(mIndexWatermark * MediaCache::BLOCK_SIZE / 1024));
-    Telemetry::Accumulate(
-      Telemetry::HistogramID::MEDIACACHE_WATERMARK_KB,
-      uint32_t(mIndexWatermark * MediaCache::BLOCK_SIZE / 1024));
-    LOG("MediaCache::~MediaCache(this=%p) MEDIACACHE_BLOCKOWNERS_WATERMARK=%u",
-        this, unsigned(mBlockOwnersWatermark));
-    Telemetry::Accumulate(
-      Telemetry::HistogramID::MEDIACACHE_BLOCKOWNERS_WATERMARK,
-      mBlockOwnersWatermark);
-
-    MOZ_COUNT_DTOR(MediaCache);
-  }
-
   // Get an instance of the file-backed MediaCache.
   // Returns nullptr if initialization failed.
   static MediaCache* GetMediaCache();
 
-  // Main thread only. Creates the backing cache file. If this fails,
-  // then the cache is still in a semi-valid state; mFD will be null,
-  // so all I/O on the cache file will fail.
-  nsresult Init();
   // Shut down the global cache if it's no longer needed. We shut down
   // the cache as soon as there are no streams. This means that during
   // normal operation we are likely to start up the cache and shut it down
   // many times, but that's OK since starting it up is cheap and
   // shutting it down cleans things up and releases disk space.
   void MaybeShutdown();
 
   // Brutally flush the cache contents. Main thread only.
@@ -287,16 +250,59 @@ public:
     }
   private:
     MediaCache* mMediaCache;
     int64_t  mResourceID;
     uint32_t mNext;
   };
 
 protected:
+  MediaCache()
+    : mNextResourceID(1)
+    , mReentrantMonitor("MediaCache.mReentrantMonitor")
+    , mUpdateQueued(false)
+#ifdef DEBUG
+    , mInUpdate(false)
+#endif
+  {
+    MOZ_COUNT_CTOR(MediaCache);
+    MediaCacheFlusher::RegisterMediaCache(this);
+  }
+
+  ~MediaCache()
+  {
+    MediaCacheFlusher::UnregisterMediaCache(this);
+    NS_ASSERTION(mStreams.IsEmpty(), "Stream(s) still open!");
+    Truncate();
+    NS_ASSERTION(mIndex.Length() == 0, "Blocks leaked?");
+    if (mFileCache) {
+      mFileCache->Close();
+      mFileCache = nullptr;
+    }
+    LOG("MediaCache::~MediaCache(this=%p) MEDIACACHE_WATERMARK_KB=%u",
+        this,
+        unsigned(mIndexWatermark * MediaCache::BLOCK_SIZE / 1024));
+    Telemetry::Accumulate(
+      Telemetry::HistogramID::MEDIACACHE_WATERMARK_KB,
+      uint32_t(mIndexWatermark * MediaCache::BLOCK_SIZE / 1024));
+    LOG("MediaCache::~MediaCache(this=%p) MEDIACACHE_BLOCKOWNERS_WATERMARK=%u",
+        this,
+        unsigned(mBlockOwnersWatermark));
+    Telemetry::Accumulate(
+      Telemetry::HistogramID::MEDIACACHE_BLOCKOWNERS_WATERMARK,
+      mBlockOwnersWatermark);
+
+    MOZ_COUNT_DTOR(MediaCache);
+  }
+
+  // Main thread only. Creates the backing cache file. If this fails,
+  // then the cache is still in a semi-valid state; mFD will be null,
+  // so all I/O on the cache file will fail.
+  nsresult Init();
+
   // Find a free or reusable block and return its index. If there are no
   // free blocks and no reusable blocks, add a new block to the cache
   // and return it. Can return -1 on OOM.
   int32_t FindBlockForIncomingData(TimeStamp aNow, MediaCacheStream* aStream);
   // Find a reusable block --- a free block, if there is one, otherwise
   // the reusable block with the latest predicted-next-use, or -1 if
   // there aren't any freeable blocks. Only block indices less than
   // aMaxSearchBlockIndex are considered. If aForStream is non-null,