Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance cookiemonster #220

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ca542f9
passing epsilon through http response header
DelphianCalamity Feb 11, 2024
5b0e55f
WIP: extending trigger registration API
DelphianCalamity Feb 15, 2024
ce74254
tweaks
DelphianCalamity Feb 16, 2024
7303189
tweaks
DelphianCalamity Feb 16, 2024
f1702fb
removing LOGs
DelphianCalamity Feb 16, 2024
a40b3dc
minor
DelphianCalamity Feb 16, 2024
3a64c66
extending source registration
DelphianCalamity Feb 16, 2024
807c863
updating submodule
DelphianCalamity Feb 16, 2024
a816295
tweaks
DelphianCalamity Feb 16, 2024
c8c1799
tweaks
DelphianCalamity Feb 17, 2024
a479c87
many2many and attribution algo
DelphianCalamity Feb 19, 2024
57df04f
tweaks
DelphianCalamity Feb 19, 2024
836f05f
changes to parameter names and types
DelphianCalamity Feb 19, 2024
04409b8
revert unecessary change
DelphianCalamity Feb 19, 2024
8c1f2b1
some polishing
DelphianCalamity Feb 20, 2024
f7b177e
tweaks
DelphianCalamity Feb 21, 2024
8d106b5
changing contribution values from int to double
DelphianCalamity Feb 21, 2024
0d7acda
added aggregatableCapValues
DelphianCalamity Feb 21, 2024
9a323e2
wip: budget accounting
DelphianCalamity Feb 29, 2024
8fed63b
updating submodule
DelphianCalamity Feb 29, 2024
ef9bab2
budget accounting
DelphianCalamity Mar 2, 2024
98ef298
minor
DelphianCalamity Mar 2, 2024
5df07c6
changing depot_tools submodule
DelphianCalamity Mar 12, 2024
c17abec
updating submodule
DelphianCalamity Mar 12, 2024
77a1b78
last touch attribution policy
DelphianCalamity Mar 29, 2024
86e1c16
Performance Testing Changes. Enabled optimization
Anirudh-1149 Apr 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@
gclient-condition = checkout_crubit
[submodule "third_party/depot_tools"]
path = third_party/depot_tools
url = https://chromium.googlesource.com/chromium/tools/depot_tools
url = https://github.com/columbia/depot_tools.git
[submodule "third_party/devtools-frontend/src"]
path = third_party/devtools-frontend/src
url = https://chromium.googlesource.com/devtools/devtools-frontend
url = https://github.com/columbia/devtools-frontend
[submodule "third_party/devtools-frontend-internal"]
path = third_party/devtools-frontend-internal
url = https://chrome-internal.googlesource.com/devtools/devtools-internal
Expand Down
4 changes: 4 additions & 0 deletions components/attribution_reporting/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ component("attribution_reporting") {
"trigger_config.h",
"trigger_registration.cc",
"trigger_registration.h",
"global_epsilon.cc",
"global_epsilon.h",
"attribution_window.cc",
"attribution_window.h",
]

configs += [ "//build/config/compiler:wexit_time_destructors" ]
Expand Down
115 changes: 115 additions & 0 deletions components/attribution_reporting/attribution_window.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include "components/attribution_reporting/attribution_window.h"

#include <optional>
#include <string>
#include <utility>

#include "base/check.h"
#include "base/ranges/algorithm.h"
#include "base/types/expected.h"
#include "base/types/expected_macros.h"
#include "base/values.h"
#include "components/attribution_reporting/parsing_utils.h"
#include "components/attribution_reporting/trigger_registration_error.mojom.h"

namespace attribution_reporting {

namespace {

using ::attribution_reporting::mojom::TriggerRegistrationError;

constexpr char kEpochStart[] = "epoch_start";
constexpr char kEpochEnd[] = "epoch_end";

bool IsAttributionWindowValid(const uint64_t epoch_start, uint64_t epoch_end) {
return epoch_start <= epoch_end && epoch_start >=0 && epoch_end >=0;
}

base::expected<uint64_t, TriggerRegistrationError> ParseAttributionWindowStart(
const base::Value::Dict& registration) {
const base::Value* v = registration.Find(kEpochStart);
if (!v) {
return base::unexpected(
TriggerRegistrationError::kAttributionWindowStartMissing);
}
if (std::optional<uint64_t> epoch_start = v->GetIfInt()) {
if (*epoch_start < 0) {
return base::unexpected(TriggerRegistrationError::kAttributionWindowValueInvalid);
}
return *epoch_start;
}
return base::unexpected(
TriggerRegistrationError::kAttributionWindowStartMissing);
}

base::expected<uint64_t, TriggerRegistrationError> ParseAttributionWindowEnd(
const base::Value::Dict& registration) {
const base::Value* v = registration.Find(kEpochEnd);
if (!v) {
return base::unexpected(
TriggerRegistrationError::kAttributionWindowEndMissing);
}
if (std::optional<uint64_t> epoch_end = v->GetIfInt()) {
if (*epoch_end < 0) {
return base::unexpected(TriggerRegistrationError::kAttributionWindowValueInvalid);
}
return *epoch_end;
}
return base::unexpected(
TriggerRegistrationError::kAttributionWindowEndMissing);
}


} // namespace

// static
std::optional<AttributionWindow> AttributionWindow::Create(uint64_t epoch_start, uint64_t epoch_end) {
if (!IsAttributionWindowValid(epoch_start, epoch_end))
return std::nullopt;
return AttributionWindow(epoch_start, epoch_end);
}

// static
base::expected<AttributionWindow, TriggerRegistrationError>
AttributionWindow::FromJSON(const base::Value* value) {
const base::Value::Dict* dict = value->GetIfDict();
if (!dict) {
return base::unexpected(
TriggerRegistrationError::kAttributionWindowWrongType);
}

ASSIGN_OR_RETURN(auto epoch_start, ParseAttributionWindowStart(*dict));
ASSIGN_OR_RETURN(auto epoch_end, ParseAttributionWindowEnd(*dict));
return AttributionWindow(epoch_start, epoch_end);
}

AttributionWindow::AttributionWindow() = default;

AttributionWindow::AttributionWindow(uint64_t epoch_start, uint64_t epoch_end)
: epoch_start_(epoch_start), epoch_end_(epoch_end) {
DCHECK(IsAttributionWindowValid(epoch_start_, epoch_end_));
}

AttributionWindow::~AttributionWindow() = default;

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

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

AttributionWindow::AttributionWindow(AttributionWindow&&) =
default;

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

base::Value::Dict AttributionWindow::ToJson() const {
base::Value::Dict dict;

SerializeUint64(dict, kEpochStart, epoch_start_);
SerializeUint64(dict, kEpochEnd, epoch_end_);
return dict;
}

} // namespace attribution_reporting
49 changes: 49 additions & 0 deletions components/attribution_reporting/attribution_window.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef COMPONENTS_ATTRIBUTION_REPORTING_ATTRIBUTION_WINDOW_H_
#define COMPONENTS_ATTRIBUTION_REPORTING_ATTRIBUTION_WINDOW_H_

#include <optional>
#include <string>
#include <vector>

#include "base/component_export.h"
#include "base/types/expected.h"
#include "base/values.h"
#include "components/attribution_reporting/trigger_registration_error.mojom-forward.h"

namespace attribution_reporting {

class COMPONENT_EXPORT(ATTRIBUTION_REPORTING) AttributionWindow {
public:
static std::optional<AttributionWindow> Create(uint64_t epoch_start, uint64_t epoch_end);

static base::expected<AttributionWindow, mojom::TriggerRegistrationError>
FromJSON(const base::Value* value);

AttributionWindow();

~AttributionWindow();

AttributionWindow(const AttributionWindow&);
AttributionWindow& operator=(const AttributionWindow&);

AttributionWindow(AttributionWindow&&);
AttributionWindow& operator=(AttributionWindow&&);

uint64_t epoch_start() const { return epoch_start_; }
uint64_t epoch_end() const { return epoch_end_; }
uint64_t size() const { return epoch_end_ - epoch_start_ + 1; }

base::Value::Dict ToJson() const;

friend bool operator==(const AttributionWindow&, const AttributionWindow&) = default;

private:
AttributionWindow(uint64_t epoch_start, uint64_t epoch_end);

uint64_t epoch_start_ = 0;
uint64_t epoch_end_ = 0;
};

} // namespace attribution_reporting

#endif // COMPONENTS_ATTRIBUTION_REPORTING_ATTRIBUTION_WINDOW_H_
39 changes: 39 additions & 0 deletions components/attribution_reporting/filters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,45 @@ bool FilterData::Matches(mojom::SourceType source_type,
});
}

bool FilterData::MatchesM2M(const FiltersDisjunction& filters, bool negated) const {
if (filters.empty()) {
return true;
}

return base::ranges::any_of(filters, [&](const FilterConfig& config) {
return base::ranges::all_of(
config.filter_values(), [&](const auto& trigger_filter) {

auto source_filter = filter_values_.find(trigger_filter.first);
if (source_filter == filter_values_.end()) {
return true;
}

// Desired behavior is to treat any empty set of values as a
// single unique value itself. This means:
// - x:[] match x:[] is false when negated, and true otherwise.
// - x:[1,2,3] match x:[] is true when negated, and false
// otherwise.
if (trigger_filter.second.empty()) {
return negated != source_filter->second.empty();
}

bool has_intersection = base::ranges::any_of(
trigger_filter.second, [&](const std::string& value) {
return base::Contains(source_filter->second, value);
});
// Negating filters are considered matched if the intersection of
// the filter values is empty.
return negated != has_intersection;
});
});
}

bool FilterData::MatchesM2M(const FilterPair& filters) const {
return MatchesM2M(filters.positive, /*negated=*/false) &&
MatchesM2M(filters.negative, /*negated=*/true);
}

bool FilterData::MatchesForTesting(mojom::SourceType source_type,
const base::Time& source_time,
const base::Time& trigger_time,
Expand Down
5 changes: 5 additions & 0 deletions components/attribution_reporting/filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class COMPONENT_EXPORT(ATTRIBUTION_REPORTING) FilterData {
const base::Time& trigger_time,
const FilterPair&) const;

bool MatchesM2M(const FilterPair&) const;

bool MatchesForTesting(mojom::SourceType,
const base::Time& source_time,
const base::Time& trigger_time,
Expand All @@ -75,6 +77,9 @@ class COMPONENT_EXPORT(ATTRIBUTION_REPORTING) FilterData {
const FiltersDisjunction&,
bool negated) const;

bool MatchesM2M(const FiltersDisjunction&,
bool negated) const;

FilterValues filter_values_;
};

Expand Down
80 changes: 80 additions & 0 deletions components/attribution_reporting/global_epsilon.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "components/attribution_reporting/global_epsilon.h"

#include <optional>

#include "base/check.h"
#include "base/check_op.h"
#include "base/types/expected.h"
#include "base/values.h"
#include "components/attribution_reporting/trigger_registration_error.mojom.h"

namespace attribution_reporting {

namespace {

// using ::attribution_reporting::mojom::SourceRegistrationError;
using ::attribution_reporting::mojom::TriggerRegistrationError;

constexpr char kGlobalEpsilon[] = "global_epsilon";

double g_max_global_epsilon = 14;

bool IsGlobalEpsilonValid(double epsilon) {
return epsilon >= 0 && epsilon <= g_max_global_epsilon;
}

} // namespace

// static
base::expected<GlobalEpsilon, TriggerRegistrationError>
GlobalEpsilon::Parse(const base::Value::Dict& dict) {
const base::Value* value = dict.Find(kGlobalEpsilon);
if (!value) {
return GlobalEpsilon();
}

std::optional<double> d = value->GetIfDouble();
if (!d.has_value()) {
return base::unexpected(
TriggerRegistrationError::kGlobalEpsilonWrongType);
}

if (!IsGlobalEpsilonValid(*d)) {
return base::unexpected(
TriggerRegistrationError::kGlobalEpsilonValueInvalid);
}

return GlobalEpsilon(*d);
}

GlobalEpsilon::GlobalEpsilon()
: GlobalEpsilon(g_max_global_epsilon) {}

GlobalEpsilon::GlobalEpsilon(double epsilon) : epsilon_(epsilon) {
CHECK(IsGlobalEpsilonValid(epsilon_));
}

bool GlobalEpsilon::SetIfValid(double epsilon) {
if (!IsGlobalEpsilonValid(epsilon)) {
return false;
}
epsilon_ = epsilon;
return true;
}

void GlobalEpsilon::Serialize(base::Value::Dict& dict) const {
dict.Set(kGlobalEpsilon, epsilon_);
}

ScopedMaxGlobalEpsilonForTesting::ScopedMaxGlobalEpsilonForTesting(
double epsilon)
: previous_(g_max_global_epsilon) {
CHECK_GE(epsilon, 0);
g_max_global_epsilon = epsilon;
}

ScopedMaxGlobalEpsilonForTesting::~ScopedMaxGlobalEpsilonForTesting() {
g_max_global_epsilon = previous_;
}

} // namespace attribution_reporting