Bug 1321471. Part 1 - Use of MozPromise::ThenPromise() in place of CompletionPromise(). r=jya.
authorJW Wang <jwwang@mozilla.com>
Wed, 30 Nov 2016 18:19:26 +0800
changeset 325064 31c6008a6773d09b0f84d6db482d25b88d2c1639
parent 325063 76bbb68f8441b2067e45a75baaac6d7c6a00400b
child 325065 24424daa3526192a331fa0f75f67fb33790f6546
push id31028
push userkwierso@gmail.com
push dateFri, 02 Dec 2016 20:27:00 +0000
treeherdermozilla-central@919596f62a27 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1321471
milestone53.0a1
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 1321471. Part 1 - Use of MozPromise::ThenPromise() in place of CompletionPromise(). r=jya. MozReview-Commit-ID: INbGpzwK4f9
dom/media/MediaDecoderReaderWrapper.cpp
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaFormatReader.cpp
dom/media/gmp/GMPServiceParent.cpp
dom/media/gtest/TestMozPromise.cpp
dom/media/platforms/omx/OmxDataDecoder.cpp
--- a/dom/media/MediaDecoderReaderWrapper.cpp
+++ b/dom/media/MediaDecoderReaderWrapper.cpp
@@ -28,20 +28,19 @@ MediaDecoderReaderWrapper::StartTime() c
 
 RefPtr<MediaDecoderReaderWrapper::MetadataPromise>
 MediaDecoderReaderWrapper::ReadMetadata()
 {
   MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
   MOZ_ASSERT(!mShutdown);
   return InvokeAsync(mReader->OwnerThread(), mReader.get(), __func__,
                      &MediaDecoderReader::AsyncReadMetadata)
-         ->Then(mOwnerThread, __func__, this,
-                &MediaDecoderReaderWrapper::OnMetadataRead,
-                &MediaDecoderReaderWrapper::OnMetadataNotRead)
-         ->CompletionPromise();
+         ->ThenPromise(mOwnerThread, __func__, this,
+                       &MediaDecoderReaderWrapper::OnMetadataRead,
+                       &MediaDecoderReaderWrapper::OnMetadataNotRead);
 }
 
 void
 MediaDecoderReaderWrapper::RequestAudioData()
 {
   MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
   MOZ_ASSERT(!mShutdown);
 
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1651,21 +1651,20 @@ ShutdownState::Enter()
   master->mNextFrameStatus.DisconnectAll();
   master->mCurrentPosition.DisconnectAll();
   master->mPlaybackOffset.DisconnectAll();
   master->mIsAudioDataAudible.DisconnectAll();
 
   // Shut down the watch manager to stop further notifications.
   master->mWatchManager.Shutdown();
 
-  return Reader()->Shutdown()
-    ->Then(OwnerThread(), __func__, master,
-           &MediaDecoderStateMachine::FinishShutdown,
-           &MediaDecoderStateMachine::FinishShutdown)
-    ->CompletionPromise();
+  return Reader()->Shutdown()->ThenPromise(
+    OwnerThread(), __func__, master,
+    &MediaDecoderStateMachine::FinishShutdown,
+    &MediaDecoderStateMachine::FinishShutdown);
 }
 
 #define INIT_WATCHABLE(name, val) \
   name(val, "MediaDecoderStateMachine::" #name)
 #define INIT_MIRROR(name, val) \
   name(mTaskQueue, val, "MediaDecoderStateMachine::" #name " (Mirror)")
 #define INIT_CANONICAL(name, val) \
   name(mTaskQueue, val, "MediaDecoderStateMachine::" #name " (Canonical)")
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -926,23 +926,23 @@ MediaFormatReader::OnDemuxFailed(TrackTy
 
 void
 MediaFormatReader::DoDemuxVideo()
 {
   auto p = mVideo.mTrackDemuxer->GetSamples(1);
 
   if (mVideo.mFirstDemuxedSampleTime.isNothing()) {
     RefPtr<MediaFormatReader> self = this;
-    p = p->Then(OwnerThread(), __func__,
+    p = p->ThenPromise(OwnerThread(), __func__,
                 [self] (RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples) {
                   self->OnFirstDemuxCompleted(TrackInfo::kVideoTrack, aSamples);
                 },
                 [self] (const MediaResult& aError) {
                   self->OnFirstDemuxFailed(TrackInfo::kVideoTrack, aError);
-                })->CompletionPromise();
+                });
   }
 
   mVideo.mDemuxRequest.Begin(p->Then(OwnerThread(), __func__, this,
                                      &MediaFormatReader::OnVideoDemuxCompleted,
                                      &MediaFormatReader::OnVideoDemuxFailed));
 }
 
 void
@@ -992,23 +992,23 @@ MediaFormatReader::RequestAudioData()
 
 void
 MediaFormatReader::DoDemuxAudio()
 {
   auto p = mAudio.mTrackDemuxer->GetSamples(1);
 
   if (mAudio.mFirstDemuxedSampleTime.isNothing()) {
     RefPtr<MediaFormatReader> self = this;
-    p = p->Then(OwnerThread(), __func__,
+    p = p->ThenPromise(OwnerThread(), __func__,
                 [self] (RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples) {
                   self->OnFirstDemuxCompleted(TrackInfo::kAudioTrack, aSamples);
                 },
                 [self] (const MediaResult& aError) {
                   self->OnFirstDemuxFailed(TrackInfo::kAudioTrack, aError);
-                })->CompletionPromise();
+                });
   }
 
   mAudio.mDemuxRequest.Begin(p->Then(OwnerThread(), __func__, this,
                                      &MediaFormatReader::OnAudioDemuxCompleted,
                                      &MediaFormatReader::OnAudioDemuxFailed));
 }
 
 void
--- a/dom/media/gmp/GMPServiceParent.cpp
+++ b/dom/media/gmp/GMPServiceParent.cpp
@@ -904,28 +904,27 @@ GeckoMediaPluginServiceParent::AsyncAddP
     return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
   }
 
   nsString dir(aDirectory);
   RefPtr<GeckoMediaPluginServiceParent> self = this;
   return InvokeAsync<nsString&&>(
            thread, this, __func__,
            &GeckoMediaPluginServiceParent::AddOnGMPThread, dir)
-    ->Then(AbstractThread::MainThread(), __func__,
+    ->ThenPromise(AbstractThread::MainThread(), __func__,
       [dir, self]() -> void {
         LOGD(("GeckoMediaPluginServiceParent::AsyncAddPluginDirectory %s succeeded",
               NS_ConvertUTF16toUTF8(dir).get()));
         MOZ_ASSERT(NS_IsMainThread());
         self->UpdateContentProcessGMPCapabilities();
       },
       [dir]() -> void {
         LOGD(("GeckoMediaPluginServiceParent::AsyncAddPluginDirectory %s failed",
               NS_ConvertUTF16toUTF8(dir).get()));
-      })
-    ->CompletionPromise();
+      });
 }
 
 NS_IMETHODIMP
 GeckoMediaPluginServiceParent::AddPluginDirectory(const nsAString& aDirectory)
 {
   MOZ_ASSERT(NS_IsMainThread());
   RefPtr<GenericPromise> p = AsyncAddPluginDirectory(aDirectory);
   Unused << p;
@@ -1130,28 +1129,27 @@ GeckoMediaPluginServiceParent::AddOnGMPT
 
   RefPtr<GMPParent> gmp = CreateGMPParent();
   if (!gmp) {
     NS_WARNING("Can't Create GMPParent");
     return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
   }
 
   RefPtr<GeckoMediaPluginServiceParent> self(this);
-  return gmp->Init(this, directory)->Then(thread, __func__,
+  return gmp->Init(this, directory)->ThenPromise(thread, __func__,
     [gmp, self, dir]() -> void {
       LOGD(("%s::%s: %s Succeeded", __CLASS__, __FUNCTION__, dir.get()));
       {
         MutexAutoLock lock(self->mMutex);
         self->mPlugins.AppendElement(gmp);
       }
     },
     [dir]() -> void {
       LOGD(("%s::%s: %s Failed", __CLASS__, __FUNCTION__, dir.get()));
-    })
-    ->CompletionPromise();
+    });
 }
 
 void
 GeckoMediaPluginServiceParent::RemoveOnGMPThread(const nsAString& aDirectory,
                                                  const bool aDeleteFromDisk,
                                                  const bool aCanDefer)
 {
   MOZ_ASSERT(NS_GetCurrentThread() == mGMPThread);
--- a/dom/media/gtest/TestMozPromise.cpp
+++ b/dom/media/gtest/TestMozPromise.cpp
@@ -143,35 +143,31 @@ TEST(MozPromise, AsyncResolve)
 
 TEST(MozPromise, CompletionPromises)
 {
   bool invokedPass = false;
   AutoTaskQueue atq;
   RefPtr<TaskQueue> queue = atq.Queue();
   RunOnTaskQueue(queue, [queue, &invokedPass] () -> void {
     TestPromise::CreateAndResolve(40, __func__)
-    ->Then(queue, __func__,
+    ->ThenPromise(queue, __func__,
       [] (int aVal) -> RefPtr<TestPromise> { return TestPromise::CreateAndResolve(aVal + 10, __func__); },
       DO_FAIL)
-    ->CompletionPromise()
-    ->Then(queue, __func__, [&invokedPass] () -> void { invokedPass = true; }, DO_FAIL)
-    ->CompletionPromise()
-    ->Then(queue, __func__,
+    ->ThenPromise(queue, __func__, [&invokedPass] () -> void { invokedPass = true; }, DO_FAIL)
+    ->ThenPromise(queue, __func__,
       [queue] (int aVal) -> RefPtr<TestPromise> {
         RefPtr<TestPromise::Private> p = new TestPromise::Private(__func__);
         nsCOMPtr<nsIRunnable> resolver = new DelayedResolveOrReject(queue, p, RRValue::MakeResolve(aVal - 8), 10);
         queue->Dispatch(resolver.forget());
         return RefPtr<TestPromise>(p);
       },
       DO_FAIL)
-    ->CompletionPromise()
-    ->Then(queue, __func__,
+    ->ThenPromise(queue, __func__,
       [queue] (int aVal) -> RefPtr<TestPromise> { return TestPromise::CreateAndReject(double(aVal - 42) + 42.0, __func__); },
       DO_FAIL)
-    ->CompletionPromise()
     ->Then(queue, __func__,
       DO_FAIL,
       [queue, &invokedPass] (double aVal) -> void { EXPECT_EQ(aVal, 42.0); EXPECT_TRUE(invokedPass); queue->BeginShutdown(); });
   });
 }
 
 TEST(MozPromise, PromiseAllResolve)
 {
@@ -227,22 +223,22 @@ TEST(MozPromise, Chaining)
   AutoTaskQueue atq;
   RefPtr<TaskQueue> queue = atq.Queue();
   MozPromiseRequestHolder<TestPromise> holder;
 
   RunOnTaskQueue(queue, [queue, &holder] () {
     auto p = TestPromise::CreateAndResolve(42, __func__);
     const size_t kIterations = 100;
     for (size_t i = 0; i < kIterations; ++i) {
-      p = p->Then(queue, __func__,
+      p = p->ThenPromise(queue, __func__,
         [] (int aVal) {
           EXPECT_EQ(aVal, 42);
         },
         [] () {}
-      )->CompletionPromise();
+      );
 
       if (i == kIterations / 2) {
         p->Then(queue, __func__,
           [queue, &holder] () {
             holder.Disconnect();
             queue->BeginShutdown();
           },
           DO_FAIL);
--- a/dom/media/platforms/omx/OmxDataDecoder.cpp
+++ b/dom/media/platforms/omx/OmxDataDecoder.cpp
@@ -254,26 +254,25 @@ OmxDataDecoder::DoAsyncShutdown()
   MOZ_ASSERT(!mFlushing);
 
   mWatchManager.Unwatch(mOmxState, &OmxDataDecoder::OmxStateRunner);
   mWatchManager.Unwatch(mPortSettingsChanged, &OmxDataDecoder::PortSettingsChanged);
 
   // Flush to all ports, so all buffers can be returned from component.
   RefPtr<OmxDataDecoder> self = this;
   mOmxLayer->SendCommand(OMX_CommandFlush, OMX_ALL, nullptr)
-    ->Then(mOmxTaskQueue, __func__,
+    ->ThenPromise(mOmxTaskQueue, __func__,
            [self] () -> RefPtr<OmxCommandPromise> {
              LOGL("DoAsyncShutdown: flush complete");
              return self->mOmxLayer->SendCommand(OMX_CommandStateSet, OMX_StateIdle, nullptr);
            },
            [self] () {
              self->mOmxLayer->Shutdown();
            })
-    ->CompletionPromise()
-    ->Then(mOmxTaskQueue, __func__,
+    ->ThenPromise(mOmxTaskQueue, __func__,
            [self] () -> RefPtr<OmxCommandPromise> {
              RefPtr<OmxCommandPromise> p =
                self->mOmxLayer->SendCommand(OMX_CommandStateSet, OMX_StateLoaded, nullptr);
 
              // According to spec 3.1.1.2.2.1:
              // OMX_StateLoaded needs to be sent before releasing buffers.
              // And state transition from OMX_StateIdle to OMX_StateLoaded
              // is completed when all of the buffers have been removed
@@ -285,17 +284,16 @@ OmxDataDecoder::DoAsyncShutdown()
              self->ReleaseBuffers(OMX_DirInput);
              self->ReleaseBuffers(OMX_DirOutput);
 
              return p;
            },
            [self] () {
              self->mOmxLayer->Shutdown();
            })
-    ->CompletionPromise()
     ->Then(mOmxTaskQueue, __func__,
            [self] () {
              LOGL("DoAsyncShutdown: OMX_StateLoaded, it is safe to shutdown omx");
              self->mOmxLayer->Shutdown();
              self->mWatchManager.Shutdown();
              self->mOmxLayer = nullptr;
              self->mMediaDataHelper = nullptr;
 
@@ -793,17 +791,17 @@ OmxDataDecoder::PortSettingsChanged()
                                               sizeof(def));
   CHECK_OMX_ERR(err);
 
   RefPtr<OmxDataDecoder> self = this;
   if (def.bEnabled) {
     // 1. disable port.
     LOG("PortSettingsChanged: disable port %d", def.nPortIndex);
     mOmxLayer->SendCommand(OMX_CommandPortDisable, mPortSettingsChanged, nullptr)
-      ->Then(mOmxTaskQueue, __func__,
+      ->ThenPromise(mOmxTaskQueue, __func__,
              [self, def] () -> RefPtr<OmxCommandPromise> {
                // 3. enable port.
                // Send enable port command.
                RefPtr<OmxCommandPromise> p =
                  self->mOmxLayer->SendCommand(OMX_CommandPortEnable,
                                               self->mPortSettingsChanged,
                                               nullptr);
 
@@ -814,17 +812,16 @@ OmxDataDecoder::PortSettingsChanged()
                  self->NotifyError(OMX_ErrorUndefined, __func__);
                }
 
                return p;
              },
              [self] () {
                self->NotifyError(OMX_ErrorUndefined, __func__);
              })
-      ->CompletionPromise()
       ->Then(mOmxTaskQueue, __func__,
              [self] () {
                LOGL("PortSettingsChanged: port settings changed complete");
                // finish port setting changed.
                self->mPortSettingsChanged = -1;
                self->FillAndEmptyBuffers();
              },
              [self] () {