Bug 1415438 - move mReopenOnError from ChannelMediaResource to ChannelMediaResource::Listener. r=bechen,gerald
authorJW Wang <jwwang@mozilla.com>
Wed, 08 Nov 2017 14:25:31 +0800
changeset 444503 a0bfda2158697b8414394fb30402b55de989f304
parent 444502 0082c7b883119b1272ce76cf57dcddf62bd833fe
child 444504 f62b1c3fe4ff6a4198fce20796fab5c23d42d037
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbechen, gerald
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 1415438 - move mReopenOnError from ChannelMediaResource to ChannelMediaResource::Listener. r=bechen,gerald http://searchfox.org/mozilla-central/rev/ed212c79cfe86357e9a5740082b9364e7f6e526f/dom/media/ChannelMediaResource.cpp#727-729 mReopenOnError is a flag to reopen the channel when resume fails. It makes more sense to associate this member with the channel we are resuming. MozReview-Commit-ID: DwKUyvyzWdi
--- a/dom/media/ChannelMediaResource.cpp
+++ b/dom/media/ChannelMediaResource.cpp
@@ -24,29 +24,27 @@ mozilla::LazyLogModule gMediaResourceLog
 namespace mozilla {
 ChannelMediaResource::ChannelMediaResource(MediaResourceCallback* aCallback,
                                            nsIChannel* aChannel,
                                            nsIURI* aURI,
                                            bool aIsPrivateBrowsing)
   : BaseMediaResource(aCallback, aChannel, aURI)
-  , mReopenOnError(false)
   , mCacheStream(this, aIsPrivateBrowsing)
   , mSuspendAgent(mChannel, mCacheStream)
   MediaResourceCallback* aCallback,
   nsIChannel* aChannel,
   nsIURI* aURI,
   const MediaChannelStatistics& aStatistics)
   : BaseMediaResource(aCallback, aChannel, aURI)
-  , mReopenOnError(false)
   , mCacheStream(this, /* aIsPrivateBrowsing = */ false)
   , mChannelStatistics(aStatistics)
   , mSuspendAgent(mChannel, mCacheStream)
@@ -81,17 +79,17 @@ ChannelMediaResource::Listener::OnStartR
 ChannelMediaResource::Listener::OnStopRequest(nsIRequest* aRequest,
                                               nsISupports* aContext,
                                               nsresult aStatus)
   if (!mResource)
     return NS_OK;
-  return mResource->OnStopRequest(aRequest, aStatus);
+  return mResource->OnStopRequest(aRequest, aStatus, mReopenOnError);
 ChannelMediaResource::Listener::OnDataAvailable(nsIRequest* aRequest,
                                                 nsISupports* aContext,
                                                 nsIInputStream* aStream,
                                                 uint64_t aOffset,
                                                 uint32_t aCount)
@@ -291,17 +289,16 @@ ChannelMediaResource::OnStartRequest(nsI
   // Update principals before OnDataAvailable() putting the data in the cache.
   // This is important, we want to make sure all principals are updated before
   // any consumer can see the new data.
   mCacheStream.NotifyDataStarted(mLoadID, startOffset, seekable);
   mIsTransportSeekable = seekable;
-  mReopenOnError = false;
   // Fires an initial progress event.
   // TODO: Don't turn this on until we fix all data races.
   nsCOMPtr<nsIThreadRetargetableRequest> retarget;
@@ -366,32 +363,34 @@ ChannelMediaResource::ParseContentRangeH
   LOG("Received bytes [%" PRId64 "] to [%" PRId64 "] of [%" PRId64 "] for decoder[%p]",
       aRangeStart, aRangeEnd, aRangeTotal, mCallback.get());
   return NS_OK;
-ChannelMediaResource::OnStopRequest(nsIRequest* aRequest, nsresult aStatus)
+ChannelMediaResource::OnStopRequest(nsIRequest* aRequest,
+                                    nsresult aStatus,
+                                    bool aReopenOnError)
   NS_ASSERTION(mChannel.get() == aRequest, "Wrong channel!");
                "How can OnStopRequest fire while we're suspended?");
   // Note that aStatus might have succeeded --- this might be a normal close
   // --- even in situations where the server cut us off because we were
   // suspended. So we need to "reopen on error" in that case too. The only
   // cases where we don't need to reopen are when *we* closed the stream.
   // But don't reopen if we need to seek and we don't think we can... that would
   // cause us to just re-read the stream, which would be really bad.
-  if (mReopenOnError && aStatus != NS_ERROR_PARSED_DATA_CACHED &&
+  if (aReopenOnError && aStatus != NS_ERROR_PARSED_DATA_CACHED &&
       aStatus != NS_BINDING_ABORTED &&
       (GetOffset() == 0 || (GetLength() > 0 && GetOffset() != GetLength() &&
                             mIsTransportSeekable))) {
     // If the stream did close normally, restart the channel if we're either
     // at the start of the resource, or if the server is seekable and we're
     // not at the end of stream. We don't restart the stream if we're at the
     // end because not all web servers handle this case consistently; see:
     // https://bugzilla.mozilla.org/show_bug.cgi?id=1373618#c36
@@ -725,17 +724,17 @@ ChannelMediaResource::Resume()
   if (mSuspendAgent.Resume()) {
     if (mChannel) {
       // Just wake up our existing channel
       // if an error occurs after Resume, assume it's because the server
       // timed out the connection and we should reopen it.
-      mReopenOnError = true;
+      mListener->SetReopenOnError();
     } else {
       int64_t totalLength = GetLength();
       // If mOffset is at the end of the stream, then we shouldn't try to
       // seek to it. The seek will fail and be wasted anyway. We can leave
       // the channel dead; if the media cache wants to read some other data
       // in the future, it will call CacheClientSeek itself which will reopen the
       // channel.
--- a/dom/media/ChannelMediaResource.h
+++ b/dom/media/ChannelMediaResource.h
@@ -176,37 +176,44 @@ public:
     void Revoke();
+    void SetReopenOnError() { mReopenOnError = true; }
     Mutex mMutex;
     // mResource should only be modified on the main thread with the lock.
     // So it can be read without lock on the main thread or on other threads
     // with the lock.
     RefPtr<ChannelMediaResource> mResource;
+    // When this flag is set, if we get a network error we should silently
+    // reopen the stream. Main thread only.
+    bool mReopenOnError = false;
     const int64_t mOffset;
     const uint32_t mLoadID;
   friend class Listener;
   nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override;
   nsresult Seek(int64_t aOffset, bool aResume);
   bool IsSuspendedByCache();
   // These are called on the main thread by Listener.
   nsresult OnStartRequest(nsIRequest* aRequest, int64_t aRequestOffset);
-  nsresult OnStopRequest(nsIRequest* aRequest, nsresult aStatus);
+  nsresult OnStopRequest(nsIRequest* aRequest,
+                         nsresult aStatus,
+                         bool aReopenOnError);
   nsresult OnDataAvailable(uint32_t aLoadID,
                            nsIInputStream* aStream,
                            uint32_t aCount);
   nsresult OnChannelRedirect(nsIChannel* aOld,
                              nsIChannel* aNew,
                              uint32_t aFlags,
                              int64_t aOffset);
@@ -250,19 +257,16 @@ protected:
   // The last reported seekability state for the underlying channel
   bool mIsTransportSeekable = false;
   RefPtr<Listener> mListener;
   // A mono-increasing integer to uniquely identify the channel we are loading.
   uint32_t mLoadID = 0;
   // Used by the cache to store the offset to seek to when we are resumed.
   // -1 means no seek initiated by the cache is waiting.
   int64_t mPendingSeekOffset = -1;
-  // When this flag is set, if we get a network error we should silently
-  // reopen the stream.
-  bool               mReopenOnError;
   // Any thread access
   MediaCacheStream mCacheStream;
   MediaChannelStatistics mChannelStatistics;
   ChannelSuspendAgent mSuspendAgent;