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_SETS_CONTEXT_CONFIG_H_ 6 #define NET_FIRST_PARTY_SETS_FIRST_PARTY_SETS_CONTEXT_CONFIG_H_ 7 8 #include "base/containers/flat_map.h" 9 #include "base/functional/function_ref.h" 10 #include "net/base/schemeful_site.h" 11 #include "net/first_party_sets/first_party_set_entry_override.h" 12 #include "third_party/abseil-cpp/absl/types/optional.h" 13 14 namespace mojo { 15 template <typename DataViewType, typename T> 16 struct StructTraits; 17 } // namespace mojo 18 namespace network::mojom { 19 class FirstPartySetsContextConfigDataView; 20 } // namespace network::mojom 21 22 namespace net { 23 24 // This struct bundles together the customized settings to First-Party Sets 25 // info in the given network context. 26 class NET_EXPORT FirstPartySetsContextConfig { 27 public: 28 FirstPartySetsContextConfig(); 29 explicit FirstPartySetsContextConfig( 30 base::flat_map<SchemefulSite, FirstPartySetEntryOverride> customizations); 31 32 FirstPartySetsContextConfig(FirstPartySetsContextConfig&& other); 33 FirstPartySetsContextConfig& operator=(FirstPartySetsContextConfig&& other); 34 35 ~FirstPartySetsContextConfig(); 36 37 FirstPartySetsContextConfig Clone() const; 38 39 bool operator==(const FirstPartySetsContextConfig& other) const; 40 empty()41 bool empty() const { return customizations_.empty(); } 42 43 // Finds an override for the given site, in this context. Returns: 44 // - nullopt if no override was found. 45 // - optional(override) if an override was found. The override may be a 46 // deletion or a modification/addition. 47 absl::optional<FirstPartySetEntryOverride> FindOverride( 48 const SchemefulSite& site) const; 49 50 // Returns whether an override can be found for the given site in this 51 // context. 52 bool Contains(const SchemefulSite& site) const; 53 54 // Synchronously iterate over all the override entries. Each iteration will be 55 // invoked with the relevant site and the override that applies to it. 56 // 57 // Returns early if any of the iterations returns false. Returns false if 58 // iteration was incomplete; true if all iterations returned true. No 59 // guarantees are made re: iteration order. 60 bool ForEachCustomizationEntry( 61 base::FunctionRef<bool(const SchemefulSite&, 62 const FirstPartySetEntryOverride&)> f) const; 63 64 private: 65 // mojo (de)serialization needs access to private details. 66 friend struct mojo::StructTraits< 67 network::mojom::FirstPartySetsContextConfigDataView, 68 FirstPartySetsContextConfig>; 69 70 base::flat_map<SchemefulSite, FirstPartySetEntryOverride> customizations_; 71 }; 72 73 } // namespace net 74 75 #endif // NET_FIRST_PARTY_SETS_FIRST_PARTY_SETS_CONTEXT_CONFIG_H_