Bug 1466681 P4 Make ServiceWorkerContainer::Inner::GetRegistrations() use callbacks instead of MozPromise. r=asuth

This commit is contained in:
Ben Kelly 2018-06-15 12:21:33 -07:00
parent 285d32a9aa
commit 0fed96cd14
5 changed files with 44 additions and 21 deletions

View File

@ -412,13 +412,9 @@ ServiceWorkerContainer::GetRegistrations(ErrorResult& aRv)
}
RefPtr<ServiceWorkerContainer> self = this;
RefPtr<DOMMozPromiseRequestHolder<ServiceWorkerRegistrationListPromise>> holder =
new DOMMozPromiseRequestHolder<ServiceWorkerRegistrationListPromise>(global);
mInner->GetRegistrations(clientInfo.ref())->Then(
global->EventTargetFor(TaskCategory::Other), __func__,
[self, outer, holder] (const nsTArray<ServiceWorkerRegistrationDescriptor>& aDescList) {
holder->Complete();
mInner->GetRegistrations(clientInfo.ref(),
[self, outer] (const nsTArray<ServiceWorkerRegistrationDescriptor>& aDescList) {
ErrorResult rv;
nsIGlobalObject* global = self->GetGlobalIfValid(rv);
if (rv.Failed()) {
@ -434,10 +430,9 @@ ServiceWorkerContainer::GetRegistrations(ErrorResult& aRv)
}
}
outer->MaybeResolve(regList);
}, [self, outer, holder] (const CopyableErrorResult& aRv) {
holder->Complete();
outer->MaybeReject(CopyableErrorResult(aRv));
})->Track(*holder);
}, [self, outer] (ErrorResult& aRv) {
outer->MaybeReject(aRv);
});
return outer.forget();
}

View File

@ -46,8 +46,10 @@ public:
ServiceWorkerRegistrationCallback&& aSuccessCB,
ServiceWorkerFailureCallback&& aFailureCB) const = 0;
virtual RefPtr<ServiceWorkerRegistrationListPromise>
GetRegistrations(const ClientInfo& aClientInfo) const = 0;
virtual void
GetRegistrations(const ClientInfo& aClientInfo,
ServiceWorkerRegistrationListCallback&& aSuccessCB,
ServiceWorkerFailureCallback&& aFailureCB) const = 0;
virtual void
GetReady(const ClientInfo& aClientInfo,

View File

@ -105,16 +105,37 @@ ServiceWorkerContainerImpl::GetRegistration(const ClientInfo& aClientInfo,
})->Track(*holder);
}
RefPtr<ServiceWorkerRegistrationListPromise>
ServiceWorkerContainerImpl::GetRegistrations(const ClientInfo& aClientInfo) const
void
ServiceWorkerContainerImpl::GetRegistrations(const ClientInfo& aClientInfo,
ServiceWorkerRegistrationListCallback&& aSuccessCB,
ServiceWorkerFailureCallback&& aFailureCB) const
{
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
if (NS_WARN_IF(!swm)) {
return ServiceWorkerRegistrationListPromise::CreateAndReject(NS_ERROR_DOM_INVALID_STATE_ERR,
__func__);
MOZ_DIAGNOSTIC_ASSERT(mOuter);
nsIGlobalObject* global = mOuter->GetParentObject();
if (NS_WARN_IF(!global)) {
aFailureCB(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
return;
}
return swm->GetRegistrations(aClientInfo);
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
if (NS_WARN_IF(!swm)) {
aFailureCB(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
return;
}
auto holder =
MakeRefPtr<DOMMozPromiseRequestHolder<ServiceWorkerRegistrationListPromise>>(global);
swm->GetRegistrations(aClientInfo)->Then(
global->EventTargetFor(TaskCategory::Other), __func__,
[successCB = std::move(aSuccessCB), holder] (const nsTArray<ServiceWorkerRegistrationDescriptor>& aList) {
holder->Complete();
successCB(aList);
}, [failureCB = std::move(aFailureCB), holder] (const CopyableErrorResult& aResult) {
holder->Complete();
failureCB(CopyableErrorResult(aResult));
})->Track(*holder);
}
void

View File

@ -42,8 +42,10 @@ public:
ServiceWorkerRegistrationCallback&& aSuccessCB,
ServiceWorkerFailureCallback&& aFailureCB) const override;
RefPtr<ServiceWorkerRegistrationListPromise>
GetRegistrations(const ClientInfo& aClientInfo) const override;
void
GetRegistrations(const ClientInfo& aClientInfo,
ServiceWorkerRegistrationListCallback&& aSuccessCB,
ServiceWorkerFailureCallback&& aFailureCB) const override;
void
GetReady(const ClientInfo& aClientInfo,

View File

@ -28,6 +28,9 @@ typedef MozPromise<nsTArray<ServiceWorkerRegistrationDescriptor>, CopyableErrorR
typedef std::function<void (const ServiceWorkerRegistrationDescriptor&)>
ServiceWorkerRegistrationCallback;
typedef std::function<void (const nsTArray<ServiceWorkerRegistrationDescriptor>&)>
ServiceWorkerRegistrationListCallback;
typedef std::function<void (ErrorResult&)>
ServiceWorkerFailureCallback;