зеркало из https://github.com/mozilla/gecko-dev.git
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
This commit is contained in:
Родитель
fbfcb37762
Коммит
d4d5d4d5bb
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -931,7 +931,7 @@ MediaFormatReader::DoDemuxVideo()
|
|||
|
||||
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);
|
||||
},
|
||||
|
@ -997,7 +997,7 @@ MediaFormatReader::DoDemuxAudio()
|
|||
|
||||
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);
|
||||
},
|
||||
|
|
|
@ -909,7 +909,7 @@ GeckoMediaPluginServiceParent::AsyncAddPluginDirectory(const nsAString& aDirecto
|
|||
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()));
|
||||
|
@ -1134,7 +1134,7 @@ GeckoMediaPluginServiceParent::AddOnGMPThread(nsString aDirectory)
|
|||
}
|
||||
|
||||
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()));
|
||||
{
|
||||
|
|
|
@ -148,11 +148,11 @@ TEST(MozPromise, CompletionPromises)
|
|||
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);
|
||||
|
@ -160,7 +160,7 @@ TEST(MozPromise, CompletionPromises)
|
|||
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__,
|
||||
|
@ -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);
|
||||
},
|
||||
|
|
|
@ -259,7 +259,7 @@ OmxDataDecoder::DoAsyncShutdown()
|
|||
// 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);
|
||||
|
@ -267,7 +267,7 @@ OmxDataDecoder::DoAsyncShutdown()
|
|||
[self] () {
|
||||
self->mOmxLayer->Shutdown();
|
||||
})
|
||||
->ThenPromise(mOmxTaskQueue, __func__,
|
||||
->Then(mOmxTaskQueue, __func__,
|
||||
[self] () -> RefPtr<OmxCommandPromise> {
|
||||
RefPtr<OmxCommandPromise> 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<OmxCommandPromise> {
|
||||
// 3. enable port.
|
||||
// Send enable port command.
|
||||
|
|
|
@ -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<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
|
||||
|
|
Загрузка…
Ссылка в новой задаче