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 file,
5
* You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "ServiceWorkerUpdaterChild.h"
8
#include "nsThreadUtils.h"
9
10
namespace mozilla {
11
namespace dom {
12
13
ServiceWorkerUpdaterChild::ServiceWorkerUpdaterChild(
14
GenericPromise* aPromise, CancelableRunnable* aSuccessRunnable,
15
CancelableRunnable* aFailureRunnable)
16
: mSuccessRunnable(aSuccessRunnable), mFailureRunnable(aFailureRunnable) {
17
// TODO: remove the main thread restriction after fixing bug 1364821.
18
MOZ_ASSERT(NS_IsMainThread());
19
20
MOZ_DIAGNOSTIC_ASSERT(!ServiceWorkerParentInterceptEnabled());
21
22
MOZ_ASSERT(aPromise);
23
MOZ_ASSERT(aSuccessRunnable);
24
MOZ_ASSERT(aFailureRunnable);
25
26
aPromise
27
->Then(GetMainThreadSerialEventTarget(), __func__,
28
[this]() {
29
mPromiseHolder.Complete();
30
Unused << Send__delete__(this);
31
})
32
.Track(mPromiseHolder);
33
}
34
35
mozilla::ipc::IPCResult ServiceWorkerUpdaterChild::RecvProceed(
36
const bool& aAllowed) {
37
// If we have a callback, it will resolve the promise.
38
39
if (aAllowed) {
40
mSuccessRunnable->Run();
41
mFailureRunnable->Cancel();
42
} else {
43
mFailureRunnable->Run();
44
mSuccessRunnable->Cancel();
45
}
46
47
mSuccessRunnable = nullptr;
48
mFailureRunnable = nullptr;
49
50
return IPC_OK();
51
}
52
53
void ServiceWorkerUpdaterChild::ActorDestroy(ActorDestroyReason aWhy) {
54
if (mSuccessRunnable) {
55
mSuccessRunnable->Cancel();
56
}
57
58
if (mFailureRunnable) {
59
mFailureRunnable->Cancel();
60
}
61
62
mPromiseHolder.DisconnectIfExists();
63
}
64
65
} // namespace dom
66
} // namespace mozilla