Bug 1398659. P1 - tighten up the assertions in InitAsClone(). r=gerald
authorJW Wang <jwwang@mozilla.com>
Tue, 05 Sep 2017 17:28:14 +0800
changeset 429484 3563eaa019d3eefc8cdca9ba839a4ecbd39ef9d0
parent 429483 4aac84ba2f8e08c806fe5c3a9e1e8a429fa4cc7c
child 429485 3928ea56c1d334d0b5e550639004bec6a6b27dda
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1398659
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1398659. P1 - tighten up the assertions in InitAsClone(). r=gerald We also make it return void since it now always succeeds. MozReview-Commit-ID: H1oQWoguEzF
dom/media/MediaCache.cpp
dom/media/MediaCache.h
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -2556,27 +2556,23 @@ MediaCacheStream::Init(int64_t aContentL
   mMediaCache = MediaCache::GetMediaCache(aContentLength);
   if (!mMediaCache) {
     return NS_ERROR_FAILURE;
   }
   mMediaCache->OpenStream(this);
   return NS_OK;
 }
 
-nsresult
+void
 MediaCacheStream::InitAsClone(MediaCacheStream* aOriginal)
 {
-  if (!aOriginal->IsAvailableForSharing())
-    return NS_ERROR_FAILURE;
+  MOZ_ASSERT(aOriginal->IsAvailableForSharing());
+  MOZ_ASSERT(!mMediaCache, "Has been initialized.");
+  MOZ_ASSERT(aOriginal->mMediaCache, "Don't clone an uninitialized stream.");
 
-  if (mMediaCache) {
-    return NS_OK;
-  }
-
-  NS_ASSERTION(aOriginal->mMediaCache, "Don't clone an uninitialized stream");
   // Use the same MediaCache as our clone.
   mMediaCache = aOriginal->mMediaCache;
 
   mMediaCache->OpenStream(this);
 
   mResourceID = aOriginal->mResourceID;
 
   // Grab cache blocks from aOriginal as readahead blocks for our stream
@@ -2604,18 +2600,16 @@ MediaCacheStream::InitAsClone(MediaCache
 
     while (i >= mBlocks.Length()) {
       mBlocks.AppendElement(-1);
     }
     // Every block is a readahead block for the clone because the clone's initial
     // stream offset is zero
     mMediaCache->AddBlockOwnerAsReadahead(cacheBlockIndex, this, i);
   }
-
-  return NS_OK;
 }
 
 nsresult MediaCacheStream::GetCachedRanges(MediaByteRangeSet& aRanges)
 {
   // Take the monitor, so that the cached data ranges can't grow while we're
   // trying to loop over them.
   ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
 
--- a/dom/media/MediaCache.h
+++ b/dom/media/MediaCache.h
@@ -200,20 +200,20 @@ public:
 
   // Set up this stream with the cache. Can fail on OOM.
   // aContentLength is the content length if known, otherwise -1.
   // Exactly one of InitAsClone or Init must be called before any other method
   // on this class. Does nothing if already initialized.
   nsresult Init(int64_t aContentLength);
 
   // Set up this stream with the cache, assuming it's for the same data
-  // as the aOriginal stream. Can fail on OOM.
+  // as the aOriginal stream.
   // Exactly one of InitAsClone or Init must be called before any other method
-  // on this class. Does nothing if already initialized.
-  nsresult InitAsClone(MediaCacheStream* aOriginal);
+  // on this class.
+  void InitAsClone(MediaCacheStream* aOriginal);
 
   // These are called on the main thread.
   // Tell us whether the stream is seekable or not. Non-seekable streams
   // will always pass 0 for aOffset to CacheClientSeek. This should only
   // be called while the stream is at channel offset 0. Seekability can
   // change during the lifetime of the MediaCacheStream --- every time
   // we do an HTTP load the seekability may be different (and sometimes
   // is, in practice, due to the effects of caching proxies).