xref: /aosp_15_r20/external/cronet/net/first_party_sets/first_party_sets_cache_filter.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_cache_filter.h"
6 
7 namespace net {
8 
9 FirstPartySetsCacheFilter::MatchInfo::MatchInfo() = default;
10 
11 FirstPartySetsCacheFilter::MatchInfo::MatchInfo(
12     const FirstPartySetsCacheFilter::MatchInfo& other) = default;
13 
14 FirstPartySetsCacheFilter::MatchInfo::MatchInfo::~MatchInfo() = default;
15 
16 bool FirstPartySetsCacheFilter::MatchInfo::operator==(
17     const FirstPartySetsCacheFilter::MatchInfo& other) const = default;
18 
19 FirstPartySetsCacheFilter::FirstPartySetsCacheFilter() = default;
FirstPartySetsCacheFilter(base::flat_map<net::SchemefulSite,int64_t> filter,int64_t browser_run_id)20 FirstPartySetsCacheFilter::FirstPartySetsCacheFilter(
21     base::flat_map<net::SchemefulSite, int64_t> filter,
22     int64_t browser_run_id)
23     : filter_(std::move(filter)), browser_run_id_(std::move(browser_run_id)) {
24   CHECK(browser_run_id != 0 || filter_.empty());
25 }
26 
27 FirstPartySetsCacheFilter::FirstPartySetsCacheFilter(
28     FirstPartySetsCacheFilter&& other) = default;
29 FirstPartySetsCacheFilter& FirstPartySetsCacheFilter::operator=(
30     FirstPartySetsCacheFilter&& other) = default;
31 
32 FirstPartySetsCacheFilter::~FirstPartySetsCacheFilter() = default;
33 
34 bool FirstPartySetsCacheFilter::operator==(
35     const FirstPartySetsCacheFilter& other) const = default;
36 
Clone() const37 FirstPartySetsCacheFilter FirstPartySetsCacheFilter::Clone() const {
38   return FirstPartySetsCacheFilter(filter_, browser_run_id_);
39 }
40 
GetMatchInfo(const net::SchemefulSite & site) const41 FirstPartySetsCacheFilter::MatchInfo FirstPartySetsCacheFilter::GetMatchInfo(
42     const net::SchemefulSite& site) const {
43   FirstPartySetsCacheFilter::MatchInfo res;
44   if (browser_run_id_ > 0) {
45     res.browser_run_id = browser_run_id_;
46     if (const auto it = filter_.find(site); it != filter_.end())
47       res.clear_at_run_id = it->second;
48   }
49   return res;
50 }
51 
52 }  // namespace net
53