1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/PServiceWorkerContainerChild.h"
8 #include "mozilla/dom/WorkerCommon.h"
9 #include "mozilla/dom/WorkerRef.h"
11 #include "ServiceWorkerContainer.h"
12 #include "ServiceWorkerContainerChild.h"
14 namespace mozilla::dom
{
16 void ServiceWorkerContainerChild::ActorDestroy(ActorDestroyReason aReason
) {
17 mIPCWorkerRef
= nullptr;
20 mOwner
->RevokeActor(this);
21 MOZ_DIAGNOSTIC_ASSERT(!mOwner
);
26 already_AddRefed
<ServiceWorkerContainerChild
>
27 ServiceWorkerContainerChild::Create() {
28 RefPtr actor
= new ServiceWorkerContainerChild
;
30 if (!NS_IsMainThread()) {
31 WorkerPrivate
* workerPrivate
= GetCurrentThreadWorkerPrivate();
32 MOZ_DIAGNOSTIC_ASSERT(workerPrivate
);
34 RefPtr
<IPCWorkerRefHelper
<ServiceWorkerContainerChild
>> helper
=
35 new IPCWorkerRefHelper
<ServiceWorkerContainerChild
>(actor
);
37 actor
->mIPCWorkerRef
= IPCWorkerRef::Create(
38 workerPrivate
, "ServiceWorkerContainerChild",
39 [helper
] { helper
->Actor()->MaybeStartTeardown(); });
40 if (NS_WARN_IF(!actor
->mIPCWorkerRef
)) {
45 return actor
.forget();
48 ServiceWorkerContainerChild::ServiceWorkerContainerChild()
49 : mOwner(nullptr), mTeardownStarted(false) {}
51 void ServiceWorkerContainerChild::SetOwner(ServiceWorkerContainer
* aOwner
) {
52 MOZ_DIAGNOSTIC_ASSERT(!mOwner
);
53 MOZ_DIAGNOSTIC_ASSERT(aOwner
);
57 void ServiceWorkerContainerChild::RevokeOwner(ServiceWorkerContainer
* aOwner
) {
58 MOZ_DIAGNOSTIC_ASSERT(mOwner
);
59 MOZ_DIAGNOSTIC_ASSERT(aOwner
== mOwner
);
63 void ServiceWorkerContainerChild::MaybeStartTeardown() {
64 if (mTeardownStarted
) {
67 mTeardownStarted
= true;
70 } // namespace mozilla::dom