first_party_set_entry.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #ifndef NET_COOKIES_FIRST_PARTY_SET_ENTRY_H_
  5. #define NET_COOKIES_FIRST_PARTY_SET_ENTRY_H_
  6. #include "net/base/net_export.h"
  7. #include "net/base/schemeful_site.h"
  8. namespace net {
  9. enum class SiteType {
  10. // The First-Party Set declaration listed this site as the "primary" site for
  11. // the set.
  12. kPrimary,
  13. // The First-Party Set declaration listed this site as an associated site in
  14. // the set.
  15. kAssociated,
  16. };
  17. // This class bundles together metadata associated with an entry in a
  18. // First-Party Set.
  19. class NET_EXPORT FirstPartySetEntry {
  20. public:
  21. class NET_EXPORT SiteIndex {
  22. public:
  23. SiteIndex();
  24. explicit SiteIndex(uint32_t value);
  25. bool operator==(const SiteIndex& other) const;
  26. uint32_t value() const { return value_; }
  27. private:
  28. uint32_t value_;
  29. };
  30. FirstPartySetEntry();
  31. // `primary` is the primary site in the First-Party Set associated with this
  32. // entry.
  33. FirstPartySetEntry(SchemefulSite primary,
  34. SiteType site_type,
  35. absl::optional<SiteIndex> site_index);
  36. FirstPartySetEntry(SchemefulSite primary,
  37. SiteType site_type,
  38. uint32_t site_index);
  39. FirstPartySetEntry(const FirstPartySetEntry&);
  40. FirstPartySetEntry& operator=(const FirstPartySetEntry&);
  41. FirstPartySetEntry(FirstPartySetEntry&&);
  42. FirstPartySetEntry& operator=(FirstPartySetEntry&&);
  43. ~FirstPartySetEntry();
  44. bool operator==(const FirstPartySetEntry& other) const;
  45. bool operator!=(const FirstPartySetEntry& other) const;
  46. const SchemefulSite& primary() const { return primary_; }
  47. SiteType site_type() const { return site_type_; }
  48. const absl::optional<SiteIndex>& site_index() const { return site_index_; }
  49. private:
  50. // The primary site associated with this site's set.
  51. SchemefulSite primary_;
  52. // The type associated with this site.
  53. SiteType site_type_;
  54. // The index of this site in the set declaration, if a meaningful index
  55. // exists. Primary sites do not have indices, nor do sites that were defined
  56. // or affected by an enterprise policy set.
  57. absl::optional<SiteIndex> site_index_;
  58. };
  59. NET_EXPORT std::ostream& operator<<(
  60. std::ostream& os,
  61. const FirstPartySetEntry::SiteIndex& site_index);
  62. NET_EXPORT std::ostream& operator<<(std::ostream& os,
  63. const FirstPartySetEntry& fpse);
  64. } // namespace net
  65. #endif // NET_COOKIES_FIRST_PARTY_SET_ENTRY_H_