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"
16 using mozilla::ipc::IPCResult
;
18 void ServiceWorkerRegistrationChild::ActorDestroy(ActorDestroyReason aReason
) {
19 mIPCWorkerRef
= nullptr;
22 mOwner
->RevokeActor(this);
23 MOZ_DIAGNOSTIC_ASSERT(!mOwner
);
27 IPCResult
ServiceWorkerRegistrationChild::RecvUpdateState(
28 const IPCServiceWorkerRegistrationDescriptor
& aDescriptor
) {
30 mOwner
->UpdateState(ServiceWorkerRegistrationDescriptor(aDescriptor
));
35 IPCResult
ServiceWorkerRegistrationChild::RecvFireUpdateFound() {
37 mOwner
->FireUpdateFound();
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
)) {
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
);
76 void ServiceWorkerRegistrationChild::RevokeOwner(
77 RemoteServiceWorkerRegistrationImpl
* aOwner
) {
78 MOZ_DIAGNOSTIC_ASSERT(mOwner
);
79 MOZ_DIAGNOSTIC_ASSERT(aOwner
== mOwner
);
83 void ServiceWorkerRegistrationChild::MaybeStartTeardown() {
84 if (mTeardownStarted
) {
87 mTeardownStarted
= true;
88 Unused
<< SendTeardown();
92 } // namespace mozilla