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
operator ==(const FirstPartySetsCacheFilter::MatchInfo & other) const16 bool FirstPartySetsCacheFilter::MatchInfo::operator==(
17 const FirstPartySetsCacheFilter::MatchInfo& other) const {
18 return std::tie(clear_at_run_id, browser_run_id) ==
19 std::tie(other.clear_at_run_id, other.browser_run_id);
20 }
21
22 FirstPartySetsCacheFilter::FirstPartySetsCacheFilter() = default;
FirstPartySetsCacheFilter(base::flat_map<net::SchemefulSite,int64_t> filter,int64_t browser_run_id)23 FirstPartySetsCacheFilter::FirstPartySetsCacheFilter(
24 base::flat_map<net::SchemefulSite, int64_t> filter,
25 int64_t browser_run_id)
26 : filter_(std::move(filter)), browser_run_id_(std::move(browser_run_id)) {
27 CHECK(browser_run_id != 0 || filter_.empty());
28 }
29
30 FirstPartySetsCacheFilter::FirstPartySetsCacheFilter(
31 FirstPartySetsCacheFilter&& other) = default;
32 FirstPartySetsCacheFilter& FirstPartySetsCacheFilter::operator=(
33 FirstPartySetsCacheFilter&& other) = default;
34
35 FirstPartySetsCacheFilter::~FirstPartySetsCacheFilter() = default;
36
operator ==(const FirstPartySetsCacheFilter & other) const37 bool FirstPartySetsCacheFilter::operator==(
38 const FirstPartySetsCacheFilter& other) const {
39 return std::tie(filter_, browser_run_id_) ==
40 std::tie(other.filter_, other.browser_run_id_);
41 }
42
Clone() const43 FirstPartySetsCacheFilter FirstPartySetsCacheFilter::Clone() const {
44 return FirstPartySetsCacheFilter(filter_, browser_run_id_);
45 }
46
GetMatchInfo(const net::SchemefulSite & site) const47 FirstPartySetsCacheFilter::MatchInfo FirstPartySetsCacheFilter::GetMatchInfo(
48 const net::SchemefulSite& site) const {
49 FirstPartySetsCacheFilter::MatchInfo res;
50 if (browser_run_id_ > 0) {
51 res.browser_run_id = browser_run_id_;
52 if (const auto it = filter_.find(site); it != filter_.end())
53 res.clear_at_run_id = it->second;
54 }
55 return res;
56 }
57
58 } // namespace net
59