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 "ServiceWorkerRegistrationParent.h"
8
9
#include "ServiceWorkerRegistrationProxy.h"
10
11
namespace mozilla {
12
namespace dom {
13
14
using mozilla::ipc::IPCResult;
15
16
void ServiceWorkerRegistrationParent::ActorDestroy(ActorDestroyReason aReason) {
17
if (mProxy) {
18
mProxy->RevokeActor(this);
19
mProxy = nullptr;
20
}
21
}
22
23
IPCResult ServiceWorkerRegistrationParent::RecvTeardown() {
24
MaybeSendDelete();
25
return IPC_OK();
26
}
27
28
namespace {
29
30
void ResolveUnregister(
31
PServiceWorkerRegistrationParent::UnregisterResolver&& aResolver,
32
bool aSuccess, nsresult aRv) {
33
aResolver(Tuple<const bool&, const CopyableErrorResult&>(
34
aSuccess, CopyableErrorResult(aRv)));
35
}
36
37
} // anonymous namespace
38
39
IPCResult ServiceWorkerRegistrationParent::RecvUnregister(
40
UnregisterResolver&& aResolver) {
41
if (!mProxy) {
42
ResolveUnregister(std::move(aResolver), false,
43
NS_ERROR_DOM_INVALID_STATE_ERR);
44
return IPC_OK();
45
}
46
47
mProxy->Unregister()->Then(
48
GetCurrentThreadSerialEventTarget(), __func__,
49
[aResolver](bool aSuccess) mutable {
50
ResolveUnregister(std::move(aResolver), aSuccess, NS_OK);
51
},
52
[aResolver](nsresult aRv) mutable {
53
ResolveUnregister(std::move(aResolver), false, aRv);
54
});
55
56
return IPC_OK();
57
}
58
59
IPCResult ServiceWorkerRegistrationParent::RecvUpdate(
60
UpdateResolver&& aResolver) {
61
if (!mProxy) {
62
aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
63
return IPC_OK();
64
}
65
66
mProxy->Update()->Then(
67
GetCurrentThreadSerialEventTarget(), __func__,
68
[aResolver](const ServiceWorkerRegistrationDescriptor& aDescriptor) {
69
aResolver(aDescriptor.ToIPC());
70
},
71
[aResolver](const CopyableErrorResult& aResult) { aResolver(aResult); });
72
73
return IPC_OK();
74
}
75
76
ServiceWorkerRegistrationParent::ServiceWorkerRegistrationParent()
77
: mDeleteSent(false) {}
78
79
ServiceWorkerRegistrationParent::~ServiceWorkerRegistrationParent() {
80
MOZ_DIAGNOSTIC_ASSERT(!mProxy);
81
}
82
83
void ServiceWorkerRegistrationParent::Init(
84
const IPCServiceWorkerRegistrationDescriptor& aDescriptor) {
85
MOZ_DIAGNOSTIC_ASSERT(!mProxy);
86
mProxy = new ServiceWorkerRegistrationProxy(
87
ServiceWorkerRegistrationDescriptor(aDescriptor));
88
mProxy->Init(this);
89
}
90
91
void ServiceWorkerRegistrationParent::MaybeSendDelete() {
92
if (mDeleteSent) {
93
return;
94
}
95
mDeleteSent = true;
96
Unused << Send__delete__(this);
97
}
98
99
} // namespace dom
100
} // namespace mozilla