#include "content/browser/interest_group/trusted_signals_cache_impl.h"
#include <stdint.h>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "base/types/expected.h"
#include "base/unguessable_token.h"
#include "content/browser/interest_group/bidding_and_auction_server_key_fetcher.h"
#include "content/browser/interest_group/trusted_signals_fetcher.h"
#include "content/services/auction_worklet/public/mojom/trusted_signals_cache.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "third_party/blink/public/mojom/interest_group/interest_group_types.mojom.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace content {
namespace {
CachedResult;
void SendResultToClient(
mojo::PendingRemote<auction_worklet::mojom::TrustedSignalsCacheClient>
pending_client,
const CachedResult& result) { … }
void SendNoLiveEntryErrorToClient(
mojo::PendingRemote<auction_worklet::mojom::TrustedSignalsCacheClient>
pending_client) { … }
}
TrustedSignalsCacheImpl::Handle::Handle() = default;
TrustedSignalsCacheImpl::Handle::~Handle() = default;
TrustedSignalsCacheImpl::FetchKey::FetchKey() = default;
TrustedSignalsCacheImpl::FetchKey::FetchKey(
const url::Origin& main_frame_origin,
SignalsType signals_type,
const url::Origin& script_origin,
const GURL& trusted_signals_url,
const url::Origin& coordinator)
: … { … }
TrustedSignalsCacheImpl::FetchKey::FetchKey(const FetchKey&) = default;
TrustedSignalsCacheImpl::FetchKey::FetchKey(FetchKey&&) = default;
TrustedSignalsCacheImpl::FetchKey& TrustedSignalsCacheImpl::FetchKey::operator=(
const FetchKey&) = default;
TrustedSignalsCacheImpl::FetchKey& TrustedSignalsCacheImpl::FetchKey::operator=(
FetchKey&&) = default;
TrustedSignalsCacheImpl::FetchKey::~FetchKey() = default;
bool TrustedSignalsCacheImpl::FetchKey::operator<(const FetchKey& other) const { … }
struct TrustedSignalsCacheImpl::Fetch { … };
TrustedSignalsCacheImpl::BiddingCacheKey::BiddingCacheKey() = default;
TrustedSignalsCacheImpl::BiddingCacheKey::BiddingCacheKey(
const url::Origin& interest_group_owner,
std::optional<std::string> interest_group_name,
const GURL& trusted_signals_url,
const url::Origin& coordinator,
const url::Origin& main_frame_origin,
const url::Origin& joining_origin,
base::Value::Dict additional_params)
: … { … }
TrustedSignalsCacheImpl::BiddingCacheKey::BiddingCacheKey(BiddingCacheKey&&) =
default;
TrustedSignalsCacheImpl::BiddingCacheKey::~BiddingCacheKey() = default;
TrustedSignalsCacheImpl::BiddingCacheKey&
TrustedSignalsCacheImpl::BiddingCacheKey::operator=(BiddingCacheKey&&) =
default;
bool TrustedSignalsCacheImpl::BiddingCacheKey::operator<(
const BiddingCacheKey& other) const { … }
struct TrustedSignalsCacheImpl::BiddingCacheEntry { … };
TrustedSignalsCacheImpl::ScoringCacheKey::ScoringCacheKey() = default;
TrustedSignalsCacheImpl::ScoringCacheKey::ScoringCacheKey(
const url::Origin& seller,
const GURL& trusted_signals_url,
const url::Origin& coordinator,
const url::Origin& main_frame_origin,
const url::Origin& interest_group_owner,
const url::Origin& joining_origin,
const GURL& render_url,
const std::vector<GURL>& component_render_urls,
base::Value::Dict additional_params)
: … { … }
TrustedSignalsCacheImpl::ScoringCacheKey::ScoringCacheKey(ScoringCacheKey&&) =
default;
TrustedSignalsCacheImpl::ScoringCacheKey::~ScoringCacheKey() = default;
TrustedSignalsCacheImpl::ScoringCacheKey&
TrustedSignalsCacheImpl::ScoringCacheKey::operator=(ScoringCacheKey&&) =
default;
bool TrustedSignalsCacheImpl::ScoringCacheKey::operator<(
const ScoringCacheKey& other) const { … }
struct TrustedSignalsCacheImpl::ScoringCacheEntry { … };
class TrustedSignalsCacheImpl::CompressionGroupData : public Handle { … };
bool TrustedSignalsCacheImpl::ReceiverRestrictions::operator==(
const ReceiverRestrictions& other) const = default;
TrustedSignalsCacheImpl::TrustedSignalsCacheImpl(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
GetCoordinatorKeyCallback get_coordinator_key_callback)
: … { … }
TrustedSignalsCacheImpl::~TrustedSignalsCacheImpl() = default;
mojo::PendingRemote<auction_worklet::mojom::TrustedSignalsCache>
TrustedSignalsCacheImpl::CreateMojoPipe(SignalsType signals_type,
const url::Origin& script_origin) { … }
scoped_refptr<TrustedSignalsCacheImpl::Handle>
TrustedSignalsCacheImpl::RequestTrustedBiddingSignals(
const url::Origin& main_frame_origin,
const url::Origin& interest_group_owner,
const std::string& interest_group_name,
blink::mojom::InterestGroup_ExecutionMode execution_mode,
const url::Origin& joining_origin,
const GURL& trusted_signals_url,
const url::Origin& coordinator,
base::optional_ref<const std::vector<std::string>>
trusted_bidding_signals_keys,
base::Value::Dict additional_params,
int& partition_id) { … }
scoped_refptr<TrustedSignalsCacheImpl::Handle>
TrustedSignalsCacheImpl::RequestTrustedScoringSignals(
const url::Origin& main_frame_origin,
const url::Origin& seller,
const GURL& trusted_signals_url,
const url::Origin& coordinator,
const url::Origin& interest_group_owner,
const url::Origin& joining_origin,
const GURL& render_url,
const std::vector<GURL>& component_render_urls,
base::Value::Dict additional_params,
int& partition_id) { … }
scoped_refptr<TrustedSignalsCacheImpl::CompressionGroupData>
TrustedSignalsCacheImpl::FindOrCreateCompressionGroupDataAndQueueFetch(
const FetchKey& fetch_key,
const url::Origin& joining_origin,
base::optional_ref<const url::Origin>
interest_group_owner_if_scoring_signals) { … }
void TrustedSignalsCacheImpl::GetTrustedSignals(
const base::UnguessableToken& compression_group_token,
mojo::PendingRemote<auction_worklet::mojom::TrustedSignalsCacheClient>
client) { … }
void TrustedSignalsCacheImpl::GetCoordinatorKey(FetchMap::iterator fetch_it) { … }
void TrustedSignalsCacheImpl::OnCoordinatorKeyReceived(
FetchMap::iterator fetch_it,
base::expected<BiddingAndAuctionServerKey, std::string>
bidding_and_auction_server_key) { … }
void TrustedSignalsCacheImpl::StartBiddingSignalsFetch(
FetchMap::iterator fetch_it,
const BiddingAndAuctionServerKey& bidding_and_auction_key) { … }
void TrustedSignalsCacheImpl::StartScoringSignalsFetch(
FetchMap::iterator fetch_it,
const BiddingAndAuctionServerKey& bidding_and_auction_key) { … }
void TrustedSignalsCacheImpl::OnFetchComplete(
FetchMap::iterator fetch_it,
TrustedSignalsFetcher::SignalsFetchResult signals_fetch_result) { … }
void TrustedSignalsCacheImpl::OnCompressionGroupDataDestroyed(
CompressionGroupData& compression_group_data) { … }
void TrustedSignalsCacheImpl::DestroyBiddingCacheEntry(
BiddingCacheEntryMap::iterator cache_entry_it) { … }
void TrustedSignalsCacheImpl::DestroyScoringCacheEntry(
ScoringCacheEntryMap::iterator cache_entry_it) { … }
std::unique_ptr<TrustedSignalsFetcher>
TrustedSignalsCacheImpl::CreateFetcher() { … }
}