Skip to content

Commit

Permalink
Rename AttributionAggregatableSources to AttributionAggregatableSource
Browse files Browse the repository at this point in the history
Also renamed the "sources" field to "keys" to make it clear that a
single event encodes many keys, rather than many different sources.

Also renamed the data structures on browser side.

Bug: 1293037
Change-Id: Ic11bd8223be082f2f1faafaee69ae7f77d896353
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3507811
Reviewed-by: John Delaney <johnidel@chromium.org>
Reviewed-by: Andrew Paseltiner <apaseltiner@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Nan Lin <linnan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#980815}
  • Loading branch information
linnan-github authored and Chromium LUCI CQ committed Mar 14, 2022
1 parent 0507d15 commit df06231
Show file tree
Hide file tree
Showing 27 changed files with 298 additions and 303 deletions.
4 changes: 2 additions & 2 deletions content/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ source_set("browser") {
"attribution_reporting/aggregatable_histogram_contribution.cc",
"attribution_reporting/aggregatable_histogram_contribution.h",
"attribution_reporting/attribution_aggregatable_key.h",
"attribution_reporting/attribution_aggregatable_sources.cc",
"attribution_reporting/attribution_aggregatable_sources.h",
"attribution_reporting/attribution_aggregatable_source.cc",
"attribution_reporting/attribution_aggregatable_source.h",
"attribution_reporting/attribution_aggregatable_trigger.cc",
"attribution_reporting/attribution_aggregatable_trigger.h",
"attribution_reporting/attribution_cookie_checker.h",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "base/check.h"
#include "base/containers/flat_map.h"
#include "content/browser/attribution_reporting/aggregatable_histogram_contribution.h"
#include "content/browser/attribution_reporting/attribution_aggregatable_sources.h"
#include "content/browser/attribution_reporting/attribution_aggregatable_source.h"
#include "content/browser/attribution_reporting/attribution_aggregatable_trigger.h"
#include "content/browser/attribution_reporting/attribution_filter_data.h"
#include "content/browser/attribution_reporting/attribution_utils.h"
Expand All @@ -22,14 +22,14 @@ namespace content {

std::vector<AggregatableHistogramContribution> CreateAggregatableHistogram(
const AttributionFilterData& source_filter_data,
const AttributionAggregatableSources& sources,
const AttributionAggregatableSource& source,
const AttributionAggregatableTrigger& trigger) {
// TODO(linnan): Log metrics for early returns.

// Pairs of key id and bucket key.
std::vector<std::pair<std::string, absl::uint128>> buckets;
buckets.reserve(sources.proto().sources().size());
for (const auto& [key_id, key] : sources.proto().sources()) {
buckets.reserve(source.proto().keys().size());
for (const auto& [key_id, key] : source.proto().keys()) {
buckets.emplace_back(key_id,
absl::MakeUint128(key.high_bits(), key.low_bits()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
namespace content {

class AggregatableHistogramContribution;
class AttributionAggregatableSources;
class AttributionAggregatableSource;
class AttributionAggregatableTrigger;
class AttributionFilterData;

// Creates histograms from the specified source and trigger data.
CONTENT_EXPORT std::vector<AggregatableHistogramContribution>
CreateAggregatableHistogram(const AttributionFilterData& source_filter_data,
const AttributionAggregatableSources& sources,
const AttributionAggregatableSource& source,
const AttributionAggregatableTrigger& trigger);

} // namespace content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <vector>

#include "content/browser/attribution_reporting/aggregatable_histogram_contribution.h"
#include "content/browser/attribution_reporting/attribution_aggregatable_sources.h"
#include "content/browser/attribution_reporting/attribution_aggregatable_source.h"
#include "content/browser/attribution_reporting/attribution_aggregatable_trigger.h"
#include "content/browser/attribution_reporting/attribution_filter_data.h"
#include "content/browser/attribution_reporting/attribution_reporting.pb.h"
Expand All @@ -29,8 +29,8 @@ using FilterValues = base::flat_map<std::string, std::vector<std::string>>;
} // namespace

TEST(AggregatableAttributionUtilsTest, CreateAggregatableHistogram) {
proto::AttributionAggregatableSources sources_proto =
AggregatableSourcesProtoBuilder()
proto::AttributionAggregatableSource source_proto =
AggregatableSourceProtoBuilder()
.AddKey("key1", AggregatableKeyProtoBuilder()
.SetHighBits(0)
.SetLowBits(345)
Expand Down Expand Up @@ -97,16 +97,16 @@ TEST(AggregatableAttributionUtilsTest, CreateAggregatableHistogram) {
AttributionFilterData::FromSourceFilterValues({{"filter", {"value"}}});
ASSERT_TRUE(source_filter_data.has_value());

absl::optional<AttributionAggregatableSources> sources =
AttributionAggregatableSources::Create(std::move(sources_proto));
ASSERT_TRUE(sources.has_value());
absl::optional<AttributionAggregatableSource> source =
AttributionAggregatableSource::Create(std::move(source_proto));
ASSERT_TRUE(source.has_value());

absl::optional<AttributionAggregatableTrigger> trigger =
AttributionAggregatableTrigger::FromMojo(std::move(trigger_mojo));
ASSERT_TRUE(trigger.has_value());

std::vector<AggregatableHistogramContribution> contributions =
CreateAggregatableHistogram(*source_filter_data, *sources, *trigger);
CreateAggregatableHistogram(*source_filter_data, *source, *trigger);

// "key3" is not present as no value is found.
EXPECT_THAT(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/attribution_reporting/attribution_aggregatable_source.h"

#include <utility>

#include "base/ranges/algorithm.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/blink/public/common/attribution_reporting/constants.h"

namespace content {

// static
absl::optional<AttributionAggregatableSource>
AttributionAggregatableSource::Create(
proto::AttributionAggregatableSource proto) {
bool is_valid =
proto.keys().size() <=
blink::kMaxAttributionAggregatableKeysPerSourceOrTrigger &&
base::ranges::all_of(proto.keys(), [](const auto& key) {
return key.first.size() <=
blink::kMaxBytesPerAttributionAggregatableKeyId &&
key.second.has_high_bits() && key.second.has_low_bits();
});
return is_valid ? absl::make_optional(
AttributionAggregatableSource(std::move(proto)))
: absl::nullopt;
}

AttributionAggregatableSource::AttributionAggregatableSource(
proto::AttributionAggregatableSource proto)
: proto_(std::move(proto)) {}

AttributionAggregatableSource::AttributionAggregatableSource() = default;

AttributionAggregatableSource::~AttributionAggregatableSource() = default;

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

AttributionAggregatableSource::AttributionAggregatableSource(
AttributionAggregatableSource&&) = default;

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

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

} // namespace content
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_ATTRIBUTION_REPORTING_ATTRIBUTION_AGGREGATABLE_SOURCE_H_
#define CONTENT_BROWSER_ATTRIBUTION_REPORTING_ATTRIBUTION_AGGREGATABLE_SOURCE_H_

#include "content/browser/attribution_reporting/attribution_reporting.pb.h"
#include "content/common/content_export.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

namespace content {

// This is a wrapper of `proto::AttributionAggregatableSource`.
class CONTENT_EXPORT AttributionAggregatableSource {
public:
// Returns `absl::nullopt` if `proto` is invalid.
static absl::optional<AttributionAggregatableSource> Create(
proto::AttributionAggregatableSource proto);

AttributionAggregatableSource();
~AttributionAggregatableSource();

AttributionAggregatableSource(const AttributionAggregatableSource&);
AttributionAggregatableSource(AttributionAggregatableSource&&);

AttributionAggregatableSource& operator=(
const AttributionAggregatableSource&);
AttributionAggregatableSource& operator=(AttributionAggregatableSource&&);

const proto::AttributionAggregatableSource& proto() const { return proto_; }

private:
explicit AttributionAggregatableSource(
proto::AttributionAggregatableSource proto);

proto::AttributionAggregatableSource proto_;
};

} // namespace content

#endif // CONTENT_BROWSER_ATTRIBUTION_REPORTING_ATTRIBUTION_AGGREGATABLE_SOURCE_H_

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "base/bind.h"
#include "base/check.h"
#include "base/time/time.h"
#include "content/browser/attribution_reporting/attribution_aggregatable_sources.h"
#include "content/browser/attribution_reporting/attribution_aggregatable_source.h"
#include "content/browser/attribution_reporting/attribution_filter_data.h"
#include "content/browser/attribution_reporting/attribution_host_utils.h"
#include "content/browser/attribution_reporting/attribution_manager.h"
Expand All @@ -32,17 +32,17 @@ namespace content {

namespace {

proto::AttributionAggregatableSources ConvertToProto(
const blink::mojom::AttributionAggregatableSources& aggregatable_sources) {
proto::AttributionAggregatableSources result;
proto::AttributionAggregatableSource ConvertToProto(
const blink::mojom::AttributionAggregatableSource& aggregatable_source) {
proto::AttributionAggregatableSource result;

for (const auto& [key_id, key_ptr] : aggregatable_sources.sources) {
for (const auto& [key_id, key_ptr] : aggregatable_source.keys) {
DCHECK(key_ptr);
proto::AttributionAggregatableKey key;
key.set_high_bits(key_ptr->high_bits);
key.set_low_bits(key_ptr->low_bits);

(*result.mutable_sources())[key_id] = std::move(key);
(*result.mutable_keys())[key_id] = std::move(key);
}

return result;
Expand Down Expand Up @@ -117,10 +117,10 @@ void AttributionDataHostManagerImpl::SourceDataAvailable(
if (!filter_data.has_value())
return;

absl::optional<AttributionAggregatableSources> aggregatable_sources =
AttributionAggregatableSources::Create(
ConvertToProto(*data->aggregatable_sources));
if (!aggregatable_sources.has_value())
absl::optional<AttributionAggregatableSource> aggregatable_source =
AttributionAggregatableSource::Create(
ConvertToProto(*data->aggregatable_source));
if (!aggregatable_source.has_value())
return;

StorableSource storable_source(CommonSourceInfo(
Expand All @@ -131,7 +131,7 @@ void AttributionDataHostManagerImpl::SourceDataAvailable(
context.source_type, data->priority, std::move(*filter_data),
data->debug_key ? absl::make_optional(data->debug_key->value)
: absl::nullopt,
std::move(*aggregatable_sources)));
std::move(*aggregatable_source)));

attribution_manager_->HandleSource(std::move(storable_source));
}
Expand Down
Loading

0 comments on commit df06231

Please sign in to comment.