#include "content/browser/interest_group/interest_group_update_manager.h"
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <cstddef>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/base64.h"
#include "base/containers/flat_map.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/json/json_string_value_serializer.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/rand_util.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/aggregation_service/aggregation_coordinator_utils.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/interest_group_update.h"
#include "content/browser/interest_group/storage_interest_group.h"
#include "content/common/features.h"
#include "content/public/browser/interest_group_manager.h"
#include "content/services/auction_worklet/public/cpp/auction_downloader.h"
#include "net/base/isolation_info.h"
#include "net/base/net_errors.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/data_decoder/public/cpp/data_decoder.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/client_security_state.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/interest_group/ad_display_size_utils.h"
#include "third_party/blink/public/common/interest_group/interest_group.h"
#include "third_party/blink/public/mojom/interest_group/interest_group_types.mojom.h"
#include "third_party/boringssl/src/include/openssl/curve25519.h"
#include "url/gurl.h"
#include "url/origin.h"
#include "url/url_constants.h"
namespace content {
namespace {
constexpr size_t kMaxUpdateSize = …;
constexpr base::TimeDelta kMaxUpdateRoundDuration = …;
constexpr int kMaxParallelUpdates = …;
enum class GroupUpdateResizeOperation { … };
constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation = …;
[[nodiscard]] bool ValidateNameAndOwnerIfPresent(
const blink::InterestGroupKey& group_key,
const base::Value::Dict& dict) { … }
[[nodiscard]] bool TryToCopyPriorityVector(
const base::Value::Dict& dict,
std::optional<base::flat_map<std::string, double>>& priority_vector) { … }
[[nodiscard]] bool TryToCopyPrioritySignalsOverrides(
const base::Value::Dict& dict,
std::optional<base::flat_map<std::string, std::optional<double>>>&
priority_signals_overrides) { … }
[[nodiscard]] bool TryToCopySellerCapabilities(
const base::Value::Dict& dict,
InterestGroupUpdate& interest_group_update) { … }
[[nodiscard]] bool TryToCopyExecutionMode(
const base::Value::Dict& dict,
InterestGroupUpdate& interest_group_update) { … }
[[nodiscard]] bool TryToCopyTrustedBiddingSignalsKeys(
const base::Value::Dict& dict,
InterestGroupUpdate& interest_group_update) { … }
[[nodiscard]] bool TryToCopyUserBiddingSignals(
const base::Value::Dict& dict,
InterestGroupUpdate& interest_group_update) { … }
[[nodiscard]] bool TryToCopyTrustedBiddingSignalsSlotSizeMode(
const base::Value::Dict& dict,
InterestGroupUpdate& interest_group_update) { … }
[[nodiscard]] bool TryToCopyMaxTrustedBiddingSignalsURLLength(
const base::Value::Dict& dict,
InterestGroupUpdate& interest_group_update) { … }
[[nodiscard]] bool TryToCopyTrustedBiddingSignalsCoordinator(
const base::Value::Dict& dict,
InterestGroupUpdate& interest_group_update) { … }
[[nodiscard]] std::optional<std::vector<blink::InterestGroup::Ad>> ExtractAds(
const base::Value::List& ads_list,
bool for_components) { … }
[[nodiscard]] bool TryToCopyAds(const base::Value::Dict& dict,
InterestGroupUpdate& interest_group_update) { … }
[[nodiscard]] bool TryToCopyAdComponents(
const base::Value::Dict& dict,
InterestGroupUpdate& interest_group_update) { … }
[[nodiscard]] bool TryToCopyAdSizes(
const base::Value::Dict& dict,
InterestGroupUpdate& interest_group_update) { … }
[[nodiscard]] bool TryToCopySizeGroups(
const base::Value::Dict& dict,
InterestGroupUpdate& interest_group_update) { … }
[[nodiscard]] bool TryToCopyAuctionServerRequestFlags(
const base::Value::Dict& dict,
InterestGroupUpdate& interest_group_update) { … }
[[nodiscard]] bool TryToCopyPrivateAggregationConfig(
const base::Value::Dict& dict,
InterestGroupUpdate& interest_group_update) { … }
std::optional<InterestGroupUpdate> ParseUpdateJson(
const blink::InterestGroupKey& group_key,
const data_decoder::DataDecoder::ValueOrError& result) { … }
}
InterestGroupUpdateManager::InterestGroupUpdateManager(
InterestGroupManagerImpl* manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory)
: … { … }
InterestGroupUpdateManager::~InterestGroupUpdateManager() = default;
void InterestGroupUpdateManager::UpdateInterestGroupsOfOwner(
const url::Origin& owner,
network::mojom::ClientSecurityStatePtr client_security_state,
AreReportingOriginsAttestedCallback callback) { … }
void InterestGroupUpdateManager::UpdateInterestGroupsOfOwners(
base::span<url::Origin> owners,
network::mojom::ClientSecurityStatePtr client_security_state,
AreReportingOriginsAttestedCallback callback) { … }
void InterestGroupUpdateManager::set_max_update_round_duration_for_testing(
base::TimeDelta delta) { … }
void InterestGroupUpdateManager::set_max_parallel_updates_for_testing(
int max_parallel_updates) { … }
InterestGroupUpdateManager::OwnersToUpdate::OwnersToUpdate() = default;
InterestGroupUpdateManager::OwnersToUpdate::~OwnersToUpdate() = default;
bool InterestGroupUpdateManager::OwnersToUpdate::Empty() const { … }
const url::Origin& InterestGroupUpdateManager::OwnersToUpdate::FrontOwner()
const { … }
network::mojom::ClientSecurityStatePtr
InterestGroupUpdateManager::OwnersToUpdate::FrontSecurityState() const { … }
bool InterestGroupUpdateManager::OwnersToUpdate::Enqueue(
const url::Origin& owner,
network::mojom::ClientSecurityStatePtr client_security_state) { … }
void InterestGroupUpdateManager::OwnersToUpdate::PopFront() { … }
net::IsolationInfo*
InterestGroupUpdateManager::OwnersToUpdate::GetIsolationInfoByJoiningOrigin(
const url::Origin& joining_origin) { … }
void InterestGroupUpdateManager::OwnersToUpdate::
ClearJoiningOriginIsolationInfoMap() { … }
void InterestGroupUpdateManager::OwnersToUpdate::Clear() { … }
void InterestGroupUpdateManager::MaybeContinueUpdatingCurrentOwner() { … }
void InterestGroupUpdateManager::GetInterestGroupsForUpdate(
const url::Origin& owner,
base::OnceCallback<void(std::vector<InterestGroupUpdateParameter>)>
callback) { … }
void InterestGroupUpdateManager::UpdateInterestGroupByBatch(
const url::Origin& owner,
std::vector<InterestGroupUpdateParameter> update_parameters) { … }
void InterestGroupUpdateManager::DidUpdateInterestGroupsOfOwnerDbLoad(
url::Origin owner,
std::vector<InterestGroupUpdateParameter> update_parameters) { … }
void InterestGroupUpdateManager::DidUpdateInterestGroupsOfOwnerNetFetch(
UrlLoadersList::iterator simple_url_loader_it,
blink::InterestGroupKey group_key,
base::TimeTicks start_time,
std::unique_ptr<std::string> fetch_body) { … }
void InterestGroupUpdateManager::DidUpdateInterestGroupsOfOwnerJsonParse(
blink::InterestGroupKey group_key,
data_decoder::DataDecoder::ValueOrError result) { … }
void InterestGroupUpdateManager::UpdateInterestGroup(
const blink::InterestGroupKey& group_key,
InterestGroupUpdate update) { … }
void InterestGroupUpdateManager::OnUpdateInterestGroupCompleted(
const blink::InterestGroupKey& group_key,
bool success) { … }
void InterestGroupUpdateManager::OnOneUpdateCompleted() { … }
void InterestGroupUpdateManager::ReportUpdateFailed(
const blink::InterestGroupKey& group_key,
UpdateDelayType delay_type) { … }
}