From d4d5d4d5bb87baf928ae01757bcfcdff6c2e103a Mon Sep 17 00:00:00 2001 From: JW Wang Date: Sun, 4 Dec 2016 08:51:25 +0800 Subject: [PATCH] Bug 1321744. Part 3 - remove ThenPromise and replace its use with Then. r=gerald MozReview-Commit-ID: AsmePdCp2tC --HG-- extra : rebase_source : e08ac48584375d2bc12f5b73a1e60f2800359ed9 extra : intermediate-source : 94e727f7cd11bb04812da3662a0ee1fd461cc832 extra : source : 5307716231f93b01c0357011f8849015d4d97d0a --- dom/media/MediaDecoderReaderWrapper.cpp | 6 +-- dom/media/MediaDecoderStateMachine.cpp | 2 +- dom/media/MediaFormatReader.cpp | 4 +- dom/media/gmp/GMPServiceParent.cpp | 4 +- dom/media/gtest/TestMozPromise.cpp | 10 ++--- dom/media/platforms/omx/OmxDataDecoder.cpp | 6 +-- xpcom/threads/MozPromise.h | 44 ---------------------- 7 files changed, 16 insertions(+), 60 deletions(-) diff --git a/dom/media/MediaDecoderReaderWrapper.cpp b/dom/media/MediaDecoderReaderWrapper.cpp index 88d32364dbff..c73ea018e6e1 100644 --- a/dom/media/MediaDecoderReaderWrapper.cpp +++ b/dom/media/MediaDecoderReaderWrapper.cpp @@ -33,9 +33,9 @@ MediaDecoderReaderWrapper::ReadMetadata() MOZ_ASSERT(!mShutdown); return InvokeAsync(mReader->OwnerThread(), mReader.get(), __func__, &MediaDecoderReader::AsyncReadMetadata) - ->ThenPromise(mOwnerThread, __func__, this, - &MediaDecoderReaderWrapper::OnMetadataRead, - &MediaDecoderReaderWrapper::OnMetadataNotRead); + ->Then(mOwnerThread, __func__, this, + &MediaDecoderReaderWrapper::OnMetadataRead, + &MediaDecoderReaderWrapper::OnMetadataNotRead); } void diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index ae4d72463ac4..9431264eed3f 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -1656,7 +1656,7 @@ ShutdownState::Enter() // Shut down the watch manager to stop further notifications. master->mWatchManager.Shutdown(); - return Reader()->Shutdown()->ThenPromise( + return Reader()->Shutdown()->Then( OwnerThread(), __func__, master, &MediaDecoderStateMachine::FinishShutdown, &MediaDecoderStateMachine::FinishShutdown); diff --git a/dom/media/MediaFormatReader.cpp b/dom/media/MediaFormatReader.cpp index f9533a258c72..8f7de2bc8829 100644 --- a/dom/media/MediaFormatReader.cpp +++ b/dom/media/MediaFormatReader.cpp @@ -931,7 +931,7 @@ MediaFormatReader::DoDemuxVideo() if (mVideo.mFirstDemuxedSampleTime.isNothing()) { RefPtr self = this; - p = p->ThenPromise(OwnerThread(), __func__, + p = p->Then(OwnerThread(), __func__, [self] (RefPtr aSamples) { self->OnFirstDemuxCompleted(TrackInfo::kVideoTrack, aSamples); }, @@ -997,7 +997,7 @@ MediaFormatReader::DoDemuxAudio() if (mAudio.mFirstDemuxedSampleTime.isNothing()) { RefPtr self = this; - p = p->ThenPromise(OwnerThread(), __func__, + p = p->Then(OwnerThread(), __func__, [self] (RefPtr aSamples) { self->OnFirstDemuxCompleted(TrackInfo::kAudioTrack, aSamples); }, diff --git a/dom/media/gmp/GMPServiceParent.cpp b/dom/media/gmp/GMPServiceParent.cpp index dea4e36aa957..594b2254b4ce 100644 --- a/dom/media/gmp/GMPServiceParent.cpp +++ b/dom/media/gmp/GMPServiceParent.cpp @@ -909,7 +909,7 @@ GeckoMediaPluginServiceParent::AsyncAddPluginDirectory(const nsAString& aDirecto return InvokeAsync( thread, this, __func__, &GeckoMediaPluginServiceParent::AddOnGMPThread, dir) - ->ThenPromise(AbstractThread::MainThread(), __func__, + ->Then(AbstractThread::MainThread(), __func__, [dir, self]() -> void { LOGD(("GeckoMediaPluginServiceParent::AsyncAddPluginDirectory %s succeeded", NS_ConvertUTF16toUTF8(dir).get())); @@ -1134,7 +1134,7 @@ GeckoMediaPluginServiceParent::AddOnGMPThread(nsString aDirectory) } RefPtr self(this); - return gmp->Init(this, directory)->ThenPromise(thread, __func__, + return gmp->Init(this, directory)->Then(thread, __func__, [gmp, self, dir]() -> void { LOGD(("%s::%s: %s Succeeded", __CLASS__, __FUNCTION__, dir.get())); { diff --git a/dom/media/gtest/TestMozPromise.cpp b/dom/media/gtest/TestMozPromise.cpp index 77d0fe37d754..c6c2ed9b6498 100644 --- a/dom/media/gtest/TestMozPromise.cpp +++ b/dom/media/gtest/TestMozPromise.cpp @@ -148,11 +148,11 @@ TEST(MozPromise, CompletionPromises) RefPtr queue = atq.Queue(); RunOnTaskQueue(queue, [queue, &invokedPass] () -> void { TestPromise::CreateAndResolve(40, __func__) - ->ThenPromise(queue, __func__, + ->Then(queue, __func__, [] (int aVal) -> RefPtr { return TestPromise::CreateAndResolve(aVal + 10, __func__); }, DO_FAIL) - ->ThenPromise(queue, __func__, [&invokedPass] () -> void { invokedPass = true; }, DO_FAIL) - ->ThenPromise(queue, __func__, + ->Then(queue, __func__, [&invokedPass] () -> void { invokedPass = true; }, DO_FAIL) + ->Then(queue, __func__, [queue] (int aVal) -> RefPtr { RefPtr p = new TestPromise::Private(__func__); nsCOMPtr resolver = new DelayedResolveOrReject(queue, p, RRValue::MakeResolve(aVal - 8), 10); @@ -160,7 +160,7 @@ TEST(MozPromise, CompletionPromises) return RefPtr(p); }, DO_FAIL) - ->ThenPromise(queue, __func__, + ->Then(queue, __func__, [queue] (int aVal) -> RefPtr { return TestPromise::CreateAndReject(double(aVal - 42) + 42.0, __func__); }, DO_FAIL) ->Then(queue, __func__, @@ -228,7 +228,7 @@ TEST(MozPromise, Chaining) auto p = TestPromise::CreateAndResolve(42, __func__); const size_t kIterations = 100; for (size_t i = 0; i < kIterations; ++i) { - p = p->ThenPromise(queue, __func__, + p = p->Then(queue, __func__, [] (int aVal) { EXPECT_EQ(aVal, 42); }, diff --git a/dom/media/platforms/omx/OmxDataDecoder.cpp b/dom/media/platforms/omx/OmxDataDecoder.cpp index c257937f3618..886c7bb5d2d3 100644 --- a/dom/media/platforms/omx/OmxDataDecoder.cpp +++ b/dom/media/platforms/omx/OmxDataDecoder.cpp @@ -259,7 +259,7 @@ OmxDataDecoder::DoAsyncShutdown() // Flush to all ports, so all buffers can be returned from component. RefPtr self = this; mOmxLayer->SendCommand(OMX_CommandFlush, OMX_ALL, nullptr) - ->ThenPromise(mOmxTaskQueue, __func__, + ->Then(mOmxTaskQueue, __func__, [self] () -> RefPtr { LOGL("DoAsyncShutdown: flush complete"); return self->mOmxLayer->SendCommand(OMX_CommandStateSet, OMX_StateIdle, nullptr); @@ -267,7 +267,7 @@ OmxDataDecoder::DoAsyncShutdown() [self] () { self->mOmxLayer->Shutdown(); }) - ->ThenPromise(mOmxTaskQueue, __func__, + ->Then(mOmxTaskQueue, __func__, [self] () -> RefPtr { RefPtr p = self->mOmxLayer->SendCommand(OMX_CommandStateSet, OMX_StateLoaded, nullptr); @@ -796,7 +796,7 @@ OmxDataDecoder::PortSettingsChanged() // 1. disable port. LOG("PortSettingsChanged: disable port %d", def.nPortIndex); mOmxLayer->SendCommand(OMX_CommandPortDisable, mPortSettingsChanged, nullptr) - ->ThenPromise(mOmxTaskQueue, __func__, + ->Then(mOmxTaskQueue, __func__, [self, def] () -> RefPtr { // 3. enable port. // Send enable port command. diff --git a/xpcom/threads/MozPromise.h b/xpcom/threads/MozPromise.h index db54e308ee57..237f7fd3898e 100644 --- a/xpcom/threads/MozPromise.h +++ b/xpcom/threads/MozPromise.h @@ -591,50 +591,6 @@ public: } } -public: - - // ThenPromise() can be called on any thread as Then(). - // The syntax is close to JS promise and makes promise chaining easier - // where you can do: p->ThenPromise()->ThenPromise()->ThenPromise(); - // - // Note you would have to call Then() instead when the result needs to be held - // by a MozPromiseRequestHolder for future disconnection. - template - MOZ_MUST_USE RefPtr - ThenPromise(AbstractThread* aResponseThread, const char* aCallSite, ThisType* aThisVal, - ResolveMethodType aResolveMethod, RejectMethodType aRejectMethod) - { - using ThenType = MethodThenValue; - RefPtr thenValue = new ThenType( - aResponseThread, aThisVal, aResolveMethod, aRejectMethod, aCallSite); - // mCompletionPromise must be created before ThenInternal() to avoid race. - RefPtr p = new MozPromise::Private( - "", true /* aIsCompletionPromise */); - thenValue->mCompletionPromise = p; - // Note ThenInternal() might nullify mCompletionPromise before return. - // So we need to return p instead of mCompletionPromise. - ThenInternal(aResponseThread, thenValue, aCallSite); - return p; - } - - template - MOZ_MUST_USE RefPtr - ThenPromise(AbstractThread* aResponseThread, const char* aCallSite, - ResolveFunction&& aResolveFunction, RejectFunction&& aRejectFunction) - { - using ThenType = FunctionThenValue; - RefPtr thenValue = new ThenType( - aResponseThread, Move(aResolveFunction), Move(aRejectFunction), aCallSite); - // mCompletionPromise must be created before ThenInternal() to avoid race. - RefPtr p = new MozPromise::Private( - "", true /* aIsCompletionPromise */); - thenValue->mCompletionPromise = p; - // Note ThenInternal() might nullify mCompletionPromise before return. - // So we need to return p instead of mCompletionPromise. - ThenInternal(aResponseThread, thenValue, aCallSite); - return p; - } - private: /* * A command object to store all information needed to make a request to