ManagerId.h (1517B)
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/. */ 6 7 #ifndef mozilla_dom_cache_ManagerId_h 8 #define mozilla_dom_cache_ManagerId_h 9 10 #include "mozilla/dom/SafeRefPtr.h" 11 #include "mozilla/dom/cache/Types.h" 12 #include "nsCOMPtr.h" 13 #include "nsError.h" 14 #include "nsISupportsImpl.h" 15 #include "nsString.h" 16 17 class nsIPrincipal; 18 19 namespace mozilla::dom::cache { 20 21 class ManagerId final : public AtomicSafeRefCounted<ManagerId> { 22 public: 23 // Main thread only 24 static Result<SafeRefPtr<ManagerId>, nsresult> Create( 25 nsIPrincipal* aPrincipal); 26 27 // Main thread only 28 already_AddRefed<nsIPrincipal> Principal() const; 29 30 const nsACString& QuotaOrigin() const { return mQuotaOrigin; } 31 32 bool operator==(const ManagerId& aOther) const { 33 return mQuotaOrigin == aOther.mQuotaOrigin; 34 } 35 36 private: 37 // only accessible on main thread 38 nsCOMPtr<nsIPrincipal> mPrincipal; 39 40 // immutable to allow threadsfe access 41 const nsCString mQuotaOrigin; 42 43 struct ConstructorGuard {}; 44 45 public: 46 ManagerId(nsIPrincipal* aPrincipal, const nsACString& aOrigin, 47 ConstructorGuard); 48 ~ManagerId(); 49 50 MOZ_DECLARE_REFCOUNTED_TYPENAME(mozilla::dom::cache::ManagerId) 51 }; 52 53 } // namespace mozilla::dom::cache 54 55 #endif // mozilla_dom_cache_ManagerId_h