Bug 1686945 [wpt PR 27199] - Correctly pass --py2 or --py3 to some Azure Pipeline...
[gecko.git] / caps / PrincipalHashKey.h
blob1c245532a60722baace88e81ed0d592e160e9a86
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_PrincipalHashKey_h
8 #define mozilla_PrincipalHashKey_h
10 #include "BasePrincipal.h"
11 #include "PLDHashTable.h"
12 #include "mozilla/Unused.h"
13 #include "nsCOMPtr.h"
14 #include "nsHashKeys.h"
16 namespace mozilla {
18 class PrincipalHashKey : public PLDHashEntryHdr {
19 public:
20 using KeyType = nsIPrincipal*;
21 using KeyTypePointer = const nsIPrincipal*;
23 explicit PrincipalHashKey(const nsIPrincipal* aKey)
24 : mPrincipal(const_cast<nsIPrincipal*>(aKey)) {
25 MOZ_ASSERT(aKey);
26 MOZ_COUNT_CTOR(PrincipalHashKey);
28 PrincipalHashKey(PrincipalHashKey&& aKey)
29 : mPrincipal(std::move(aKey.mPrincipal)) {
30 MOZ_COUNT_CTOR(PrincipalHashKey);
33 MOZ_COUNTED_DTOR(PrincipalHashKey)
35 nsIPrincipal* GetKey() const { return mPrincipal; }
37 bool KeyEquals(const nsIPrincipal* aKey) const {
38 return BasePrincipal::Cast(mPrincipal)
39 ->FastEquals(const_cast<nsIPrincipal*>(aKey));
42 static const nsIPrincipal* KeyToPointer(const nsIPrincipal* aKey) {
43 return aKey;
45 static PLDHashNumber HashKey(const nsIPrincipal* aKey) {
46 auto* bp = BasePrincipal::Cast(aKey);
47 return HashGeneric(bp->GetOriginNoSuffixHash(), bp->GetOriginSuffixHash());
50 enum { ALLOW_MEMMOVE = true };
52 protected:
53 nsCOMPtr<nsIPrincipal> mPrincipal;
56 } // namespace mozilla
58 #endif