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)12FirstPartySetsContextConfig::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() const23FirstPartySetsContextConfig FirstPartySetsContextConfig::Clone() const { 24 return FirstPartySetsContextConfig(customizations_); 25 } 26 operator ==(const FirstPartySetsContextConfig & other) const27bool FirstPartySetsContextConfig::operator==( 28 const FirstPartySetsContextConfig& other) const { 29 return customizations_ == other.customizations_; 30 } 31 32 absl::optional<FirstPartySetEntryOverride> FindOverride(const SchemefulSite & site) const33FirstPartySetsContextConfig::FindOverride(const SchemefulSite& site) const { 34 if (const auto it = customizations_.find(site); it != customizations_.end()) { 35 return it->second; 36 } 37 return absl::nullopt; 38 } 39 Contains(const SchemefulSite & site) const40bool FirstPartySetsContextConfig::Contains(const SchemefulSite& site) const { 41 return FindOverride(site).has_value(); 42 } 43 ForEachCustomizationEntry(base::FunctionRef<bool (const SchemefulSite &,const FirstPartySetEntryOverride &)> f) const44bool FirstPartySetsContextConfig::ForEachCustomizationEntry( 45 base::FunctionRef<bool(const SchemefulSite&, 46 const FirstPartySetEntryOverride&)> f) const { 47 for (const auto& [site, override] : customizations_) { 48 if (!f(site, override)) 49 return false; 50 } 51 return true; 52 } 53 54 } // namespace net 55