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 "ServiceWorkerChild.h"
8
#include "mozilla/dom/WorkerRef.h"
9
10
namespace mozilla {
11
namespace dom {
12
13
void ServiceWorkerChild::ActorDestroy(ActorDestroyReason aReason) {
14
mIPCWorkerRef = nullptr;
15
16
if (mOwner) {
17
mOwner->RevokeActor(this);
18
MOZ_DIAGNOSTIC_ASSERT(!mOwner);
19
}
20
}
21
22
// static
23
ServiceWorkerChild* ServiceWorkerChild::Create() {
24
ServiceWorkerChild* actor = new ServiceWorkerChild();
25
26
if (!NS_IsMainThread()) {
27
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
28
MOZ_DIAGNOSTIC_ASSERT(workerPrivate);
29
30
RefPtr<IPCWorkerRefHelper<ServiceWorkerChild>> helper =
31
new IPCWorkerRefHelper<ServiceWorkerChild>(actor);
32
33
actor->mIPCWorkerRef = IPCWorkerRef::Create(
34
workerPrivate, "ServiceWorkerChild",
35
[helper] { helper->Actor()->MaybeStartTeardown(); });
36
37
if (NS_WARN_IF(!actor->mIPCWorkerRef)) {
38
delete actor;
39
return nullptr;
40
}
41
}
42
43
return actor;
44
}
45
46
ServiceWorkerChild::ServiceWorkerChild()
47
: mOwner(nullptr), mTeardownStarted(false) {}
48
49
void ServiceWorkerChild::SetOwner(RemoteServiceWorkerImpl* aOwner) {
50
MOZ_DIAGNOSTIC_ASSERT(!mOwner);
51
MOZ_DIAGNOSTIC_ASSERT(aOwner);
52
mOwner = aOwner;
53
}
54
55
void ServiceWorkerChild::RevokeOwner(RemoteServiceWorkerImpl* aOwner) {
56
MOZ_DIAGNOSTIC_ASSERT(mOwner);
57
MOZ_DIAGNOSTIC_ASSERT(aOwner == mOwner);
58
mOwner = nullptr;
59
}
60
61
void ServiceWorkerChild::MaybeStartTeardown() {
62
if (mTeardownStarted) {
63
return;
64
}
65
mTeardownStarted = true;
66
Unused << SendTeardown();
67
}
68
69
} // namespace dom
70
} // namespace mozilla