Bug 1221009. Part 3 - add assertions to functions that shouldn't be called after shutdown. r=roc. draft
authorJW Wang <jwwang@mozilla.com>
Thu, 12 Nov 2015 18:17:43 +0800
changeset 308399 fa132b061b6ae9ad023adfa15f0cec0840a50211
parent 308398 9c2f3624f05f9de3a3c8bc1060c95050f3a3b653
child 511157 e388a7050784289bc9cb5f4197e34b673cd63d4b
push id7467
push userjwwang@mozilla.com
push dateThu, 12 Nov 2015 10:21:39 +0000
reviewersroc
bugs1221009
milestone45.0a1
Bug 1221009. Part 3 - add assertions to functions that shouldn't be called after shutdown. r=roc.
dom/media/MediaDecoder.cpp
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -478,16 +478,17 @@ MediaDecoder::CanonicalDurationOrNull()
   MOZ_ASSERT(mDecoderStateMachine);
   return mDecoderStateMachine->CanonicalDuration();
 }
 
 void
 MediaDecoder::SetInfinite(bool aInfinite)
 {
   MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(!mShuttingDown);
   mInfiniteStream = aInfinite;
   DurationChanged();
 }
 
 bool
 MediaDecoder::IsInfinite()
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -874,28 +875,28 @@ MediaDecoder::FirstFrameLoaded(nsAutoPtr
   // that autoplay should run.
   NotifySuspendedStatusChanged();
 }
 
 nsresult
 MediaDecoder::FinishDecoderSetup(MediaResource* aResource)
 {
   MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(!mShuttingDown);
   HTMLMediaElement* element = mOwner->GetMediaElement();
   NS_ENSURE_TRUE(element, NS_ERROR_FAILURE);
   element->FinishDecoderSetup(this, aResource);
   return NS_OK;
 }
 
 void
 MediaDecoder::ResetConnectionState()
 {
   MOZ_ASSERT(NS_IsMainThread());
-  if (mShuttingDown)
-    return;
+  MOZ_ASSERT(!mShuttingDown);
 
   // Notify the media element that connection gets lost.
   mOwner->ResetConnectionState();
 
   // Since we have notified the media element the connection
   // lost event, the decoder will be reloaded when user tries
   // to play the Rtsp streaming next time.
   Shutdown();
@@ -1029,19 +1030,17 @@ MediaDecoder::UpdatePlaybackRate()
 
   mResource->SetPlaybackRate(rate);
 }
 
 void
 MediaDecoder::NotifySuspendedStatusChanged()
 {
   MOZ_ASSERT(NS_IsMainThread());
-  if (mShuttingDown) {
-    return;
-  }
+  MOZ_ASSERT(!mShuttingDown);
   if (mResource) {
     bool suspended = mResource->IsSuspendedByCache();
     mOwner->NotifySuspendedByCache(suspended);
   }
 }
 
 void
 MediaDecoder::NotifyBytesDownloaded()
@@ -1053,20 +1052,17 @@ MediaDecoder::NotifyBytesDownloaded()
   UpdatePlaybackRate();
   mOwner->DownloadProgressed();
 }
 
 void
 MediaDecoder::NotifyDownloadEnded(nsresult aStatus)
 {
   MOZ_ASSERT(NS_IsMainThread());
-
-  if (mShuttingDown) {
-    return;
-  }
+  MOZ_ASSERT(!mShuttingDown);
 
   DECODER_LOG("NotifyDownloadEnded, status=%x", aStatus);
 
   if (aStatus == NS_BINDING_ABORTED) {
     // Download has been cancelled by user.
     mOwner->LoadAborted();
     return;
   }
@@ -1082,28 +1078,27 @@ MediaDecoder::NotifyDownloadEnded(nsresu
     NetworkError();
   }
 }
 
 void
 MediaDecoder::NotifyPrincipalChanged()
 {
   MOZ_ASSERT(NS_IsMainThread());
-  if (mShuttingDown) {
-    return;
-  }
+  MOZ_ASSERT(!mShuttingDown);
   mOwner->NotifyDecoderPrincipalChanged();
 }
 
 void
 MediaDecoder::NotifyBytesConsumed(int64_t aBytes, int64_t aOffset)
 {
   MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(!mShuttingDown);
 
-  if (mShuttingDown || mIgnoreProgressData) {
+  if (mIgnoreProgressData) {
     return;
   }
 
   MOZ_ASSERT(mDecoderStateMachine);
   if (aOffset >= mDecoderPosition) {
     mPlaybackStatistics->AddBytes(aBytes);
   }
   mDecoderPosition = aOffset + aBytes;