Bug 1371882 - Rename MediaCache::mFileCache to mBlockCache - r?cpearce draft
authorGerald Squelart <gsquelart@mozilla.com>
Wed, 14 Jun 2017 17:01:46 +1200
changeset 595159 eb59cf2b0424123e68acfdb7d0c0de6f701e2ea8
parent 595158 87b067ce2b9793f896880da4cfaf8624214ddd92
child 595160 6fb8b5d967dc21b6ae7a6489f287508f0b3fed35
push id64265
push usergsquelart@mozilla.com
push dateFri, 16 Jun 2017 03:37:56 +0000
reviewerscpearce
bugs1371882
milestone56.0a1
Bug 1371882 - Rename MediaCache::mFileCache to mBlockCache - r?cpearce Because blocks may not necessarily be held in files anymore. MozReview-Commit-ID: 2GNc7B5w2Jt
dom/media/MediaCache.cpp
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -271,19 +271,19 @@ protected:
   }
 
   ~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;
+    if (mBlockCache) {
+      mBlockCache->Close();
+      mBlockCache = 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",
@@ -411,17 +411,17 @@ protected:
   nsTArray<MediaCacheStream*> mStreams;
   // The Blocks describing the cache entries.
   nsTArray<Block> mIndex;
   // Keep track for highest number of blocks used, for telemetry purposes.
   int32_t mIndexWatermark = 0;
   // Keep track for highest number of blocks owners, for telemetry purposes.
   uint32_t mBlockOwnersWatermark = 0;
   // Writer which performs IO, asynchronously writing cache blocks.
-  RefPtr<MediaBlockCacheBase> mFileCache;
+  RefPtr<MediaBlockCacheBase> mBlockCache;
   // The list of free blocks; they are not ordered.
   BlockList       mFreeBlocks;
   // True if an event to run Update() has been queued but not processed
   bool            mUpdateQueued;
   // Main-thread only. True when shutting down, and the update task should
   // destroy this MediaCache.
   bool            mShutdownInsteadOfUpdating;
 #ifdef DEBUG
@@ -658,20 +658,20 @@ MediaCacheStream::BlockList::NotifyBlock
     e2->mPrevBlock = e2Prev;
   }
 }
 
 nsresult
 MediaCache::Init()
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
-  NS_ASSERTION(!mFileCache, "Cache file already open?");
+  NS_ASSERTION(!mBlockCache, "Block cache already open?");
 
-  mFileCache = new FileBlockCache();
-  nsresult rv = mFileCache->Init();
+  mBlockCache = new FileBlockCache();
+  nsresult rv = mBlockCache->Init();
   NS_ENSURE_SUCCESS(rv,rv);
 
   return NS_OK;
 }
 
 void
 MediaCache::Flush()
 {
@@ -680,19 +680,19 @@ MediaCache::Flush()
 
   for (uint32_t blockIndex = 0; blockIndex < mIndex.Length(); ++blockIndex) {
     FreeBlock(blockIndex);
   }
 
   // Truncate file, close it, and reopen
   Truncate();
   NS_ASSERTION(mIndex.Length() == 0, "Blocks leaked?");
-  if (mFileCache) {
-    mFileCache->Close();
-    mFileCache = nullptr;
+  if (mBlockCache) {
+    mBlockCache->Close();
+    mBlockCache = nullptr;
   }
   Init();
 }
 
 void
 MediaCache::CloseStreamsForPrivateBrowsing()
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -771,26 +771,26 @@ MediaCache::GetMediaCache(int64_t aConte
   return gMediaCache;
 }
 
 nsresult
 MediaCache::ReadCacheFile(
   int64_t aOffset, void* aData, int32_t aLength, int32_t* aBytes)
 {
   mReentrantMonitor.AssertCurrentThreadIn();
-  RefPtr<MediaBlockCacheBase> fileCache = mFileCache;
-  if (!fileCache) {
+  RefPtr<MediaBlockCacheBase> blockCache = mBlockCache;
+  if (!blockCache) {
     return NS_ERROR_FAILURE;
   }
   {
     // Since the monitor might be acquired on the main thread, we need to drop
     // the monitor while doing IO in order not to block the main thread.
     ReentrantMonitorAutoExit unlock(mReentrantMonitor);
-    return fileCache->Read(aOffset,
-      reinterpret_cast<uint8_t*>(aData), aLength, aBytes);
+    return blockCache->Read(
+      aOffset, reinterpret_cast<uint8_t*>(aData), aLength, aBytes);
   }
 }
 
 static int32_t GetMaxBlocks()
 {
   // We look up the cache size every time. This means dynamic changes
   // to the pref are applied.
   // Cache size is in KB
@@ -1220,17 +1220,17 @@ MediaCache::Update()
         break;
       }
 
       if (IsBlockFree(destinationBlockIndex) ||
           PredictNextUse(now, destinationBlockIndex) > latestPredictedUseForOverflow) {
         // Reuse blocks in the main part of the cache that are less useful than
         // the least useful overflow blocks
 
-        nsresult rv = mFileCache->MoveBlock(blockIndex, destinationBlockIndex);
+        nsresult rv = mBlockCache->MoveBlock(blockIndex, destinationBlockIndex);
 
         if (NS_SUCCEEDED(rv)) {
           // We successfully copied the file data.
           LOG("Swapping blocks %d and %d (trimming cache)",
               blockIndex, destinationBlockIndex);
           // Swapping the block metadata here lets us maintain the
           // correct positions in the linked lists
           SwapBlocks(blockIndex, destinationBlockIndex);
@@ -1680,17 +1680,17 @@ MediaCache::AllocateAndWriteBlock(
       }
     }
 
     // Invariant: block->mOwners.IsEmpty() iff we can find an entry
     // in mFreeBlocks for a given blockIndex.
     MOZ_DIAGNOSTIC_ASSERT(!block->mOwners.IsEmpty());
     mFreeBlocks.RemoveBlock(blockIndex);
 
-    nsresult rv = mFileCache->WriteBlock(blockIndex, aData1, aData2);
+    nsresult rv = mBlockCache->WriteBlock(blockIndex, aData1, aData2);
     if (NS_FAILED(rv)) {
       LOG("Released block %d from stream %p block %d(%" PRId64 ")",
           blockIndex, aStream, streamBlockIndex, streamBlockIndex*BLOCK_SIZE);
       FreeBlock(blockIndex);
     }
   }
 
   // Queue an Update since the cache state has changed (for example