Skip to content

Commit

Permalink
Bug 1653470 - refcount PServiceWorkerRegistration r=dom-workers-and-s…
Browse files Browse the repository at this point in the history
…torage-reviewers,asuth

Depends on D83884

Differential Revision: https://phabricator.services.mozilla.com/D83885
  • Loading branch information
perryjiang committed Oct 23, 2020
1 parent 260415e commit 0e70329
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 74 deletions.
2 changes: 1 addition & 1 deletion dom/serviceworkers/PServiceWorkerRegistration.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include IPCServiceWorkerRegistrationDescriptor;
namespace mozilla {
namespace dom {

protocol PServiceWorkerRegistration
refcounted protocol PServiceWorkerRegistration
{
manager PBackground;

Expand Down
7 changes: 3 additions & 4 deletions dom/serviceworkers/RemoteServiceWorkerRegistrationImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,15 @@ void RemoteServiceWorkerRegistrationImpl::Unregister(

RemoteServiceWorkerRegistrationImpl::RemoteServiceWorkerRegistrationImpl(
const ServiceWorkerRegistrationDescriptor& aDescriptor)
: mActor(nullptr), mOuter(nullptr), mShutdown(false) {
: mOuter(nullptr), mShutdown(false) {
PBackgroundChild* parentActor =
BackgroundChild::GetOrCreateForCurrentThread();
if (NS_WARN_IF(!parentActor)) {
Shutdown();
return;
}

ServiceWorkerRegistrationChild* actor =
ServiceWorkerRegistrationChild::Create();
auto actor = ServiceWorkerRegistrationChild::Create();
if (NS_WARN_IF(!actor)) {
Shutdown();
return;
Expand All @@ -132,7 +131,7 @@ RemoteServiceWorkerRegistrationImpl::RemoteServiceWorkerRegistrationImpl(
}
MOZ_DIAGNOSTIC_ASSERT(sentActor == actor);

mActor = actor;
mActor = std::move(actor);
mActor->SetOwner(this);
}

Expand Down
2 changes: 1 addition & 1 deletion dom/serviceworkers/RemoteServiceWorkerRegistrationImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ServiceWorkerRegistrationChild;

class RemoteServiceWorkerRegistrationImpl final
: public ServiceWorkerRegistration::Inner {
ServiceWorkerRegistrationChild* mActor;
RefPtr<ServiceWorkerRegistrationChild> mActor;
ServiceWorkerRegistration* mOuter;
bool mShutdown;

Expand Down
22 changes: 0 additions & 22 deletions dom/serviceworkers/ServiceWorkerActors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,6 @@ void InitServiceWorkerContainerParent(PServiceWorkerContainerParent* aActor) {
actor->Init();
}

PServiceWorkerRegistrationChild* AllocServiceWorkerRegistrationChild() {
MOZ_CRASH("should not be called");
}

bool DeallocServiceWorkerRegistrationChild(
PServiceWorkerRegistrationChild* aActor) {
auto actor = static_cast<ServiceWorkerRegistrationChild*>(aActor);
delete actor;
return true;
}

PServiceWorkerRegistrationParent* AllocServiceWorkerRegistrationParent() {
return new ServiceWorkerRegistrationParent();
}

bool DeallocServiceWorkerRegistrationParent(
PServiceWorkerRegistrationParent* aActor) {
auto actor = static_cast<ServiceWorkerRegistrationParent*>(aActor);
delete actor;
return true;
}

void InitServiceWorkerRegistrationParent(
PServiceWorkerRegistrationParent* aActor,
const IPCServiceWorkerRegistrationDescriptor& aDescriptor) {
Expand Down
12 changes: 0 additions & 12 deletions dom/serviceworkers/ServiceWorkerActors.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace dom {
// PServiceWorker

class IPCServiceWorkerDescriptor;
class PServiceWorkerChild;
class PServiceWorkerParent;

void InitServiceWorkerParent(PServiceWorkerParent* aActor,
Expand All @@ -28,19 +27,8 @@ void InitServiceWorkerContainerParent(PServiceWorkerContainerParent* aActor);
// PServiceWorkerRegistration

class IPCServiceWorkerRegistrationDescriptor;
class PServiceWorkerRegistrationChild;
class PServiceWorkerRegistrationParent;

PServiceWorkerRegistrationChild* AllocServiceWorkerRegistrationChild();

bool DeallocServiceWorkerRegistrationChild(
PServiceWorkerRegistrationChild* aActor);

PServiceWorkerRegistrationParent* AllocServiceWorkerRegistrationParent();

bool DeallocServiceWorkerRegistrationParent(
PServiceWorkerRegistrationParent* aActor);

void InitServiceWorkerRegistrationParent(
PServiceWorkerRegistrationParent* aActor,
const IPCServiceWorkerRegistrationDescriptor& aDescriptor);
Expand Down
6 changes: 3 additions & 3 deletions dom/serviceworkers/ServiceWorkerRegistrationChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ IPCResult ServiceWorkerRegistrationChild::RecvFireUpdateFound() {
}

// static
ServiceWorkerRegistrationChild* ServiceWorkerRegistrationChild::Create() {
ServiceWorkerRegistrationChild* actor = new ServiceWorkerRegistrationChild();
RefPtr<ServiceWorkerRegistrationChild>
ServiceWorkerRegistrationChild::Create() {
RefPtr actor = new ServiceWorkerRegistrationChild;

if (!NS_IsMainThread()) {
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
Expand All @@ -54,7 +55,6 @@ ServiceWorkerRegistrationChild* ServiceWorkerRegistrationChild::Create() {
[helper] { helper->Actor()->MaybeStartTeardown(); });

if (NS_WARN_IF(!actor->mIPCWorkerRef)) {
delete actor;
return nullptr;
}
}
Expand Down
6 changes: 4 additions & 2 deletions dom/serviceworkers/ServiceWorkerRegistrationChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class ServiceWorkerRegistrationChild final

ServiceWorkerRegistrationChild();

~ServiceWorkerRegistrationChild() = default;

// PServiceWorkerRegistrationChild
void ActorDestroy(ActorDestroyReason aReason) override;

Expand All @@ -32,9 +34,9 @@ class ServiceWorkerRegistrationChild final
mozilla::ipc::IPCResult RecvFireUpdateFound() override;

public:
static ServiceWorkerRegistrationChild* Create();
NS_INLINE_DECL_REFCOUNTING(ServiceWorkerRegistrationChild, override);

~ServiceWorkerRegistrationChild() = default;
static RefPtr<ServiceWorkerRegistrationChild> Create();

void SetOwner(RemoteServiceWorkerRegistrationImpl* aOwner);

Expand Down
5 changes: 4 additions & 1 deletion dom/serviceworkers/ServiceWorkerRegistrationParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class ServiceWorkerRegistrationParent final
RefPtr<ServiceWorkerRegistrationProxy> mProxy;
bool mDeleteSent;

~ServiceWorkerRegistrationParent();

// PServiceWorkerRegistrationParent
void ActorDestroy(ActorDestroyReason aReason) override;

Expand All @@ -32,8 +34,9 @@ class ServiceWorkerRegistrationParent final
UpdateResolver&& aResolver) override;

public:
NS_INLINE_DECL_REFCOUNTING(ServiceWorkerRegistrationParent, override);

ServiceWorkerRegistrationParent();
~ServiceWorkerRegistrationParent();

void Init(const IPCServiceWorkerRegistrationDescriptor& aDescriptor);

Expand Down
4 changes: 1 addition & 3 deletions dom/serviceworkers/ServiceWorkerRegistrationProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ bool ServiceWorkerRegistrationProxy::MatchesDescriptor(

ServiceWorkerRegistrationProxy::ServiceWorkerRegistrationProxy(
const ServiceWorkerRegistrationDescriptor& aDescriptor)
: mActor(nullptr),
mEventTarget(GetCurrentSerialEventTarget()),
mDescriptor(aDescriptor) {}
: mEventTarget(GetCurrentSerialEventTarget()), mDescriptor(aDescriptor) {}

void ServiceWorkerRegistrationProxy::Init(
ServiceWorkerRegistrationParent* aActor) {
Expand Down
2 changes: 1 addition & 1 deletion dom/serviceworkers/ServiceWorkerRegistrationProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ServiceWorkerRegistrationParent;
class ServiceWorkerRegistrationProxy final
: public ServiceWorkerRegistrationListener {
// Background thread only
ServiceWorkerRegistrationParent* mActor;
RefPtr<ServiceWorkerRegistrationParent> mActor;

// Written on background thread and read on main thread
nsCOMPtr<nsISerialEventTarget> mEventTarget;
Expand Down
2 changes: 2 additions & 0 deletions dom/serviceworkers/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ EXPORTS.mozilla.dom += [
'ServiceWorkerParent.h',
'ServiceWorkerRegistrar.h',
'ServiceWorkerRegistration.h',
'ServiceWorkerRegistrationChild.h',
'ServiceWorkerRegistrationDescriptor.h',
'ServiceWorkerRegistrationInfo.h',
'ServiceWorkerRegistrationParent.h',
'ServiceWorkerShutdownState.h',
'ServiceWorkerUtils.h',
]
Expand Down
10 changes: 3 additions & 7 deletions ipc/glue/BackgroundChildImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,15 +653,11 @@ BackgroundChildImpl::AllocPServiceWorkerContainerChild() {
return mozilla::dom::ServiceWorkerContainerChild::Create();
}

PServiceWorkerRegistrationChild*
already_AddRefed<PServiceWorkerRegistrationChild>
BackgroundChildImpl::AllocPServiceWorkerRegistrationChild(
const IPCServiceWorkerRegistrationDescriptor&) {
return dom::AllocServiceWorkerRegistrationChild();
}

bool BackgroundChildImpl::DeallocPServiceWorkerRegistrationChild(
PServiceWorkerRegistrationChild* aActor) {
return dom::DeallocServiceWorkerRegistrationChild(aActor);
MOZ_CRASH("Shouldn't be called.");
return {};
}

dom::PEndpointForReportChild* BackgroundChildImpl::AllocPEndpointForReportChild(
Expand Down
8 changes: 3 additions & 5 deletions ipc/glue/BackgroundChildImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,9 @@ class BackgroundChildImpl : public PBackgroundChild,
already_AddRefed<PServiceWorkerContainerChild>
AllocPServiceWorkerContainerChild();

virtual PServiceWorkerRegistrationChild* AllocPServiceWorkerRegistrationChild(
const IPCServiceWorkerRegistrationDescriptor&) override;

virtual bool DeallocPServiceWorkerRegistrationChild(
PServiceWorkerRegistrationChild*) override;
already_AddRefed<PServiceWorkerRegistrationChild>
AllocPServiceWorkerRegistrationChild(
const IPCServiceWorkerRegistrationDescriptor&);

virtual PEndpointForReportChild* AllocPEndpointForReportChild(
const nsString& aGroupName, const PrincipalInfo& aPrincipalInfo) override;
Expand Down
10 changes: 3 additions & 7 deletions ipc/glue/BackgroundParentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "mozilla/dom/ServiceWorkerManagerParent.h"
#include "mozilla/dom/ServiceWorkerParent.h"
#include "mozilla/dom/ServiceWorkerRegistrar.h"
#include "mozilla/dom/ServiceWorkerRegistrationParent.h"
#include "mozilla/dom/SessionStorageManager.h"
#include "mozilla/dom/SharedWorkerParent.h"
#include "mozilla/dom/StorageActivityService.h"
Expand Down Expand Up @@ -1277,15 +1278,10 @@ BackgroundParentImpl::RecvPServiceWorkerContainerConstructor(
return IPC_OK();
}

PServiceWorkerRegistrationParent*
already_AddRefed<PServiceWorkerRegistrationParent>
BackgroundParentImpl::AllocPServiceWorkerRegistrationParent(
const IPCServiceWorkerRegistrationDescriptor&) {
return dom::AllocServiceWorkerRegistrationParent();
}

bool BackgroundParentImpl::DeallocPServiceWorkerRegistrationParent(
PServiceWorkerRegistrationParent* aActor) {
return dom::DeallocServiceWorkerRegistrationParent(aActor);
return MakeAndAddRef<mozilla::dom::ServiceWorkerRegistrationParent>();
}

mozilla::ipc::IPCResult
Expand Down
8 changes: 3 additions & 5 deletions ipc/glue/BackgroundParentImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,9 @@ class BackgroundParentImpl : public PBackgroundParent,
mozilla::ipc::IPCResult RecvPServiceWorkerContainerConstructor(
PServiceWorkerContainerParent* aActor) override;

PServiceWorkerRegistrationParent* AllocPServiceWorkerRegistrationParent(
const IPCServiceWorkerRegistrationDescriptor&) override;

bool DeallocPServiceWorkerRegistrationParent(
PServiceWorkerRegistrationParent*) override;
already_AddRefed<PServiceWorkerRegistrationParent>
AllocPServiceWorkerRegistrationParent(
const IPCServiceWorkerRegistrationDescriptor&) final;

mozilla::ipc::IPCResult RecvPServiceWorkerRegistrationConstructor(
PServiceWorkerRegistrationParent* aActor,
Expand Down

0 comments on commit 0e70329

Please sign in to comment.