chromium/content/browser/interest_group/interest_group_pa_report_util.cc

// Copyright 2023 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_pa_report_util.h"

#include <stdint.h>

#include <cmath>
#include <map>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "base/check.h"
#include "base/check_op.h"
#include "base/containers/flat_map.h"
#include "base/feature_list.h"
#include "base/notreached.h"
#include "base/numerics/clamped_math.h"
#include "components/aggregation_service/aggregation_coordinator_utils.h"
#include "content/browser/private_aggregation/private_aggregation_host.h"
#include "content/browser/private_aggregation/private_aggregation_manager.h"
#include "content/common/content_export.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 "mojo/public/cpp/bindings/remote.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/aggregation_service/aggregatable_report.mojom.h"
#include "third_party/blink/public/mojom/private_aggregation/private_aggregation_host.mojom.h"
#include "url/origin.h"
#include "url/url_constants.h"

namespace content {

namespace {

// Returns the actual value of `base_value` with corresponding post auction
// signal such as `winning_bid`. Returns std::nullopt if corresponding signal
// is not available.
std::optional<double> GetBaseValue(
    auction_worklet::mojom::BaseValue base_value,
    double winning_bid,
    double highest_scoring_other_bid,
    const std::optional<auction_worklet::mojom::RejectReason> reject_reason,
    const PrivateAggregationTimings& timings) {}

// Returns contribution's bucket calculated from `base`, and `bucket_obj`'s
// scale and offset. Returns std::nullopt if `base` is std::nullopt, or base
// or scale is NaN/infinity. Applies saturation arithmetic (in which all
// operations are limited to a fixed range) to uint128 bucket (also applied to
// intermediate results when they are too large to fit into a uint128). The
// fixed range is 0 to absl::Uint128Max().
std::optional<absl::uint128> CalculateBucket(
    const auction_worklet::mojom::SignalBucketPtr& bucket_obj,
    std::optional<double> base) {}

// Returns contribution's value calculated from `base`, and `value_obj`'s scale
// and offset. Returns 0 if the calculated value is negative. Returns
// std::nullopt if `base` is std::nullopt, or base or scale is NaN/infinity.
std::optional<int32_t> CalculateValue(
    const auction_worklet::mojom::SignalValuePtr& value_obj,
    std::optional<double> base) {}

// Calculates given for-event `contribution`'s bucket and value with given post
// auction signals such as `winning_bid`, and returns a histogram contribution
// with calculated bucket and value. A negative value will be clamped to 0.
// Returns nullptr if `contribution`'s bucket cannot be calculated to a valid
// uint128 number, or `contribution`'s value cannot be calculated to a valid
// integer.
blink::mojom::AggregatableReportHistogramContributionPtr
CalculateContributionBucketAndValue(
    auction_worklet::mojom::AggregatableReportForEventContributionPtr
        contribution,
    double winning_bid,
    double highest_scoring_other_bid,
    const std::optional<auction_worklet::mojom::RejectReason> reject_reason,
    const PrivateAggregationTimings& timings) {}

}  // namespace

PrivateAggregationKey::PrivateAggregationKey(
    url::Origin reporting_origin,
    std::optional<url::Origin> aggregation_coordinator_origin)
    :{}

PrivateAggregationKey::PrivateAggregationKey(
    const PrivateAggregationKey& other) = default;

PrivateAggregationKey& PrivateAggregationKey::operator=(
    const PrivateAggregationKey& other) = default;

PrivateAggregationKey::PrivateAggregationKey(PrivateAggregationKey&& other) =
    default;

PrivateAggregationKey& PrivateAggregationKey::operator=(
    PrivateAggregationKey&& other) = default;

PrivateAggregationKey::~PrivateAggregationKey() = default;

PrivateAggregationPhaseKey::PrivateAggregationPhaseKey(
    url::Origin reporting_origin,
    PrivateAggregationPhase phase,
    std::optional<url::Origin> aggregation_coordinator_origin)
    :{}

PrivateAggregationPhaseKey::PrivateAggregationPhaseKey(
    const PrivateAggregationPhaseKey&) = default;

PrivateAggregationPhaseKey& PrivateAggregationPhaseKey::operator=(
    const PrivateAggregationPhaseKey&) = default;

PrivateAggregationPhaseKey::PrivateAggregationPhaseKey(
    PrivateAggregationPhaseKey&&) = default;

PrivateAggregationPhaseKey& PrivateAggregationPhaseKey::operator=(
    PrivateAggregationPhaseKey&&) = default;

PrivateAggregationPhaseKey::~PrivateAggregationPhaseKey() = default;

PrivateAggregationRequestWithEventType::PrivateAggregationRequestWithEventType(
    auction_worklet::mojom::PrivateAggregationRequestPtr request,
    std::optional<std::string> event_type)
    :{}

PrivateAggregationRequestWithEventType::PrivateAggregationRequestWithEventType(
    PrivateAggregationRequestWithEventType&&) = default;

bool PrivateAggregationRequestWithEventType::operator==(
    const PrivateAggregationRequestWithEventType& rhs) const {}

PrivateAggregationRequestWithEventType::
    ~PrivateAggregationRequestWithEventType() = default;

std::optional<PrivateAggregationRequestWithEventType>
FillInPrivateAggregationRequest(
    auction_worklet::mojom::PrivateAggregationRequestPtr request,
    double winning_bid,
    double highest_scoring_other_bid,
    const std::optional<auction_worklet::mojom::RejectReason> reject_reason,
    const PrivateAggregationTimings& timings,
    bool is_winner) {}

void SplitContributionsIntoBatchesThenSendToHost(
    std::vector<auction_worklet::mojom::PrivateAggregationRequestPtr> requests,
    PrivateAggregationManager& pa_manager,
    const url::Origin& reporting_origin,
    std::optional<url::Origin> aggregation_coordinator_origin,
    const url::Origin& main_frame_origin) {}

bool HasValidFilteringId(
    const auction_worklet::mojom::PrivateAggregationRequestPtr& request) {}

bool IsValidFilteringId(std::optional<uint64_t> filtering_id) {}

}  // namespace content