Bug 1688354 [wpt PR 27298] - Treat 'rem' as an absolute unit for font size, a=testonly
[gecko.git] / dom / cache / PrincipalVerifier.h
blobc7d8755e4a7b84c177c8903e00f29e56f033a129
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 ContentParent;
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 // set in originating thread at construction, but must be accessed and
66 // released on main thread
67 RefPtr<ContentParent> mActor;
69 const mozilla::ipc::PrincipalInfo mPrincipalInfo;
70 nsCOMPtr<nsIEventTarget> mInitiatingEventTarget;
71 nsresult mResult;
72 SafeRefPtr<ManagerId> mManagerId;
74 public:
75 NS_DECL_NSIRUNNABLE
78 } // namespace cache
79 } // namespace dom
80 } // namespace mozilla
82 #endif // mozilla_dom_cache_PrincipalVerifier_h