зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1466681 P3 Make ServiceWorkerContainer::Inner::GetReady() use callbacks instead of MozPromise. r=asuth
This commit is contained in:
Родитель
a65f650d11
Коммит
285d32a9aa
|
@ -537,13 +537,9 @@ ServiceWorkerContainer::GetReady(ErrorResult& aRv)
|
|||
|
||||
RefPtr<ServiceWorkerContainer> self = this;
|
||||
RefPtr<Promise> outer = mReadyPromise;
|
||||
RefPtr<DOMMozPromiseRequestHolder<ServiceWorkerRegistrationPromise>> holder =
|
||||
new DOMMozPromiseRequestHolder<ServiceWorkerRegistrationPromise>(global);
|
||||
|
||||
mInner->GetReady(clientInfo.ref())->Then(
|
||||
global->EventTargetFor(TaskCategory::Other), __func__,
|
||||
[self, outer, holder] (const ServiceWorkerRegistrationDescriptor& aDescriptor) {
|
||||
holder->Complete();
|
||||
mInner->GetReady(clientInfo.ref(),
|
||||
[self, outer] (const ServiceWorkerRegistrationDescriptor& aDescriptor) {
|
||||
ErrorResult rv;
|
||||
nsIGlobalObject* global = self->GetGlobalIfValid(rv);
|
||||
if (rv.Failed()) {
|
||||
|
@ -554,10 +550,9 @@ ServiceWorkerContainer::GetReady(ErrorResult& aRv)
|
|||
global->GetOrCreateServiceWorkerRegistration(aDescriptor);
|
||||
NS_ENSURE_TRUE_VOID(reg);
|
||||
outer->MaybeResolve(reg);
|
||||
}, [self, outer, holder] (const CopyableErrorResult& aRv) {
|
||||
holder->Complete();
|
||||
outer->MaybeReject(CopyableErrorResult(aRv));
|
||||
})->Track(*holder);
|
||||
}, [self, outer] (ErrorResult& aRv) {
|
||||
outer->MaybeReject(aRv);
|
||||
});
|
||||
|
||||
return mReadyPromise;
|
||||
}
|
||||
|
|
|
@ -49,8 +49,10 @@ public:
|
|||
virtual RefPtr<ServiceWorkerRegistrationListPromise>
|
||||
GetRegistrations(const ClientInfo& aClientInfo) const = 0;
|
||||
|
||||
virtual RefPtr<ServiceWorkerRegistrationPromise>
|
||||
GetReady(const ClientInfo& aClientInfo) const = 0;
|
||||
virtual void
|
||||
GetReady(const ClientInfo& aClientInfo,
|
||||
ServiceWorkerRegistrationCallback&& aSuccessCB,
|
||||
ServiceWorkerFailureCallback&& aFailureCB) const = 0;
|
||||
|
||||
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
|
||||
};
|
||||
|
|
|
@ -117,16 +117,37 @@ ServiceWorkerContainerImpl::GetRegistrations(const ClientInfo& aClientInfo) cons
|
|||
return swm->GetRegistrations(aClientInfo);
|
||||
}
|
||||
|
||||
RefPtr<ServiceWorkerRegistrationPromise>
|
||||
ServiceWorkerContainerImpl::GetReady(const ClientInfo& aClientInfo) const
|
||||
void
|
||||
ServiceWorkerContainerImpl::GetReady(const ClientInfo& aClientInfo,
|
||||
ServiceWorkerRegistrationCallback&& aSuccessCB,
|
||||
ServiceWorkerFailureCallback&& aFailureCB) const
|
||||
{
|
||||
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
||||
if (NS_WARN_IF(!swm)) {
|
||||
return ServiceWorkerRegistrationPromise::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->WhenReady(aClientInfo);
|
||||
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
||||
if (NS_WARN_IF(!swm)) {
|
||||
aFailureCB(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
|
||||
return;
|
||||
}
|
||||
|
||||
auto holder =
|
||||
MakeRefPtr<DOMMozPromiseRequestHolder<ServiceWorkerRegistrationPromise>>(global);
|
||||
|
||||
swm->WhenReady(aClientInfo)->Then(
|
||||
global->EventTargetFor(TaskCategory::Other), __func__,
|
||||
[successCB = std::move(aSuccessCB), holder] (const ServiceWorkerRegistrationDescriptor& aDescriptor) {
|
||||
holder->Complete();
|
||||
successCB(aDescriptor);
|
||||
}, [failureCB = std::move(aFailureCB), holder] (const CopyableErrorResult& aResult) {
|
||||
holder->Complete();
|
||||
failureCB(CopyableErrorResult(aResult));
|
||||
})->Track(*holder);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -45,8 +45,10 @@ public:
|
|||
RefPtr<ServiceWorkerRegistrationListPromise>
|
||||
GetRegistrations(const ClientInfo& aClientInfo) const override;
|
||||
|
||||
RefPtr<ServiceWorkerRegistrationPromise>
|
||||
GetReady(const ClientInfo& aClientInfo) const override;
|
||||
void
|
||||
GetReady(const ClientInfo& aClientInfo,
|
||||
ServiceWorkerRegistrationCallback&& aSuccessCB,
|
||||
ServiceWorkerFailureCallback&& aFailureCB) const override;
|
||||
|
||||
NS_INLINE_DECL_REFCOUNTING(ServiceWorkerContainerImpl, override)
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче