Bug 1653470 - refcount PServiceWorker r=dom-workers-and-storage-reviewers,asuth

Differential Revision: https://phabricator.services.mozilla.com/D83883
This commit is contained in:
Perry Jiang 2020-10-23 11:50:00 +00:00
parent c6950091db
commit bad3dff4d7
15 changed files with 36 additions and 65 deletions

View File

@ -10,7 +10,7 @@ include DOMTypes;
namespace mozilla {
namespace dom {
protocol PServiceWorker
refcounted protocol PServiceWorker
{
manager PBackground;

View File

@ -6,6 +6,8 @@
#include "RemoteServiceWorkerImpl.h"
#include <utility>
#include "mozilla/dom/ClientInfo.h"
#include "mozilla/dom/ClientState.h"
#include "mozilla/ipc/BackgroundChild.h"
@ -77,7 +79,7 @@ void RemoteServiceWorkerImpl::PostMessage(
RemoteServiceWorkerImpl::RemoteServiceWorkerImpl(
const ServiceWorkerDescriptor& aDescriptor)
: mActor(nullptr), mWorker(nullptr), mShutdown(false) {
: mWorker(nullptr), mShutdown(false) {
PBackgroundChild* parentActor =
BackgroundChild::GetOrCreateForCurrentThread();
if (NS_WARN_IF(!parentActor)) {
@ -85,7 +87,7 @@ RemoteServiceWorkerImpl::RemoteServiceWorkerImpl(
return;
}
ServiceWorkerChild* actor = ServiceWorkerChild::Create();
RefPtr<ServiceWorkerChild> actor = ServiceWorkerChild::Create();
if (NS_WARN_IF(!actor)) {
Shutdown();
return;
@ -99,7 +101,7 @@ RemoteServiceWorkerImpl::RemoteServiceWorkerImpl(
}
MOZ_DIAGNOSTIC_ASSERT(sentActor == actor);
mActor = actor;
mActor = std::move(actor);
mActor->SetOwner(this);
}

View File

@ -15,7 +15,7 @@ namespace dom {
class ServiceWorkerChild;
class RemoteServiceWorkerImpl final : public ServiceWorker::Inner {
ServiceWorkerChild* mActor;
RefPtr<ServiceWorkerChild> mActor;
ServiceWorker* mWorker;
bool mShutdown;

View File

@ -16,26 +16,6 @@
namespace mozilla {
namespace dom {
PServiceWorkerChild* AllocServiceWorkerChild() {
MOZ_CRASH("should not be called");
}
bool DeallocServiceWorkerChild(PServiceWorkerChild* aActor) {
auto actor = static_cast<ServiceWorkerChild*>(aActor);
delete actor;
return true;
}
PServiceWorkerParent* AllocServiceWorkerParent() {
return new ServiceWorkerParent();
}
bool DeallocServiceWorkerParent(PServiceWorkerParent* aActor) {
auto actor = static_cast<ServiceWorkerParent*>(aActor);
delete actor;
return true;
}
void InitServiceWorkerParent(PServiceWorkerParent* aActor,
const IPCServiceWorkerDescriptor& aDescriptor) {
auto actor = static_cast<ServiceWorkerParent*>(aActor);

View File

@ -16,14 +16,6 @@ class IPCServiceWorkerDescriptor;
class PServiceWorkerChild;
class PServiceWorkerParent;
PServiceWorkerChild* AllocServiceWorkerChild();
bool DeallocServiceWorkerChild(PServiceWorkerChild* aActor);
PServiceWorkerParent* AllocServiceWorkerParent();
bool DeallocServiceWorkerParent(PServiceWorkerParent* aActor);
void InitServiceWorkerParent(PServiceWorkerParent* aActor,
const IPCServiceWorkerDescriptor& aDescriptor);

View File

@ -20,8 +20,8 @@ void ServiceWorkerChild::ActorDestroy(ActorDestroyReason aReason) {
}
// static
ServiceWorkerChild* ServiceWorkerChild::Create() {
ServiceWorkerChild* actor = new ServiceWorkerChild();
RefPtr<ServiceWorkerChild> ServiceWorkerChild::Create() {
RefPtr<ServiceWorkerChild> actor = new ServiceWorkerChild();
if (!NS_IsMainThread()) {
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
@ -35,7 +35,6 @@ ServiceWorkerChild* ServiceWorkerChild::Create() {
[helper] { helper->Actor()->MaybeStartTeardown(); });
if (NS_WARN_IF(!actor->mIPCWorkerRef)) {
delete actor;
return nullptr;
}
}

View File

@ -22,13 +22,15 @@ class ServiceWorkerChild final : public PServiceWorkerChild {
ServiceWorkerChild();
~ServiceWorkerChild() = default;
// PServiceWorkerChild
void ActorDestroy(ActorDestroyReason aReason) override;
public:
static ServiceWorkerChild* Create();
NS_INLINE_DECL_REFCOUNTING(ServiceWorkerChild, override);
~ServiceWorkerChild() = default;
static RefPtr<ServiceWorkerChild> Create();
void SetOwner(RemoteServiceWorkerImpl* aOwner);

View File

@ -19,6 +19,8 @@ class ServiceWorkerParent final : public PServiceWorkerParent {
RefPtr<ServiceWorkerProxy> mProxy;
bool mDeleteSent;
~ServiceWorkerParent();
// PServiceWorkerParent
void ActorDestroy(ActorDestroyReason aReason) override;
@ -29,8 +31,9 @@ class ServiceWorkerParent final : public PServiceWorkerParent {
const ClientInfoAndState& aSource) override;
public:
NS_INLINE_DECL_REFCOUNTING(ServiceWorkerParent, override);
ServiceWorkerParent();
~ServiceWorkerParent();
void Init(const IPCServiceWorkerDescriptor& aDescriptor);

View File

@ -66,9 +66,7 @@ void ServiceWorkerProxy::StopListeningOnMainThread() {
ServiceWorkerProxy::ServiceWorkerProxy(
const ServiceWorkerDescriptor& aDescriptor)
: mActor(nullptr),
mEventTarget(GetCurrentSerialEventTarget()),
mDescriptor(aDescriptor) {}
: mEventTarget(GetCurrentSerialEventTarget()), mDescriptor(aDescriptor) {}
void ServiceWorkerProxy::Init(ServiceWorkerParent* aActor) {
AssertIsOnBackgroundThread();

View File

@ -19,7 +19,7 @@ class ServiceWorkerParent;
class ServiceWorkerProxy final {
// Background thread only
ServiceWorkerParent* mActor;
RefPtr<ServiceWorkerParent> mActor;
// Written on background thread and read on main thread
nsCOMPtr<nsISerialEventTarget> mEventTarget;

View File

@ -15,6 +15,7 @@ EXPORTS.mozilla.dom += [
'FetchEventOpProxyParent.h',
'ServiceWorker.h',
'ServiceWorkerActors.h',
'ServiceWorkerChild.h',
'ServiceWorkerCloneData.h',
'ServiceWorkerContainer.h',
'ServiceWorkerDescriptor.h',
@ -27,6 +28,7 @@ EXPORTS.mozilla.dom += [
'ServiceWorkerManagerParent.h',
'ServiceWorkerOp.h',
'ServiceWorkerOpPromise.h',
'ServiceWorkerParent.h',
'ServiceWorkerRegistrar.h',
'ServiceWorkerRegistration.h',
'ServiceWorkerRegistrationDescriptor.h',

View File

@ -35,6 +35,7 @@
#include "mozilla/dom/RemoteWorkerChild.h"
#include "mozilla/dom/RemoteWorkerControllerChild.h"
#include "mozilla/dom/RemoteWorkerServiceChild.h"
#include "mozilla/dom/ServiceWorkerChild.h"
#include "mozilla/dom/SharedWorkerChild.h"
#include "mozilla/dom/StorageIPC.h"
#include "mozilla/dom/GamepadEventChannelChild.h"
@ -639,14 +640,11 @@ bool BackgroundChildImpl::DeallocPWebAuthnTransactionChild(
return true;
}
PServiceWorkerChild* BackgroundChildImpl::AllocPServiceWorkerChild(
already_AddRefed<PServiceWorkerChild>
BackgroundChildImpl::AllocPServiceWorkerChild(
const IPCServiceWorkerDescriptor&) {
return dom::AllocServiceWorkerChild();
}
bool BackgroundChildImpl::DeallocPServiceWorkerChild(
PServiceWorkerChild* aActor) {
return dom::DeallocServiceWorkerChild(aActor);
MOZ_CRASH("Shouldn't be called.");
return {};
}
PServiceWorkerContainerChild*

View File

@ -243,10 +243,8 @@ class BackgroundChildImpl : public PBackgroundChild,
virtual PMIDIManagerChild* AllocPMIDIManagerChild() override;
virtual bool DeallocPMIDIManagerChild(PMIDIManagerChild*) override;
virtual PServiceWorkerChild* AllocPServiceWorkerChild(
const IPCServiceWorkerDescriptor&) override;
virtual bool DeallocPServiceWorkerChild(PServiceWorkerChild*) override;
already_AddRefed<PServiceWorkerChild> AllocPServiceWorkerChild(
const IPCServiceWorkerDescriptor&);
virtual PServiceWorkerContainerChild* AllocPServiceWorkerContainerChild()
override;

View File

@ -39,6 +39,7 @@
#include "mozilla/dom/ReportingHeader.h"
#include "mozilla/dom/ServiceWorkerActors.h"
#include "mozilla/dom/ServiceWorkerManagerParent.h"
#include "mozilla/dom/ServiceWorkerParent.h"
#include "mozilla/dom/ServiceWorkerRegistrar.h"
#include "mozilla/dom/SessionStorageManager.h"
#include "mozilla/dom/SharedWorkerParent.h"
@ -91,6 +92,7 @@ using mozilla::dom::PMIDIPortParent;
using mozilla::dom::PServiceWorkerContainerParent;
using mozilla::dom::PServiceWorkerParent;
using mozilla::dom::PServiceWorkerRegistrationParent;
using mozilla::dom::ServiceWorkerParent;
using mozilla::dom::UDPSocketParent;
using mozilla::dom::WebAuthnTransactionParent;
using mozilla::dom::cache::PCacheParent;
@ -1249,14 +1251,11 @@ IPCResult BackgroundParentImpl::RecvStorageActivity(
return IPC_OK();
}
PServiceWorkerParent* BackgroundParentImpl::AllocPServiceWorkerParent(
already_AddRefed<PServiceWorkerParent>
BackgroundParentImpl::AllocPServiceWorkerParent(
const IPCServiceWorkerDescriptor&) {
return dom::AllocServiceWorkerParent();
}
bool BackgroundParentImpl::DeallocPServiceWorkerParent(
PServiceWorkerParent* aActor) {
return dom::DeallocServiceWorkerParent(aActor);
return MakeAndAddRef<ServiceWorkerParent>();
;
}
IPCResult BackgroundParentImpl::RecvPServiceWorkerConstructor(

View File

@ -361,10 +361,8 @@ class BackgroundParentImpl : public PBackgroundParent,
mozilla::ipc::IPCResult RecvStorageActivity(
const PrincipalInfo& aPrincipalInfo) override;
PServiceWorkerParent* AllocPServiceWorkerParent(
const IPCServiceWorkerDescriptor&) override;
bool DeallocPServiceWorkerParent(PServiceWorkerParent*) override;
already_AddRefed<PServiceWorkerParent> AllocPServiceWorkerParent(
const IPCServiceWorkerDescriptor&) final;
mozilla::ipc::IPCResult RecvPServiceWorkerConstructor(
PServiceWorkerParent* aActor,