Bug 1732409 let fake:true getUserMedia() parameter override loopback prefs r=jib
[gecko.git] / dom / serviceworkers / ServiceWorkerRegistrationChild.cpp
blob93d702be507255c173e167aebfa7353be5be402c
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 "RemoteServiceWorkerRegistrationImpl.h"
10 #include "mozilla/dom/WorkerCommon.h"
11 #include "mozilla/dom/WorkerRef.h"
13 namespace mozilla {
14 namespace dom {
16 using mozilla::ipc::IPCResult;
18 void ServiceWorkerRegistrationChild::ActorDestroy(ActorDestroyReason aReason) {
19 mIPCWorkerRef = nullptr;
21 if (mOwner) {
22 mOwner->RevokeActor(this);
23 MOZ_DIAGNOSTIC_ASSERT(!mOwner);
27 IPCResult ServiceWorkerRegistrationChild::RecvUpdateState(
28 const IPCServiceWorkerRegistrationDescriptor& aDescriptor) {
29 if (mOwner) {
30 mOwner->UpdateState(ServiceWorkerRegistrationDescriptor(aDescriptor));
32 return IPC_OK();
35 IPCResult ServiceWorkerRegistrationChild::RecvFireUpdateFound() {
36 if (mOwner) {
37 mOwner->FireUpdateFound();
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 RemoteServiceWorkerRegistrationImpl* aOwner) {
71 MOZ_DIAGNOSTIC_ASSERT(!mOwner);
72 MOZ_DIAGNOSTIC_ASSERT(aOwner);
73 mOwner = aOwner;
76 void ServiceWorkerRegistrationChild::RevokeOwner(
77 RemoteServiceWorkerRegistrationImpl* 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 dom
92 } // namespace mozilla