0

Change owner to entry

Change instances of Owner to Entry in FirstPartySetsManager and related
files to reflect the change of FirstPartySetsManager::FindOwners, which
now returns the full FirstPartySetEntries, not just owner domains

Bug: 1360890
Change-Id: Iefb71afbba805a3b222237ec4ade90a37c3868b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3879927
Reviewed-by: Chris Fredrickson <cfredric@chromium.org>
Reviewed-by: Dylan Cutler <dylancutler@google.com>
Commit-Queue: Sam LeDoux <sledoux@google.com>
Cr-Commit-Position: refs/heads/main@{#1046902}
This commit is contained in:
Sam LeDoux
2022-09-14 15:18:48 +00:00
committed by Chromium LUCI CQ
parent 2ce3fcd3e5
commit dde1ba29cf
15 changed files with 114 additions and 119 deletions

@@ -48,7 +48,7 @@ CookieAccessDelegate::FirstPartySetifyPartitionKey(
} }
absl::optional<base::flat_map<net::SchemefulSite, FirstPartySetEntry>> absl::optional<base::flat_map<net::SchemefulSite, FirstPartySetEntry>>
maybe_entries = delegate->FindFirstPartySetOwners( maybe_entries = delegate->FindFirstPartySetEntries(
{cookie_partition_key.site()}, {cookie_partition_key.site()},
base::BindOnce(&CreateCookiePartitionKeyFromFirstPartySetEntry, base::BindOnce(&CreateCookiePartitionKeyFromFirstPartySetEntry,
cookie_partition_key) cookie_partition_key)

@@ -78,7 +78,7 @@ class NET_EXPORT CookieAccessDelegate {
// not both, and not neither. // not both, and not neither.
[[nodiscard]] virtual absl::optional< [[nodiscard]] virtual absl::optional<
base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>> base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>>
FindFirstPartySetOwners( FindFirstPartySetEntries(
const base::flat_set<net::SchemefulSite>& sites, const base::flat_set<net::SchemefulSite>& sites,
base::OnceCallback< base::OnceCallback<
void(base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>)> void(base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>)>

@@ -2263,7 +2263,7 @@ bool CookieMonster::DoRecordPeriodicStats() {
} }
} }
absl::optional<base::flat_map<SchemefulSite, FirstPartySetEntry>> absl::optional<base::flat_map<SchemefulSite, FirstPartySetEntry>>
maybe_sets = cookie_access_delegate()->FindFirstPartySetOwners( maybe_sets = cookie_access_delegate()->FindFirstPartySetEntries(
sites, sites,
base::BindOnce(&CookieMonster::RecordPeriodicFirstPartySetsStats, base::BindOnce(&CookieMonster::RecordPeriodicFirstPartySetsStats,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));

@@ -82,7 +82,7 @@ CookiePartitionKeyCollection::FirstPartySetify(
if (sites.empty()) if (sites.empty())
return *this; return *this;
absl::optional<base::flat_map<SchemefulSite, FirstPartySetEntry>> absl::optional<base::flat_map<SchemefulSite, FirstPartySetEntry>>
maybe_sites_to_entries = cookie_access_delegate->FindFirstPartySetOwners( maybe_sites_to_entries = cookie_access_delegate->FindFirstPartySetEntries(
sites, sites,
base::BindOnce(&TransformWithFirstPartySetEntries, PartitionKeys()) base::BindOnce(&TransformWithFirstPartySetEntries, PartitionKeys())
.Then(std::move(callback))); .Then(std::move(callback)));

@@ -56,18 +56,16 @@ TestCookieAccessDelegate::ComputeFirstPartySetMetadataMaybeAsync(
const std::set<SchemefulSite>& party_context, const std::set<SchemefulSite>& party_context,
base::OnceCallback<void(FirstPartySetMetadata)> callback) const { base::OnceCallback<void(FirstPartySetMetadata)> callback) const {
absl::optional<FirstPartySetEntry> top_frame_owner = absl::optional<FirstPartySetEntry> top_frame_owner =
top_frame_site ? FindFirstPartySetOwnerSync(*top_frame_site) top_frame_site ? FindFirstPartySetEntry(*top_frame_site) : absl::nullopt;
: absl::nullopt;
return RunMaybeAsync( return RunMaybeAsync(
FirstPartySetMetadata( FirstPartySetMetadata(SamePartyContext(),
SamePartyContext(), base::OptionalToPtr(FindFirstPartySetEntry(site)),
base::OptionalToPtr(FindFirstPartySetOwnerSync(site)), base::OptionalToPtr(top_frame_owner)),
base::OptionalToPtr(top_frame_owner)),
std::move(callback)); std::move(callback));
} }
absl::optional<FirstPartySetEntry> absl::optional<FirstPartySetEntry>
TestCookieAccessDelegate::FindFirstPartySetOwnerSync( TestCookieAccessDelegate::FindFirstPartySetEntry(
const SchemefulSite& site) const { const SchemefulSite& site) const {
auto entry = first_party_sets_.find(site); auto entry = first_party_sets_.find(site);
@@ -76,13 +74,13 @@ TestCookieAccessDelegate::FindFirstPartySetOwnerSync(
} }
absl::optional<base::flat_map<SchemefulSite, FirstPartySetEntry>> absl::optional<base::flat_map<SchemefulSite, FirstPartySetEntry>>
TestCookieAccessDelegate::FindFirstPartySetOwners( TestCookieAccessDelegate::FindFirstPartySetEntries(
const base::flat_set<SchemefulSite>& sites, const base::flat_set<SchemefulSite>& sites,
base::OnceCallback<void(base::flat_map<SchemefulSite, FirstPartySetEntry>)> base::OnceCallback<void(base::flat_map<SchemefulSite, FirstPartySetEntry>)>
callback) const { callback) const {
std::vector<std::pair<SchemefulSite, FirstPartySetEntry>> mapping; std::vector<std::pair<SchemefulSite, FirstPartySetEntry>> mapping;
for (const SchemefulSite& site : sites) { for (const SchemefulSite& site : sites) {
absl::optional<FirstPartySetEntry> entry = FindFirstPartySetOwnerSync(site); absl::optional<FirstPartySetEntry> entry = FindFirstPartySetEntry(site);
if (entry) if (entry)
mapping.emplace_back(site, *entry); mapping.emplace_back(site, *entry);
} }

@@ -47,7 +47,7 @@ class TestCookieAccessDelegate : public CookieAccessDelegate {
const std::set<SchemefulSite>& party_context, const std::set<SchemefulSite>& party_context,
base::OnceCallback<void(FirstPartySetMetadata)> callback) const override; base::OnceCallback<void(FirstPartySetMetadata)> callback) const override;
absl::optional<base::flat_map<SchemefulSite, FirstPartySetEntry>> absl::optional<base::flat_map<SchemefulSite, FirstPartySetEntry>>
FindFirstPartySetOwners( FindFirstPartySetEntries(
const base::flat_set<SchemefulSite>& sites, const base::flat_set<SchemefulSite>& sites,
base::OnceCallback< base::OnceCallback<
void(base::flat_map<SchemefulSite, FirstPartySetEntry>)> callback) void(base::flat_map<SchemefulSite, FirstPartySetEntry>)> callback)
@@ -67,7 +67,7 @@ class TestCookieAccessDelegate : public CookieAccessDelegate {
bool require_secure_origin); bool require_secure_origin);
// Set the test delegate's First-Party Sets. The map's keys are the sites in // Set the test delegate's First-Party Sets. The map's keys are the sites in
// the sets. Owner sites must be included among the keys for a given set. // the sets. Primary sites must be included among the keys for a given set.
void SetFirstPartySets( void SetFirstPartySets(
const base::flat_map<SchemefulSite, FirstPartySetEntry>& sets); const base::flat_map<SchemefulSite, FirstPartySetEntry>& sets);
@@ -76,8 +76,8 @@ class TestCookieAccessDelegate : public CookieAccessDelegate {
} }
private: private:
// Synchronous version of FindFirstPartySetOwner, for convenience. // Finds a FirstPartySetEntry for the given site, if one exists.
absl::optional<FirstPartySetEntry> FindFirstPartySetOwnerSync( absl::optional<FirstPartySetEntry> FindFirstPartySetEntry(
const SchemefulSite& site) const; const SchemefulSite& site) const;
// Discard any leading dot in the domain string. // Discard any leading dot in the domain string.

@@ -72,15 +72,15 @@ CookieAccessDelegateImpl::ComputeFirstPartySetMetadataMaybeAsync(
site, top_frame_site, party_context, std::move(callback)); site, top_frame_site, party_context, std::move(callback));
} }
absl::optional<FirstPartySetsAccessDelegate::OwnersResult> absl::optional<FirstPartySetsAccessDelegate::EntriesResult>
CookieAccessDelegateImpl::FindFirstPartySetOwners( CookieAccessDelegateImpl::FindFirstPartySetEntries(
const base::flat_set<net::SchemefulSite>& sites, const base::flat_set<net::SchemefulSite>& sites,
base::OnceCallback<void(FirstPartySetsAccessDelegate::OwnersResult)> base::OnceCallback<void(FirstPartySetsAccessDelegate::EntriesResult)>
callback) const { callback) const {
if (!first_party_sets_access_delegate_) if (!first_party_sets_access_delegate_)
return {{}}; return {{}};
return first_party_sets_access_delegate_->FindOwners(sites, return first_party_sets_access_delegate_->FindEntries(sites,
std::move(callback)); std::move(callback));
} }
} // namespace network } // namespace network

@@ -62,10 +62,10 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) CookieAccessDelegateImpl
const std::set<net::SchemefulSite>& party_context, const std::set<net::SchemefulSite>& party_context,
base::OnceCallback<void(net::FirstPartySetMetadata)> callback) base::OnceCallback<void(net::FirstPartySetMetadata)> callback)
const override; const override;
[[nodiscard]] absl::optional<FirstPartySetsAccessDelegate::OwnersResult> [[nodiscard]] absl::optional<FirstPartySetsAccessDelegate::EntriesResult>
FindFirstPartySetOwners( FindFirstPartySetEntries(
const base::flat_set<net::SchemefulSite>& sites, const base::flat_set<net::SchemefulSite>& sites,
base::OnceCallback<void(FirstPartySetsAccessDelegate::OwnersResult)> base::OnceCallback<void(FirstPartySetsAccessDelegate::EntriesResult)>
callback) const override; callback) const override;
private: private:

@@ -53,9 +53,9 @@ TEST_F(CookieAccessDelegateImplTest, NullFirstPartySetsManager) {
Optional(std::ref(expected_metadata))); Optional(std::ref(expected_metadata)));
EXPECT_THAT( EXPECT_THAT(
delegate().FindFirstPartySetOwners( delegate().FindFirstPartySetEntries(
{site}, {site},
base::BindOnce([](FirstPartySetsManager::OwnersResult) { FAIL(); })), base::BindOnce([](FirstPartySetsManager::EntriesResult) { FAIL(); })),
Optional(IsEmpty())); Optional(IsEmpty()));
} }

@@ -71,10 +71,10 @@ FirstPartySetsAccessDelegate::ComputeMetadata(
context_config_, std::move(callback)); context_config_, std::move(callback));
} }
absl::optional<FirstPartySetsAccessDelegate::OwnersResult> absl::optional<FirstPartySetsAccessDelegate::EntriesResult>
FirstPartySetsAccessDelegate::FindOwners( FirstPartySetsAccessDelegate::FindEntries(
const base::flat_set<net::SchemefulSite>& sites, const base::flat_set<net::SchemefulSite>& sites,
base::OnceCallback<void(FirstPartySetsAccessDelegate::OwnersResult)> base::OnceCallback<void(FirstPartySetsAccessDelegate::EntriesResult)>
callback) { callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
@@ -86,12 +86,12 @@ FirstPartySetsAccessDelegate::FindOwners(
// `pending_queries_` will not run the enqueued callbacks after `this` is // `pending_queries_` will not run the enqueued callbacks after `this` is
// destroyed. // destroyed.
EnqueuePendingQuery( EnqueuePendingQuery(
base::BindOnce(&FirstPartySetsAccessDelegate::FindOwnersAndInvoke, base::BindOnce(&FirstPartySetsAccessDelegate::FindEntriesAndInvoke,
base::Unretained(this), sites, std::move(callback))); base::Unretained(this), sites, std::move(callback)));
return absl::nullopt; return absl::nullopt;
} }
return manager_->FindOwners(sites, context_config_, std::move(callback)); return manager_->FindEntries(sites, context_config_, std::move(callback));
} }
void FirstPartySetsAccessDelegate::ComputeMetadataAndInvoke( void FirstPartySetsAccessDelegate::ComputeMetadataAndInvoke(
@@ -115,20 +115,20 @@ void FirstPartySetsAccessDelegate::ComputeMetadataAndInvoke(
std::move(callbacks.second).Run(std::move(sync_result.value())); std::move(callbacks.second).Run(std::move(sync_result.value()));
} }
void FirstPartySetsAccessDelegate::FindOwnersAndInvoke( void FirstPartySetsAccessDelegate::FindEntriesAndInvoke(
const base::flat_set<net::SchemefulSite>& sites, const base::flat_set<net::SchemefulSite>& sites,
base::OnceCallback<void(FirstPartySetsAccessDelegate::OwnersResult)> base::OnceCallback<void(FirstPartySetsAccessDelegate::EntriesResult)>
callback) const { callback) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(enabled_); DCHECK(enabled_);
std::pair< std::pair<
base::OnceCallback<void(FirstPartySetsAccessDelegate::OwnersResult)>, base::OnceCallback<void(FirstPartySetsAccessDelegate::EntriesResult)>,
base::OnceCallback<void(FirstPartySetsAccessDelegate::OwnersResult)>> base::OnceCallback<void(FirstPartySetsAccessDelegate::EntriesResult)>>
callbacks = base::SplitOnceCallback(std::move(callback)); callbacks = base::SplitOnceCallback(std::move(callback));
absl::optional<FirstPartySetsAccessDelegate::OwnersResult> sync_result = absl::optional<FirstPartySetsAccessDelegate::EntriesResult> sync_result =
manager_->FindOwners(sites, context_config_, std::move(callbacks.first)); manager_->FindEntries(sites, context_config_, std::move(callbacks.first));
if (sync_result.has_value()) if (sync_result.has_value())
std::move(callbacks.second).Run(sync_result.value()); std::move(callbacks.second).Run(sync_result.value());

@@ -31,7 +31,7 @@ namespace network {
class FirstPartySetsAccessDelegate class FirstPartySetsAccessDelegate
: public mojom::FirstPartySetsAccessDelegate { : public mojom::FirstPartySetsAccessDelegate {
public: public:
using OwnersResult = FirstPartySetsManager::OwnersResult; using EntriesResult = FirstPartySetsManager::EntriesResult;
using FlattenedSets = FirstPartySetsManager::FlattenedSets; using FlattenedSets = FirstPartySetsManager::FlattenedSets;
// Construct a FirstPartySetsAccessDelegate that provides customizations // Construct a FirstPartySetsAccessDelegate that provides customizations
@@ -68,21 +68,16 @@ class FirstPartySetsAccessDelegate
const std::set<net::SchemefulSite>& party_context, const std::set<net::SchemefulSite>& party_context,
base::OnceCallback<void(net::FirstPartySetMetadata)> callback); base::OnceCallback<void(net::FirstPartySetMetadata)> callback);
// Batched version of `FindOwner`. Returns the mapping of sites to owners for // Calls FirstPartySetsManager::FindEntries either asynchronously or
// the given input sites (if an owner exists). // synchronously, once initialization is complete.
//
// When FPS is disabled, returns an empty map.
// When FPS is enabled, this maps each input site to its owner (if one
// exists), and returns the resulting mapping. If a site isn't in a
// non-trivial First-Party Set, it is not added to the output map.
// //
// This may return a result synchronously, or asynchronously invoke `callback` // This may return a result synchronously, or asynchronously invoke `callback`
// with the result. The callback will be invoked iff the return value is // with the result. The callback will be invoked iff the return value is
// nullopt; i.e. a result will be provided via return value or callback, but // nullopt; i.e. a result will be provided via return value or callback, but
// not both, and not neither. // not both, and not neither.
[[nodiscard]] absl::optional<OwnersResult> FindOwners( [[nodiscard]] absl::optional<EntriesResult> FindEntries(
const base::flat_set<net::SchemefulSite>& sites, const base::flat_set<net::SchemefulSite>& sites,
base::OnceCallback<void(OwnersResult)> callback); base::OnceCallback<void(EntriesResult)> callback);
private: private:
// Same as `ComputeMetadata`, but plumbs the result into the callback. Must // Same as `ComputeMetadata`, but plumbs the result into the callback. Must
@@ -93,11 +88,11 @@ class FirstPartySetsAccessDelegate
const std::set<net::SchemefulSite>& party_context, const std::set<net::SchemefulSite>& party_context,
base::OnceCallback<void(net::FirstPartySetMetadata)> callback) const; base::OnceCallback<void(net::FirstPartySetMetadata)> callback) const;
// Same as `FindOwners`, but plumbs the result into the callback. Must only be // Same as `FindEntries`, but plumbs the result into the callback. Must only
// called once the instance is fully initialized. // be called once the instance is fully initialized.
void FindOwnersAndInvoke( void FindEntriesAndInvoke(
const base::flat_set<net::SchemefulSite>& sites, const base::flat_set<net::SchemefulSite>& sites,
base::OnceCallback<void(OwnersResult)> callback) const; base::OnceCallback<void(EntriesResult)> callback) const;
// Runs all pending queries. Must not be called until the instance is fully // Runs all pending queries. Must not be called until the instance is fully
// initialized. // initialized.

@@ -111,10 +111,11 @@ TEST_F(NoopFirstPartySetsAccessDelegateTest, ComputeMetadata) {
net::SamePartyContext(Type::kSameParty)); net::SamePartyContext(Type::kSameParty));
} }
TEST_F(NoopFirstPartySetsAccessDelegateTest, FindOwners) { TEST_F(NoopFirstPartySetsAccessDelegateTest, FindEntries) {
EXPECT_THAT( EXPECT_THAT(
delegate().FindOwners({kSet1Member1, kSet2Member1}, base::NullCallback()), delegate().FindEntries({kSet1Member1, kSet2Member1},
FirstPartySetsAccessDelegate::OwnersResult({ base::NullCallback()),
FirstPartySetsAccessDelegate::EntriesResult({
{kSet1Member1, {kSet1Member1,
net::FirstPartySetEntry(kSet1Owner, net::SiteType::kAssociated, 0)}, net::FirstPartySetEntry(kSet1Owner, net::SiteType::kAssociated, 0)},
{kSet2Member1, {kSet2Member1,
@@ -159,11 +160,11 @@ class FirstPartySetsAccessDelegateTest : public ::testing::Test {
return result.has_value() ? std::move(result).value() : future.Take(); return result.has_value() ? std::move(result).value() : future.Take();
} }
FirstPartySetsAccessDelegate::OwnersResult FindOwnersAndWait( FirstPartySetsAccessDelegate::EntriesResult FindEntriesAndWait(
const base::flat_set<net::SchemefulSite>& site) { const base::flat_set<net::SchemefulSite>& site) {
base::test::TestFuture<FirstPartySetsAccessDelegate::OwnersResult> future; base::test::TestFuture<FirstPartySetsAccessDelegate::EntriesResult> future;
absl::optional<FirstPartySetsAccessDelegate::OwnersResult> result = absl::optional<FirstPartySetsAccessDelegate::EntriesResult> result =
delegate_.FindOwners(site, future.GetCallback()); delegate_.FindEntries(site, future.GetCallback());
return result.has_value() ? result.value() : future.Get(); return result.has_value() ? result.value() : future.Get();
} }
@@ -201,11 +202,11 @@ TEST_F(FirstPartySetsAccessDelegateDisabledTest, ComputeMetadata) {
Optional(std::ref(expected_metadata))); Optional(std::ref(expected_metadata)));
} }
TEST_F(FirstPartySetsAccessDelegateDisabledTest, FindOwners) { TEST_F(FirstPartySetsAccessDelegateDisabledTest, FindEntries) {
EXPECT_THAT( EXPECT_THAT(
delegate().FindOwners( delegate().FindEntries(
{kSet1Member1, kSet2Member1}, {kSet1Member1, kSet2Member1},
base::BindOnce([](FirstPartySetsManager::OwnersResult) { FAIL(); })), base::BindOnce([](FirstPartySetsManager::EntriesResult) { FAIL(); })),
Optional(IsEmpty())); Optional(IsEmpty()));
} }
@@ -236,16 +237,16 @@ TEST_F(AsyncFirstPartySetsAccessDelegateTest,
&entry, &entry)); &entry, &entry));
} }
TEST_F(AsyncFirstPartySetsAccessDelegateTest, QueryBeforeReady_FindOwners) { TEST_F(AsyncFirstPartySetsAccessDelegateTest, QueryBeforeReady_FindEntries) {
base::test::TestFuture<FirstPartySetsAccessDelegate::OwnersResult> future; base::test::TestFuture<FirstPartySetsAccessDelegate::EntriesResult> future;
EXPECT_FALSE(delegate().FindOwners({kSet1Member1, kSet2Member1}, EXPECT_FALSE(delegate().FindEntries({kSet1Member1, kSet2Member1},
future.GetCallback())); future.GetCallback()));
delegate_remote()->NotifyReady(mojom::FirstPartySetsReadyEvent::New()); delegate_remote()->NotifyReady(mojom::FirstPartySetsReadyEvent::New());
EXPECT_THAT( EXPECT_THAT(
future.Get(), future.Get(),
FirstPartySetsAccessDelegate::OwnersResult({ FirstPartySetsAccessDelegate::EntriesResult({
{kSet1Member1, {kSet1Member1,
net::FirstPartySetEntry(kSet1Owner, net::SiteType::kAssociated, 0)}, net::FirstPartySetEntry(kSet1Owner, net::SiteType::kAssociated, 0)},
{kSet2Member1, {kSet2Member1,
@@ -271,14 +272,14 @@ TEST_F(AsyncFirstPartySetsAccessDelegateTest, OverrideSets_ComputeMetadata) {
&primary_entry, &associated_entry)); &primary_entry, &associated_entry));
} }
TEST_F(AsyncFirstPartySetsAccessDelegateTest, OverrideSets_FindOwners) { TEST_F(AsyncFirstPartySetsAccessDelegateTest, OverrideSets_FindEntries) {
delegate_remote()->NotifyReady(CreateFirstPartySetsReadyEvent({ delegate_remote()->NotifyReady(CreateFirstPartySetsReadyEvent({
{kSet3Owner, {kSet3Owner,
{net::FirstPartySetEntry(kSet3Owner, net::SiteType::kPrimary, {net::FirstPartySetEntry(kSet3Owner, net::SiteType::kPrimary,
absl::nullopt)}}, absl::nullopt)}},
})); }));
EXPECT_THAT(FindOwnersAndWait({kSet3Owner}), EXPECT_THAT(FindEntriesAndWait({kSet3Owner}),
UnorderedElementsAre(Pair(kSet3Owner, _))); UnorderedElementsAre(Pair(kSet3Owner, _)));
} }
@@ -303,10 +304,10 @@ TEST_F(SyncFirstPartySetsAccessDelegateTest, ComputeMetadata) {
&entry, &entry)); &entry, &entry));
} }
TEST_F(SyncFirstPartySetsAccessDelegateTest, FindOwners) { TEST_F(SyncFirstPartySetsAccessDelegateTest, FindEntries) {
EXPECT_THAT( EXPECT_THAT(
FindOwnersAndWait({kSet1Member1, kSet2Member1, kSet3Member1}), FindEntriesAndWait({kSet1Member1, kSet2Member1, kSet3Member1}),
FirstPartySetsAccessDelegate::OwnersResult({ FirstPartySetsAccessDelegate::EntriesResult({
{kSet1Member1, {kSet1Member1,
net::FirstPartySetEntry(kSet1Owner, net::SiteType::kAssociated, 0)}, net::FirstPartySetEntry(kSet1Owner, net::SiteType::kAssociated, 0)},
{kSet2Member1, {kSet2Member1,

@@ -137,13 +137,13 @@ net::FirstPartySetMetadata FirstPartySetsManager::ComputeMetadataInternal(
"Cookie.FirstPartySets.ComputeContext.Latency", timer.Elapsed(), "Cookie.FirstPartySets.ComputeContext.Latency", timer.Elapsed(),
base::Microseconds(1), base::Milliseconds(100), 50); base::Microseconds(1), base::Milliseconds(100), 50);
absl::optional<net::FirstPartySetEntry> top_frame_owner = absl::optional<net::FirstPartySetEntry> top_frame_entry =
top_frame_site ? FindEntry(*top_frame_site, fps_context_config) top_frame_site ? FindEntry(*top_frame_site, fps_context_config)
: absl::nullopt; : absl::nullopt;
return net::FirstPartySetMetadata( return net::FirstPartySetMetadata(
context, base::OptionalToPtr(FindEntry(site, fps_context_config)), context, base::OptionalToPtr(FindEntry(site, fps_context_config)),
base::OptionalToPtr(top_frame_owner)); base::OptionalToPtr(top_frame_entry));
} }
absl::optional<net::FirstPartySetEntry> FirstPartySetsManager::FindEntry( absl::optional<net::FirstPartySetEntry> FirstPartySetsManager::FindEntry(
@@ -163,27 +163,28 @@ absl::optional<net::FirstPartySetEntry> FirstPartySetsManager::FindEntry(
return entry; return entry;
} }
absl::optional<FirstPartySetsManager::OwnersResult> absl::optional<FirstPartySetsManager::EntriesResult>
FirstPartySetsManager::FindOwners( FirstPartySetsManager::FindEntries(
const base::flat_set<net::SchemefulSite>& sites, const base::flat_set<net::SchemefulSite>& sites,
const net::FirstPartySetsContextConfig& fps_context_config, const net::FirstPartySetsContextConfig& fps_context_config,
base::OnceCallback<void(FirstPartySetsManager::OwnersResult)> callback) { base::OnceCallback<void(FirstPartySetsManager::EntriesResult)> callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!sets_.has_value()) { if (!sets_.has_value()) {
EnqueuePendingQuery(base::BindOnce( EnqueuePendingQuery(
&FirstPartySetsManager::FindOwnersAndInvoke, weak_factory_.GetWeakPtr(), base::BindOnce(&FirstPartySetsManager::FindEntriesAndInvoke,
sites, fps_context_config, std::move(callback), base::ElapsedTimer())); weak_factory_.GetWeakPtr(), sites, fps_context_config,
std::move(callback), base::ElapsedTimer()));
return absl::nullopt; return absl::nullopt;
} }
return FindOwnersInternal(sites, fps_context_config); return FindEntriesInternal(sites, fps_context_config);
} }
void FirstPartySetsManager::FindOwnersAndInvoke( void FirstPartySetsManager::FindEntriesAndInvoke(
const base::flat_set<net::SchemefulSite>& sites, const base::flat_set<net::SchemefulSite>& sites,
const net::FirstPartySetsContextConfig& fps_context_config, const net::FirstPartySetsContextConfig& fps_context_config,
base::OnceCallback<void(FirstPartySetsManager::OwnersResult)> callback, base::OnceCallback<void(FirstPartySetsManager::EntriesResult)> callback,
base::ElapsedTimer timer) const { base::ElapsedTimer timer) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(sets_.has_value()); DCHECK(sets_.has_value());
@@ -191,10 +192,10 @@ void FirstPartySetsManager::FindOwnersAndInvoke(
UMA_HISTOGRAM_TIMES("Cookie.FirstPartySets.EnqueueingDelay.FindOwners", UMA_HISTOGRAM_TIMES("Cookie.FirstPartySets.EnqueueingDelay.FindOwners",
timer.Elapsed()); timer.Elapsed());
std::move(callback).Run(FindOwnersInternal(sites, fps_context_config)); std::move(callback).Run(FindEntriesInternal(sites, fps_context_config));
} }
FirstPartySetsManager::OwnersResult FirstPartySetsManager::FindOwnersInternal( FirstPartySetsManager::EntriesResult FirstPartySetsManager::FindEntriesInternal(
const base::flat_set<net::SchemefulSite>& sites, const base::flat_set<net::SchemefulSite>& sites,
const net::FirstPartySetsContextConfig& fps_context_config) const { const net::FirstPartySetsContextConfig& fps_context_config) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

@@ -30,7 +30,7 @@ namespace network {
// answers queries about First-Party Sets after they've been loaded. // answers queries about First-Party Sets after they've been loaded.
class FirstPartySetsManager { class FirstPartySetsManager {
public: public:
using OwnersResult = using EntriesResult =
base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>; base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>;
using FlattenedSets = using FlattenedSets =
base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>; base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>;
@@ -80,10 +80,10 @@ class FirstPartySetsManager {
// with the result. The callback will be invoked iff the return value is // with the result. The callback will be invoked iff the return value is
// nullopt; i.e. a result will be provided via return value or callback, but // nullopt; i.e. a result will be provided via return value or callback, but
// not both, and not neither. // not both, and not neither.
[[nodiscard]] absl::optional<OwnersResult> FindOwners( [[nodiscard]] absl::optional<EntriesResult> FindEntries(
const base::flat_set<net::SchemefulSite>& sites, const base::flat_set<net::SchemefulSite>& sites,
const net::FirstPartySetsContextConfig& fps_context_config, const net::FirstPartySetsContextConfig& fps_context_config,
base::OnceCallback<void(OwnersResult)> callback); base::OnceCallback<void(EntriesResult)> callback);
private: private:
// Same as `ComputeMetadata`, but plumbs the result into the callback. Must // Same as `ComputeMetadata`, but plumbs the result into the callback. Must
@@ -125,17 +125,17 @@ class FirstPartySetsManager {
const net::SchemefulSite& site, const net::SchemefulSite& site,
const net::FirstPartySetsContextConfig& fps_context_config) const; const net::FirstPartySetsContextConfig& fps_context_config) const;
// Same as `FindOwners`, but plumbs the result into the callback. Must only be // Same as `FindEntries`, but plumbs the result into the callback. Must only
// called once the instance is fully initialized. // be called once the instance is fully initialized.
void FindOwnersAndInvoke( void FindEntriesAndInvoke(
const base::flat_set<net::SchemefulSite>& sites, const base::flat_set<net::SchemefulSite>& sites,
const net::FirstPartySetsContextConfig& fps_context_config, const net::FirstPartySetsContextConfig& fps_context_config,
base::OnceCallback<void(OwnersResult)> callback, base::OnceCallback<void(EntriesResult)> callback,
base::ElapsedTimer timer) const; base::ElapsedTimer timer) const;
// Synchronous version of `FindOwners`, to be run only once the instance is // Synchronous version of `FindEntries`, to be run only once the instance is
// initialized. // initialized.
OwnersResult FindOwnersInternal( EntriesResult FindEntriesInternal(
const base::flat_set<net::SchemefulSite>& sites, const base::flat_set<net::SchemefulSite>& sites,
const net::FirstPartySetsContextConfig& fps_context_config) const; const net::FirstPartySetsContextConfig& fps_context_config) const;

@@ -60,11 +60,11 @@ class FirstPartySetsManagerTest : public ::testing::Test {
return result.has_value() ? std::move(result).value() : future.Take(); return result.has_value() ? std::move(result).value() : future.Take();
} }
FirstPartySetsManager::OwnersResult FindOwnersAndWait( FirstPartySetsManager::EntriesResult FindEntriesAndWait(
const base::flat_set<net::SchemefulSite>& site) { const base::flat_set<net::SchemefulSite>& site) {
base::test::TestFuture<FirstPartySetsManager::OwnersResult> future; base::test::TestFuture<FirstPartySetsManager::EntriesResult> future;
absl::optional<FirstPartySetsManager::OwnersResult> result = absl::optional<FirstPartySetsManager::EntriesResult> result =
manager_.FindOwners(site, fps_context_config_, future.GetCallback()); manager_.FindEntries(site, fps_context_config_, future.GetCallback());
return result.has_value() ? result.value() : future.Get(); return result.has_value() ? result.value() : future.Get();
} }
@@ -105,7 +105,7 @@ TEST_F(FirstPartySetsManagerDisabledTest, SetCompleteSets) {
example_test, net::SiteType::kPrimary, absl::nullopt)}}, example_test, net::SiteType::kPrimary, absl::nullopt)}},
{{example_cctld, example_test}}); {{example_cctld, example_test}});
EXPECT_THAT(FindOwnersAndWait({ EXPECT_THAT(FindEntriesAndWait({
aaaa, aaaa,
example_test, example_test,
example_cctld, example_cctld,
@@ -113,11 +113,11 @@ TEST_F(FirstPartySetsManagerDisabledTest, SetCompleteSets) {
IsEmpty()); IsEmpty());
} }
TEST_F(FirstPartySetsManagerDisabledTest, FindOwners) { TEST_F(FirstPartySetsManagerDisabledTest, FindEntries) {
net::SchemefulSite kExample = net::SchemefulSite kExample =
net::SchemefulSite(GURL("https://example.test")); net::SchemefulSite(GURL("https://example.test"));
EXPECT_THAT(FindOwnersAndWait({kExample}), IsEmpty()); EXPECT_THAT(FindEntriesAndWait({kExample}), IsEmpty());
} }
TEST_F(FirstPartySetsManagerDisabledTest, ComputeMetadata_InfersSingletons) { TEST_F(FirstPartySetsManagerDisabledTest, ComputeMetadata_InfersSingletons) {
@@ -168,7 +168,7 @@ TEST_F(FirstPartySetsEnabledTest, SetCompleteSets) {
{{example_cctld, example_test}}); {{example_cctld, example_test}});
EXPECT_THAT( EXPECT_THAT(
FindOwnersAndWait({ FindEntriesAndWait({
aaaa, aaaa,
example_test, example_test,
example_cctld, example_cctld,
@@ -186,7 +186,7 @@ TEST_F(FirstPartySetsEnabledTest, SetCompleteSets) {
TEST_F(FirstPartySetsEnabledTest, SetCompleteSets_Idempotent) { TEST_F(FirstPartySetsEnabledTest, SetCompleteSets_Idempotent) {
SetCompleteSets({}, {}); SetCompleteSets({}, {});
EXPECT_THAT(FindOwnersAndWait({}), IsEmpty()); EXPECT_THAT(FindEntriesAndWait({}), IsEmpty());
// The second call to SetCompleteSets should have no effect. // The second call to SetCompleteSets should have no effect.
SetCompleteSets({{net::SchemefulSite(GURL("https://aaaa.test")), SetCompleteSets({{net::SchemefulSite(GURL("https://aaaa.test")),
@@ -198,7 +198,7 @@ TEST_F(FirstPartySetsEnabledTest, SetCompleteSets_Idempotent) {
net::SchemefulSite(GURL("https://example.test")), net::SchemefulSite(GURL("https://example.test")),
net::SiteType::kPrimary, absl::nullopt)}}, net::SiteType::kPrimary, absl::nullopt)}},
{}); {});
EXPECT_THAT(FindOwnersAndWait({ EXPECT_THAT(FindEntriesAndWait({
net::SchemefulSite(GURL("https://aaaa.test")), net::SchemefulSite(GURL("https://aaaa.test")),
net::SchemefulSite(GURL("https://example.test")), net::SchemefulSite(GURL("https://example.test")),
}), }),
@@ -276,9 +276,9 @@ TEST_F(AsyncPopulatedFirstPartySetsManagerTest,
} }
} }
TEST_F(AsyncPopulatedFirstPartySetsManagerTest, QueryBeforeReady_FindOwners) { TEST_F(AsyncPopulatedFirstPartySetsManagerTest, QueryBeforeReady_FindEntries) {
base::test::TestFuture<FirstPartySetsManager::OwnersResult> future; base::test::TestFuture<FirstPartySetsManager::EntriesResult> future;
EXPECT_FALSE(manager().FindOwners( EXPECT_FALSE(manager().FindEntries(
{ {
net::SchemefulSite(GURL("https://member1.test")), net::SchemefulSite(GURL("https://member1.test")),
net::SchemefulSite(GURL("https://member2.test")), net::SchemefulSite(GURL("https://member2.test")),
@@ -793,41 +793,41 @@ TEST_F(PopulatedFirstPartySetsManagerTest, ComputeMetadata) {
&associated_entry, &associated_entry)); &associated_entry, &associated_entry));
} }
TEST_F(PopulatedFirstPartySetsManagerTest, FindOwners) { TEST_F(PopulatedFirstPartySetsManagerTest, FindEntries) {
net::SchemefulSite kExample(GURL("https://example.test")); net::SchemefulSite kExample(GURL("https://example.test"));
net::SchemefulSite kFoo(GURL("https://foo.test")); net::SchemefulSite kFoo(GURL("https://foo.test"));
net::SchemefulSite kMember1(GURL("https://member1.test")); net::SchemefulSite kMember1(GURL("https://member1.test"));
net::SchemefulSite kMember2(GURL("https://member2.test")); net::SchemefulSite kMember2(GURL("https://member2.test"));
net::SchemefulSite kNonmember(GURL("https://nonmember.test")); net::SchemefulSite kNonmember(GURL("https://nonmember.test"));
EXPECT_THAT(FindOwnersAndWait({kExample}), EXPECT_THAT(FindEntriesAndWait({kExample}),
UnorderedElementsAre( UnorderedElementsAre(
Pair(SerializesTo("https://example.test"), Pair(SerializesTo("https://example.test"),
net::FirstPartySetEntry( net::FirstPartySetEntry(
net::SchemefulSite(GURL("https://example.test")), net::SchemefulSite(GURL("https://example.test")),
net::SiteType::kPrimary, absl::nullopt)))); net::SiteType::kPrimary, absl::nullopt))));
EXPECT_THAT(FindOwnersAndWait({kMember1}), EXPECT_THAT(FindEntriesAndWait({kMember1}),
UnorderedElementsAre( UnorderedElementsAre(
Pair(SerializesTo("https://member1.test"), Pair(SerializesTo("https://member1.test"),
net::FirstPartySetEntry( net::FirstPartySetEntry(
net::SchemefulSite(GURL("https://example.test")), net::SchemefulSite(GURL("https://example.test")),
net::SiteType::kAssociated, 0)))); net::SiteType::kAssociated, 0))));
EXPECT_THAT(FindOwnersAndWait({kNonmember}), IsEmpty()); EXPECT_THAT(FindEntriesAndWait({kNonmember}), IsEmpty());
EXPECT_THAT(FindOwnersAndWait({kExample, kNonmember}), EXPECT_THAT(FindEntriesAndWait({kExample, kNonmember}),
UnorderedElementsAre( UnorderedElementsAre(
Pair(SerializesTo("https://example.test"), Pair(SerializesTo("https://example.test"),
net::FirstPartySetEntry( net::FirstPartySetEntry(
net::SchemefulSite(GURL("https://example.test")), net::SchemefulSite(GURL("https://example.test")),
net::SiteType::kPrimary, absl::nullopt)))); net::SiteType::kPrimary, absl::nullopt))));
EXPECT_THAT(FindOwnersAndWait({kMember1, kNonmember}), EXPECT_THAT(FindEntriesAndWait({kMember1, kNonmember}),
UnorderedElementsAre( UnorderedElementsAre(
Pair(SerializesTo("https://member1.test"), Pair(SerializesTo("https://member1.test"),
net::FirstPartySetEntry( net::FirstPartySetEntry(
net::SchemefulSite(GURL("https://example.test")), net::SchemefulSite(GURL("https://example.test")),
net::SiteType::kAssociated, 0)))); net::SiteType::kAssociated, 0))));
EXPECT_THAT(FindOwnersAndWait({kExample, kFoo}), EXPECT_THAT(FindEntriesAndWait({kExample, kFoo}),
UnorderedElementsAre( UnorderedElementsAre(
Pair(SerializesTo("https://example.test"), Pair(SerializesTo("https://example.test"),
net::FirstPartySetEntry( net::FirstPartySetEntry(
@@ -837,7 +837,7 @@ TEST_F(PopulatedFirstPartySetsManagerTest, FindOwners) {
net::FirstPartySetEntry( net::FirstPartySetEntry(
net::SchemefulSite(GURL("https://foo.test")), net::SchemefulSite(GURL("https://foo.test")),
net::SiteType::kPrimary, absl::nullopt)))); net::SiteType::kPrimary, absl::nullopt))));
EXPECT_THAT(FindOwnersAndWait({kMember1, kFoo}), EXPECT_THAT(FindEntriesAndWait({kMember1, kFoo}),
UnorderedElementsAre( UnorderedElementsAre(
Pair(SerializesTo("https://member1.test"), Pair(SerializesTo("https://member1.test"),
net::FirstPartySetEntry( net::FirstPartySetEntry(
@@ -847,7 +847,7 @@ TEST_F(PopulatedFirstPartySetsManagerTest, FindOwners) {
net::FirstPartySetEntry( net::FirstPartySetEntry(
net::SchemefulSite(GURL("https://foo.test")), net::SchemefulSite(GURL("https://foo.test")),
net::SiteType::kPrimary, absl::nullopt)))); net::SiteType::kPrimary, absl::nullopt))));
EXPECT_THAT(FindOwnersAndWait({kExample, kMember2}), EXPECT_THAT(FindEntriesAndWait({kExample, kMember2}),
UnorderedElementsAre( UnorderedElementsAre(
Pair(SerializesTo("https://example.test"), Pair(SerializesTo("https://example.test"),
net::FirstPartySetEntry( net::FirstPartySetEntry(
@@ -857,7 +857,7 @@ TEST_F(PopulatedFirstPartySetsManagerTest, FindOwners) {
net::FirstPartySetEntry( net::FirstPartySetEntry(
net::SchemefulSite(GURL("https://foo.test")), net::SchemefulSite(GURL("https://foo.test")),
net::SiteType::kAssociated, 0)))); net::SiteType::kAssociated, 0))));
EXPECT_THAT(FindOwnersAndWait({kMember1, kMember2}), EXPECT_THAT(FindEntriesAndWait({kMember1, kMember2}),
UnorderedElementsAre( UnorderedElementsAre(
Pair(SerializesTo("https://member1.test"), Pair(SerializesTo("https://member1.test"),
net::FirstPartySetEntry( net::FirstPartySetEntry(
@@ -907,13 +907,13 @@ class OverrideSetsFirstPartySetsManagerTest : public FirstPartySetsEnabledTest {
} }
}; };
TEST_F(OverrideSetsFirstPartySetsManagerTest, FindOwners) { TEST_F(OverrideSetsFirstPartySetsManagerTest, FindEntries) {
net::SchemefulSite foo(GURL("https://foo.test")); net::SchemefulSite foo(GURL("https://foo.test"));
net::SchemefulSite example_test(GURL("https://example.test")); net::SchemefulSite example_test(GURL("https://example.test"));
net::SchemefulSite example_cctld(GURL("https://example.cctld")); net::SchemefulSite example_cctld(GURL("https://example.cctld"));
net::SchemefulSite member2(GURL("https://member2.test")); net::SchemefulSite member2(GURL("https://member2.test"));
EXPECT_THAT(FindOwnersAndWait({ EXPECT_THAT(FindEntriesAndWait({
net::SchemefulSite(GURL("https://member1.test")), net::SchemefulSite(GURL("https://member1.test")),
member2, member2,
foo, foo,