Bug 1371882 - MediaCache::Flush reinitializes block cache instead of recreating it - r?cpearce draft
authorGerald Squelart <gsquelart@mozilla.com>
Thu, 15 Jun 2017 16:12:30 +1200
changeset 595167 38054b35434d5f77a17fe4273ef626228486e117
parent 595166 80cd4f7e6c13c04eec2e6ef7e1fb394c7701d2cb
child 595168 6da7c3e9504cd58c6d3afc656ae58b9ab445db5e
push id64265
push usergsquelart@mozilla.com
push dateFri, 16 Jun 2017 03:37:56 +0000
reviewerscpearce
bugs1371882
milestone56.0a1
Bug 1371882 - MediaCache::Flush reinitializes block cache instead of recreating it - r?cpearce This saves from destruction&re-construction efforts, makes the flushing less prone to first-initialization failures. And it will allow moving the choice of block cache outside of MediaCache::Init. MozReview-Commit-ID: 8vSunM3rRkL
dom/media/MediaCache.cpp
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -698,21 +698,22 @@ MediaCache::Flush()
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
   ReentrantMonitorAutoEnter mon(mReentrantMonitor);
 
   for (uint32_t blockIndex = 0; blockIndex < mIndex.Length(); ++blockIndex) {
     FreeBlock(blockIndex);
   }
 
-  // Truncate file, close it, and reopen
+  // Truncate index array.
   Truncate();
   NS_ASSERTION(mIndex.Length() == 0, "Blocks leaked?");
-  mBlockCache = nullptr;
-  Init();
+  // Re-initialize block cache.
+  nsresult rv = mBlockCache->Init();
+  NS_ENSURE_SUCCESS_VOID(rv);
 }
 
 void
 MediaCache::CloseStreamsForPrivateBrowsing()
 {
   MOZ_ASSERT(NS_IsMainThread());
   for (MediaCacheStream* s : mStreams) {
     if (s->mIsPrivateBrowsing) {