Bug 1385274 - Don't try to resolve WebAuthnManager::mPBackgroundCreationPromise twice r=jcj
authorTim Taubert <ttaubert@mozilla.com>
Fri, 28 Jul 2017 15:53:42 +0200
changeset 420427 ee929726e09380236f2c8c5ba8eabc120c8a8cfd
parent 420426 4de88c868d39d9da24acb8836d0b8e45a4457b4c
child 420428 f78bdc8e529b898112a505e1905b4c7a7c66bf66
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjcj
bugs1385274
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1385274 - Don't try to resolve WebAuthnManager::mPBackgroundCreationPromise twice r=jcj
dom/webauthn/WebAuthnManager.cpp
dom/webauthn/WebAuthnManager.h
--- a/dom/webauthn/WebAuthnManager.cpp
+++ b/dom/webauthn/WebAuthnManager.cpp
@@ -234,24 +234,35 @@ WebAuthnManager::MaybeClearTransaction()
   }
 }
 
 WebAuthnManager::~WebAuthnManager()
 {
   MaybeClearTransaction();
 }
 
-already_AddRefed<MozPromise<nsresult, nsresult, false>>
+RefPtr<WebAuthnManager::BackgroundActorPromise>
 WebAuthnManager::GetOrCreateBackgroundActor()
 {
-  bool ok = BackgroundChild::GetOrCreateForCurrentThread(this);
-  if (NS_WARN_IF(!ok)) {
-    ActorFailed();
+  MOZ_ASSERT(NS_IsMainThread());
+
+  PBackgroundChild *actor = BackgroundChild::GetForCurrentThread();
+  RefPtr<WebAuthnManager::BackgroundActorPromise> 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
 WebAuthnManager*
 WebAuthnManager::GetOrCreate()
 {
   MOZ_ASSERT(NS_IsMainThread());
   if (gWebAuthnManager) {
@@ -870,18 +881,23 @@ WebAuthnManager::Cancel(const nsresult& 
     mTransactionPromise->MaybeReject(aError);
   }
   MaybeClearTransaction();
 }
 
 void
 WebAuthnManager::ActorCreated(PBackgroundChild* aActor)
 {
+  MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aActor);
 
+  if (mChild) {
+    return;
+  }
+
   RefPtr<WebAuthnTransactionChild> mgr(new WebAuthnTransactionChild());
   PWebAuthnTransactionChild* constructedMgr =
     aActor->SendPWebAuthnTransactionConstructor(mgr);
 
   if (NS_WARN_IF(!constructedMgr)) {
     ActorFailed();
     return;
   }
--- a/dom/webauthn/WebAuthnManager.h
+++ b/dom/webauthn/WebAuthnManager.h
@@ -94,18 +94,19 @@ public:
   void ActorFailed() override;
   void ActorDestroyed();
 private:
   WebAuthnManager();
   virtual ~WebAuthnManager();
 
   void MaybeClearTransaction();
 
-  already_AddRefed<MozPromise<nsresult, nsresult, false>>
-  GetOrCreateBackgroundActor();
+  typedef MozPromise<nsresult, nsresult, false> BackgroundActorPromise;
+
+  RefPtr<BackgroundActorPromise> GetOrCreateBackgroundActor();
 
   // JS Promise representing transaction status.
   RefPtr<Promise> mTransactionPromise;
 
   // IPC Channel for the current transaction.
   RefPtr<WebAuthnTransactionChild> mChild;
 
   // Parent of the context we're currently running the transaction in.
@@ -115,15 +116,15 @@ private:
   // used to assemble reply objects.
   Maybe<nsCString> mClientData;
 
   // Holds the parameters of the current transaction, as we need them both
   // before the transaction request is sent, and on successful return.
   Maybe<WebAuthnTransactionInfo> mInfo;
 
   // Promise for dealing with PBackground Actor creation.
-  MozPromiseHolder<MozPromise<nsresult, nsresult, false>> mPBackgroundCreationPromise;
+  MozPromiseHolder<BackgroundActorPromise> mPBackgroundCreationPromise;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_WebAuthnManager_h