xref: /aosp_15_r20/external/cronet/net/first_party_sets/local_set_declaration.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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_LOCAL_SET_DECLARATION_H_
6 #define NET_FIRST_PARTY_SETS_LOCAL_SET_DECLARATION_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 // LocalSetDeclaration represents a Related Website Set that was defined locally
16 // by a web developer (as opposed to being one of the public Related Website
17 // Sets, or a set from the RelatedWebsiteSetsOverrides policy).
18 //
19 // Locally-defined sets take precedence over the public sets (for testing
20 // purposes), but can be overridden by the RelatedWebsiteSetsOverrides policy.
21 //
22 // See `GlobalFirstPartySets` for how overlaps/shadowing between public sets,
23 // locally-defined sets, and enterprise policy sets is handled.
24 class NET_EXPORT LocalSetDeclaration {
25  public:
26   // Constructs an empty (no-op) set declaration.
27   LocalSetDeclaration();
28 
29   // Constructs a set declaration with the given entries. All entries must be in
30   // the same set (i.e. they must have the same primary site). The set must not
31   // be a singleton (i.e. must have more than one entry, or must be empty).
32   explicit LocalSetDeclaration(
33       base::flat_map<SchemefulSite, FirstPartySetEntry> set_entries,
34       base::flat_map<SchemefulSite, SchemefulSite> aliases);
35 
36   ~LocalSetDeclaration();
37 
38   LocalSetDeclaration(const LocalSetDeclaration&);
39   LocalSetDeclaration& operator=(const LocalSetDeclaration&);
40   LocalSetDeclaration(LocalSetDeclaration&&);
41   LocalSetDeclaration& operator=(LocalSetDeclaration&&);
42 
empty()43   bool empty() const { return entries_.empty(); }
44 
size()45   size_t size() const { return entries_.size(); }
46 
entries()47   const base::flat_map<SchemefulSite, FirstPartySetEntry>& entries() const {
48     return entries_;
49   }
50 
aliases()51   const base::flat_map<SchemefulSite, SchemefulSite>& aliases() const {
52     return aliases_;
53   }
54 
55  private:
56   // Stores the set of entries, without ccTLD aliases. This may be empty if no
57   // set was locally defined.
58   base::flat_map<SchemefulSite, FirstPartySetEntry> entries_;
59 
60   // Stores the ccTLD aliases. May be empty.
61   base::flat_map<SchemefulSite, SchemefulSite> aliases_;
62 };
63 
64 }  // namespace net
65 
66 #endif  // NET_FIRST_PARTY_SETS_LOCAL_SET_DECLARATION_H_
67