зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1459209 P9 Implement RemoteServiceWorkerRegistrationImpl::Update() across IPC to the parent-side SWM. r=mrbkap
--HG-- extra : rebase_source : 87d77ea7472b59b7e0d243d714ad19158cd7c332
This commit is contained in:
Родитель
6323d7c413
Коммит
94f85205a9
|
@ -6,6 +6,7 @@ include PBackgroundSharedTypes;
|
|||
include IPCServiceWorkerDescriptor;
|
||||
|
||||
using ServiceWorkerUpdateViaCache from "mozilla/dom/ServiceWorkerIPCUtils.h";
|
||||
using mozilla::CopyableErrorResult from "ipc/ErrorIPCUtils.h";
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -33,5 +34,11 @@ struct IPCServiceWorkerRegistrationDescriptor
|
|||
OptionalIPCServiceWorkerDescriptor active;
|
||||
};
|
||||
|
||||
union IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult
|
||||
{
|
||||
IPCServiceWorkerRegistrationDescriptor;
|
||||
CopyableErrorResult;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
include protocol PBackground;
|
||||
|
||||
include IPCServiceWorkerRegistrationDescriptor;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
|
@ -14,6 +16,8 @@ protocol PServiceWorkerRegistration
|
|||
parent:
|
||||
async Teardown();
|
||||
|
||||
async Update() returns (IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult aResult);
|
||||
|
||||
child:
|
||||
async __delete__();
|
||||
};
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
using mozilla::ipc::IPCResult;
|
||||
using mozilla::ipc::ResponseRejectReason;
|
||||
|
||||
RemoteServiceWorkerRegistrationImpl::~RemoteServiceWorkerRegistrationImpl()
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(!mOuter);
|
||||
|
@ -54,7 +57,28 @@ void
|
|||
RemoteServiceWorkerRegistrationImpl::Update(ServiceWorkerRegistrationCallback&& aSuccessCB,
|
||||
ServiceWorkerFailureCallback&& aFailureCB)
|
||||
{
|
||||
// TODO
|
||||
if (!mActor) {
|
||||
aFailureCB(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
|
||||
return;
|
||||
}
|
||||
|
||||
mActor->SendUpdate(
|
||||
[successCB = std::move(aSuccessCB), aFailureCB]
|
||||
(const IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult& aResult) {
|
||||
if (aResult.type() == IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult::TCopyableErrorResult) {
|
||||
// application layer error
|
||||
auto& rv = aResult.get_CopyableErrorResult();
|
||||
MOZ_DIAGNOSTIC_ASSERT(rv.Failed());
|
||||
aFailureCB(CopyableErrorResult(rv));
|
||||
return;
|
||||
}
|
||||
// success
|
||||
auto& ipcDesc = aResult.get_IPCServiceWorkerRegistrationDescriptor();
|
||||
successCB(ServiceWorkerRegistrationDescriptor(ipcDesc));
|
||||
}, [aFailureCB] (ResponseRejectReason aReason) {
|
||||
// IPC layer error
|
||||
aFailureCB(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -29,6 +29,24 @@ ServiceWorkerRegistrationParent::RecvTeardown()
|
|||
return IPC_OK();
|
||||
}
|
||||
|
||||
IPCResult
|
||||
ServiceWorkerRegistrationParent::RecvUpdate(UpdateResolver&& aResolver)
|
||||
{
|
||||
if (!mProxy) {
|
||||
aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mProxy->Update()->Then(GetCurrentThreadSerialEventTarget(), __func__,
|
||||
[aResolver] (const ServiceWorkerRegistrationDescriptor& aDescriptor) {
|
||||
aResolver(aDescriptor.ToIPC());
|
||||
}, [aResolver] (const CopyableErrorResult& aResult) {
|
||||
aResolver(aResult);
|
||||
});
|
||||
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
ServiceWorkerRegistrationParent::ServiceWorkerRegistrationParent()
|
||||
: mDeleteSent(false)
|
||||
{
|
||||
|
|
|
@ -27,6 +27,9 @@ class ServiceWorkerRegistrationParent final : public PServiceWorkerRegistrationP
|
|||
mozilla::ipc::IPCResult
|
||||
RecvTeardown() override;
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
RecvUpdate(UpdateResolver&& aResolver) override;
|
||||
|
||||
public:
|
||||
ServiceWorkerRegistrationParent();
|
||||
~ServiceWorkerRegistrationParent();
|
||||
|
|
|
@ -170,5 +170,66 @@ ServiceWorkerRegistrationProxy::RevokeActor(ServiceWorkerRegistrationParent* aAc
|
|||
MOZ_ALWAYS_SUCCEEDS(SystemGroup::Dispatch(TaskCategory::Other, r.forget()));
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class UpdateCallback final : public ServiceWorkerUpdateFinishCallback
|
||||
{
|
||||
RefPtr<ServiceWorkerRegistrationPromise::Private> mPromise;
|
||||
|
||||
~UpdateCallback() = default;
|
||||
|
||||
public:
|
||||
explicit UpdateCallback(RefPtr<ServiceWorkerRegistrationPromise::Private>&& aPromise)
|
||||
: mPromise(std::move(aPromise))
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(mPromise);
|
||||
}
|
||||
|
||||
void
|
||||
UpdateSucceeded(ServiceWorkerRegistrationInfo* aInfo) override
|
||||
{
|
||||
mPromise->Resolve(aInfo->Descriptor(), __func__);
|
||||
}
|
||||
|
||||
void
|
||||
UpdateFailed(ErrorResult& aResult) override
|
||||
{
|
||||
mPromise->Reject(CopyableErrorResult(aResult), __func__);
|
||||
}
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
RefPtr<ServiceWorkerRegistrationPromise>
|
||||
ServiceWorkerRegistrationProxy::Update()
|
||||
{
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
RefPtr<ServiceWorkerRegistrationProxy> self = this;
|
||||
RefPtr<ServiceWorkerRegistrationPromise::Private> promise =
|
||||
new ServiceWorkerRegistrationPromise::Private(__func__);
|
||||
|
||||
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(__func__,
|
||||
[self, promise] () mutable {
|
||||
auto scopeExit = MakeScopeExit([&] {
|
||||
promise->Reject(NS_ERROR_DOM_INVALID_STATE_ERR, __func__);
|
||||
});
|
||||
|
||||
NS_ENSURE_TRUE_VOID(self->mReg);
|
||||
|
||||
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
||||
NS_ENSURE_TRUE_VOID(swm);
|
||||
|
||||
RefPtr<UpdateCallback> cb = new UpdateCallback(std::move(promise));
|
||||
swm->Update(self->mReg->Principal(), self->mReg->Scope(), cb);
|
||||
|
||||
scopeExit.release();
|
||||
});
|
||||
|
||||
MOZ_ALWAYS_SUCCEEDS(SystemGroup::Dispatch(TaskCategory::Other, r.forget()));
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -7,9 +7,11 @@
|
|||
#ifndef moz_dom_ServiceWorkerRegistrationProxy_h
|
||||
#define moz_dom_ServiceWorkerRegistrationProxy_h
|
||||
|
||||
#include "mozilla/dom/PServiceWorkerRegistrationParent.h"
|
||||
#include "nsProxyRelease.h"
|
||||
#include "ServiceWorkerRegistrationDescriptor.h"
|
||||
#include "ServiceWorkerRegistrationListener.h"
|
||||
#include "ServiceWorkerUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -70,6 +72,9 @@ public:
|
|||
void
|
||||
RevokeActor(ServiceWorkerRegistrationParent* aActor);
|
||||
|
||||
RefPtr<ServiceWorkerRegistrationPromise>
|
||||
Update();
|
||||
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ServiceWorkerRegistrationProxy, override);
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче