Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / cache / PrincipalVerifier.h
blobd464bc4d0164a661f5f5bdd19521391ca5af53d1
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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_cache_PrincipalVerifier_h
8 #define mozilla_dom_cache_PrincipalVerifier_h
10 #include "mozilla/dom/SafeRefPtr.h"
11 #include "mozilla/ipc/PBackgroundSharedTypes.h"
12 #include "nsThreadUtils.h"
13 #include "nsTObserverArray.h"
15 namespace mozilla {
17 namespace ipc {
18 class PBackgroundParent;
19 } // namespace ipc
21 namespace dom {
23 class ThreadsafeContentParentHandle;
25 namespace cache {
27 class ManagerId;
29 class PrincipalVerifier final : public Runnable {
30 public:
31 // An interface to be implemented by code wishing to use the
32 // PrincipalVerifier. Note, the Listener implementation is responsible
33 // for calling RemoveListener() on the PrincipalVerifier to clear the
34 // weak reference.
35 class Listener {
36 public:
37 virtual void OnPrincipalVerified(
38 nsresult aRv, const SafeRefPtr<ManagerId>& aManagerId) = 0;
41 static already_AddRefed<PrincipalVerifier> CreateAndDispatch(
42 Listener& aListener, mozilla::ipc::PBackgroundParent* aActor,
43 const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
45 void AddListener(Listener& aListener);
47 // The Listener must call RemoveListener() when OnPrincipalVerified() is
48 // called or when the Listener is destroyed.
49 void RemoveListener(Listener& aListener);
51 private:
52 PrincipalVerifier(Listener& aListener,
53 mozilla::ipc::PBackgroundParent* aActor,
54 const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
55 virtual ~PrincipalVerifier();
57 void VerifyOnMainThread();
58 void CompleteOnInitiatingThread();
60 void DispatchToInitiatingThread(nsresult aRv);
62 // Weak reference cleared by RemoveListener()
63 nsTObserverArray<NotNull<Listener*>> mListenerList;
65 RefPtr<ThreadsafeContentParentHandle> mHandle;
67 const mozilla::ipc::PrincipalInfo mPrincipalInfo;
68 nsCOMPtr<nsIEventTarget> mInitiatingEventTarget;
69 nsresult mResult;
70 SafeRefPtr<ManagerId> mManagerId;
72 public:
73 NS_DECL_NSIRUNNABLE
76 } // namespace cache
77 } // namespace dom
78 } // namespace mozilla
80 #endif // mozilla_dom_cache_PrincipalVerifier_h