xref: /aosp_15_r20/external/cronet/net/first_party_sets/first_party_sets_context_config.cc (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 #include "net/first_party_sets/first_party_sets_context_config.h"
6 
7 #include "net/first_party_sets/first_party_set_entry_override.h"
8 
9 namespace net {
10 
11 FirstPartySetsContextConfig::FirstPartySetsContextConfig() = default;
FirstPartySetsContextConfig(base::flat_map<SchemefulSite,FirstPartySetEntryOverride> customizations)12 FirstPartySetsContextConfig::FirstPartySetsContextConfig(
13     base::flat_map<SchemefulSite, FirstPartySetEntryOverride> customizations)
14     : customizations_(std::move(customizations)) {}
15 
16 FirstPartySetsContextConfig::FirstPartySetsContextConfig(
17     FirstPartySetsContextConfig&& other) = default;
18 FirstPartySetsContextConfig& FirstPartySetsContextConfig::operator=(
19     FirstPartySetsContextConfig&& other) = default;
20 
21 FirstPartySetsContextConfig::~FirstPartySetsContextConfig() = default;
22 
Clone() const23 FirstPartySetsContextConfig FirstPartySetsContextConfig::Clone() const {
24   return FirstPartySetsContextConfig(customizations_);
25 }
26 
27 bool FirstPartySetsContextConfig::operator==(
28     const FirstPartySetsContextConfig& other) const = default;
29 
30 std::optional<FirstPartySetEntryOverride>
FindOverride(const SchemefulSite & site) const31 FirstPartySetsContextConfig::FindOverride(const SchemefulSite& site) const {
32   if (const auto it = customizations_.find(site); it != customizations_.end()) {
33     return it->second;
34   }
35   return std::nullopt;
36 }
37 
Contains(const SchemefulSite & site) const38 bool FirstPartySetsContextConfig::Contains(const SchemefulSite& site) const {
39   return FindOverride(site).has_value();
40 }
41 
ForEachCustomizationEntry(base::FunctionRef<bool (const SchemefulSite &,const FirstPartySetEntryOverride &)> f) const42 bool FirstPartySetsContextConfig::ForEachCustomizationEntry(
43     base::FunctionRef<bool(const SchemefulSite&,
44                            const FirstPartySetEntryOverride&)> f) const {
45   for (const auto& [site, override] : customizations_) {
46     if (!f(site, override))
47       return false;
48   }
49   return true;
50 }
51 
52 }  // namespace net
53