• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "net/base/net_export.h"
9 #include "net/first_party_sets/first_party_set_entry.h"
10 #include "third_party/abseil-cpp/absl/types/optional.h"
11 
12 namespace net {
13 
14 // This class bundles together metadata about the First-Party Set associated
15 // with a given context.
16 class NET_EXPORT FirstPartySetMetadata {
17  public:
18   FirstPartySetMetadata();
19 
20   // `frame_entry` and `top_frame_entry` must live for the duration of the ctor;
21   // nullptr indicates that there's no First-Party Set that's associated with
22   // the current frame or the top frame, respectively, in the given context.
23   FirstPartySetMetadata(const FirstPartySetEntry* frame_entry,
24                         const FirstPartySetEntry* top_frame_entry);
25 
26   FirstPartySetMetadata(FirstPartySetMetadata&&);
27   FirstPartySetMetadata& operator=(FirstPartySetMetadata&&);
28 
29   ~FirstPartySetMetadata();
30 
31   bool operator==(const FirstPartySetMetadata& other) const;
32   bool operator!=(const FirstPartySetMetadata& other) const;
33 
frame_entry()34   const absl::optional<FirstPartySetEntry>& frame_entry() const {
35     return frame_entry_;
36   }
top_frame_entry()37   const absl::optional<FirstPartySetEntry>& top_frame_entry() const {
38     return top_frame_entry_;
39   }
40 
41   // Returns true if `frame_entry` and `top_frame_entry` are both non-null and
42   // have the same primary.
43   bool AreSitesInSameFirstPartySet() const;
44 
45  private:
46   absl::optional<FirstPartySetEntry> frame_entry_ = absl::nullopt;
47   absl::optional<FirstPartySetEntry> top_frame_entry_ = absl::nullopt;
48 };
49 
50 NET_EXPORT std::ostream& operator<<(std::ostream& os,
51                                     const FirstPartySetMetadata& fpsm);
52 
53 }  // namespace net
54 
55 #endif  // NET_FIRST_PARTY_SETS_FIRST_PARTY_SET_METADATA_H_
56