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