1 // Copyright 2022 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_FIRST_PARTY_SETS_FIRST_PARTY_SET_METADATA_H_ 6 #define NET_FIRST_PARTY_SETS_FIRST_PARTY_SET_METADATA_H_ 7 8 #include <optional> 9 10 #include "net/base/net_export.h" 11 #include "net/first_party_sets/first_party_set_entry.h" 12 13 namespace net { 14 15 // This class bundles together metadata about the First-Party Set associated 16 // with a given context. 17 class NET_EXPORT FirstPartySetMetadata { 18 public: 19 FirstPartySetMetadata(); 20 21 // `frame_entry` and `top_frame_entry` must live for the duration of the ctor; 22 // nullptr indicates that there's no First-Party Set that's associated with 23 // the current frame or the top frame, respectively, in the given context. 24 FirstPartySetMetadata(const FirstPartySetEntry* frame_entry, 25 const FirstPartySetEntry* top_frame_entry); 26 27 FirstPartySetMetadata(FirstPartySetMetadata&&); 28 FirstPartySetMetadata& operator=(FirstPartySetMetadata&&); 29 30 ~FirstPartySetMetadata(); 31 32 bool operator==(const FirstPartySetMetadata& other) const; 33 bool operator!=(const FirstPartySetMetadata& other) const; 34 frame_entry()35 const std::optional<FirstPartySetEntry>& frame_entry() const { 36 return frame_entry_; 37 } top_frame_entry()38 const std::optional<FirstPartySetEntry>& top_frame_entry() const { 39 return top_frame_entry_; 40 } 41 42 // Returns true if `frame_entry` and `top_frame_entry` are both non-null and 43 // have the same primary. 44 bool AreSitesInSameFirstPartySet() const; 45 46 private: 47 std::optional<FirstPartySetEntry> frame_entry_ = std::nullopt; 48 std::optional<FirstPartySetEntry> top_frame_entry_ = std::nullopt; 49 }; 50 51 NET_EXPORT std::ostream& operator<<(std::ostream& os, 52 const FirstPartySetMetadata& fpsm); 53 54 } // namespace net 55 56 #endif // NET_FIRST_PARTY_SETS_FIRST_PARTY_SET_METADATA_H_ 57