Bug 1459209 P3 Scaffold RemoteServiceWorkerContainerImpl to connect the binding ServiceWorkerContainer to the PServiceWorkerContainerChild actor. r=mrbkap

--HG--
extra : rebase_source : b0a51ce7bbc1b9b27531584d0647ae28d56b15e2
This commit is contained in:
Ben Kelly 2018-07-09 16:02:39 -07:00
parent 09c855d41b
commit 9797d85bc5
10 changed files with 305 additions and 4 deletions

View File

@ -0,0 +1,144 @@
/* -*- 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 "RemoteServiceWorkerContainerImpl.h"
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/PBackgroundChild.h"
#include "ServiceWorkerContainerChild.h"
namespace mozilla {
namespace dom {
using mozilla::ipc::BackgroundChild;
using mozilla::ipc::PBackgroundChild;
RemoteServiceWorkerContainerImpl::~RemoteServiceWorkerContainerImpl()
{
Shutdown();
MOZ_DIAGNOSTIC_ASSERT(!mOuter);
}
void
RemoteServiceWorkerContainerImpl::Shutdown()
{
if (mShutdown) {
return;
}
mShutdown = true;
if (mActor) {
mActor->RevokeOwner(this);
mActor->MaybeStartTeardown();
mActor = nullptr;
}
}
void
RemoteServiceWorkerContainerImpl::AddContainer(ServiceWorkerContainer* aOuter)
{
MOZ_DIAGNOSTIC_ASSERT(aOuter);
MOZ_DIAGNOSTIC_ASSERT(!mOuter);
mOuter = aOuter;
}
void
RemoteServiceWorkerContainerImpl::RemoveContainer(ServiceWorkerContainer* aOuter)
{
MOZ_DIAGNOSTIC_ASSERT(aOuter);
MOZ_DIAGNOSTIC_ASSERT(mOuter == aOuter);
mOuter = nullptr;
}
void
RemoteServiceWorkerContainerImpl::Register(const ClientInfo& aClientInfo,
const nsACString& aScopeURL,
const nsACString& aScriptURL,
ServiceWorkerUpdateViaCache aUpdateViaCache,
ServiceWorkerRegistrationCallback&& aSuccessCB,
ServiceWorkerFailureCallback&& aFailureCB) const
{
// TODO
}
void
RemoteServiceWorkerContainerImpl::GetRegistration(const ClientInfo& aClientInfo,
const nsACString& aURL,
ServiceWorkerRegistrationCallback&& aSuccessCB,
ServiceWorkerFailureCallback&& aFailureCB) const
{
// TODO
}
void
RemoteServiceWorkerContainerImpl::GetRegistrations(const ClientInfo& aClientInfo,
ServiceWorkerRegistrationListCallback&& aSuccessCB,
ServiceWorkerFailureCallback&& aFailureCB) const
{
// TODO
}
void
RemoteServiceWorkerContainerImpl::GetReady(const ClientInfo& aClientInfo,
ServiceWorkerRegistrationCallback&& aSuccessCB,
ServiceWorkerFailureCallback&& aFailureCB) const
{
// TODO
}
RemoteServiceWorkerContainerImpl::RemoteServiceWorkerContainerImpl()
: mActor(nullptr)
, mOuter(nullptr)
, mShutdown(false)
{
PBackgroundChild* parentActor = BackgroundChild::GetOrCreateForCurrentThread();
if (NS_WARN_IF(!parentActor)) {
Shutdown();
return;
}
RefPtr<WorkerHolderToken> workerHolderToken;
if (!NS_IsMainThread()) {
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_DIAGNOSTIC_ASSERT(workerPrivate);
workerHolderToken =
WorkerHolderToken::Create(workerPrivate, Terminating,
WorkerHolderToken::AllowIdleShutdownStart);
if (NS_WARN_IF(!workerHolderToken)) {
Shutdown();
return;
}
}
ServiceWorkerContainerChild* actor =
new ServiceWorkerContainerChild(workerHolderToken);
PServiceWorkerContainerChild* sentActor =
parentActor->SendPServiceWorkerContainerConstructor(actor);
if (NS_WARN_IF(!sentActor)) {
Shutdown();
return;
}
MOZ_DIAGNOSTIC_ASSERT(sentActor == actor);
mActor = actor;
mActor->SetOwner(this);
}
void
RemoteServiceWorkerContainerImpl::RevokeActor(ServiceWorkerContainerChild* aActor)
{
MOZ_DIAGNOSTIC_ASSERT(mActor);
MOZ_DIAGNOSTIC_ASSERT(mActor == aActor);
mActor->RevokeOwner(this);
mActor = nullptr;
mShutdown = true;
}
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,71 @@
/* -*- 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 mozilla_dom_remoteserviceworkercontainerimpl_h__
#define mozilla_dom_remoteserviceworkercontainerimpl_h__
#include "ServiceWorkerContainer.h"
namespace mozilla {
namespace dom {
class ServiceWorkerContainerChild;
class RemoteServiceWorkerContainerImpl final : public ServiceWorkerContainer::Inner
{
ServiceWorkerContainerChild* mActor;
ServiceWorkerContainer* mOuter;
bool mShutdown;
~RemoteServiceWorkerContainerImpl();
void
Shutdown();
// ServiceWorkerContainer::Inner implementation
void
AddContainer(ServiceWorkerContainer* aOuter) override;
void
RemoveContainer(ServiceWorkerContainer* aOuter) override;
void
Register(const ClientInfo& aClientInfo,
const nsACString& aScopeURL,
const nsACString& aScriptURL,
ServiceWorkerUpdateViaCache aUpdateViaCache,
ServiceWorkerRegistrationCallback&& aSuccessCB,
ServiceWorkerFailureCallback&& aFailureCB) const override;
void
GetRegistration(const ClientInfo& aClientInfo,
const nsACString& aURL,
ServiceWorkerRegistrationCallback&& aSuccessCB,
ServiceWorkerFailureCallback&& aFailureCB) const override;
void
GetRegistrations(const ClientInfo& aClientInfo,
ServiceWorkerRegistrationListCallback&& aSuccessCB,
ServiceWorkerFailureCallback&& aFailureCB) const override;
void
GetReady(const ClientInfo& aClientInfo,
ServiceWorkerRegistrationCallback&& aSuccessCB,
ServiceWorkerFailureCallback&& aFailureCB) const override;
public:
RemoteServiceWorkerContainerImpl();
void
RevokeActor(ServiceWorkerContainerChild* aActor);
NS_INLINE_DECL_REFCOUNTING(RemoteServiceWorkerContainerImpl, override)
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_remoteserviceworkercontainerimpl_h__

View File

@ -55,7 +55,7 @@ InitServiceWorkerParent(PServiceWorkerParent* aActor,
PServiceWorkerContainerChild*
AllocServiceWorkerContainerChild()
{
return new ServiceWorkerContainerChild();
MOZ_CRASH("should not be called");
}
bool

View File

@ -28,9 +28,11 @@
#include "mozilla/dom/ServiceWorker.h"
#include "mozilla/dom/ServiceWorkerContainerBinding.h"
#include "RemoteServiceWorkerContainerImpl.h"
#include "ServiceWorker.h"
#include "ServiceWorkerContainerImpl.h"
#include "ServiceWorkerRegistration.h"
#include "ServiceWorkerUtils.h"
namespace mozilla {
namespace dom {
@ -67,7 +69,14 @@ ServiceWorkerContainer::IsEnabled(JSContext* aCx, JSObject* aGlobal)
already_AddRefed<ServiceWorkerContainer>
ServiceWorkerContainer::Create(nsIGlobalObject* aGlobal)
{
RefPtr<Inner> inner = new ServiceWorkerContainerImpl();
RefPtr<Inner> inner;
if (ServiceWorkerParentInterceptEnabled()) {
inner = new RemoteServiceWorkerContainerImpl();
} else {
inner = new ServiceWorkerContainerImpl();
}
NS_ENSURE_TRUE(inner, nullptr);
RefPtr<ServiceWorkerContainer> ref =
new ServiceWorkerContainer(aGlobal, inner.forget());
return ref.forget();

View File

@ -6,13 +6,64 @@
#include "mozilla/dom/PServiceWorkerContainerChild.h"
#include "RemoteServiceWorkerContainerImpl.h"
namespace mozilla {
namespace dom {
void
ServiceWorkerContainerChild::ActorDestroy(ActorDestroyReason aReason)
{
// TODO
if (mWorkerHolderToken) {
mWorkerHolderToken->RemoveListener(this);
mWorkerHolderToken = nullptr;
}
if (mOwner) {
mOwner->RevokeActor(this);
MOZ_DIAGNOSTIC_ASSERT(!mOwner);
}
}
void
ServiceWorkerContainerChild::WorkerShuttingDown()
{
MaybeStartTeardown();
}
ServiceWorkerContainerChild::ServiceWorkerContainerChild(WorkerHolderToken* aWorkerHolderToken)
: mWorkerHolderToken(aWorkerHolderToken)
, mOwner(nullptr)
, mTeardownStarted(false)
{
if (mWorkerHolderToken) {
mWorkerHolderToken->AddListener(this);
}
}
void
ServiceWorkerContainerChild::SetOwner(RemoteServiceWorkerContainerImpl* aOwner)
{
MOZ_DIAGNOSTIC_ASSERT(!mOwner);
MOZ_DIAGNOSTIC_ASSERT(aOwner);
mOwner = aOwner;
}
void
ServiceWorkerContainerChild::RevokeOwner(RemoteServiceWorkerContainerImpl* aOwner)
{
MOZ_DIAGNOSTIC_ASSERT(mOwner);
MOZ_DIAGNOSTIC_ASSERT(aOwner == mOwner);
mOwner = nullptr;
}
void
ServiceWorkerContainerChild::MaybeStartTeardown()
{
if (mTeardownStarted) {
return;
}
mTeardownStarted = true;
}
} // namespace dom

View File

@ -8,19 +8,38 @@
#define mozilla_dom_serviceworkercontainerchild_h__
#include "mozilla/dom/PServiceWorkerContainerChild.h"
#include "mozilla/dom/WorkerHolderToken.h"
namespace mozilla {
namespace dom {
class ServiceWorkerContainerChild final : public PServiceWorkerContainerChild
, public WorkerHolderToken::Listener
{
RefPtr<WorkerHolderToken> mWorkerHolderToken;
RemoteServiceWorkerContainerImpl* mOwner;
bool mTeardownStarted;
// PServiceWorkerContainerChild
void
ActorDestroy(ActorDestroyReason aReason) override;
// WorkerHolderToken::Listener
void
WorkerShuttingDown() override;
public:
ServiceWorkerContainerChild() = default;
explicit ServiceWorkerContainerChild(WorkerHolderToken* aWorkerHolderToken);
~ServiceWorkerContainerChild() = default;
void
SetOwner(RemoteServiceWorkerContainerImpl* aOwner);
void
RevokeOwner(RemoteServiceWorkerContainerImpl* aOwner);
void
MaybeStartTeardown();
};
} // namespace dom

View File

@ -6,6 +6,8 @@
#include "ServiceWorkerContainerImpl.h"
#include "ServiceWorkerRegistration.h"
namespace mozilla {
namespace dom {

View File

@ -6,6 +6,7 @@
#include "ServiceWorkerJobQueue.h"
#include "nsThreadUtils.h"
#include "ServiceWorkerJob.h"
#include "mozilla/dom/WorkerCommon.h"

View File

@ -6,7 +6,10 @@
#include "ServiceWorkerUnregisterJob.h"
#include "mozilla/Unused.h"
#include "nsIPushService.h"
#include "nsThreadUtils.h"
#include "ServiceWorkerManager.h"
namespace mozilla {
namespace dom {

View File

@ -28,6 +28,7 @@ EXPORTS.mozilla.dom += [
]
UNIFIED_SOURCES += [
'RemoteServiceWorkerContainerImpl.cpp',
'RemoteServiceWorkerImpl.cpp',
'ServiceWorker.cpp',
'ServiceWorkerActors.cpp',