Source code

Revision control

Other Tools

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/. */
6
7
#include "ServiceWorkerRegistrationChild.h"
8
9
#include "RemoteServiceWorkerRegistrationImpl.h"
10
#include "mozilla/dom/WorkerRef.h"
11
12
namespace mozilla {
13
namespace dom {
14
15
using mozilla::ipc::IPCResult;
16
17
void ServiceWorkerRegistrationChild::ActorDestroy(ActorDestroyReason aReason) {
18
mIPCWorkerRef = nullptr;
19
20
if (mOwner) {
21
mOwner->RevokeActor(this);
22
MOZ_DIAGNOSTIC_ASSERT(!mOwner);
23
}
24
}
25
26
IPCResult ServiceWorkerRegistrationChild::RecvUpdateState(
27
const IPCServiceWorkerRegistrationDescriptor& aDescriptor) {
28
if (mOwner) {
29
mOwner->UpdateState(ServiceWorkerRegistrationDescriptor(aDescriptor));
30
}
31
return IPC_OK();
32
}
33
34
IPCResult ServiceWorkerRegistrationChild::RecvFireUpdateFound() {
35
if (mOwner) {
36
mOwner->FireUpdateFound();
37
}
38
return IPC_OK();
39
}
40
41
// static
42
ServiceWorkerRegistrationChild* ServiceWorkerRegistrationChild::Create() {
43
ServiceWorkerRegistrationChild* actor = new ServiceWorkerRegistrationChild();
44
45
if (!NS_IsMainThread()) {
46
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
47
MOZ_DIAGNOSTIC_ASSERT(workerPrivate);
48
49
RefPtr<IPCWorkerRefHelper<ServiceWorkerRegistrationChild>> helper =
50
new IPCWorkerRefHelper<ServiceWorkerRegistrationChild>(actor);
51
52
actor->mIPCWorkerRef = IPCWorkerRef::Create(
53
workerPrivate, "ServiceWorkerRegistrationChild",
54
[helper] { helper->Actor()->MaybeStartTeardown(); });
55
56
if (NS_WARN_IF(!actor->mIPCWorkerRef)) {
57
delete actor;
58
return nullptr;
59
}
60
}
61
62
return actor;
63
}
64
65
ServiceWorkerRegistrationChild::ServiceWorkerRegistrationChild()
66
: mOwner(nullptr), mTeardownStarted(false) {}
67
68
void ServiceWorkerRegistrationChild::SetOwner(
69
RemoteServiceWorkerRegistrationImpl* aOwner) {
70
MOZ_DIAGNOSTIC_ASSERT(!mOwner);
71
MOZ_DIAGNOSTIC_ASSERT(aOwner);
72
mOwner = aOwner;
73
}
74
75
void ServiceWorkerRegistrationChild::RevokeOwner(
76
RemoteServiceWorkerRegistrationImpl* aOwner) {
77
MOZ_DIAGNOSTIC_ASSERT(mOwner);
78
MOZ_DIAGNOSTIC_ASSERT(aOwner == mOwner);
79
mOwner = nullptr;
80
}
81
82
void ServiceWorkerRegistrationChild::MaybeStartTeardown() {
83
if (mTeardownStarted) {
84
return;
85
}
86
mTeardownStarted = true;
87
Unused << SendTeardown();
88
}
89
90
} // namespace dom
91
} // namespace mozilla