зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1459209 P6 Scaffold a ServiceWorkerRegistrationProxy class to connect the parent actor to the main thread SWM. r=mrbkap
--HG-- extra : rebase_source : 355d278c7b891ae8de0a136d5c7db024ad0d0a76
This commit is contained in:
Родитель
d6345919a0
Коммит
5e3089171b
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include "ServiceWorkerRegistrationParent.h"
|
||||
|
||||
#include "ServiceWorkerRegistrationProxy.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
|
@ -14,20 +16,45 @@ using mozilla::ipc::IPCResult;
|
|||
void
|
||||
ServiceWorkerRegistrationParent::ActorDestroy(ActorDestroyReason aReason)
|
||||
{
|
||||
// TODO
|
||||
if (mProxy) {
|
||||
mProxy->RevokeActor(this);
|
||||
mProxy = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
IPCResult
|
||||
ServiceWorkerRegistrationParent::RecvTeardown()
|
||||
{
|
||||
// TODO
|
||||
MaybeSendDelete();
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
ServiceWorkerRegistrationParent::ServiceWorkerRegistrationParent()
|
||||
: mDeleteSent(false)
|
||||
{
|
||||
}
|
||||
|
||||
ServiceWorkerRegistrationParent::~ServiceWorkerRegistrationParent()
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(!mProxy);
|
||||
}
|
||||
|
||||
void
|
||||
ServiceWorkerRegistrationParent::Init(const IPCServiceWorkerRegistrationDescriptor& aDescriptor)
|
||||
{
|
||||
// TODO
|
||||
MOZ_DIAGNOSTIC_ASSERT(!mProxy);
|
||||
mProxy = new ServiceWorkerRegistrationProxy(ServiceWorkerRegistrationDescriptor(aDescriptor));
|
||||
mProxy->Init(this);
|
||||
}
|
||||
|
||||
void
|
||||
ServiceWorkerRegistrationParent::MaybeSendDelete()
|
||||
{
|
||||
if (mDeleteSent) {
|
||||
return;
|
||||
}
|
||||
mDeleteSent = true;
|
||||
Unused << Send__delete__(this);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -13,9 +13,13 @@ namespace mozilla {
|
|||
namespace dom {
|
||||
|
||||
class IPCServiceWorkerRegistrationDescriptor;
|
||||
class ServiceWorkerRegistrationProxy;
|
||||
|
||||
class ServiceWorkerRegistrationParent final : public PServiceWorkerRegistrationParent
|
||||
{
|
||||
RefPtr<ServiceWorkerRegistrationProxy> mProxy;
|
||||
bool mDeleteSent;
|
||||
|
||||
// PServiceWorkerRegistrationParent
|
||||
void
|
||||
ActorDestroy(ActorDestroyReason aReason) override;
|
||||
|
@ -24,11 +28,14 @@ class ServiceWorkerRegistrationParent final : public PServiceWorkerRegistrationP
|
|||
RecvTeardown() override;
|
||||
|
||||
public:
|
||||
ServiceWorkerRegistrationParent() = default;
|
||||
~ServiceWorkerRegistrationParent() = default;
|
||||
ServiceWorkerRegistrationParent();
|
||||
~ServiceWorkerRegistrationParent();
|
||||
|
||||
void
|
||||
Init(const IPCServiceWorkerRegistrationDescriptor& aDescriptor);
|
||||
|
||||
void
|
||||
MaybeSendDelete();
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -0,0 +1,174 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "ServiceWorkerRegistrationProxy.h"
|
||||
|
||||
#include "mozilla/ipc/BackgroundParent.h"
|
||||
#include "ServiceWorkerManager.h"
|
||||
#include "ServiceWorkerRegistrationParent.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
using mozilla::ipc::AssertIsOnBackgroundThread;
|
||||
|
||||
ServiceWorkerRegistrationProxy::~ServiceWorkerRegistrationProxy()
|
||||
{
|
||||
// Any thread
|
||||
MOZ_DIAGNOSTIC_ASSERT(!mActor);
|
||||
MOZ_DIAGNOSTIC_ASSERT(!mReg);
|
||||
}
|
||||
|
||||
void
|
||||
ServiceWorkerRegistrationProxy::MaybeShutdownOnBGThread()
|
||||
{
|
||||
AssertIsOnBackgroundThread();
|
||||
if (!mActor) {
|
||||
return;
|
||||
}
|
||||
mActor->MaybeSendDelete();
|
||||
}
|
||||
|
||||
void
|
||||
ServiceWorkerRegistrationProxy::UpdateStateOnBGThread(const ServiceWorkerRegistrationDescriptor& aDescriptor)
|
||||
{
|
||||
AssertIsOnBackgroundThread();
|
||||
if (!mActor) {
|
||||
return;
|
||||
}
|
||||
// TODO: send update
|
||||
}
|
||||
|
||||
void
|
||||
ServiceWorkerRegistrationProxy::InitOnMainThread()
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
||||
auto scopeExit = MakeScopeExit([&] {
|
||||
MaybeShutdownOnMainThread();
|
||||
});
|
||||
|
||||
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
||||
NS_ENSURE_TRUE_VOID(swm);
|
||||
|
||||
RefPtr<ServiceWorkerRegistrationInfo> reg =
|
||||
swm->GetRegistration(mDescriptor.PrincipalInfo(), mDescriptor.Scope());
|
||||
NS_ENSURE_TRUE_VOID(reg);
|
||||
|
||||
scopeExit.release();
|
||||
|
||||
mReg = new nsMainThreadPtrHolder<ServiceWorkerRegistrationInfo>(
|
||||
"ServiceWorkerRegistrationProxy::mInfo", reg);
|
||||
|
||||
mReg->AddInstance(this, mDescriptor);
|
||||
}
|
||||
|
||||
void
|
||||
ServiceWorkerRegistrationProxy::MaybeShutdownOnMainThread()
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
||||
nsCOMPtr<nsIRunnable> r =
|
||||
NewRunnableMethod(__func__, this,
|
||||
&ServiceWorkerRegistrationProxy::MaybeShutdownOnBGThread);
|
||||
|
||||
MOZ_ALWAYS_SUCCEEDS(mEventTarget->Dispatch(r.forget(), NS_DISPATCH_NORMAL));
|
||||
}
|
||||
|
||||
void
|
||||
ServiceWorkerRegistrationProxy::StopListeningOnMainThread()
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
||||
if (!mReg) {
|
||||
return;
|
||||
}
|
||||
|
||||
mReg->RemoveInstance(this);
|
||||
mReg = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
ServiceWorkerRegistrationProxy::UpdateState(const ServiceWorkerRegistrationDescriptor& aDescriptor)
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
||||
if (mDescriptor == aDescriptor) {
|
||||
return;
|
||||
}
|
||||
mDescriptor = aDescriptor;
|
||||
|
||||
nsCOMPtr<nsIRunnable> r = NewRunnableMethod<ServiceWorkerRegistrationDescriptor>(
|
||||
__func__, this, &ServiceWorkerRegistrationProxy::UpdateStateOnBGThread,
|
||||
aDescriptor);
|
||||
|
||||
MOZ_ALWAYS_SUCCEEDS(mEventTarget->Dispatch(r.forget(), NS_DISPATCH_NORMAL));
|
||||
}
|
||||
|
||||
void
|
||||
ServiceWorkerRegistrationProxy::RegistrationRemoved()
|
||||
{
|
||||
MaybeShutdownOnMainThread();
|
||||
}
|
||||
|
||||
void
|
||||
ServiceWorkerRegistrationProxy::GetScope(nsAString& aScope) const
|
||||
{
|
||||
CopyUTF8toUTF16(mDescriptor.Scope(), aScope);
|
||||
}
|
||||
|
||||
bool
|
||||
ServiceWorkerRegistrationProxy::MatchesDescriptor(const ServiceWorkerRegistrationDescriptor& aDescriptor)
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
return aDescriptor.Id() == mDescriptor.Id() &&
|
||||
aDescriptor.PrincipalInfo() == mDescriptor.PrincipalInfo() &&
|
||||
aDescriptor.Scope() == mDescriptor.Scope();
|
||||
}
|
||||
|
||||
ServiceWorkerRegistrationProxy::ServiceWorkerRegistrationProxy(const ServiceWorkerRegistrationDescriptor& aDescriptor)
|
||||
: mActor(nullptr)
|
||||
, mEventTarget(GetCurrentThreadSerialEventTarget())
|
||||
, mDescriptor(aDescriptor)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServiceWorkerRegistrationProxy::Init(ServiceWorkerRegistrationParent* aActor)
|
||||
{
|
||||
AssertIsOnBackgroundThread();
|
||||
MOZ_DIAGNOSTIC_ASSERT(aActor);
|
||||
MOZ_DIAGNOSTIC_ASSERT(!mActor);
|
||||
MOZ_DIAGNOSTIC_ASSERT(mEventTarget);
|
||||
|
||||
mActor = aActor;
|
||||
|
||||
// Note, this must be done from a separate Init() method and not in
|
||||
// the constructor. If done from the constructor the runnable can
|
||||
// execute, complete, and release its reference before the constructor
|
||||
// returns.
|
||||
nsCOMPtr<nsIRunnable> r = NewRunnableMethod(
|
||||
"ServiceWorkerRegistrationProxy::Init", this,
|
||||
&ServiceWorkerRegistrationProxy::InitOnMainThread);
|
||||
MOZ_ALWAYS_SUCCEEDS(SystemGroup::Dispatch(TaskCategory::Other, r.forget()));
|
||||
}
|
||||
|
||||
void
|
||||
ServiceWorkerRegistrationProxy::RevokeActor(ServiceWorkerRegistrationParent* aActor)
|
||||
{
|
||||
AssertIsOnBackgroundThread();
|
||||
MOZ_DIAGNOSTIC_ASSERT(mActor);
|
||||
MOZ_DIAGNOSTIC_ASSERT(mActor == aActor);
|
||||
mActor = nullptr;
|
||||
|
||||
nsCOMPtr<nsIRunnable> r =
|
||||
NewRunnableMethod(__func__, this,
|
||||
&ServiceWorkerRegistrationProxy::StopListeningOnMainThread);
|
||||
MOZ_ALWAYS_SUCCEEDS(SystemGroup::Dispatch(TaskCategory::Other, r.forget()));
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,79 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef moz_dom_ServiceWorkerRegistrationProxy_h
|
||||
#define moz_dom_ServiceWorkerRegistrationProxy_h
|
||||
|
||||
#include "nsProxyRelease.h"
|
||||
#include "ServiceWorkerRegistrationDescriptor.h"
|
||||
#include "ServiceWorkerRegistrationListener.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class ServiceWorkerRegistrationInfo;
|
||||
class ServiceWorkerRegistrationParent;
|
||||
|
||||
class ServiceWorkerRegistrationProxy final : public ServiceWorkerRegistrationListener
|
||||
{
|
||||
// Background thread only
|
||||
ServiceWorkerRegistrationParent* mActor;
|
||||
|
||||
// Written on background thread and read on main thread
|
||||
nsCOMPtr<nsISerialEventTarget> mEventTarget;
|
||||
|
||||
// Main thread only
|
||||
ServiceWorkerRegistrationDescriptor mDescriptor;
|
||||
nsMainThreadPtrHandle<ServiceWorkerRegistrationInfo> mReg;
|
||||
|
||||
~ServiceWorkerRegistrationProxy();
|
||||
|
||||
// Background thread methods
|
||||
void
|
||||
MaybeShutdownOnBGThread();
|
||||
|
||||
void
|
||||
UpdateStateOnBGThread(const ServiceWorkerRegistrationDescriptor& aDescriptor);
|
||||
|
||||
// Main thread methods
|
||||
void
|
||||
InitOnMainThread();
|
||||
|
||||
void
|
||||
MaybeShutdownOnMainThread();
|
||||
|
||||
void
|
||||
StopListeningOnMainThread();
|
||||
|
||||
// ServiceWorkerRegistrationListener interface
|
||||
void
|
||||
UpdateState(const ServiceWorkerRegistrationDescriptor& aDescriptor) override;
|
||||
|
||||
void
|
||||
RegistrationRemoved() override;
|
||||
|
||||
void
|
||||
GetScope(nsAString& aScope) const override;
|
||||
|
||||
bool
|
||||
MatchesDescriptor(const ServiceWorkerRegistrationDescriptor& aDescriptor) override;
|
||||
|
||||
public:
|
||||
explicit ServiceWorkerRegistrationProxy(const ServiceWorkerRegistrationDescriptor& aDescriptor);
|
||||
|
||||
void
|
||||
Init(ServiceWorkerRegistrationParent* aActor);
|
||||
|
||||
void
|
||||
RevokeActor(ServiceWorkerRegistrationParent* aActor);
|
||||
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ServiceWorkerRegistrationProxy, override);
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // moz_dom_ServiceWorkerRegistrationProxy_h
|
|
@ -61,6 +61,7 @@ UNIFIED_SOURCES += [
|
|||
'ServiceWorkerRegistrationImpl.cpp',
|
||||
'ServiceWorkerRegistrationInfo.cpp',
|
||||
'ServiceWorkerRegistrationParent.cpp',
|
||||
'ServiceWorkerRegistrationProxy.cpp',
|
||||
'ServiceWorkerScriptCache.cpp',
|
||||
'ServiceWorkerUnregisterJob.cpp',
|
||||
'ServiceWorkerUpdateJob.cpp',
|
||||
|
|
Загрузка…
Ссылка в новой задаче