From 0aee684c1794ea09534b41ad0dacb1f897158790 Mon Sep 17 00:00:00 2001 From: Tim Taubert Date: Fri, 28 Jul 2017 15:53:42 +0200 Subject: [PATCH] Bug 1385274 - Don't try to resolve WebAuthnManager::mPBackgroundCreationPromise twice r=jcj --- dom/webauthn/WebAuthnManager.cpp | 26 +++++++++++++++++++++----- dom/webauthn/WebAuthnManager.h | 7 ++++--- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/dom/webauthn/WebAuthnManager.cpp b/dom/webauthn/WebAuthnManager.cpp index 4ad009afcb10..835680225579 100644 --- a/dom/webauthn/WebAuthnManager.cpp +++ b/dom/webauthn/WebAuthnManager.cpp @@ -239,14 +239,25 @@ WebAuthnManager::~WebAuthnManager() MaybeClearTransaction(); } -already_AddRefed> +RefPtr WebAuthnManager::GetOrCreateBackgroundActor() { - bool ok = BackgroundChild::GetOrCreateForCurrentThread(this); - if (NS_WARN_IF(!ok)) { - ActorFailed(); + MOZ_ASSERT(NS_IsMainThread()); + + PBackgroundChild *actor = BackgroundChild::GetForCurrentThread(); + RefPtr promise = + mPBackgroundCreationPromise.Ensure(__func__); + + if (actor) { + ActorCreated(actor); + } else { + bool ok = BackgroundChild::GetOrCreateForCurrentThread(this); + if (NS_WARN_IF(!ok)) { + ActorFailed(); + } } - return mPBackgroundCreationPromise.Ensure(__func__); + + return promise; } //static @@ -875,8 +886,13 @@ WebAuthnManager::Cancel(const nsresult& aError) void WebAuthnManager::ActorCreated(PBackgroundChild* aActor) { + MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aActor); + if (mChild) { + return; + } + RefPtr mgr(new WebAuthnTransactionChild()); PWebAuthnTransactionChild* constructedMgr = aActor->SendPWebAuthnTransactionConstructor(mgr); diff --git a/dom/webauthn/WebAuthnManager.h b/dom/webauthn/WebAuthnManager.h index 730d954ab5b4..8e832742d70d 100644 --- a/dom/webauthn/WebAuthnManager.h +++ b/dom/webauthn/WebAuthnManager.h @@ -99,8 +99,9 @@ private: void MaybeClearTransaction(); - already_AddRefed> - GetOrCreateBackgroundActor(); + typedef MozPromise BackgroundActorPromise; + + RefPtr GetOrCreateBackgroundActor(); // JS Promise representing transaction status. RefPtr mTransactionPromise; @@ -120,7 +121,7 @@ private: Maybe mInfo; // Promise for dealing with PBackground Actor creation. - MozPromiseHolder> mPBackgroundCreationPromise; + MozPromiseHolder mPBackgroundCreationPromise; }; } // namespace dom