#include "content/browser/interest_group/interest_group_caching_storage.h"
#include <algorithm>
#include <cstdint>
#include "base/containers/flat_map.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "content/browser/interest_group/bidding_and_auction_server_key_fetcher.h"
#include "content/browser/interest_group/interest_group_features.h"
#include "content/browser/interest_group/interest_group_manager_impl.h"
#include "content/browser/interest_group/interest_group_storage.h"
#include "content/browser/interest_group/storage_interest_group.h"
#include "content/common/features.h"
#include "content/public/common/content_features.h"
#include "url/origin.h"
namespace {
std::optional<content::SingleStorageInterestGroup>
ConvertOptionalGroupToSingleStorageInterestGroup(
std::optional<content::StorageInterestGroup> possible_group) { … }
}
namespace content {
SingleStorageInterestGroup::SingleStorageInterestGroup(
scoped_refptr<StorageInterestGroups> storage_interest_groups_for_owner,
const StorageInterestGroup* storage_interest_group)
: … { … }
SingleStorageInterestGroup::SingleStorageInterestGroup(
const SingleStorageInterestGroup& other) = default;
SingleStorageInterestGroup::SingleStorageInterestGroup(
StorageInterestGroup&& interest_group) { … }
SingleStorageInterestGroup::~SingleStorageInterestGroup() = default;
const StorageInterestGroup* SingleStorageInterestGroup::operator->() const { … }
const StorageInterestGroup& SingleStorageInterestGroup::operator*() const { … }
StorageInterestGroups::StorageInterestGroups(
std::vector<StorageInterestGroup>&& interest_groups)
: … { … }
std::optional<SingleStorageInterestGroup> StorageInterestGroups::FindGroup(
std::string_view name) { … }
StorageInterestGroups::~StorageInterestGroups() = default;
base::WeakPtr<StorageInterestGroups> StorageInterestGroups::GetWeakPtr() { … }
InterestGroupCachingStorage::CachedOriginsInfo::CachedOriginsInfo() = default;
InterestGroupCachingStorage::CachedOriginsInfo::CachedOriginsInfo(
const blink::InterestGroup& group)
: … { … }
InterestGroupCachingStorage::CachedOriginsInfo::CachedOriginsInfo(
InterestGroupCachingStorage::CachedOriginsInfo&& other) = default;
InterestGroupCachingStorage::CachedOriginsInfo&
InterestGroupCachingStorage::CachedOriginsInfo::operator=(
InterestGroupCachingStorage::CachedOriginsInfo&& other) = default;
InterestGroupCachingStorage::CachedOriginsInfo::~CachedOriginsInfo() = default;
InterestGroupCachingStorage::InterestGroupCachingStorage(
const base::FilePath& path,
bool in_memory)
: … { … }
InterestGroupCachingStorage::~InterestGroupCachingStorage() = default;
void InterestGroupCachingStorage::GetInterestGroupsForOwner(
const url::Origin& owner,
base::OnceCallback<void(scoped_refptr<StorageInterestGroups>)> callback) { … }
bool InterestGroupCachingStorage::GetCachedOwnerAndSignalsOrigins(
const url::Origin& owner,
std::optional<url::Origin>& signals_origin) { … }
void InterestGroupCachingStorage::JoinInterestGroup(
const blink::InterestGroup& group,
const GURL& main_frame_joining_url,
base::OnceCallback<void(std::optional<InterestGroupKanonUpdateParameter>)>
callback) { … }
void InterestGroupCachingStorage::LeaveInterestGroup(
const blink::InterestGroupKey& group_key,
const url::Origin& main_frame,
base::OnceClosure callback) { … }
void InterestGroupCachingStorage::ClearOriginJoinedInterestGroups(
const url::Origin& owner,
const std::set<std::string>& interest_groups_to_keep,
const url::Origin& main_frame_origin,
base::OnceCallback<void(std::vector<std::string>)> callback) { … }
void InterestGroupCachingStorage::UpdateInterestGroup(
const blink::InterestGroupKey& group_key,
InterestGroupUpdate update,
base::OnceCallback<void(std::optional<InterestGroupKanonUpdateParameter>)>
callback) { … }
void InterestGroupCachingStorage::AllowUpdateIfOlderThan(
const blink::InterestGroupKey& group_key,
base::TimeDelta update_if_older_than) { … }
void InterestGroupCachingStorage::ReportUpdateFailed(
const blink::InterestGroupKey& group_key,
bool parse_failure) { … }
void InterestGroupCachingStorage::RecordInterestGroupBids(
const blink::InterestGroupSet& groups) { … }
void InterestGroupCachingStorage::RecordInterestGroupWin(
const blink::InterestGroupKey& group_key,
const std::string& ad_json) { … }
void InterestGroupCachingStorage::RecordDebugReportLockout(
base::Time last_report_sent_time) { … }
void InterestGroupCachingStorage::RecordDebugReportCooldown(
const url::Origin& origin,
base::Time cooldown_start,
DebugReportCooldownType cooldown_type) { … }
void InterestGroupCachingStorage::UpdateKAnonymity(
const blink::InterestGroupKey& interest_group_key,
const std::vector<std::string>& positive_hashed_keys,
const base::Time update_time,
bool replace_existing_values) { … }
void InterestGroupCachingStorage::GetLastKAnonymityReported(
const std::string& hashed_key,
base::OnceCallback<void(std::optional<base::Time>)> callback) { … }
void InterestGroupCachingStorage::UpdateLastKAnonymityReported(
const std::string& hashed_key) { … }
void InterestGroupCachingStorage::GetInterestGroup(
const blink::InterestGroupKey& group_key,
base::OnceCallback<void(std::optional<SingleStorageInterestGroup>)>
callback) { … }
void InterestGroupCachingStorage::GetAllInterestGroupOwners(
base::OnceCallback<void(std::vector<url::Origin>)> callback) { … }
void InterestGroupCachingStorage::GetInterestGroupsForUpdate(
const url::Origin& owner,
int groups_limit,
base::OnceCallback<void(std::vector<InterestGroupUpdateParameter>)>
callback) { … }
void InterestGroupCachingStorage::GetDebugReportLockout(
base::OnceCallback<void(std::optional<base::Time>)> callback) { … }
void InterestGroupCachingStorage::GetDebugReportLockoutAndCooldowns(
base::flat_set<url::Origin> origins,
base::OnceCallback<void(std::optional<DebugReportLockoutAndCooldowns>)>
callback) { … }
void InterestGroupCachingStorage::GetAllInterestGroupJoiningOrigins(
base::OnceCallback<void(std::vector<url::Origin>)> callback) { … }
void InterestGroupCachingStorage::GetAllInterestGroupOwnerJoinerPairs(
base::OnceCallback<void(std::vector<std::pair<url::Origin, url::Origin>>)>
callback) { … }
void InterestGroupCachingStorage::RemoveInterestGroupsMatchingOwnerAndJoiner(
url::Origin owner,
url::Origin joining_origin,
base::OnceClosure callback) { … }
void InterestGroupCachingStorage::DeleteInterestGroupData(
StoragePartition::StorageKeyMatcherFunction storage_key_matcher,
base::OnceClosure callback) { … }
void InterestGroupCachingStorage::DeleteAllInterestGroupData(
base::OnceClosure callback) { … }
void InterestGroupCachingStorage::SetInterestGroupPriority(
const blink::InterestGroupKey& group_key,
double priority) { … }
void InterestGroupCachingStorage::UpdateInterestGroupPriorityOverrides(
const blink::InterestGroupKey& group_key,
base::flat_map<std::string,
auction_worklet::mojom::PrioritySignalsDoublePtr>
update_priority_signals_overrides) { … }
void InterestGroupCachingStorage::SetBiddingAndAuctionServerKeys(
const url::Origin& coordinator,
const std::vector<BiddingAndAuctionServerKey>& keys,
base::Time expiration) { … }
void InterestGroupCachingStorage::GetBiddingAndAuctionServerKeys(
const url::Origin& coordinator,
base::OnceCallback<
void(std::pair<base::Time, std::vector<BiddingAndAuctionServerKey>>)>
callback) { … }
void InterestGroupCachingStorage::GetLastMaintenanceTimeForTesting(
base::RepeatingCallback<void(base::Time)> callback) const { … }
void InterestGroupCachingStorage::OnLoadInterestGroupsForOwnerNoCachingIGs(
const url::Origin& owner,
base::OnceCallback<void(scoped_refptr<StorageInterestGroups>)> callback,
std::vector<StorageInterestGroup> interest_groups) { … }
void InterestGroupCachingStorage::OnJoinInterestGroup(
const url::Origin& owner,
CachedOriginsInfo cached_origins_info,
base::OnceCallback<void(std::optional<InterestGroupKanonUpdateParameter>)>
callback,
std::optional<InterestGroupKanonUpdateParameter> update) { … }
void InterestGroupCachingStorage::OnLoadInterestGroupsForOwner(
const url::Origin& owner,
uint32_t version,
std::vector<StorageInterestGroup> interest_groups) { … }
void InterestGroupCachingStorage::InvalidateCachedInterestGroupsForOwner(
const url::Origin& owner) { … }
void InterestGroupCachingStorage::InvalidateAllCachedInterestGroups() { … }
void InterestGroupCachingStorage::
MarkOutstandingInterestGroupLoadResultOutdated(const url::Origin& owner) { … }
void InterestGroupCachingStorage::StartTimerForInterestGroupHold(
const url::Origin& owner,
scoped_refptr<StorageInterestGroups> groups) { … }
void InterestGroupCachingStorage::UpdateCachedOriginsIfEnabled(
const url::Origin& owner,
const std::vector<StorageInterestGroup>& interest_groups) { … }
}