chromium/content/browser/interest_group/interest_group_update_manager.cc

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 {

// 1 MB update size limit. We are potentially fetching many interest group
// updates, so don't let this get too large.
constexpr size_t kMaxUpdateSize =;

// The maximum amount of time that the update process can run before it gets
// cancelled for taking too long.
constexpr base::TimeDelta kMaxUpdateRoundDuration =;

// The maximum number of groups that can be updated at the same time.
constexpr int kMaxParallelUpdates =;

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
//
// For group update batch resize operations count.
enum class GroupUpdateResizeOperation {};

constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation =;

// TODO(crbug.com/40172488): Report errors to devtools for the TryToCopy*().
// functions.

// Name and owner are optional in `dict` (parsed server JSON response), but
// must match `name` and `owner`, respectively, if either is specified. Returns
// true if the check passes, and false otherwise.
[[nodiscard]] bool ValidateNameAndOwnerIfPresent(
    const blink::InterestGroupKey& group_key,
    const base::Value::Dict& dict) {}

// Copies the `priorityVector` JSON field into `priority_vector`. Returns
// true if the JSON is valid and the copy completed.
[[nodiscard]] bool TryToCopyPriorityVector(
    const base::Value::Dict& dict,
    std::optional<base::flat_map<std::string, double>>& priority_vector) {}

// Copies the prioritySignalsOverrides JSON field into
// `priority_signals_overrides`, returns true if the JSON is valid and the copy
// completed. Maps nulls to nullopt, which means a value should be deleted from
// the stored interest group.
[[nodiscard]] bool TryToCopyPrioritySignalsOverrides(
    const base::Value::Dict& dict,
    std::optional<base::flat_map<std::string, std::optional<double>>>&
        priority_signals_overrides) {}

// Copies the sellerCapabilities JSON field into
// `seller_capabilities` and `all_sellers_capabilities`, returns true if the
// JSON is valid and the copy completed.
[[nodiscard]] bool TryToCopySellerCapabilities(
    const base::Value::Dict& dict,
    InterestGroupUpdate& interest_group_update) {}

// Copies the executionMode JSON field into `interest_group_update`, returns
// true iff the JSON is valid and the copy completed.
[[nodiscard]] bool TryToCopyExecutionMode(
    const base::Value::Dict& dict,
    InterestGroupUpdate& interest_group_update) {}

// Copies the trustedBiddingSignalsKeys list JSON field into
// `interest_group_update`, returns true iff the JSON is valid and the copy
// completed.
[[nodiscard]] bool TryToCopyTrustedBiddingSignalsKeys(
    const base::Value::Dict& dict,
    InterestGroupUpdate& interest_group_update) {}

// Copies the userBiddingSignals JSON "any" field into
// `interest_group_update` as a string, returns true iff re-serialization
// succeeded and the copy completed.
[[nodiscard]] bool TryToCopyUserBiddingSignals(
    const base::Value::Dict& dict,
    InterestGroupUpdate& interest_group_update) {}

// Copies the trustedBiddingSignalsSlotSizeMode JSON field into
// `trusted_bidding_signals_slot_size_mode`. Always succeeds.
[[nodiscard]] bool TryToCopyTrustedBiddingSignalsSlotSizeMode(
    const base::Value::Dict& dict,
    InterestGroupUpdate& interest_group_update) {}

// Copies the maxTrustedBiddingSignalsURLLength JSON field into
// `max_trusted_bidding_signals_url_length`.
[[nodiscard]] bool TryToCopyMaxTrustedBiddingSignalsURLLength(
    const base::Value::Dict& dict,
    InterestGroupUpdate& interest_group_update) {}

// Copies the trustedBiddingSignalsCoordinator JSON field into
// `trusted_bidding_signals_coordinator`.
[[nodiscard]] bool TryToCopyTrustedBiddingSignalsCoordinator(
    const base::Value::Dict& dict,
    InterestGroupUpdate& interest_group_update) {}

// Helper for TryToCopyAds() and TryToCopyAdComponents().
[[nodiscard]] std::optional<std::vector<blink::InterestGroup::Ad>> ExtractAds(
    const base::Value::List& ads_list,
    bool for_components) {}

// Copies the `ads` list JSON field into `interest_group_update`, returns true
// iff the JSON is valid and the copy completed.
[[nodiscard]] bool TryToCopyAds(const base::Value::Dict& dict,
                                InterestGroupUpdate& interest_group_update) {}

// Copies the `adComponents` list JSON field into `interest_group_update`,
// returns true iff the JSON is valid and the copy completed.
[[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) {}

}  // namespace

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) {}

}  // namespace content