Bug 1415090. P5 - remove MediaCacheStream::NotifyChannelRecreated(). draft
authorJW Wang <jwwang@mozilla.com>
Thu, 16 Nov 2017 14:50:49 +0800
changeset 699436 070dc6418d76c427a08761c6a1a8c304fe22c761
parent 699435 68ed9786c9e50e59c426691830f8a97b46bbb001
child 740627 937774d65f9f9610ff318aec6658510a769b307d
push id89568
push userjwwang@mozilla.com
push dateFri, 17 Nov 2017 06:22:23 +0000
bugs1415090
milestone59.0a1
Bug 1415090. P5 - remove MediaCacheStream::NotifyChannelRecreated(). NotifyDataEnded() runs off the main thread which might set mChannelEnded wrongly after NotifyChannelRecreated reset it on the main thread. We should reset the flags in NotifyDataStarted() which indicate a new load has begun. MozReview-Commit-ID: Gi6PFXwMJqc
dom/media/ChannelMediaResource.cpp
dom/media/MediaCache.cpp
dom/media/MediaCache.h
--- a/dom/media/ChannelMediaResource.cpp
+++ b/dom/media/ChannelMediaResource.cpp
@@ -790,19 +790,16 @@ ChannelMediaResource::RecreateChannel()
 
   nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(mChannel));
   if (cos) {
     // Unconditionally disable throttling since we want the media to fluently
     // play even when we switch the tab to background.
     cos->AddClassFlags(nsIClassOfService::DontThrottle);
   }
 
-  // Tell the cache to reset the download status when the channel is reopened.
-  mCacheStream.NotifyChannelRecreated();
-
   return rv;
 }
 
 void
 ChannelMediaResource::CacheClientNotifyDataReceived()
 {
   SystemGroup::Dispatch(
     TaskCategory::Other,
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -1977,16 +1977,20 @@ MediaCacheStream::NotifyDataStarted(uint
   mIsTransportSeekable = aSeekable;
   // Queue an Update since we may change our strategy for dealing
   // with this stream
   mMediaCache->QueueUpdate();
 
   // Reset mSeekTarget since the seek is completed so MediaCache::Update() will
   // make decisions based on mChannelOffset instead of mSeekTarget.
   mSeekTarget = -1;
+
+  // Reset these flags since a new load has begun.
+  mChannelEnded = false;
+  mDidNotifyDataEnded = false;
 }
 
 void
 MediaCacheStream::UpdatePrincipal(nsIPrincipal* aPrincipal)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MediaCache::ResourceStreamIterator iter(mMediaCache, mResourceID);
   while (MediaCacheStream* stream = iter.Next()) {
@@ -2187,25 +2191,16 @@ MediaCacheStream::NotifyDataEndedInterna
       stream->mDidNotifyDataEnded = true;
       stream->mNotifyDataEndedStatus = aStatus;
       stream->mClient->CacheClientNotifyDataEnded(aStatus);
     }
   }
 }
 
 void
-MediaCacheStream::NotifyChannelRecreated()
-{
-  NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
-  ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
-  mChannelEnded = false;
-  mDidNotifyDataEnded = false;
-}
-
-void
 MediaCacheStream::NotifyDataEnded(uint32_t aLoadID,
                                   nsresult aStatus,
                                   bool aReopenOnError)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aLoadID > 0);
 
   RefPtr<ChannelMediaResource> client = mClient;
--- a/dom/media/MediaCache.h
+++ b/dom/media/MediaCache.h
@@ -273,20 +273,16 @@ public:
   // preceding NotifyDataStarted().
   void NotifyLoadID(uint32_t aLoadID);
 
   // Notifies the cache that the channel has closed with the given status.
   void NotifyDataEnded(uint32_t aLoadID,
                        nsresult aStatus,
                        bool aReopenOnError = false);
 
-  // Notifies the stream that the channel is reopened. The stream should
-  // reset variables such as |mDidNotifyDataEnded|.
-  void NotifyChannelRecreated();
-
   // Notifies the stream that the suspend status of the client has changed.
   // Main thread only.
   void NotifyClientSuspended(bool aSuspended);
 
   // These methods can be called on any thread.
   // Cached blocks associated with this stream will not be evicted
   // while the stream is pinned.
   void Pin();