chromium/content/browser/interest_group/interest_group_auction_reporter.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_auction_reporter.h"

#include <stdint.h>

#include <cmath>
#include <cstddef>
#include <limits>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "base/containers/flat_map.h"
#include "base/feature_list.h"
#include "base/functional/callback.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/rand_util.h"
#include "base/strings/strcat.h"
#include "base/time/time.h"
#include "base/trace_event/common/trace_event_common.h"
#include "base/trace_event/trace_event.h"
#include "content/browser/fenced_frame/fenced_frame_reporter.h"
#include "content/browser/fenced_frame/fenced_frame_url_mapping.h"
#include "content/browser/interest_group/auction_metrics_recorder.h"
#include "content/browser/interest_group/auction_worklet_manager.h"
#include "content/browser/interest_group/interest_group_auction.h"
#include "content/browser/interest_group/interest_group_k_anonymity_manager.h"
#include "content/browser/interest_group/interest_group_manager_impl.h"
#include "content/browser/interest_group/interest_group_pa_report_util.h"
#include "content/browser/interest_group/interest_group_storage.h"
#include "content/browser/interest_group/noiser_and_bucketer.h"
#include "content/browser/private_aggregation/private_aggregation_manager.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/privacy_sandbox_invoking_api.h"
#include "content/public/common/content_client.h"
#include "content/services/auction_worklet/public/mojom/bidder_worklet.mojom.h"
#include "content/services/auction_worklet/public/mojom/private_aggregation_request.mojom.h"
#include "content/services/auction_worklet/public/mojom/seller_worklet.mojom.h"
#include "services/network/public/cpp/shared_url_loader_factory.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/fenced_frame/redacted_fenced_frame_config.h"
#include "third_party/blink/public/common/interest_group/ad_auction_currencies.h"
#include "third_party/blink/public/common/interest_group/interest_group.h"
#include "third_party/blink/public/mojom/fenced_frame/fenced_frame.mojom-shared.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 {

// All event-level reporting URLs received from worklets must be valid HTTPS
// URLs. It's up to callers to call ReportBadMessage() on invalid URLs.
bool IsEventLevelReportingUrlValid(const GURL& url) {}

const blink::InterestGroup::Ad& ChosenAd(
    const SingleStorageInterestGroup& storage_interest_group,
    const GURL& winning_ad_url) {}

bool IsKAnonForReporting(
    const SingleStorageInterestGroup& storage_interest_group,
    const blink::InterestGroup::Ad& chosen_ad,
    base::optional_ref<const std::string>
        selected_buyer_and_seller_reporting_id) {}

// Sets the reporting IDs to pass to the worklet's `reportWin()` method,
// based on the reporting ID fields present in the winning ad.
//
// `reporting_id_field` will be set to the field that's populated, and the
// corresponding output parameter will be populated with the reporting ID
// from the winning ad.
//
// The order of precedence for which reporting ID is sent is:
//   1. `selected_buyer_and_seller_reporting_id` (more context below)
//   2. `buyer_and_seller_reporting_id`
//   3. `buyer_reporting_id`
//   4. `interest_group_name` (Only if none of the above are present)
//
// When `selected_buyer_and_seller_reporting_id` is set in the winning ad,
// the `buyer_reporting_id` and `buyer_and_seller_reporting_id` fields may
// also be populated.
//
// If `selected_buyer_and_seller_reporting_id` is not set, then only one
// reporting ID field will be populated.
void SetReportWinReportingIds(
    const std::string& interest_group_name,
    const std::optional<std::string>&
        maybe_selected_buyer_and_seller_reporting_id,
    const blink::InterestGroup::Ad& chosen_ad,
    auction_worklet::mojom::ReportingIdField& reporting_id_field,
    std::optional<std::string>& interest_group_name_reporting_id,
    std::optional<std::string>& buyer_reporting_id,
    std::optional<std::string>& buyer_and_seller_reporting_id,
    std::optional<std::string>& selected_buyer_and_seller_reporting_id) {}

}  // namespace

BASE_FEATURE();
// For now default bid and score to full resolution.
const base::FeatureParam<int> kFledgeBidReportingBits{};
const base::FeatureParam<int> kFledgeScoreReportingBits{};
const base::FeatureParam<int> kFledgeAdCostReportingBits{};

InterestGroupAuctionReporter::SellerWinningBidInfo::SellerWinningBidInfo() =
    default;
InterestGroupAuctionReporter::SellerWinningBidInfo::SellerWinningBidInfo(
    SellerWinningBidInfo&&) = default;
InterestGroupAuctionReporter::SellerWinningBidInfo::~SellerWinningBidInfo() =
    default;
InterestGroupAuctionReporter::SellerWinningBidInfo&
InterestGroupAuctionReporter::SellerWinningBidInfo::operator=(
    SellerWinningBidInfo&&) = default;

InterestGroupAuctionReporter::WinningBidInfo::WinningBidInfo(
    const SingleStorageInterestGroup& storage_interest_group)
    :{}
InterestGroupAuctionReporter::WinningBidInfo::WinningBidInfo(WinningBidInfo&&) =
    default;
InterestGroupAuctionReporter::WinningBidInfo::~WinningBidInfo() = default;

InterestGroupAuctionReporter::InterestGroupAuctionReporter(
    InterestGroupManagerImpl* interest_group_manager,
    AuctionWorkletManager* auction_worklet_manager,
    BrowserContext* browser_context,
    PrivateAggregationManager* private_aggregation_manager,
    LogPrivateAggregationRequestsCallback
        log_private_aggregation_requests_callback,
    AdAuctionPageDataCallback ad_auction_page_data_callback,
    std::unique_ptr<blink::AuctionConfig> auction_config,
    const std::string& devtools_auction_id,
    const url::Origin& main_frame_origin,
    const url::Origin& frame_origin,
    network::mojom::ClientSecurityStatePtr client_security_state,
    scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
    auction_worklet::mojom::KAnonymityBidMode kanon_mode,
    bool bid_is_kanon,
    WinningBidInfo winning_bid_info,
    SellerWinningBidInfo top_level_seller_winning_bid_info,
    std::optional<SellerWinningBidInfo> component_seller_winning_bid_info,
    blink::InterestGroupSet interest_groups_that_bid,
    std::vector<GURL> debug_win_report_urls,
    std::vector<GURL> debug_loss_report_urls,
    base::flat_set<std::string> k_anon_keys_to_join,
    std::map<PrivateAggregationKey, PrivateAggregationRequests>
        private_aggregation_requests_reserved,
    std::map<std::string, PrivateAggregationRequests>
        private_aggregation_requests_non_reserved,
    std::map<url::Origin, RealTimeReportingContributions>
        real_time_contributions)
    :{}

InterestGroupAuctionReporter ::~InterestGroupAuctionReporter() {}

void InterestGroupAuctionReporter::Start(base::OnceClosure callback) {}

void InterestGroupAuctionReporter::InitializeFromServerResponse(
    const BiddingAndAuctionResponse& response,
    blink::FencedFrame::ReportingDestination seller_destination) {}

base::RepeatingClosure
InterestGroupAuctionReporter::OnNavigateToWinningAdCallback(
    int frame_tree_node_id) {}

void InterestGroupAuctionReporter::OnFledgePrivateAggregationRequests(
    PrivateAggregationManager* private_aggregation_manager,
    const url::Origin& main_frame_origin,
    std::map<PrivateAggregationKey,
             std::vector<auction_worklet::mojom::PrivateAggregationRequestPtr>>
        private_aggregation_requests) {}

/* static */
double InterestGroupAuctionReporter::RoundBidStochastically(double bid) {}

/* static */
double InterestGroupAuctionReporter::RoundStochasticallyToKBits(double value,
                                                                unsigned k) {}

/* static */
std::optional<double> InterestGroupAuctionReporter::RoundStochasticallyToKBits(
    std::optional<double> maybe_value,
    unsigned k) {}

void InterestGroupAuctionReporter::RequestSellerWorklet(
    const SellerWinningBidInfo* seller_info,
    const std::optional<std::string>& top_seller_signals) {}

void InterestGroupAuctionReporter::OnSellerWorkletFatalError(
    const SellerWinningBidInfo* seller_info,
    AuctionWorkletManager::FatalErrorType fatal_error_type,
    const std::vector<std::string>& errors) {}

void InterestGroupAuctionReporter::OnSellerWorkletReceived(
    const SellerWinningBidInfo* seller_info,
    const std::optional<std::string>& top_seller_signals) {}

void InterestGroupAuctionReporter::OnSellerReportResultComplete(
    const SellerWinningBidInfo* seller_info,
    double winning_bid,
    double highest_scoring_other_bid,
    const std::optional<std::string>& signals_for_winner,
    const std::optional<GURL>& seller_report_url,
    const base::flat_map<std::string, GURL>& seller_ad_beacon_map,
    PrivateAggregationRequests pa_requests,
    base::TimeDelta reporting_latency,
    const std::vector<std::string>& errors) {}

bool InterestGroupAuctionReporter::AddReportResultResult(
    const url::Origin& seller_origin,
    const std::optional<GURL>& seller_report_url,
    const base::flat_map<std::string, GURL>& seller_ad_beacon_map,
    blink::FencedFrame::ReportingDestination destination,
    std::vector<std::string>& errors_out) {}

void InterestGroupAuctionReporter::RequestBidderWorklet(
    const std::string& signals_for_winner) {}

void InterestGroupAuctionReporter::OnBidderWorkletReceived(
    const std::string& signals_for_winner) {}

void InterestGroupAuctionReporter::OnBidderWorkletFatalError(
    AuctionWorkletManager::FatalErrorType fatal_error_type,
    const std::vector<std::string>& errors) {}

void InterestGroupAuctionReporter::OnBidderReportWinComplete(
    double winning_bid,
    double highest_scoring_other_bid,
    const std::optional<GURL>& bidder_report_url,
    const base::flat_map<std::string, GURL>& bidder_ad_beacon_map,
    const base::flat_map<std::string, std::string>& bidder_ad_macro_map,
    PrivateAggregationRequests pa_requests,
    base::TimeDelta reporting_latency,
    const std::vector<std::string>& errors) {}

bool InterestGroupAuctionReporter::AddReportWinResult(
    const url::Origin& bidder_origin,
    const std::optional<GURL>& bidder_report_url,
    const base::flat_map<std::string, GURL>& bidder_ad_beacon_map,
    const std::optional<base::flat_map<std::string, std::string>>&
        bidder_ad_macro_map,
    std::vector<std::string>& errors_out) {}

void InterestGroupAuctionReporter::OnReportingComplete(
    const std::vector<std::string>& errors) {}

void InterestGroupAuctionReporter::OnNavigateToWinningAd(
    int frame_tree_node_id) {}

void InterestGroupAuctionReporter::MaybeInvokeCallback() {}

const InterestGroupAuctionReporter::SellerWinningBidInfo&
InterestGroupAuctionReporter::GetBidderAuction() {}

void InterestGroupAuctionReporter::AddPendingReportUrl(const GURL& report_url) {}

void InterestGroupAuctionReporter::SendPendingReportsIfNavigated() {}

void InterestGroupAuctionReporter::MaybeSendPrivateAggregationReports() {}

bool InterestGroupAuctionReporter::CheckReportUrl(const GURL& url) {}

void InterestGroupAuctionReporter::EnforceAttestationsReportUrls(
    std::vector<GURL>& urls) {}

}  // namespace content