• 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_ENTRY_OVERRIDE_H_
6 #define NET_FIRST_PARTY_SETS_FIRST_PARTY_SET_ENTRY_OVERRIDE_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 mojo {
13 template <typename DataViewType, typename T>
14 struct StructTraits;
15 }  // namespace mojo
16 namespace network::mojom {
17 class FirstPartySetEntryOverrideDataView;
18 }  // namespace network::mojom
19 
20 namespace net {
21 
22 // This class represents a single modification to be applied on top of the
23 // global First-Party Sets list. A modifications may be a deletion, remapping,
24 // or new mapping.
25 class NET_EXPORT FirstPartySetEntryOverride {
26  public:
27   // Creates a new modification representing a deletion.
28   FirstPartySetEntryOverride();
29   // Creates a new modification representing a remapping/additional mapping.
30   explicit FirstPartySetEntryOverride(FirstPartySetEntry entry);
31 
32   FirstPartySetEntryOverride(FirstPartySetEntryOverride&& other);
33   FirstPartySetEntryOverride& operator=(FirstPartySetEntryOverride&& other);
34   FirstPartySetEntryOverride(const FirstPartySetEntryOverride& other);
35   FirstPartySetEntryOverride& operator=(
36       const FirstPartySetEntryOverride& other);
37 
38   ~FirstPartySetEntryOverride();
39 
40   bool operator==(const FirstPartySetEntryOverride& other) const;
41 
42   // Returns true iff this override is a deletion.
IsDeletion()43   bool IsDeletion() const { return !entry_.has_value(); }
44 
45   // Returns the new target entry, if this override is not a deletion. Must not
46   // be called if `IsDeletion()` is true.
GetEntry()47   const FirstPartySetEntry& GetEntry() const {
48     DCHECK(!IsDeletion());
49     return entry_.value();
50   }
51 
52  private:
53   // mojo (de)serialization needs access to private details.
54   friend struct mojo::StructTraits<
55       network::mojom::FirstPartySetEntryOverrideDataView,
56       FirstPartySetEntryOverride>;
57 
58   absl::optional<FirstPartySetEntry> entry_;
59 };
60 
61 NET_EXPORT std::ostream& operator<<(std::ostream& os,
62                                     const FirstPartySetEntryOverride& override);
63 
64 }  // namespace net
65 
66 #endif  // NET_FIRST_PARTY_SETS_FIRST_PARTY_SET_ENTRY_OVERRIDE_H_