Bug 1663089 [wpt PR 25399] - idle-detection: Implement requestPermission() method...
[gecko.git] / dom / serviceworkers / ServiceWorkerUpdaterChild.cpp
blob36244cfca75d24358d40cd0b057cf705eb13860d
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/. */
7 #include "ServiceWorkerUpdaterChild.h"
8 #include "nsThreadUtils.h"
10 namespace mozilla {
11 namespace dom {
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());
20 MOZ_DIAGNOSTIC_ASSERT(!ServiceWorkerParentInterceptEnabled());
22 MOZ_ASSERT(aPromise);
23 MOZ_ASSERT(aSuccessRunnable);
24 MOZ_ASSERT(aFailureRunnable);
26 aPromise
27 ->Then(GetMainThreadSerialEventTarget(), __func__,
28 [this]() {
29 mPromiseHolder.Complete();
30 Unused << Send__delete__(this);
32 .Track(mPromiseHolder);
35 mozilla::ipc::IPCResult ServiceWorkerUpdaterChild::RecvProceed(
36 const bool& aAllowed) {
37 // If we have a callback, it will resolve the promise.
39 if (aAllowed) {
40 mSuccessRunnable->Run();
41 mFailureRunnable->Cancel();
42 } else {
43 mFailureRunnable->Run();
44 mSuccessRunnable->Cancel();
47 mSuccessRunnable = nullptr;
48 mFailureRunnable = nullptr;
50 return IPC_OK();
53 void ServiceWorkerUpdaterChild::ActorDestroy(ActorDestroyReason aWhy) {
54 if (mSuccessRunnable) {
55 mSuccessRunnable->Cancel();
58 if (mFailureRunnable) {
59 mFailureRunnable->Cancel();
62 mPromiseHolder.DisconnectIfExists();
65 } // namespace dom
66 } // namespace mozilla