xref: /aosp_15_r20/external/cronet/net/first_party_sets/sets_mutation.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2023 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_SETS_MUTATION_H_
6 #define NET_FIRST_PARTY_SETS_SETS_MUTATION_H_
7 
8 #include "base/containers/flat_map.h"
9 #include "net/base/net_export.h"
10 #include "net/base/schemeful_site.h"
11 #include "net/first_party_sets/first_party_set_entry.h"
12 
13 namespace net {
14 
15 // SetsMutation represents a mutation to be applied to the list of global
16 // Related Website Sets. A mutation can come from the
17 // RelatedWebsiteSetsOverrides policy.
18 //
19 // See `GlobalFirstPartySets` for how SetsMutations are layered on top of the
20 // public sets and the local set declaration (if any).
21 class NET_EXPORT SetsMutation {
22  public:
23   SetsMutation();
24 
25   // Preconditions: sets defined by `replacement_sets` and
26   // `addition_sets` must be disjoint.
27   explicit SetsMutation(
28       std::vector<base::flat_map<SchemefulSite, FirstPartySetEntry>>
29           replacement_sets,
30       std::vector<base::flat_map<SchemefulSite, FirstPartySetEntry>>
31           addition_sets);
32 
33   ~SetsMutation();
34 
35   SetsMutation(const SetsMutation&);
36   SetsMutation& operator=(const SetsMutation&);
37   SetsMutation(SetsMutation&&);
38   SetsMutation& operator=(SetsMutation&&);
39 
40   bool operator==(const SetsMutation& other) const;
41 
42   const std::vector<base::flat_map<SchemefulSite, FirstPartySetEntry>>&
replacements()43   replacements() const {
44     return replacements_;
45   }
46 
47   const std::vector<base::flat_map<SchemefulSite, FirstPartySetEntry>>&
additions()48   additions() const {
49     return additions_;
50   }
51 
52  private:
53   // The list of "replacement" sets.
54   std::vector<base::flat_map<SchemefulSite, FirstPartySetEntry>> replacements_;
55 
56   // The list of "addition" sets.
57   std::vector<base::flat_map<SchemefulSite, FirstPartySetEntry>> additions_;
58 };
59 
60 NET_EXPORT std::ostream& operator<<(std::ostream& os,
61                                     const SetsMutation& mutation);
62 
63 }  // namespace net
64 
65 #endif  // NET_FIRST_PARTY_SETS_SETS_MUTATIONS_H_
66