Bug 1417305. P2 - move some code from NotifyDataEnded() into NotifyDownloadEnded() to make the code more readable. draft
authorJW Wang <jwwang@mozilla.com>
Wed, 15 Nov 2017 11:07:06 +0800
changeset 698005 50dfc5450770d50e2c31835adce4c7adf068751c
parent 698004 8dd01cf049c7dfae898075b51bda1f3d80932f68
child 698006 d17b8a45e6a280af6cf25ec95be4a2e09dfac6dc
push id89171
push userjwwang@mozilla.com
push dateWed, 15 Nov 2017 05:14:20 +0000
bugs1417305
milestone59.0a1
Bug 1417305. P2 - move some code from NotifyDataEnded() into NotifyDownloadEnded() to make the code more readable. MozReview-Commit-ID: LveThVjuemq
dom/media/ChannelMediaDecoder.cpp
--- a/dom/media/ChannelMediaDecoder.cpp
+++ b/dom/media/ChannelMediaDecoder.cpp
@@ -99,29 +99,18 @@ ChannelMediaDecoder::ResourceCallback::N
     TimerCallback, this, sDelay, nsITimer::TYPE_ONE_SHOT,
     "ChannelMediaDecoder::ResourceCallback::TimerCallback");
 }
 
 void
 ChannelMediaDecoder::ResourceCallback::NotifyDataEnded(nsresult aStatus)
 {
   MOZ_ASSERT(NS_IsMainThread());
-  if (!mDecoder) {
-    return;
-  }
-  mDecoder->NotifyDownloadEnded(aStatus);
-  if (NS_SUCCEEDED(aStatus)) {
-    MediaDecoderOwner* owner = GetMediaOwner();
-    MOZ_ASSERT(owner);
-    owner->DownloadSuspended();
-
-    // NotifySuspendedStatusChanged will tell the element that download
-    // has been suspended "by the cache", which is true since we never
-    // download anything. The element can then transition to HAVE_ENOUGH_DATA.
-    owner->NotifySuspendedByCache(true);
+  if (mDecoder) {
+    mDecoder->NotifyDownloadEnded(aStatus);
   }
 }
 
 void
 ChannelMediaDecoder::ResourceCallback::NotifyPrincipalChanged()
 {
   MOZ_ASSERT(NS_IsMainThread());
   if (mDecoder) {
@@ -300,29 +289,31 @@ void
 ChannelMediaDecoder::NotifyDownloadEnded(nsresult aStatus)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
   AbstractThread::AutoEnter context(AbstractMainThread());
 
   LOG("NotifyDownloadEnded, status=%" PRIx32, static_cast<uint32_t>(aStatus));
 
+  MediaDecoderOwner* owner = GetOwner();
   if (aStatus == NS_BINDING_ABORTED) {
     // Download has been cancelled by user.
-    GetOwner()->LoadAborted();
+    owner->LoadAborted();
     return;
   }
 
   UpdatePlaybackRate();
 
   if (NS_SUCCEEDED(aStatus)) {
-    // A final progress event will be fired by the MediaResource calling
-    // DownloadSuspended on the element.
-    // Also NotifySuspendedStatusChanged() will be called to update readyState
-    // if download ended with success.
+    owner->DownloadSuspended();
+    // NotifySuspendedStatusChanged will tell the element that download
+    // has been suspended "by the cache", which is true since we never
+    // download anything. The element can then transition to HAVE_ENOUGH_DATA.
+    owner->NotifySuspendedByCache(true);
   } else if (aStatus != NS_BASE_STREAM_CLOSED) {
     NetworkError();
   }
 }
 
 void
 ChannelMediaDecoder::NotifyBytesConsumed(int64_t aBytes, int64_t aOffset)
 {