mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1466681 P4 Make ServiceWorkerContainer::Inner::GetRegistrations() use callbacks instead of MozPromise. r=asuth
This commit is contained in:
parent
285d32a9aa
commit
0fed96cd14
@ -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();
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user