Backed out changeset 9d8b4c0b99ed (bug 1945683) for causing btime failures. CLOSED...
[gecko.git] / dom / webauthn / WebAuthnPromiseHolder.h
blobca70fedb147a3f6d0995aefdc084e1c793310411
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_dom_WebAuthnPromiseHolder_h
6 #define mozilla_dom_WebAuthnPromiseHolder_h
8 #include "mozilla/MozPromise.h"
9 #include "nsIWebAuthnResult.h"
10 #include "nsIWebAuthnPromise.h"
11 #include "nsIThread.h"
13 namespace mozilla::dom {
16 * WebAuthnRegisterPromiseHolder and WebAuthnSignPromiseHolder wrap a
17 * MozPromiseHolder with an XPCOM interface that allows the contained promise
18 * to be resolved, rejected, or disconnected safely from any thread.
20 * Calls to Resolve(), Reject(), and Disconnect() are dispatched to the serial
21 * event target with wich the promise holder was initialized. At most one of
22 * these calls will be processed; the first call to reach the event target
23 * wins. Once the promise is initialized with Ensure() the program MUST call
24 * at least one of Resolve(), Reject(), or Disconnect().
27 using WebAuthnRegisterPromise =
28 MozPromise<RefPtr<nsIWebAuthnRegisterResult>, nsresult, true>;
30 using WebAuthnSignPromise =
31 MozPromise<RefPtr<nsIWebAuthnSignResult>, nsresult, true>;
33 class WebAuthnRegisterPromiseHolder final : public nsIWebAuthnRegisterPromise {
34 public:
35 NS_DECL_THREADSAFE_ISUPPORTS
36 NS_DECL_NSIWEBAUTHNREGISTERPROMISE
38 explicit WebAuthnRegisterPromiseHolder(nsISerialEventTarget* aEventTarget)
39 : mEventTarget(aEventTarget) {}
41 already_AddRefed<WebAuthnRegisterPromise> Ensure();
43 private:
44 ~WebAuthnRegisterPromiseHolder() = default;
46 nsCOMPtr<nsISerialEventTarget> mEventTarget;
47 MozPromiseHolder<WebAuthnRegisterPromise> mRegisterPromise;
50 class WebAuthnSignPromiseHolder final : public nsIWebAuthnSignPromise {
51 public:
52 NS_DECL_THREADSAFE_ISUPPORTS
53 NS_DECL_NSIWEBAUTHNSIGNPROMISE
55 explicit WebAuthnSignPromiseHolder(nsISerialEventTarget* aEventTarget)
56 : mEventTarget(aEventTarget) {}
58 already_AddRefed<WebAuthnSignPromise> Ensure();
60 private:
61 ~WebAuthnSignPromiseHolder() = default;
63 nsCOMPtr<nsISerialEventTarget> mEventTarget;
64 MozPromiseHolder<WebAuthnSignPromise> mSignPromise;
67 } // namespace mozilla::dom
69 #endif // mozilla_dom_WebAuthnPromiseHolder_h