#include "components/attribution_reporting/privacy_math.h"
#include <stdint.h>
#include <algorithm>
#include <cmath>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <optional>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/notreached.h"
#include "base/numerics/byte_conversions.h"
#include "base/numerics/checked_math.h"
#include "base/numerics/safe_conversions.h"
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "base/types/expected.h"
#include "base/types/expected_macros.h"
#include "components/attribution_reporting/attribution_scopes_data.h"
#include "components/attribution_reporting/event_report_windows.h"
#include "components/attribution_reporting/max_event_level_reports.h"
#include "components/attribution_reporting/source_type.mojom.h"
#include "components/attribution_reporting/trigger_config.h"
#include "components/attribution_reporting/trigger_data_matching.mojom.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
namespace attribution_reporting {
namespace {
uint32_t g_max_trigger_state_cardinality = …;
double g_max_channel_capacity_navigation = …;
double g_max_channel_capacity_scopes_navigation = …;
double g_max_channel_capacity_event = …;
double g_max_channel_capacity_scopes_event = …;
base::CheckedNumeric<uint32_t> GetNumStatesRecursive(TriggerSpecs::Iterator it,
int max_reports,
int window_val,
int max_reports_per_type,
internal::StateMap& map) { … }
base::expected<void, RandomizedResponseError> GetReportsFromIndexRecursive(
TriggerSpecs::Iterator it,
int max_reports,
int window_val,
int max_reports_per_type,
uint32_t index,
std::vector<FakeEventLevelReport>& reports,
internal::StateMap& map) { … }
base::expected<uint32_t, RandomizedResponseError> GetNumStatesCached(
const TriggerSpecs& specs,
internal::StateMap& map) { … }
}
RandomizedResponseData::RandomizedResponseData(double rate,
RandomizedResponse response)
: … { … }
RandomizedResponseData::~RandomizedResponseData() = default;
RandomizedResponseData::RandomizedResponseData(const RandomizedResponseData&) =
default;
RandomizedResponseData& RandomizedResponseData::operator=(
const RandomizedResponseData&) = default;
RandomizedResponseData::RandomizedResponseData(RandomizedResponseData&&) =
default;
RandomizedResponseData& RandomizedResponseData::operator=(
RandomizedResponseData&&) = default;
uint32_t MaxTriggerStateCardinality() { … }
double GetMaxChannelCapacity(mojom::SourceType source_type) { … }
double GetMaxChannelCapacityScopes(mojom::SourceType source_type) { … }
bool GenerateWithRate(double r) { … }
double GetRandomizedResponseRate(uint32_t num_states, double epsilon) { … }
base::expected<uint32_t, RandomizedResponseError> GetNumStates(
const TriggerSpecs& specs) { … }
base::expected<RandomizedResponseData, RandomizedResponseError>
DoRandomizedResponse(const TriggerSpecs& specs,
double epsilon,
mojom::SourceType source_type,
const std::optional<AttributionScopesData>& scopes_data) { … }
bool IsValid(const RandomizedResponse& response, const TriggerSpecs& specs) { … }
namespace internal {
base::CheckedNumeric<uint32_t> BinomialCoefficient(int n, int k) { … }
std::vector<int> GetKCombinationAtIndex(
base::StrictNumeric<uint32_t> combination_index,
int k) { … }
base::expected<std::vector<FakeEventLevelReport>, RandomizedResponseError>
GetFakeReportsForSequenceIndex(const TriggerSpecs& specs,
base::StrictNumeric<uint32_t> index,
StateMap& map) { … }
base::CheckedNumeric<uint32_t> GetNumberOfStarsAndBarsSequences(int num_stars,
int num_bars) { … }
base::expected<std::vector<int>, absl::monostate> GetStarIndices(
int num_stars,
int num_bars,
base::StrictNumeric<uint32_t> sequence_index) { … }
std::vector<int> GetBarsPrecedingEachStar(std::vector<int> out) { … }
double BinaryEntropy(double p) { … }
double ComputeChannelCapacity(
const base::StrictNumeric<uint32_t> num_states_strict,
const double randomized_response_rate) { … }
double ComputeChannelCapacityScopes(
const base::StrictNumeric<uint32_t> num_states,
const uint32_t max_event_states,
const uint32_t attribution_scope_limit) { … }
base::expected<std::vector<FakeEventLevelReport>, RandomizedResponseError>
GetFakeReportsForSequenceIndex(
const TriggerSpecs& specs,
base::StrictNumeric<uint32_t> random_stars_and_bars_sequence_index) { … }
base::expected<RandomizedResponseData, RandomizedResponseError>
DoRandomizedResponseWithCache(
const TriggerSpecs& specs,
double epsilon,
StateMap& map,
mojom::SourceType source_type,
const std::optional<AttributionScopesData>& scopes_data) { … }
}
ScopedMaxTriggerStateCardinalityForTesting::
ScopedMaxTriggerStateCardinalityForTesting(
uint32_t max_trigger_state_cardinality)
: … { … }
ScopedMaxTriggerStateCardinalityForTesting::
~ScopedMaxTriggerStateCardinalityForTesting() { … }
ScopedMaxNavigationChannelCapacityForTesting::
ScopedMaxNavigationChannelCapacityForTesting(
double max_navigation_channel_capacity)
: … { … }
ScopedMaxNavigationChannelCapacityForTesting::
~ScopedMaxNavigationChannelCapacityForTesting() { … }
ScopedMaxEventChannelCapacityForTesting::
ScopedMaxEventChannelCapacityForTesting(double max_event_channel_capacity)
: … { … }
ScopedMaxEventChannelCapacityForTesting::
~ScopedMaxEventChannelCapacityForTesting() { … }
ScopedMaxScopesNavigationChannelCapacityForTesting::
ScopedMaxScopesNavigationChannelCapacityForTesting(
double max_scoped_navigation_channel_capacity)
: … { … }
ScopedMaxScopesNavigationChannelCapacityForTesting::
~ScopedMaxScopesNavigationChannelCapacityForTesting() { … }
ScopedMaxScopesEventChannelCapacityForTesting::
ScopedMaxScopesEventChannelCapacityForTesting(
double max_scoped_event_channel_capacity)
: … { … }
ScopedMaxScopesEventChannelCapacityForTesting::
~ScopedMaxScopesEventChannelCapacityForTesting() { … }
}