Bug 1842509 - Remove media.webvtt.regions.enabled pref r=alwu,webidl,smaug,peterv
[gecko.git] / dom / serviceworkers / ServiceWorkerContainerChild.cpp
blob1093bca91a20920063a9b689dccee5dd04de1a94
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;
19 if (mOwner) {
20 mOwner->RevokeActor(this);
21 MOZ_DIAGNOSTIC_ASSERT(!mOwner);
25 // static
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)) {
41 return nullptr;
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);
54 mOwner = aOwner;
57 void ServiceWorkerContainerChild::RevokeOwner(ServiceWorkerContainer* aOwner) {
58 MOZ_DIAGNOSTIC_ASSERT(mOwner);
59 MOZ_DIAGNOSTIC_ASSERT(aOwner == mOwner);
60 mOwner = nullptr;
63 void ServiceWorkerContainerChild::MaybeStartTeardown() {
64 if (mTeardownStarted) {
65 return;
67 mTeardownStarted = true;
70 } // namespace mozilla::dom