Bug 1398659. P1 - tighten up the assertions in InitAsClone().
We also make it return void since it now always succeeds.
MozReview-Commit-ID: H1oQWoguEzF
--- 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).