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"
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());
23 MOZ_ASSERT(aSuccessRunnable
);
24 MOZ_ASSERT(aFailureRunnable
);
27 ->Then(GetMainThreadSerialEventTarget(), __func__
,
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.
40 mSuccessRunnable
->Run();
41 mFailureRunnable
->Cancel();
43 mFailureRunnable
->Run();
44 mSuccessRunnable
->Cancel();
47 mSuccessRunnable
= nullptr;
48 mFailureRunnable
= nullptr;
53 void ServiceWorkerUpdaterChild::ActorDestroy(ActorDestroyReason aWhy
) {
54 if (mSuccessRunnable
) {
55 mSuccessRunnable
->Cancel();
58 if (mFailureRunnable
) {
59 mFailureRunnable
->Cancel();
62 mPromiseHolder
.DisconnectIfExists();
66 } // namespace mozilla