Bug 1349883 - Part 4: Strengthen precondition of ReturnDecodedData(). r=jya, a=gchang
authorJohn Lin <jolin@mozilla.com>
Fri, 07 Apr 2017 17:17:17 +0800
changeset 393534 0e6f81e3f63e6ffd7bf03067975ce58755b55244
parent 393533 327f2348eb373976c561b418b50ffa0b136d7a71
child 393535 8c3b90886a8c8aac5d94e26e3fe262cbc82b625e
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya, gchang
bugs1349883
milestone54.0a2
Bug 1349883 - Part 4: Strengthen precondition of ReturnDecodedData(). r=jya, a=gchang MozReview-Commit-ID: 2jLNlrHEE0b
dom/media/platforms/android/RemoteDataDecoder.cpp
--- a/dom/media/platforms/android/RemoteDataDecoder.cpp
+++ b/dom/media/platforms/android/RemoteDataDecoder.cpp
@@ -518,16 +518,19 @@ RemoteDataDecoder::Flush()
   });
 }
 
 RefPtr<MediaDataDecoder::DecodePromise>
 RemoteDataDecoder::Drain()
 {
   RefPtr<RemoteDataDecoder> self = this;
   return InvokeAsync(mTaskQueue, __func__, [self, this]() {
+    if (mShutdown) {
+      return DecodePromise::CreateAndReject(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
+    }
     RefPtr<DecodePromise> p = mDrainPromise.Ensure(__func__);
     if (mDrainStatus == DrainStatus::DRAINED) {
       // There's no operation to perform other than returning any already
       // decoded data.
       ReturnDecodedData();
       return p;
     }
 
@@ -649,25 +652,19 @@ RemoteDataDecoder::UpdateOutputStatus(Me
   }
   mDecodedData.AppendElement(aSample);
   ReturnDecodedData();
 }
 
 void
 RemoteDataDecoder::ReturnDecodedData()
 {
-  if (!mTaskQueue->IsCurrentThreadIn()) {
-    mTaskQueue->Dispatch(
-      NewRunnableMethod(this, &RemoteDataDecoder::ReturnDecodedData));
-    return;
-  }
   AssertOnTaskQueue();
-  if (mShutdown) {
-    return;
-  }
+  MOZ_ASSERT(!mShutdown);
+
   // We only want to clear mDecodedData when we have resolved the promises.
   if (!mDecodePromise.IsEmpty()) {
     mDecodePromise.Resolve(mDecodedData, __func__);
     mDecodedData.Clear();
   } else if (!mDrainPromise.IsEmpty()) {
     mDrainPromise.Resolve(mDecodedData, __func__);
     mDecodedData.Clear();
   }