#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 attribution_reporting {
enum AggregatableDebugReportingConfigError {
kRootInvalid = 0,
kBudgetInvalid = 1,
kKeyPieceInvalid = 2,
kDebugDataInvalid = 3,
kDebugDataKeyPieceInvalid = 4,
kDebugDataValueInvalid = 5,
kDebugDataTypesInvalid = 6,
kAggregationCoordinatorOriginInvalid = 7,
kMaxValue = kAggregationCoordinatorOriginInvalid,
};
class COMPONENT_EXPORT(ATTRIBUTION_REPORTING)
AggregatableDebugReportingContribution {
public:
static std::optional<AggregatableDebugReportingContribution> Create(
absl::uint128 key_piece,
uint32_t value);
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>;
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_;
};
}
#endif