Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / dom / serviceworkers / ServiceWorkerRegistrationChild.cpp
blobb382f6dcfaf92d7bbcfc42eea7727a1741d84cc2
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 "ServiceWorkerRegistrationChild.h"
9 #include "ServiceWorkerRegistration.h"
10 #include "mozilla/dom/WorkerCommon.h"
11 #include "mozilla/dom/WorkerRef.h"
13 namespace mozilla::dom {
15 using mozilla::ipc::IPCResult;
17 void ServiceWorkerRegistrationChild::ActorDestroy(ActorDestroyReason aReason) {
18 mIPCWorkerRef = nullptr;
20 if (mOwner) {
21 mOwner->RevokeActor(this);
22 MOZ_DIAGNOSTIC_ASSERT(!mOwner);
26 IPCResult ServiceWorkerRegistrationChild::RecvUpdateState(
27 const IPCServiceWorkerRegistrationDescriptor& aDescriptor) {
28 if (mOwner) {
29 RefPtr<ServiceWorkerRegistration> owner = mOwner;
30 owner->UpdateState(ServiceWorkerRegistrationDescriptor(aDescriptor));
32 return IPC_OK();
35 IPCResult ServiceWorkerRegistrationChild::RecvFireUpdateFound() {
36 if (mOwner) {
37 mOwner->MaybeDispatchUpdateFoundRunnable();
39 return IPC_OK();
42 // static
43 RefPtr<ServiceWorkerRegistrationChild>
44 ServiceWorkerRegistrationChild::Create() {
45 RefPtr actor = new ServiceWorkerRegistrationChild;
47 if (!NS_IsMainThread()) {
48 WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
49 MOZ_DIAGNOSTIC_ASSERT(workerPrivate);
51 RefPtr<IPCWorkerRefHelper<ServiceWorkerRegistrationChild>> helper =
52 new IPCWorkerRefHelper<ServiceWorkerRegistrationChild>(actor);
54 actor->mIPCWorkerRef = IPCWorkerRef::Create(
55 workerPrivate, "ServiceWorkerRegistrationChild",
56 [helper] { helper->Actor()->MaybeStartTeardown(); });
58 if (NS_WARN_IF(!actor->mIPCWorkerRef)) {
59 return nullptr;
63 return actor;
66 ServiceWorkerRegistrationChild::ServiceWorkerRegistrationChild()
67 : mOwner(nullptr), mTeardownStarted(false) {}
69 void ServiceWorkerRegistrationChild::SetOwner(
70 ServiceWorkerRegistration* aOwner) {
71 MOZ_DIAGNOSTIC_ASSERT(!mOwner);
72 MOZ_DIAGNOSTIC_ASSERT(aOwner);
73 mOwner = aOwner;
76 void ServiceWorkerRegistrationChild::RevokeOwner(
77 ServiceWorkerRegistration* aOwner) {
78 MOZ_DIAGNOSTIC_ASSERT(mOwner);
79 MOZ_DIAGNOSTIC_ASSERT(aOwner == mOwner);
80 mOwner = nullptr;
83 void ServiceWorkerRegistrationChild::MaybeStartTeardown() {
84 if (mTeardownStarted) {
85 return;
87 mTeardownStarted = true;
88 Unused << SendTeardown();
91 } // namespace mozilla::dom