tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

OriginAttributesHashKey.h (1555B)


      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_OriginAttributesHashKey_h
      8 #define mozilla_OriginAttributesHashKey_h
      9 
     10 #include "OriginAttributes.h"
     11 #include "PLDHashTable.h"
     12 #include "nsHashKeys.h"
     13 
     14 namespace mozilla {
     15 
     16 class OriginAttributesHashKey : public PLDHashEntryHdr {
     17 public:
     18  using KeyType = OriginAttributes;
     19  using KeyTypeRef = const KeyType&;
     20  using KeyTypePointer = const KeyType*;
     21 
     22  explicit OriginAttributesHashKey(KeyTypePointer aKey) {
     23    mOriginAttributes = *aKey;
     24    MOZ_COUNT_CTOR(OriginAttributesHashKey);
     25  }
     26  OriginAttributesHashKey(OriginAttributesHashKey&& aKey) noexcept {
     27    mOriginAttributes = std::move(aKey.mOriginAttributes);
     28    MOZ_COUNT_CTOR(OriginAttributesHashKey);
     29  }
     30 
     31  MOZ_COUNTED_DTOR(OriginAttributesHashKey)
     32 
     33  KeyTypeRef GetKey() const { return mOriginAttributes; }
     34 
     35  bool KeyEquals(KeyTypePointer aKey) const {
     36    return mOriginAttributes == *aKey;
     37  }
     38 
     39  static KeyTypePointer KeyToPointer(KeyTypeRef aKey) { return &aKey; }
     40 
     41  static PLDHashNumber HashKey(KeyTypePointer aKey) {
     42    nsAutoCString suffix;
     43    aKey->CreateSuffix(suffix);
     44    return mozilla::HashString(suffix);
     45  }
     46 
     47  enum { ALLOW_MEMMOVE = true };
     48 
     49 protected:
     50  OriginAttributes mOriginAttributes;
     51 };
     52 
     53 }  // namespace mozilla
     54 
     55 #endif