/src/mozilla-central/dom/serviceworkers/ServiceWorkerUpdaterChild.cpp
Line | Count | Source (jump to first uncovered line) |
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(GenericPromise* aPromise, |
14 | | CancelableRunnable* aSuccessRunnable, |
15 | | CancelableRunnable* aFailureRunnable) |
16 | | : mSuccessRunnable(aSuccessRunnable) |
17 | | , mFailureRunnable(aFailureRunnable) |
18 | 0 | { |
19 | 0 | // TODO: remove the main thread restriction after fixing bug 1364821. |
20 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
21 | 0 |
|
22 | 0 | MOZ_DIAGNOSTIC_ASSERT(!ServiceWorkerParentInterceptEnabled()); |
23 | 0 |
|
24 | 0 | MOZ_ASSERT(aPromise); |
25 | 0 | MOZ_ASSERT(aSuccessRunnable); |
26 | 0 | MOZ_ASSERT(aFailureRunnable); |
27 | 0 |
|
28 | 0 | aPromise->Then(GetMainThreadSerialEventTarget(), __func__, |
29 | 0 | [this]() { |
30 | 0 | mPromiseHolder.Complete(); |
31 | 0 | Unused << Send__delete__(this); |
32 | 0 | }).Track(mPromiseHolder); |
33 | 0 | } |
34 | | |
35 | | mozilla::ipc::IPCResult |
36 | | ServiceWorkerUpdaterChild::RecvProceed(const bool& aAllowed) |
37 | 0 | { |
38 | 0 | // If we have a callback, it will resolve the promise. |
39 | 0 |
|
40 | 0 | if (aAllowed) { |
41 | 0 | mSuccessRunnable->Run(); |
42 | 0 | mFailureRunnable->Cancel(); |
43 | 0 | } else { |
44 | 0 | mFailureRunnable->Run(); |
45 | 0 | mSuccessRunnable->Cancel(); |
46 | 0 | } |
47 | 0 |
|
48 | 0 | mSuccessRunnable = nullptr; |
49 | 0 | mFailureRunnable = nullptr; |
50 | 0 |
|
51 | 0 | return IPC_OK(); |
52 | 0 | } |
53 | | |
54 | | void |
55 | | ServiceWorkerUpdaterChild::ActorDestroy(ActorDestroyReason aWhy) |
56 | 0 | { |
57 | 0 | if (mSuccessRunnable) { |
58 | 0 | mSuccessRunnable->Cancel(); |
59 | 0 | } |
60 | 0 |
|
61 | 0 | if (mFailureRunnable) { |
62 | 0 | mFailureRunnable->Cancel(); |
63 | 0 | } |
64 | 0 |
|
65 | 0 | mPromiseHolder.DisconnectIfExists(); |
66 | 0 | } |
67 | | |
68 | | } // namespace dom |
69 | | } // namespace mozilla |