first_party_set_entry.cc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "net/cookies/first_party_set_entry.h"
  5. #include <tuple>
  6. #include "net/base/schemeful_site.h"
  7. namespace net {
  8. FirstPartySetEntry::SiteIndex::SiteIndex() = default;
  9. FirstPartySetEntry::SiteIndex::SiteIndex(uint32_t value) : value_(value) {}
  10. bool FirstPartySetEntry::SiteIndex::operator==(const SiteIndex& other) const {
  11. return value_ == other.value_;
  12. }
  13. FirstPartySetEntry::FirstPartySetEntry() = default;
  14. FirstPartySetEntry::FirstPartySetEntry(
  15. SchemefulSite primary,
  16. SiteType site_type,
  17. absl::optional<FirstPartySetEntry::SiteIndex> site_index)
  18. : primary_(primary), site_type_(site_type), site_index_(site_index) {
  19. if (site_type_ == SiteType::kPrimary) {
  20. DCHECK(!site_index_.has_value());
  21. }
  22. }
  23. FirstPartySetEntry::FirstPartySetEntry(SchemefulSite primary,
  24. SiteType site_type,
  25. uint32_t site_index)
  26. : FirstPartySetEntry(
  27. primary,
  28. site_type,
  29. absl::make_optional(FirstPartySetEntry::SiteIndex(site_index))) {}
  30. FirstPartySetEntry::FirstPartySetEntry(const FirstPartySetEntry&) = default;
  31. FirstPartySetEntry& FirstPartySetEntry::operator=(const FirstPartySetEntry&) =
  32. default;
  33. FirstPartySetEntry::FirstPartySetEntry(FirstPartySetEntry&&) = default;
  34. FirstPartySetEntry& FirstPartySetEntry::operator=(FirstPartySetEntry&&) =
  35. default;
  36. FirstPartySetEntry::~FirstPartySetEntry() = default;
  37. bool FirstPartySetEntry::operator==(const FirstPartySetEntry& other) const {
  38. return std::tie(primary_, site_type_, site_index_) ==
  39. std::tie(other.primary_, other.site_type_, other.site_index_);
  40. }
  41. bool FirstPartySetEntry::operator!=(const FirstPartySetEntry& other) const {
  42. return !(*this == other);
  43. }
  44. std::ostream& operator<<(std::ostream& os,
  45. const FirstPartySetEntry::SiteIndex& index) {
  46. os << index.value();
  47. return os;
  48. }
  49. std::ostream& operator<<(std::ostream& os, const FirstPartySetEntry& entry) {
  50. os << "{" << entry.primary() << ", " << static_cast<int>(entry.site_type())
  51. << ", ";
  52. if (entry.site_index().has_value()) {
  53. os << entry.site_index().value();
  54. } else {
  55. os << "{}";
  56. }
  57. os << "}";
  58. return os;
  59. }
  60. } // namespace net