Bug 1321744. Part 3 - remove ThenPromise and replace its use with Then.
MozReview-Commit-ID: AsmePdCp2tC
--- a/dom/media/MediaDecoderReaderWrapper.cpp
+++ b/dom/media/MediaDecoderReaderWrapper.cpp
@@ -28,19 +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)
- ->ThenPromise(mOwnerThread, __func__, this,
- &MediaDecoderReaderWrapper::OnMetadataRead,
- &MediaDecoderReaderWrapper::OnMetadataNotRead);
+ ->Then(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,17 +1651,17 @@ 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()->ThenPromise(
+ return Reader()->Shutdown()->Then(
OwnerThread(), __func__, master,
&MediaDecoderStateMachine::FinishShutdown,
&MediaDecoderStateMachine::FinishShutdown);
}
#define INIT_WATCHABLE(name, val) \
name(val, "MediaDecoderStateMachine::" #name)
#define INIT_MIRROR(name, val) \
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -926,17 +926,17 @@ MediaFormatReader::OnDemuxFailed(TrackTy
void
MediaFormatReader::DoDemuxVideo()
{
auto p = mVideo.mTrackDemuxer->GetSamples(1);
if (mVideo.mFirstDemuxedSampleTime.isNothing()) {
RefPtr<MediaFormatReader> self = this;
- p = p->ThenPromise(OwnerThread(), __func__,
+ p = p->Then(OwnerThread(), __func__,
[self] (RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples) {
self->OnFirstDemuxCompleted(TrackInfo::kVideoTrack, aSamples);
},
[self] (const MediaResult& aError) {
self->OnFirstDemuxFailed(TrackInfo::kVideoTrack, aError);
});
}
@@ -992,17 +992,17 @@ MediaFormatReader::RequestAudioData()
void
MediaFormatReader::DoDemuxAudio()
{
auto p = mAudio.mTrackDemuxer->GetSamples(1);
if (mAudio.mFirstDemuxedSampleTime.isNothing()) {
RefPtr<MediaFormatReader> self = this;
- p = p->ThenPromise(OwnerThread(), __func__,
+ p = p->Then(OwnerThread(), __func__,
[self] (RefPtr<MediaTrackDemuxer::SamplesHolder> aSamples) {
self->OnFirstDemuxCompleted(TrackInfo::kAudioTrack, aSamples);
},
[self] (const MediaResult& aError) {
self->OnFirstDemuxFailed(TrackInfo::kAudioTrack, aError);
});
}
--- a/dom/media/gmp/GMPServiceParent.cpp
+++ b/dom/media/gmp/GMPServiceParent.cpp
@@ -904,17 +904,17 @@ 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)
- ->ThenPromise(AbstractThread::MainThread(), __func__,
+ ->Then(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",
@@ -1129,17 +1129,17 @@ 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)->ThenPromise(thread, __func__,
+ return gmp->Init(this, directory)->Then(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 {
--- a/dom/media/gtest/TestMozPromise.cpp
+++ b/dom/media/gtest/TestMozPromise.cpp
@@ -143,29 +143,29 @@ 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__)
- ->ThenPromise(queue, __func__,
+ ->Then(queue, __func__,
[] (int aVal) -> RefPtr<TestPromise> { 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<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)
- ->ThenPromise(queue, __func__,
+ ->Then(queue, __func__,
[queue] (int aVal) -> RefPtr<TestPromise> { return TestPromise::CreateAndReject(double(aVal - 42) + 42.0, __func__); },
DO_FAIL)
->Then(queue, __func__,
DO_FAIL,
[queue, &invokedPass] (double aVal) -> void { EXPECT_EQ(aVal, 42.0); EXPECT_TRUE(invokedPass); queue->BeginShutdown(); });
});
}
@@ -223,17 +223,17 @@ 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->ThenPromise(queue, __func__,
+ p = p->Then(queue, __func__,
[] (int aVal) {
EXPECT_EQ(aVal, 42);
},
[] () {}
);
if (i == kIterations / 2) {
p->Then(queue, __func__,
--- a/dom/media/platforms/omx/OmxDataDecoder.cpp
+++ b/dom/media/platforms/omx/OmxDataDecoder.cpp
@@ -254,25 +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)
- ->ThenPromise(mOmxTaskQueue, __func__,
+ ->Then(mOmxTaskQueue, __func__,
[self] () -> RefPtr<OmxCommandPromise> {
LOGL("DoAsyncShutdown: flush complete");
return self->mOmxLayer->SendCommand(OMX_CommandStateSet, OMX_StateIdle, nullptr);
},
[self] () {
self->mOmxLayer->Shutdown();
})
- ->ThenPromise(mOmxTaskQueue, __func__,
+ ->Then(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
@@ -791,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)
- ->ThenPromise(mOmxTaskQueue, __func__,
+ ->Then(mOmxTaskQueue, __func__,
[self, def] () -> RefPtr<OmxCommandPromise> {
// 3. enable port.
// Send enable port command.
RefPtr<OmxCommandPromise> p =
self->mOmxLayer->SendCommand(OMX_CommandPortEnable,
self->mPortSettingsChanged,
nullptr);
--- a/xpcom/threads/MozPromise.h
+++ b/xpcom/threads/MozPromise.h
@@ -586,60 +586,16 @@ public:
aCallSite, this, aThenValue, (int) IsPending());
if (!IsPending()) {
aThenValue->Dispatch(this);
} else {
mThenValues.AppendElement(aThenValue);
}
}
-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<typename ThisType, typename ResolveMethodType, typename RejectMethodType>
- MOZ_MUST_USE RefPtr<MozPromise>
- ThenPromise(AbstractThread* aResponseThread, const char* aCallSite, ThisType* aThisVal,
- ResolveMethodType aResolveMethod, RejectMethodType aRejectMethod)
- {
- using ThenType = MethodThenValue<ThisType, ResolveMethodType, RejectMethodType>;
- RefPtr<ThenValueBase> thenValue = new ThenType(
- aResponseThread, aThisVal, aResolveMethod, aRejectMethod, aCallSite);
- // mCompletionPromise must be created before ThenInternal() to avoid race.
- RefPtr<MozPromise> p = new MozPromise::Private(
- "<completion promise>", 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<typename ResolveFunction, typename RejectFunction>
- MOZ_MUST_USE RefPtr<MozPromise>
- ThenPromise(AbstractThread* aResponseThread, const char* aCallSite,
- ResolveFunction&& aResolveFunction, RejectFunction&& aRejectFunction)
- {
- using ThenType = FunctionThenValue<ResolveFunction, RejectFunction>;
- RefPtr<ThenValueBase> thenValue = new ThenType(
- aResponseThread, Move(aResolveFunction), Move(aRejectFunction), aCallSite);
- // mCompletionPromise must be created before ThenInternal() to avoid race.
- RefPtr<MozPromise> p = new MozPromise::Private(
- "<completion promise>", 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
* the promise. This allows us to delay the request until further use is
* known (whether it is ->Then() again for more promise chaining or passed
* to MozPromiseRequestHolder::Begin() to terminate chaining and issue
* the request).
*