From 6dcbfcbee7491190259799b3c7ef8d2f1fc85dcc Mon Sep 17 00:00:00 2001 From: JW Wang Date: Tue, 5 Sep 2017 17:39:57 +0800 Subject: [PATCH] Bug 1398659. P4 - remove unused code and add some assertions. r=gerald MozReview-Commit-ID: LRgF9qjdMXz --HG-- extra : rebase_source : af8b8bb4272c9be0f0ab8b51356362e9676c7076 extra : intermediate-source : 640d38acf9d3cf4aa583c67fc20ea487c849a570 extra : source : 0faec6a6b214ce4d5ca59ac2b098d4a5bfe4470b --- dom/media/ChannelMediaDecoder.cpp | 13 ++----------- dom/media/ChannelMediaDecoder.h | 1 - dom/media/MediaCache.cpp | 5 +---- dom/media/MediaResource.cpp | 26 ++++++++++---------------- 4 files changed, 13 insertions(+), 32 deletions(-) diff --git a/dom/media/ChannelMediaDecoder.cpp b/dom/media/ChannelMediaDecoder.cpp index b379e05df8fe..53b37647cd41 100644 --- a/dom/media/ChannelMediaDecoder.cpp +++ b/dom/media/ChannelMediaDecoder.cpp @@ -226,16 +226,6 @@ ChannelMediaDecoder::Shutdown() } } -nsresult -ChannelMediaDecoder::OpenResource(nsIStreamListener** aStreamListener) -{ - MOZ_ASSERT(NS_IsMainThread()); - if (aStreamListener) { - *aStreamListener = nullptr; - } - return mResource->Open(aStreamListener); -} - nsresult ChannelMediaDecoder::Load(nsIChannel* aChannel, bool aIsPrivateBrowsing, @@ -243,6 +233,7 @@ ChannelMediaDecoder::Load(nsIChannel* aChannel, { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(!mResource); + MOZ_ASSERT(aStreamListener); mResource = BaseMediaResource::Create(mResourceCallback, aChannel, aIsPrivateBrowsing); @@ -255,7 +246,7 @@ ChannelMediaDecoder::Load(nsIChannel* aChannel, return rv; } - rv = OpenResource(aStreamListener); + rv = mResource->Open(aStreamListener); NS_ENSURE_SUCCESS(rv, rv); // Set mode to METADATA since we are about to read metadata. diff --git a/dom/media/ChannelMediaDecoder.h b/dom/media/ChannelMediaDecoder.h index 879cafff7c31..ce17b5abbe09 100644 --- a/dom/media/ChannelMediaDecoder.h +++ b/dom/media/ChannelMediaDecoder.h @@ -93,7 +93,6 @@ private: // Create a new state machine to run this decoder. MediaDecoderStateMachine* CreateStateMachine(); - nsresult OpenResource(nsIStreamListener** aStreamListener); nsresult Load(BaseMediaResource* aOriginal); // Called by MediaResource when the download has ended. diff --git a/dom/media/MediaCache.cpp b/dom/media/MediaCache.cpp index ce87c17a05c8..482a70fd8b1a 100644 --- a/dom/media/MediaCache.cpp +++ b/dom/media/MediaCache.cpp @@ -2536,10 +2536,7 @@ nsresult MediaCacheStream::Init(int64_t aContentLength) { NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); - - if (mMediaCache) { - return NS_OK; - } + MOZ_ASSERT(!mMediaCache, "Has been initialized."); if (aContentLength > 0) { uint32_t length = uint32_t(std::min(aContentLength, int64_t(UINT32_MAX))); diff --git a/dom/media/MediaResource.cpp b/dom/media/MediaResource.cpp index f6c9f198a1e6..9f6fbf39818c 100644 --- a/dom/media/MediaResource.cpp +++ b/dom/media/MediaResource.cpp @@ -515,33 +515,27 @@ ChannelMediaResource::OnDataAvailable(nsIRequest* aRequest, return NS_OK; } -nsresult ChannelMediaResource::Open(nsIStreamListener **aStreamListener) +nsresult +ChannelMediaResource::Open(nsIStreamListener** aStreamListener) { NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); + MOZ_ASSERT(aStreamListener); + MOZ_ASSERT(mChannel); int64_t cl = -1; - if (mChannel) { - nsCOMPtr hc = do_QueryInterface(mChannel); - if (hc && !IsPayloadCompressed(hc)) { - if (NS_FAILED(hc->GetContentLength(&cl))) { - cl = -1; - } + nsCOMPtr hc = do_QueryInterface(mChannel); + if (hc && !IsPayloadCompressed(hc)) { + if (NS_FAILED(hc->GetContentLength(&cl))) { + cl = -1; } } nsresult rv = mCacheStream.Init(cl); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) { return rv; - NS_ASSERTION(mOffset == 0, "Who set mOffset already?"); - - if (!mChannel) { - // When we're a clone, the decoder might ask us to Open even though - // we haven't established an mChannel (because we might not need one) - NS_ASSERTION(!aStreamListener, - "Should have already been given a channel if we're to return a stream listener"); - return NS_OK; } + MOZ_ASSERT(mOffset == 0, "Who set mOffset already?"); return OpenChannel(aStreamListener); }