From b8f562f05e976130cae4c3a5e28e0f8f1b266e86 Mon Sep 17 00:00:00 2001 From: JW Wang Date: Tue, 5 Sep 2017 17:28:14 +0800 Subject: [PATCH] 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 --HG-- extra : rebase_source : b5c6714832bed6fceb80c4afcdf4a590cc7dc567 extra : intermediate-source : 01aa9da848391bbf0b39f8dca874c0234f3202fb extra : source : af04510d8603ffe407069ef342fdb4d3bca33509 --- dom/media/MediaCache.cpp | 14 ++++---------- dom/media/MediaCache.h | 6 +++--- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/dom/media/MediaCache.cpp b/dom/media/MediaCache.cpp index 9c5b0db327ff..ce87c17a05c8 100644 --- a/dom/media/MediaCache.cpp +++ b/dom/media/MediaCache.cpp @@ -2561,17 +2561,13 @@ MediaCacheStream::Init(int64_t aContentLength) 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; @@ -2609,8 +2605,6 @@ MediaCacheStream::InitAsClone(MediaCacheStream* aOriginal) // stream offset is zero mMediaCache->AddBlockOwnerAsReadahead(cacheBlockIndex, this, i); } - - return NS_OK; } nsresult MediaCacheStream::GetCachedRanges(MediaByteRangeSet& aRanges) diff --git a/dom/media/MediaCache.h b/dom/media/MediaCache.h index 90c2962a32b5..486dd6899022 100644 --- a/dom/media/MediaCache.h +++ b/dom/media/MediaCache.h @@ -205,10 +205,10 @@ public: 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