1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_ATTRIBUTION_REPORTING_AGGREGATABLE_DEBUG_REPORTING_CONFIG_H_
#define COMPONENTS_ATTRIBUTION_REPORTING_AGGREGATABLE_DEBUG_REPORTING_CONFIG_H_
#include <stdint.h>
#include <optional>
#include "base/component_export.h"
#include "base/containers/flat_map.h"
#include "base/types/expected.h"
#include "components/attribution_reporting/debug_types.mojom-forward.h"
#include "components/attribution_reporting/suitable_origin.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
namespace base {
class DictValue;
} // namespace base
namespace attribution_reporting {
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
//
// LINT.IfChange(AggregatableDebugReportingConfigError)
enum AggregatableDebugReportingConfigError {
kRootInvalid = 0,
// This value only applies to source registrations.
kBudgetInvalid = 1,
kKeyPieceInvalid = 2,
kDebugDataInvalid = 3,
kDebugDataKeyPieceInvalid = 4,
kDebugDataValueInvalid = 5,
kDebugDataTypesInvalid = 6,
kAggregationCoordinatorOriginInvalid = 7,
kMaxValue = kAggregationCoordinatorOriginInvalid,
};
// LINT.ThenChange(//tools/metrics/histograms/metadata/attribution_reporting/enums.xml:ConversionAggregatableDebugReportingRegistrationError)
class COMPONENT_EXPORT(ATTRIBUTION_REPORTING)
AggregatableDebugReportingContribution {
public:
static std::optional<AggregatableDebugReportingContribution> Create(
absl::uint128 key_piece,
uint32_t value);
// Creates an invalid instance for use with Mojo deserialization, which
// requires types to be default-constructible.
AggregatableDebugReportingContribution() = default;
absl::uint128 key_piece() const;
uint32_t value() const;
friend bool operator==(const AggregatableDebugReportingContribution&,
const AggregatableDebugReportingContribution&) =
default;
private:
AggregatableDebugReportingContribution(absl::uint128 key_piece,
uint32_t value);
bool IsValid() const;
absl::uint128 key_piece_;
uint32_t value_;
};
struct COMPONENT_EXPORT(ATTRIBUTION_REPORTING)
AggregatableDebugReportingConfig {
using DebugData = base::flat_map<mojom::DebugDataType,
AggregatableDebugReportingContribution>;
// Parses the config for trigger registrations.
static base::expected<AggregatableDebugReportingConfig,
AggregatableDebugReportingConfigError>
Parse(base::DictValue&);
AggregatableDebugReportingConfig(
absl::uint128 key_piece,
DebugData,
std::optional<attribution_reporting::SuitableOrigin>
aggregation_coordinator_origin);
AggregatableDebugReportingConfig();
~AggregatableDebugReportingConfig();
AggregatableDebugReportingConfig(const AggregatableDebugReportingConfig&);
AggregatableDebugReportingConfig(AggregatableDebugReportingConfig&&);
AggregatableDebugReportingConfig& operator=(
const AggregatableDebugReportingConfig&);
AggregatableDebugReportingConfig& operator=(
AggregatableDebugReportingConfig&&);
void Serialize(base::DictValue&) const;
friend bool operator==(const AggregatableDebugReportingConfig&,
const AggregatableDebugReportingConfig&) = default;
absl::uint128 key_piece = 0;
DebugData debug_data;
std::optional<attribution_reporting::SuitableOrigin>
aggregation_coordinator_origin;
};
class COMPONENT_EXPORT(ATTRIBUTION_REPORTING)
SourceAggregatableDebugReportingConfig {
public:
static base::expected<SourceAggregatableDebugReportingConfig,
AggregatableDebugReportingConfigError>
Parse(base::DictValue&);
static std::optional<SourceAggregatableDebugReportingConfig> Create(
int budget,
AggregatableDebugReportingConfig);
SourceAggregatableDebugReportingConfig();
~SourceAggregatableDebugReportingConfig();
SourceAggregatableDebugReportingConfig(
const SourceAggregatableDebugReportingConfig&);
SourceAggregatableDebugReportingConfig(
SourceAggregatableDebugReportingConfig&&);
SourceAggregatableDebugReportingConfig& operator=(
const SourceAggregatableDebugReportingConfig&);
SourceAggregatableDebugReportingConfig& operator=(
SourceAggregatableDebugReportingConfig&&);
int budget() const { return budget_; }
const AggregatableDebugReportingConfig& config() const { return config_; }
void Serialize(base::DictValue&) const;
friend bool operator==(const SourceAggregatableDebugReportingConfig&,
const SourceAggregatableDebugReportingConfig&) =
default;
private:
SourceAggregatableDebugReportingConfig(int budget,
AggregatableDebugReportingConfig);
int budget_ = 0;
AggregatableDebugReportingConfig config_;
};
} // namespace attribution_reporting
#endif // COMPONENTS_ATTRIBUTION_REPORTING_AGGREGATABLE_DEBUG_REPORTING_CONFIG_H_
|