[IdentifiabilityStudy] Remove code for estimating REID
This code is behind a disabled feature flag. We are not using it at
the moment and we are unlikely to be using it in the near future, so
let's clean it up.
Change-Id: I814ed662b82706935d282c8d0e2232bf71a6425f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5130235
Reviewed-by: Dominic Battre <[email protected]>
Reviewed-by: Mike West <[email protected]>
Commit-Queue: Antonio Sartori <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1239170}
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 90c8bd9..f80beb38 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -955,6 +955,10 @@
constexpr char kIsolatedWebAppsEnabled[] = "ash.isolated_web_apps_enabled";
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
+// Deprecated 12/2023.
+const char kPrivacyBudgetReportedReidBlocks[] =
+ "privacy_budget.reported_reid_blocks";
+
// Register local state used only for migration (clearing or moving to a new
// key).
void RegisterLocalStatePrefsForMigration(PrefRegistrySimple* registry) {
@@ -1075,6 +1079,9 @@
#if BUILDFLAG(IS_CHROMEOS_ASH)
registry->RegisterBooleanPref(kIsolatedWebAppsEnabled, false);
#endif
+
+ // Deprecated 12/2023
+ registry->RegisterStringPref(kPrivacyBudgetReportedReidBlocks, std::string());
}
// Register prefs used only for migration (clearing or moving to a new key).
@@ -2216,6 +2223,9 @@
local_state->ClearPref(kIsolatedWebAppsEnabled);
#endif
+ // Added 12/2023
+ local_state->ClearPref(kPrivacyBudgetReportedReidBlocks);
+
// Please don't delete the following line. It is used by PRESUBMIT.py.
// END_MIGRATE_OBSOLETE_LOCAL_STATE_PREFS
diff --git a/chrome/browser/privacy_budget/BUILD.gn b/chrome/browser/privacy_budget/BUILD.gn
index 0af2b7f..752cb27 100644
--- a/chrome/browser/privacy_budget/BUILD.gn
+++ b/chrome/browser/privacy_budget/BUILD.gn
@@ -10,7 +10,6 @@
"mesa_distribution.h",
"privacy_budget_metrics_provider.h",
"privacy_budget_prefs.h",
- "privacy_budget_reid_score_estimator.h",
"privacy_budget_ukm_entry_filter.h",
"representative_surface_set.h",
"surface_set_equivalence.h",
@@ -35,7 +34,6 @@
"identifiability_study_state.cc",
"privacy_budget_metrics_provider.cc",
"privacy_budget_prefs.cc",
- "privacy_budget_reid_score_estimator.cc",
"privacy_budget_ukm_entry_filter.cc",
"representative_surface_set.cc",
"surface_set_equivalence.cc",
@@ -71,7 +69,6 @@
"inspectable_identifiability_study_state.h",
"mesa_distribution_unittest.cc",
"privacy_budget_metrics_provider_unittest.cc",
- "privacy_budget_reid_score_estimator_unittest.cc",
"privacy_budget_ukm_entry_filter_unittest.cc",
"representative_surface_set_unittest.cc",
"surface_set_equivalence_unittest.cc",
@@ -99,7 +96,6 @@
"privacy_budget_browsertest.cc",
"privacy_budget_browsertest_util.cc",
"privacy_budget_browsertest_util.h",
- "privacy_budget_reid_score_browsertest.cc",
]
defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
diff --git a/chrome/browser/privacy_budget/identifiability_study_group_settings.cc b/chrome/browser/privacy_budget/identifiability_study_group_settings.cc
index e5b2db5..ca7e399 100644
--- a/chrome/browser/privacy_budget/identifiability_study_group_settings.cc
+++ b/chrome/browser/privacy_budget/identifiability_study_group_settings.cc
@@ -26,17 +26,12 @@
// static
IdentifiabilityStudyGroupSettings
IdentifiabilityStudyGroupSettings::InitFromFeatureParams() {
- return InitFrom(
- base::FeatureList::IsEnabled(features::kIdentifiabilityStudy),
- features::kIdentifiabilityStudyExpectedSurfaceCount.Get(),
- features::kIdentifiabilityStudyActiveSurfaceBudget.Get(),
- features::kIdentifiabilityStudyBlocks.Get(),
- features::kIdentifiabilityStudyBlockWeights.Get(),
- features::kIdentifiabilityStudyAllowedRandomTypes.Get(),
- features::kIdentifiabilityStudyReidSurfaceBlocks.Get(),
- features::kIdentifiabilityStudyReidSurfaceBlocksSaltsRanges.Get(),
- features::kIdentifiabilityStudyReidSurfaceBlocksBits.Get(),
- features::kIdentifiabilityStudyReidBlocksNoiseProbabilities.Get());
+ return InitFrom(base::FeatureList::IsEnabled(features::kIdentifiabilityStudy),
+ features::kIdentifiabilityStudyExpectedSurfaceCount.Get(),
+ features::kIdentifiabilityStudyActiveSurfaceBudget.Get(),
+ features::kIdentifiabilityStudyBlocks.Get(),
+ features::kIdentifiabilityStudyBlockWeights.Get(),
+ features::kIdentifiabilityStudyAllowedRandomTypes.Get());
}
// static
@@ -46,24 +41,13 @@
int surface_budget,
const std::string& blocks,
const std::string& blocks_weights,
- const std::string& allowed_random_types,
- const std::string& reid_blocks,
- const std::string& reid_blocks_salts_ranges,
- const std::string& reid_blocks_bits,
- const std::string& reid_blocks_noise_probabilities) {
+ const std::string& allowed_random_types) {
return IdentifiabilityStudyGroupSettings(
enabled, expected_surface_count, surface_budget,
DecodeIdentifiabilityFieldTrialParam<IdentifiableSurfaceBlocks>(blocks),
DecodeIdentifiabilityFieldTrialParam<std::vector<double>>(blocks_weights),
DecodeIdentifiabilityFieldTrialParam<
- std::vector<blink::IdentifiableSurface::Type>>(allowed_random_types),
- DecodeIdentifiabilityFieldTrialParam<IdentifiableSurfaceBlocks>(
- reid_blocks),
- DecodeIdentifiabilityFieldTrialParam<std::vector<uint64_t>>(
- reid_blocks_salts_ranges),
- DecodeIdentifiabilityFieldTrialParam<std::vector<int>>(reid_blocks_bits),
- DecodeIdentifiabilityFieldTrialParam<std::vector<double>>(
- reid_blocks_noise_probabilities));
+ std::vector<blink::IdentifiableSurface::Type>>(allowed_random_types));
}
IdentifiabilityStudyGroupSettings::IdentifiabilityStudyGroupSettings(
@@ -72,11 +56,7 @@
int surface_budget,
IdentifiableSurfaceBlocks blocks,
std::vector<double> blocks_weights,
- std::vector<blink::IdentifiableSurface::Type> allowed_random_types,
- IdentifiableSurfaceBlocks reid_blocks,
- std::vector<uint64_t> reid_blocks_salts_ranges,
- std::vector<int> reid_blocks_bits,
- std::vector<double> reid_blocks_noise_probabilities)
+ std::vector<blink::IdentifiableSurface::Type> allowed_random_types)
: enabled_(enabled),
expected_surface_count_(std::clamp<int>(
expected_surface_count,
@@ -88,11 +68,6 @@
features::kMaxIdentifiabilityStudyActiveSurfaceBudget)),
blocks_(std::move(blocks)),
blocks_weights_(std::move(blocks_weights)),
- reid_blocks_(std::move(reid_blocks)),
- reid_blocks_salts_ranges_(std::move(reid_blocks_salts_ranges)),
- reid_blocks_bits_(std::move(reid_blocks_bits)),
- reid_blocks_noise_probabilities_(
- std::move(reid_blocks_noise_probabilities)),
allowed_random_types_(std::move(allowed_random_types)) {
bool validates = Validate();
UmaHistogramFinchConfigValidation(validates);
@@ -110,17 +85,14 @@
if (!enabled_)
return true;
// If the study is enabled, at least one of assigned-block-sampling or
- // reid-score-estimation or random-surface-assignment should be enabled.
- if (!IsUsingAssignedBlockSampling() && !IsUsingReidScoreEstimator() &&
- !IsUsingRandomSampling()) {
+ // random-surface-assignment should be enabled.
+ if (!IsUsingAssignedBlockSampling() && !IsUsingRandomSampling()) {
return false;
}
if (IsUsingAssignedBlockSampling() && IsUsingRandomSampling())
return false;
if (IsUsingAssignedBlockSampling() && !ValidateAssignedBlockSampling())
return false;
- if (IsUsingReidScoreEstimator() && !ValidateReidBlockEstimator())
- return false;
return true;
}
@@ -161,26 +133,6 @@
return true;
}
-bool IdentifiabilityStudyGroupSettings::ValidateReidBlockEstimator() {
- if (reid_blocks_salts_ranges_.size() != reid_blocks_.size() ||
- reid_blocks_bits_.size() != reid_blocks_.size() ||
- reid_blocks_noise_probabilities_.size() != reid_blocks_.size())
- return false;
- bool valid_params =
- base::ranges::all_of(reid_blocks_salts_ranges_,
- [](uint64_t salt_range) { return salt_range > 0; });
- valid_params = valid_params &&
- base::ranges::all_of(reid_blocks_bits_, [](int reid_bits) {
- return reid_bits > 0 && reid_bits <= 32;
- });
-
- return valid_params && base::ranges::all_of(reid_blocks_noise_probabilities_,
- [](double reid_noise) {
- return reid_noise >= 0 &&
- reid_noise <= 1;
- });
-}
-
const IdentifiableSurfaceBlocks& IdentifiabilityStudyGroupSettings::blocks()
const {
return blocks_;
@@ -191,26 +143,6 @@
return blocks_weights_;
}
-const std::vector<uint64_t>&
-IdentifiabilityStudyGroupSettings::reid_blocks_salts_ranges() const {
- return reid_blocks_salts_ranges_;
-}
-
-const std::vector<int>& IdentifiabilityStudyGroupSettings::reid_blocks_bits()
- const {
- return reid_blocks_bits_;
-}
-
-const std::vector<double>&
-IdentifiabilityStudyGroupSettings::reid_blocks_noise_probabilities() const {
- return reid_blocks_noise_probabilities_;
-}
-
-const IdentifiableSurfaceBlocks&
-IdentifiabilityStudyGroupSettings::reid_blocks() const {
- return reid_blocks_;
-}
-
const std::vector<blink::IdentifiableSurface::Type>&
IdentifiabilityStudyGroupSettings::allowed_random_types() const {
return allowed_random_types_;
@@ -224,10 +156,6 @@
return expected_surface_count() > 0;
}
-bool IdentifiabilityStudyGroupSettings::IsUsingReidScoreEstimator() const {
- return !reid_blocks().empty();
-}
-
bool IdentifiabilityStudyGroupSettings::IsUsingSamplingOfSurfaces() const {
// Random and assigned block sampling are mutually exclusive.
DCHECK(!IsUsingRandomSampling() || !IsUsingAssignedBlockSampling());
diff --git a/chrome/browser/privacy_budget/identifiability_study_group_settings.h b/chrome/browser/privacy_budget/identifiability_study_group_settings.h
index 9a916514..5b37c65 100644
--- a/chrome/browser/privacy_budget/identifiability_study_group_settings.h
+++ b/chrome/browser/privacy_budget/identifiability_study_group_settings.h
@@ -25,11 +25,7 @@
int surface_budget,
const std::string& blocks,
const std::string& blocks_weights,
- const std::string& allowed_random_types,
- const std::string& reid_blocks,
- const std::string& reid_blocks_salts_ranges,
- const std::string& reid_blocks_bits,
- const std::string& reid_blocks_noise_probabilities);
+ const std::string& allowed_random_types);
IdentifiabilityStudyGroupSettings(const IdentifiabilityStudyGroupSettings&) =
delete;
@@ -46,18 +42,13 @@
bool IsUsingAssignedBlockSampling() const;
bool IsUsingRandomSampling() const;
- bool IsUsingReidScoreEstimator() const;
// Whether the study is using one of the sampling strategies (random or block
// assignment).
bool IsUsingSamplingOfSurfaces() const;
const IdentifiableSurfaceBlocks& blocks() const;
- const IdentifiableSurfaceBlocks& reid_blocks() const;
const std::vector<double>& blocks_weights() const;
- const std::vector<uint64_t>& reid_blocks_salts_ranges() const;
- const std::vector<int>& reid_blocks_bits() const;
- const std::vector<double>& reid_blocks_noise_probabilities() const;
const std::vector<blink::IdentifiableSurface::Type>& allowed_random_types()
const;
@@ -71,15 +62,10 @@
int surface_budget,
IdentifiableSurfaceBlocks blocks,
std::vector<double> blocks_weights,
- std::vector<blink::IdentifiableSurface::Type> allowed_random_types,
- IdentifiableSurfaceBlocks reid_blocks,
- std::vector<uint64_t> reid_blocks_salts_ranges,
- std::vector<int> reid_blocks_bits,
- std::vector<double> reid_blocks_noise_probabilities);
+ std::vector<blink::IdentifiableSurface::Type> allowed_random_types);
bool Validate();
bool ValidateAssignedBlockSampling();
- bool ValidateReidBlockEstimator();
// True if identifiability study is enabled. If this field is false, then none
// of the other values are applicable.
@@ -93,14 +79,6 @@
const std::vector<double> blocks_weights_;
- const IdentifiableSurfaceBlocks reid_blocks_;
-
- const std::vector<uint64_t> reid_blocks_salts_ranges_;
-
- const std::vector<int> reid_blocks_bits_;
-
- const std::vector<double> reid_blocks_noise_probabilities_;
-
// Surface types to sample from when random surface sampling is enabled. If
// this vector is empty all surface types are allowed to be sampled.
const std::vector<blink::IdentifiableSurface::Type> allowed_random_types_;
diff --git a/chrome/browser/privacy_budget/identifiability_study_group_settings_unittest.cc b/chrome/browser/privacy_budget/identifiability_study_group_settings_unittest.cc
index 63a5343..8be4512 100644
--- a/chrome/browser/privacy_budget/identifiability_study_group_settings_unittest.cc
+++ b/chrome/browser/privacy_budget/identifiability_study_group_settings_unittest.cc
@@ -13,32 +13,32 @@
};
TEST_F(IdentifiabilityStudyGroupSettingsTest, Disabled) {
- auto settings = IdentifiabilityStudyGroupSettings::InitFrom(
- false, 0, 0, "", "", "", "", "", "", "");
+ auto settings =
+ IdentifiabilityStudyGroupSettings::InitFrom(false, 0, 0, "", "", "");
EXPECT_FALSE(settings.enabled());
histogram_tester.ExpectUniqueSample(
"PrivacyBudget.Identifiability.FinchConfigValidationResult", true, 1);
}
TEST_F(IdentifiabilityStudyGroupSettingsTest, DisabledWithParams) {
- auto settings = IdentifiabilityStudyGroupSettings::InitFrom(
- false, 10, 40, "", "", "", "", "", "", "");
+ auto settings =
+ IdentifiabilityStudyGroupSettings::InitFrom(false, 10, 40, "", "", "");
EXPECT_FALSE(settings.enabled());
histogram_tester.ExpectUniqueSample(
"PrivacyBudget.Identifiability.FinchConfigValidationResult", true, 1);
}
TEST_F(IdentifiabilityStudyGroupSettingsTest, DisabledBySurfaceCountZero) {
- auto settings = IdentifiabilityStudyGroupSettings::InitFrom(
- true, 0, 40, "", "", "", "", "", "", "");
+ auto settings =
+ IdentifiabilityStudyGroupSettings::InitFrom(true, 0, 40, "", "", "");
EXPECT_FALSE(settings.enabled());
histogram_tester.ExpectUniqueSample(
"PrivacyBudget.Identifiability.FinchConfigValidationResult", false, 1);
}
TEST_F(IdentifiabilityStudyGroupSettingsTest, ValidRandomSurfaceSampling) {
- auto settings = IdentifiabilityStudyGroupSettings::InitFrom(
- true, 10, 40, "", "", "1,4", "", "", "", "");
+ auto settings =
+ IdentifiabilityStudyGroupSettings::InitFrom(true, 10, 40, "", "", "1,4");
EXPECT_TRUE(settings.enabled());
EXPECT_FALSE(settings.IsUsingAssignedBlockSampling());
EXPECT_TRUE(settings.IsUsingRandomSampling());
@@ -56,7 +56,7 @@
TEST_F(IdentifiabilityStudyGroupSettingsTest, ValidAssignedBlockSampling) {
auto settings = IdentifiabilityStudyGroupSettings::InitFrom(
- true, 0, 0, "1;2,3;4,5;6", "1,1,1", "", "", "", "", "");
+ true, 0, 0, "1;2,3;4,5;6", "1,1,1", "");
EXPECT_TRUE(settings.enabled());
EXPECT_TRUE(settings.IsUsingAssignedBlockSampling());
EXPECT_FALSE(settings.IsUsingRandomSampling());
@@ -67,7 +67,7 @@
TEST_F(IdentifiabilityStudyGroupSettingsTest, InvalidNegativeWeight) {
auto settings = IdentifiabilityStudyGroupSettings::InitFrom(
- true, 0, 0, "1;2,3;4,5;6", "-1,1,1", "", "", "", "", "");
+ true, 0, 0, "1;2,3;4,5;6", "-1,1,1", "");
EXPECT_FALSE(settings.enabled());
histogram_tester.ExpectUniqueSample(
"PrivacyBudget.Identifiability.FinchConfigValidationResult", false, 1);
@@ -75,25 +75,7 @@
TEST_F(IdentifiabilityStudyGroupSettingsTest, InvalidSurfaceTooLikely) {
auto settings = IdentifiabilityStudyGroupSettings::InitFrom(
- true, 0, 0, "1;2,1;4,5;6", "1,1,1", "", "", "", "", "");
- EXPECT_FALSE(settings.enabled());
- histogram_tester.ExpectUniqueSample(
- "PrivacyBudget.Identifiability.FinchConfigValidationResult", false, 1);
-}
-
-TEST_F(IdentifiabilityStudyGroupSettingsTest, EnableSettingsForValidReidBlock) {
- auto settings = IdentifiabilityStudyGroupSettings::InitFrom(
- true, 0, 0, "", "", "", "1;2,4;5;6", "2,2", "2,3", "0.1,0.2");
- EXPECT_TRUE(settings.IsUsingReidScoreEstimator());
- EXPECT_FALSE(settings.IsUsingSamplingOfSurfaces());
- EXPECT_TRUE(settings.enabled());
- histogram_tester.ExpectUniqueSample(
- "PrivacyBudget.Identifiability.FinchConfigValidationResult", true, 1);
-}
-
-TEST_F(IdentifiabilityStudyGroupSettingsTest, InvalidReidBlocks) {
- auto settings = IdentifiabilityStudyGroupSettings::InitFrom(
- true, 0, 0, "", "", "", "1;2,4;5;6", "2", "2,3", "0.1,0.2");
+ true, 0, 0, "1;2,1;4,5;6", "1,1,1", "");
EXPECT_FALSE(settings.enabled());
histogram_tester.ExpectUniqueSample(
"PrivacyBudget.Identifiability.FinchConfigValidationResult", false, 1);
diff --git a/chrome/browser/privacy_budget/identifiability_study_state.cc b/chrome/browser/privacy_budget/identifiability_study_state.cc
index 442fe44..44a5551 100644
--- a/chrome/browser/privacy_budget/identifiability_study_state.cc
+++ b/chrome/browser/privacy_budget/identifiability_study_state.cc
@@ -24,7 +24,6 @@
#include "base/ranges/algorithm.h"
#include "chrome/browser/privacy_budget/identifiability_study_group_settings.h"
#include "chrome/browser/privacy_budget/privacy_budget_prefs.h"
-#include "chrome/browser/privacy_budget/privacy_budget_reid_score_estimator.h"
#include "chrome/browser/privacy_budget/representative_surface_set.h"
#include "chrome/browser/privacy_budget/surface_set_equivalence.h"
#include "chrome/common/privacy_budget/field_trial_param_conversions.h"
@@ -64,9 +63,7 @@
// bigger than 0.
: 1,
kMesaDistributionRatio,
- kMesaDistributionGeometricDistributionParam),
- reid_estimator_(
- PrivacyBudgetReidScoreEstimator(&settings_, pref_service)) {
+ kMesaDistributionGeometricDistributionParam) {
InitializeGlobalStudySettings();
InitFromPrefs();
}
@@ -87,11 +84,6 @@
if (surface.GetType() == blink::IdentifiableSurface::Type::kReservedInternal)
return true;
- if (surface.GetType() ==
- blink::IdentifiableSurface::Type::kReidScoreEstimator) {
- return settings_.IsUsingReidScoreEstimator();
- }
-
// All other surfaces should be recorded only when sampling.
if (!settings_.IsUsingSamplingOfSurfaces())
return false;
@@ -342,7 +334,6 @@
void IdentifiabilityStudyState::ResetPersistedState() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- reid_estimator_.ResetPersistedState();
ResetInMemoryState();
@@ -507,8 +498,6 @@
return;
}
- reid_estimator_.Init();
-
if (settings_.IsUsingAssignedBlockSampling()) {
InitStateForAssignedBlockSampling();
}
@@ -520,14 +509,6 @@
CheckInvariants();
}
-void IdentifiabilityStudyState::MaybeStoreValueForComputingReidScore(
- blink::IdentifiableSurface surface,
- blink::IdentifiableToken token) {
- if (!settings_.IsUsingReidScoreEstimator())
- return;
- reid_estimator_.ProcessForReidScore(surface, token);
-}
-
void IdentifiabilityStudyState::InitStateForRandomSurfaceSampling() {
DCHECK(settings_.IsUsingRandomSampling());
ResetInMemoryState();
diff --git a/chrome/browser/privacy_budget/identifiability_study_state.h b/chrome/browser/privacy_budget/identifiability_study_state.h
index 2f520f2..49fd7d285 100644
--- a/chrome/browser/privacy_budget/identifiability_study_state.h
+++ b/chrome/browser/privacy_budget/identifiability_study_state.h
@@ -19,7 +19,6 @@
#include "chrome/browser/privacy_budget/encountered_surface_tracker.h"
#include "chrome/browser/privacy_budget/mesa_distribution.h"
#include "chrome/browser/privacy_budget/privacy_budget_prefs.h"
-#include "chrome/browser/privacy_budget/privacy_budget_reid_score_estimator.h"
#include "chrome/browser/privacy_budget/representative_surface_set.h"
#include "chrome/browser/privacy_budget/surface_set_equivalence.h"
#include "chrome/browser/privacy_budget/surface_set_valuation.h"
@@ -112,11 +111,6 @@
// Initializes from fields persisted in `pref_service_`.
void InitFromPrefs();
- // Checks if this surface is part of a set of surfaces we want to estimate the
- // Reid score of. If so, stores its value for later estimation.
- void MaybeStoreValueForComputingReidScore(blink::IdentifiableSurface surface,
- blink::IdentifiableToken token);
-
// The largest offset that we can select. At worst `seen_surfaces_` must keep
// track of this many (+1) surfaces. This value is approximately based on the
// 90ᵗʰ percentile surface encounter rate as measured in June 2021.
@@ -387,10 +381,6 @@
// Where kSettings is the PrivacyBudgetSettingsProvider singleton.
EncounteredSurfaceTracker surface_encounters_;
- // Keeps track of the list of surfaces for which we need to estimate the Reid
- // score.
- PrivacyBudgetReidScoreEstimator reid_estimator_;
-
SEQUENCE_CHECKER(sequence_checker_);
};
diff --git a/chrome/browser/privacy_budget/privacy_budget_prefs.cc b/chrome/browser/privacy_budget/privacy_budget_prefs.cc
index b48b8cb..283f264 100644
--- a/chrome/browser/privacy_budget/privacy_budget_prefs.cc
+++ b/chrome/browser/privacy_budget/privacy_budget_prefs.cc
@@ -9,15 +9,12 @@
namespace prefs {
const char kPrivacyBudgetGeneration[] = "privacy_budget.generation";
-const char kPrivacyBudgetReportedReidBlocks[] =
- "privacy_budget.reported_reid_blocks";
const char kPrivacyBudgetSeenSurfaces[] = "privacy_budget.seen";
const char kPrivacyBudgetSelectedOffsets[] = "privacy_budget.selected";
const char kPrivacyBudgetSelectedBlock[] = "privacy_budget.block_offset";
void RegisterPrivacyBudgetPrefs(PrefRegistrySimple* registry) {
registry->RegisterIntegerPref(kPrivacyBudgetGeneration, 0);
- registry->RegisterStringPref(kPrivacyBudgetReportedReidBlocks, std::string());
registry->RegisterStringPref(kPrivacyBudgetSeenSurfaces, std::string());
registry->RegisterStringPref(kPrivacyBudgetSelectedOffsets, std::string());
registry->RegisterIntegerPref(kPrivacyBudgetSelectedBlock, -1);
diff --git a/chrome/browser/privacy_budget/privacy_budget_prefs.h b/chrome/browser/privacy_budget/privacy_budget_prefs.h
index 8128bd4..e4873aa 100644
--- a/chrome/browser/privacy_budget/privacy_budget_prefs.h
+++ b/chrome/browser/privacy_budget/privacy_budget_prefs.h
@@ -17,11 +17,6 @@
// Value is an int stored as IntegerPref.
extern const char kPrivacyBudgetGeneration[];
-// Pref used for persisting for which blocks of surfaces we already reported the
-// hash for estimating the Reid score. Used to avoid recomputing and reporting
-// the hashes multiple times.
-extern const char kPrivacyBudgetReportedReidBlocks[];
-
// Pref used for persisting |IdentifiabilityStudyState::seen_surface_sequence_|.
//
// Value is a list of IdentifiableSurface encoded via
diff --git a/chrome/browser/privacy_budget/privacy_budget_reid_score_browsertest.cc b/chrome/browser/privacy_budget/privacy_budget_reid_score_browsertest.cc
deleted file mode 100644
index 907dde78..0000000
--- a/chrome/browser/privacy_budget/privacy_budget_reid_score_browsertest.cc
+++ /dev/null
@@ -1,195 +0,0 @@
-// Copyright 2022 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/barrier_closure.h"
-#include "build/build_config.h"
-#include "build/buildflag.h"
-#include "chrome/browser/privacy_budget/identifiability_study_state.h"
-#include "chrome/browser/privacy_budget/privacy_budget_browsertest_util.h"
-#include "chrome/browser/privacy_budget/privacy_budget_ukm_entry_filter.h"
-#include "chrome/common/privacy_budget/privacy_budget_features.h"
-#include "chrome/common/privacy_budget/scoped_privacy_budget_config.h"
-#include "chrome/test/base/chrome_test_utils.h"
-#include "components/ukm/test_ukm_recorder.h"
-#include "content/public/test/browser_test.h"
-#include "third_party/blink/public/common/privacy_budget/identifiability_study_settings.h"
-
-#if BUILDFLAG(IS_ANDROID)
-#include "chrome/test/base/android/android_browser_test.h"
-#else
-#include "chrome/test/base/in_process_browser_test.h"
-#endif
-
-namespace {
-
-using testing::IsSupersetOf;
-using testing::Key;
-
-class EnableReidEstimation {
- public:
- EnableReidEstimation() {
- test::ScopedPrivacyBudgetConfig::Parameters parameters;
-
- parameters.reid_blocks = {
- {blink::IdentifiableSurface::FromTypeAndToken(
- blink::IdentifiableSurface::Type::kWebFeature,
- blink::mojom::WebFeature::kNavigatorUserAgent),
- blink::IdentifiableSurface::FromTypeAndToken(
- blink::IdentifiableSurface::Type::kWebFeature,
- blink::mojom::WebFeature::kNavigatorLanguage)}};
-
- parameters.reid_salts_ranges = {1};
- parameters.reid_bits = {1};
- parameters.reid_noise = {0.01};
-
- scoped_config_.Apply(parameters);
- }
-
- private:
- test::ScopedPrivacyBudgetConfig scoped_config_;
-};
-
-class PrivacyBudgetReidScoreBrowserTest : private EnableReidEstimation,
- public PlatformBrowserTest {};
-
-class PrivacyBudgetReidScoreBrowserTestWithTestRecorder
- : private EnableReidEstimation,
- public PrivacyBudgetBrowserTestBaseWithTestRecorder {};
-
-} // namespace
-
-IN_PROC_BROWSER_TEST_F(PrivacyBudgetReidScoreBrowserTest, LoadsAGroup) {
- EXPECT_TRUE(base::FeatureList::IsEnabled(features::kIdentifiabilityStudy));
-
- const auto* settings = blink::IdentifiabilityStudySettings::Get();
- ASSERT_TRUE(settings->IsActive());
-}
-
-IN_PROC_BROWSER_TEST_F(PrivacyBudgetReidScoreBrowserTestWithTestRecorder,
- ReidHashIsReported) {
- blink::IdentifiabilityStudySettings::ResetStateForTesting();
- auto study_state = std::make_unique<IdentifiabilityStudyState>(
- g_browser_process->local_state());
- auto filter =
- std::make_unique<PrivacyBudgetUkmEntryFilter>(study_state.get());
- recorder().SetEntryFilter(std::move(filter));
- ASSERT_TRUE(embedded_test_server()->Start());
- content::DOMMessageQueue messages(web_contents());
- base::RunLoop run_loop;
-
- recorder().SetOnAddEntryCallback(ukm::builders::Identifiability::kEntryName,
- BarrierClosure(4u, run_loop.QuitClosure()));
-
- ASSERT_TRUE(content::NavigateToURL(
- web_contents(),
- embedded_test_server()->GetURL("/privacy_budget/calls_user_agent.html")));
-
- // The document calls the user agent and language apis and replies with done.
- // Receipt of the message indicates that the script successfully completed.
- std::string reply;
- ASSERT_TRUE(messages.WaitForMessage(&reply));
- // Navigating away from the test page causes the document to be unloaded. That
- // will cause any buffered metrics to be flushed.
- content::NavigateToURLBlockUntilNavigationsComplete(web_contents(),
- GURL("about:blank"), 1);
- // Wait for the metrics to come down the pipe.
- run_loop.Run();
-
- auto merged_entries = recorder().GetMergedEntriesByName(
- ukm::builders::Identifiability::kEntryName);
-
- // Calculate the reid surface key manually.
- constexpr auto kReidScoreType =
- blink::IdentifiableSurface::Type::kReidScoreEstimator;
- auto surface_1 = blink::IdentifiableSurface::FromTypeAndToken(
- blink::IdentifiableSurface::Type::kWebFeature,
- blink::mojom::WebFeature::kNavigatorUserAgent);
- auto surface_2 = blink::IdentifiableSurface::FromTypeAndToken(
- blink::IdentifiableSurface::Type::kWebFeature,
- blink::mojom::WebFeature::kNavigatorLanguage);
- std::vector<uint64_t> tokens{surface_1.ToUkmMetricHash(),
- surface_2.ToUkmMetricHash()};
- auto expected_surface = blink::IdentifiableSurface::FromTypeAndToken(
- kReidScoreType, base::make_span(tokens));
-
- // Merge all entries for comparison in the next step.
- base::flat_map<uint64_t, int64_t> metrics;
-
- for (auto& it : merged_entries) {
- metrics.insert(it.second->metrics.begin(), it.second->metrics.end());
- }
-
- EXPECT_THAT(metrics, IsSupersetOf({
- Key(expected_surface.ToUkmMetricHash()),
- }));
-}
-
-namespace {
-
-// Test class that allows to enable UKM recording.
-class PrivacyBudgetReidScoreBrowserTestWithUkmRecording
- : private EnableReidEstimation,
- public PrivacyBudgetBrowserTestBaseWithUkmRecording {};
-
-} // namespace
-
-IN_PROC_BROWSER_TEST_F(PrivacyBudgetReidScoreBrowserTestWithUkmRecording,
- ReidIsReported) {
- ASSERT_TRUE(base::FeatureList::IsEnabled(features::kIdentifiabilityStudy));
- ASSERT_TRUE(EnableUkmRecording());
-
- constexpr blink::IdentifiableToken kDummyToken = 1;
- constexpr blink::IdentifiableSurface kUserAgentSurface =
- blink::IdentifiableSurface::FromTypeAndToken(
- blink::IdentifiableSurface::Type::kWebFeature,
- blink::mojom::WebFeature::kNavigatorUserAgent);
- constexpr blink::IdentifiableSurface kLanguageSurface =
- blink::IdentifiableSurface::FromTypeAndToken(
- blink::IdentifiableSurface::Type::kWebFeature,
- blink::mojom::WebFeature::kNavigatorLanguage);
-
- auto* ukm_recorder = ukm::UkmRecorder::Get();
-
- blink::IdentifiabilityMetricBuilder(ukm::UkmRecorder::GetNewSourceID())
- .Add(kUserAgentSurface, kDummyToken)
- .Add(kLanguageSurface, kDummyToken)
- .Record(ukm_recorder);
-
- blink::IdentifiabilitySampleCollector::Get()->Flush(ukm_recorder);
-
- // Wait for the metrics to come down the pipe.
- content::RunAllTasksUntilIdle();
-
- ukm::UkmTestHelper ukm_test_helper(ukm_service());
- ukm_test_helper.BuildAndStoreLog();
- std::unique_ptr<ukm::Report> ukm_report = ukm_test_helper.GetUkmReport();
- ASSERT_TRUE(ukm_test_helper.HasUnsentLogs());
- ASSERT_TRUE(ukm_report);
- ASSERT_NE(ukm_report->entries_size(), 0);
-
- std::map<uint64_t, int64_t> seen_metrics;
- for (const auto& entry : ukm_report->entries()) {
- ASSERT_TRUE(entry.has_event_hash());
- if (entry.event_hash() != ukm::builders::Identifiability::kEntryNameHash) {
- continue;
- }
- for (const auto& metric : entry.metrics()) {
- ASSERT_TRUE(metric.has_metric_hash());
- ASSERT_TRUE(metric.has_value());
- seen_metrics.insert({metric.metric_hash(), metric.value()});
- }
- }
-
- // Calculate the reid surface key manually.
- constexpr auto kReidScoreType =
- blink::IdentifiableSurface::Type::kReidScoreEstimator;
- std::vector<uint64_t> tokens{kUserAgentSurface.ToUkmMetricHash(),
- kLanguageSurface.ToUkmMetricHash()};
- auto expected_surface = blink::IdentifiableSurface::FromTypeAndToken(
- kReidScoreType, base::make_span(tokens));
-
- EXPECT_THAT(seen_metrics, IsSupersetOf({
- Key(expected_surface.ToUkmMetricHash()),
- }));
-}
diff --git a/chrome/browser/privacy_budget/privacy_budget_reid_score_estimator.cc b/chrome/browser/privacy_budget/privacy_budget_reid_score_estimator.cc
deleted file mode 100644
index a19f9109..0000000
--- a/chrome/browser/privacy_budget/privacy_budget_reid_score_estimator.cc
+++ /dev/null
@@ -1,232 +0,0 @@
-// Copyright 2022 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/privacy_budget/privacy_budget_reid_score_estimator.h"
-
-#include "base/containers/contains.h"
-#include "base/containers/flat_map.h"
-#include "base/functional/bind.h"
-#include "base/rand_util.h"
-#include "base/task/sequenced_task_runner.h"
-#include "chrome/browser/privacy_budget/privacy_budget_prefs.h"
-#include "chrome/common/privacy_budget/field_trial_param_conversions.h"
-#include "chrome/common/privacy_budget/types.h"
-#include "components/prefs/pref_service.h"
-#include "services/metrics/public/cpp/ukm_recorder.h"
-#include "services/metrics/public/mojom/ukm_interface.mojom.h"
-#include "third_party/abseil-cpp/absl/types/optional.h"
-#include "third_party/blink/public/common/privacy_budget/identifiability_metric_builder.h"
-#include "third_party/blink/public/common/privacy_budget/identifiability_metrics.h"
-#include "third_party/blink/public/common/privacy_budget/identifiability_sample_collector.h"
-#include "third_party/blink/public/common/privacy_budget/identifiability_study_settings.h"
-#include "third_party/blink/public/common/privacy_budget/identifiable_surface.h"
-#include "third_party/blink/public/common/privacy_budget/identifiable_token.h"
-
-namespace {
-void ReportHashForReidScore(blink::IdentifiableSurface surface,
- uint64_t reid_hash) {
- ukm::SourceId ukm_source_id = ukm::NoURLSourceId();
- ukm::UkmRecorder* ukm_recorder = ukm::UkmRecorder::Get();
- blink::IdentifiabilityMetricBuilder(ukm_source_id)
- .Add(surface, reid_hash)
- .Record(ukm_recorder);
- blink::IdentifiabilitySampleCollector::Get()->FlushSource(ukm_recorder,
- ukm_source_id);
-}
-} // namespace
-
-PrivacyBudgetReidScoreEstimator::ReidBlockStorage::ReidBlockStorage(
- const IdentifiableSurfaceList& surface_list,
- uint64_t salt_range,
- int number_of_bits,
- double noise_probability)
- : salt_range_(salt_range),
- number_of_bits_(number_of_bits),
- noise_probability_(noise_probability) {
- std::vector<uint64_t> surface_hashes;
- for (const auto& surface : surface_list) {
- surface_hashes.emplace_back(surface.ToUkmMetricHash());
- }
- reid_surface_key_ = blink::IdentifiableSurface::FromTypeAndToken(
- blink::IdentifiableSurface::Type::kReidScoreEstimator,
- base::make_span(surface_hashes));
- std::vector<std::pair<blink::IdentifiableSurface,
- absl::optional<blink::IdentifiableToken>>>
- surfaces_vector;
- surfaces_vector.reserve(surface_list.size());
- for (blink::IdentifiableSurface surface : surface_list) {
- surfaces_vector.emplace_back(surface, absl::nullopt);
- }
- // Use the constructor which takes an unsorted vector, because inserting the
- // items one by one runs in O(n^2) time.
- surfaces_ = base::flat_map<blink::IdentifiableSurface,
- absl::optional<blink::IdentifiableToken>>(
- std::move(surfaces_vector));
-}
-
-PrivacyBudgetReidScoreEstimator::ReidBlockStorage::~ReidBlockStorage() =
- default;
-
-PrivacyBudgetReidScoreEstimator::ReidBlockStorage::ReidBlockStorage(
- ReidBlockStorage&&) = default;
-
-PrivacyBudgetReidScoreEstimator::ReidBlockStorage&
-PrivacyBudgetReidScoreEstimator::ReidBlockStorage::operator=(
- ReidBlockStorage&&) = default;
-
-bool PrivacyBudgetReidScoreEstimator::ReidBlockStorage::Full() const {
- DCHECK_LE(recorded_values_count_, surfaces_.size());
- return recorded_values_count_ == surfaces_.size();
-}
-
-void PrivacyBudgetReidScoreEstimator::ReidBlockStorage::Record(
- blink::IdentifiableSurface surface,
- blink::IdentifiableToken value) {
- auto surface_itr = surfaces_.find(surface);
- if (surface_itr != surfaces_.end()) {
- if (!surface_itr->second.has_value()) {
- ++recorded_values_count_;
- }
- surface_itr->second = value;
- }
-}
-
-uint64_t
-PrivacyBudgetReidScoreEstimator::ReidBlockStorage::ComputeHashForReidScore() {
- std::vector<uint64_t> tokens;
- uint64_t salt = base::RandGenerator(salt_range_);
-
- tokens.emplace_back(salt);
- for (blink::IdentifiableToken value : GetValues()) {
- tokens.emplace_back(static_cast<uint64_t>(value.ToUkmMetricValue()));
- }
- // Initialize Reid hash with random noise.
- uint64_t reid_hash = base::RandUint64();
- // Calculate the real hash if the random number is greater than the Reid noise
- // probability.
- if (base::RandDouble() >= noise_probability_) {
- // Use the hash function embedded in IdentifiableToken.
- reid_hash = blink::IdentifiabilityDigestOfBytes(
- base::as_bytes(base::make_span(tokens)));
- }
- // Create mask based on reid_bits required.
- constexpr uint64_t kTypedOne = 1;
- uint64_t mask = (kTypedOne << number_of_bits_) - 1;
- uint64_t needed_bits = reid_hash & mask;
- // Return salt in the left 32 bits and Reid b-bits hash in the right 32 bits.
- return ((salt << 32) | needed_bits);
-}
-
-std::vector<blink::IdentifiableToken>
-PrivacyBudgetReidScoreEstimator::ReidBlockStorage::GetValues() const {
- DCHECK(Full());
- std::vector<blink::IdentifiableToken> values;
- for (auto& [key, value] : surfaces_) {
- DCHECK(value.has_value());
- values.emplace_back(value.value());
- }
- return values;
-}
-
-uint64_t PrivacyBudgetReidScoreEstimator::ReidBlockStorage::salt_range() const {
- DCHECK(Full());
- return salt_range_;
-}
-
-int PrivacyBudgetReidScoreEstimator::ReidBlockStorage::number_of_bits() const {
- DCHECK(Full());
- return number_of_bits_;
-}
-
-double PrivacyBudgetReidScoreEstimator::ReidBlockStorage::noise_probability()
- const {
- DCHECK(Full());
- return noise_probability_;
-}
-
-PrivacyBudgetReidScoreEstimator::PrivacyBudgetReidScoreEstimator(
- const IdentifiabilityStudyGroupSettings* state_settings,
- PrefService* pref_service)
- : settings_(state_settings), pref_service_(pref_service) {}
-
-void PrivacyBudgetReidScoreEstimator::Init() {
- DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- if (!settings_->enabled() || !settings_->IsUsingReidScoreEstimator())
- return;
-
- already_reported_reid_blocks_ =
- DecodeIdentifiabilityFieldTrialParam<IdentifiableSurfaceList>(
- pref_service_->GetString(prefs::kPrivacyBudgetReportedReidBlocks));
-
- surface_blocks_.clear();
- for (size_t i = 0; i < settings_->reid_blocks().size(); ++i) {
- // All the vectors below have the same size. This is enforced by
- // `IdentifiabilityStudyGroupSettings`.
- ReidBlockStorage block(
- /*surface_list=*/settings_->reid_blocks()[i],
- /*salt_range=*/settings_->reid_blocks_salts_ranges()[i],
- /*number_of_bits=*/settings_->reid_blocks_bits()[i],
- /*noise_probability=*/
- settings_->reid_blocks_noise_probabilities()[i]);
- if (!base::Contains(already_reported_reid_blocks_,
- block.reid_surface_key())) {
- surface_blocks_.emplace_back(std::move(block));
- }
- }
-}
-
-PrivacyBudgetReidScoreEstimator::~PrivacyBudgetReidScoreEstimator() = default;
-
-void PrivacyBudgetReidScoreEstimator::ProcessForReidScore(
- blink::IdentifiableSurface surface,
- blink::IdentifiableToken token) {
- DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- bool at_least_one_reported_block = false;
- for (auto block_itr = surface_blocks_.begin();
- block_itr != surface_blocks_.end();) {
- block_itr->Record(surface, token);
- if (block_itr->Full()) {
- // Report new Reid surface if the map is full.
-
- // Compute the Reid hash for the needed Reid block.
- uint64_t reid_hash = block_itr->ComputeHashForReidScore();
-
- // Report to UKM in a separate task in order to avoid re-entrancy.
- base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
- FROM_HERE, base::BindOnce(&ReportHashForReidScore,
- block_itr->reid_surface_key(), reid_hash));
-
- // Remove this block from the map, and store the information in the
- // PrefService, since we want to report a hash for a block only once.
- DCHECK(!base::Contains(already_reported_reid_blocks_,
- block_itr->reid_surface_key()));
- already_reported_reid_blocks_.push_back(block_itr->reid_surface_key());
- // Note: The returned `block_itr` points to the next element in the
- // vector.
- block_itr = surface_blocks_.erase(block_itr);
-
- at_least_one_reported_block = true;
- } else {
- ++block_itr;
- }
- }
-
- if (at_least_one_reported_block)
- WriteReportedReidBlocksToPrefs();
-}
-
-void PrivacyBudgetReidScoreEstimator::WriteReportedReidBlocksToPrefs() const {
- DCHECK(!already_reported_reid_blocks_.empty());
- pref_service_->SetString(
- prefs::kPrivacyBudgetReportedReidBlocks,
- EncodeIdentifiabilityFieldTrialParam(already_reported_reid_blocks_));
-}
-
-void PrivacyBudgetReidScoreEstimator::ResetPersistedState() {
- DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- pref_service_->ClearPref(prefs::kPrivacyBudgetReportedReidBlocks);
- already_reported_reid_blocks_.clear();
- surface_blocks_.clear();
- Init();
-}
diff --git a/chrome/browser/privacy_budget/privacy_budget_reid_score_estimator.h b/chrome/browser/privacy_budget/privacy_budget_reid_score_estimator.h
deleted file mode 100644
index 67d5e34..0000000
--- a/chrome/browser/privacy_budget/privacy_budget_reid_score_estimator.h
+++ /dev/null
@@ -1,140 +0,0 @@
-// Copyright 2022 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_PRIVACY_BUDGET_PRIVACY_BUDGET_REID_SCORE_ESTIMATOR_H_
-#define CHROME_BROWSER_PRIVACY_BUDGET_PRIVACY_BUDGET_REID_SCORE_ESTIMATOR_H_
-
-#include <list>
-
-#include "base/containers/flat_map.h"
-#include "base/sequence_checker.h"
-#include "chrome/browser/privacy_budget/identifiability_study_group_settings.h"
-#include "chrome/common/privacy_budget/types.h"
-#include "third_party/blink/public/common/privacy_budget/identifiable_surface.h"
-#include "third_party/blink/public/common/privacy_budget/identifiable_token.h"
-
-class PrefService;
-
-// Temporary surface-value storage to estimate the Reid score of specified
-// surface set.
-class PrivacyBudgetReidScoreEstimator {
- public:
- // `state_settings` and `pref_service` pointees must outlive `this`.
- explicit PrivacyBudgetReidScoreEstimator(
- const IdentifiabilityStudyGroupSettings* state_settings,
- PrefService* pref_service);
-
- void Init();
-
- PrivacyBudgetReidScoreEstimator(const PrivacyBudgetReidScoreEstimator&) =
- delete;
- PrivacyBudgetReidScoreEstimator& operator=(
- const PrivacyBudgetReidScoreEstimator&) = delete;
-
- ~PrivacyBudgetReidScoreEstimator();
-
- // Searches the storage for the surface.
- // If found, it updates its value to the token sent.
- void ProcessForReidScore(blink::IdentifiableSurface surface,
- blink::IdentifiableToken token);
-
- void ResetPersistedState();
-
- private:
- // ReidBlockStorage is a helper class which stores a list of surfaces
- // for which we want to estimate the Reid score, i.e. corresponding to a Reid
- // block.
- class ReidBlockStorage {
- public:
- ReidBlockStorage(const IdentifiableSurfaceList& surface_list,
- uint64_t salt_range,
- int number_of_bits,
- double noise_probability);
- ~ReidBlockStorage();
-
- ReidBlockStorage(const ReidBlockStorage&) = delete;
- ReidBlockStorage& operator=(const ReidBlockStorage&) = delete;
-
- ReidBlockStorage(ReidBlockStorage&&);
- ReidBlockStorage& operator=(ReidBlockStorage&&);
-
- // Returns whether we know the values of all the surfaces in the block.
- bool Full() const;
-
- // If `surface` is one of the surfaces of this block, stores `value`
- // for `surface`. If we already have a value for `surface`, the old value
- // will be discarded. Does nothing if `surface` does not belong to this
- // block.
- void Record(blink::IdentifiableSurface surface,
- blink::IdentifiableToken value);
-
- // Compute the hash for estimating the REID score.
- uint64_t ComputeHashForReidScore();
-
- // Returns the values of the surfaces. Can be called only if full.
- std::vector<blink::IdentifiableToken> GetValues() const;
-
- // Returns the key to be used for reporting the synthetic surface
- // corresponding to this Reid block.
- blink::IdentifiableSurface reid_surface_key() const {
- return reid_surface_key_;
- }
-
- // Can be called only if full.
- uint64_t salt_range() const;
-
- // Can be called only if full.
- int number_of_bits() const;
-
- // Can be called only if full.
- double noise_probability() const;
-
- private:
- // The surfaces which we want to track in this block, together with their
- // values (if we recorded them already).
- base::flat_map<blink::IdentifiableSurface,
- absl::optional<blink::IdentifiableToken>>
- surfaces_;
-
- // Keeps track of the number of surfaces for which we have recorded a value
- // in this block.
- size_t recorded_values_count_ = 0;
-
- // A random salt for this block will be chosen in the interval
- // [0,`salt_range_`].
- uint64_t salt_range_;
-
- // The number of bits that will be reported for this block.
- int number_of_bits_;
-
- // The probability of reporting a random value, instead of the real hash,
- // for this block.
- double noise_probability_;
-
- // The surface key under which the hash for this Reid block should be
- // reported.
- blink::IdentifiableSurface reid_surface_key_;
- };
-
- void WriteReportedReidBlocksToPrefs() const
- VALID_CONTEXT_REQUIRED(sequence_checker_);
-
- // Keeps track of the blocks for which we want to compute the Reid score.
- std::list<ReidBlockStorage> surface_blocks_
- GUARDED_BY_CONTEXT(sequence_checker_);
-
- // Keeps track of the Reid blocks which where already reported.
- IdentifiableSurfaceList already_reported_reid_blocks_
- GUARDED_BY_CONTEXT(sequence_checker_);
-
- // `settings_` pointee must outlive `this`.
- raw_ptr<const IdentifiabilityStudyGroupSettings> settings_;
-
- // `pref_service_` pointee must outlive `this`. Used for persistent state.
- raw_ptr<PrefService> pref_service_ = nullptr;
-
- SEQUENCE_CHECKER(sequence_checker_);
-};
-
-#endif // CHROME_BROWSER_PRIVACY_BUDGET_PRIVACY_BUDGET_REID_SCORE_ESTIMATOR_H_
diff --git a/chrome/browser/privacy_budget/privacy_budget_reid_score_estimator_unittest.cc b/chrome/browser/privacy_budget/privacy_budget_reid_score_estimator_unittest.cc
deleted file mode 100644
index d901e70..0000000
--- a/chrome/browser/privacy_budget/privacy_budget_reid_score_estimator_unittest.cc
+++ /dev/null
@@ -1,326 +0,0 @@
-// Copyright 2022 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/privacy_budget/privacy_budget_reid_score_estimator.h"
-
-#include <cstdint>
-
-#include "base/barrier_closure.h"
-#include "base/containers/flat_set.h"
-#include "base/rand_util.h"
-#include "base/run_loop.h"
-#include "base/test/task_environment.h"
-#include "chrome/browser/privacy_budget/identifiability_study_group_settings.h"
-#include "chrome/browser/privacy_budget/privacy_budget_prefs.h"
-#include "components/prefs/testing_pref_service.h"
-#include "components/ukm/test_ukm_recorder.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/blink/public/common/privacy_budget/identifiable_surface.h"
-#include "third_party/blink/public/common/privacy_budget/identifiable_token.h"
-#include "third_party/blink/public/common/privacy_budget/scoped_identifiability_test_sample_collector.h"
-
-class PrivacyBudgetReidScoreEstimatorStandaloneTest
- : public ::testing::TestWithParam<std::tuple<uint32_t, int, int, bool>> {
- public:
- PrivacyBudgetReidScoreEstimatorStandaloneTest() {
- prefs::RegisterPrivacyBudgetPrefs(pref_service_.registry());
- }
-
- TestingPrefServiceSimple* pref_service() { return &pref_service_; }
-
- void RunUntilIdle() { task_environment_.RunUntilIdle(); }
-
- void ProcessReidRecords(IdentifiabilityStudyGroupSettings* settings,
- bool fixedToken) {
- for (int i = 0; i < kNumIterations; ++i) {
- PrivacyBudgetReidScoreEstimator reid_storage(settings, pref_service());
- reid_storage.ResetPersistedState();
- reid_storage.Init();
- int64_t token1 =
- fixedToken ? 1 : static_cast<int64_t>(base::RandUint64());
- int64_t token2 =
- fixedToken ? 2 : static_cast<int64_t>(base::RandUint64());
- // Process values for 2 surfaces.
- reid_storage.ProcessForReidScore(kSurface_1,
- blink::IdentifiableToken(token1));
- reid_storage.ProcessForReidScore(kSurface_2,
- blink::IdentifiableToken(token2));
- }
- }
-
- // Example surfaces for testing.
- const blink::IdentifiableSurface kSurface_1 =
- blink::IdentifiableSurface::FromMetricHash(2077075229u);
- const blink::IdentifiableSurface kSurface_2 =
- blink::IdentifiableSurface::FromMetricHash(1122849309u);
- const blink::IdentifiableSurface kSurface_3 =
- blink::IdentifiableSurface::FromMetricHash(1122849311u);
-
- // Expected Reid surface key to be reported based on the example surfaces
- // defined (kSurface_1, kSurface_2) using the function
- // IdentifiableSurface::FromTypeAndToken() with type
- // IdentifiableSurface::Type::kReidScoreEstimator.
- const uint64_t kExpectedSurface = 11332616172707669541u;
-
- const int kNumIterations = 50;
-
- private:
- TestingPrefServiceSimple pref_service_;
- base::test::SingleThreadTaskEnvironment task_environment_;
-};
-
-TEST_F(PrivacyBudgetReidScoreEstimatorStandaloneTest,
- ReidEstimatorWrongParameters) {
- auto settings = IdentifiabilityStudyGroupSettings::InitFrom(
- /*enabled=*/true,
- /*expected_surface_count=*/0,
- /*surface_budget=*/0,
- /*blocks=*/"",
- /*blocks_weights=*/"",
- /*allowed_random_types=*/"",
- /*reid_blocks=*/"2077075229;1122849309,2077075230;1122849310",
- /*reid_blocks_salts_ranges=*/"1000000", /*Missing Salt!*/
- /*reid_blocks_bits=*/"1,2",
- /*reid_blocks_noise_probabilities=*/"0,0");
-
- PrivacyBudgetReidScoreEstimator reid_storage(&settings, pref_service());
- reid_storage.ResetPersistedState();
- // Test passes if initializing the Reid estimator is skipped and does not
- // crash.
- reid_storage.Init();
-}
-
-TEST_P(PrivacyBudgetReidScoreEstimatorStandaloneTest,
- ReportReidwithParameters) {
- const auto [salt_ranges, bits, noise, fixed_token] = GetParam();
- auto settings = IdentifiabilityStudyGroupSettings::InitFrom(
- /*enabled=*/true,
- /*expected_surface_count=*/0,
- /*surface_budget=*/0,
- /*blocks=*/"",
- /*blocks_weights=*/"",
- /*allowed_random_types=*/"",
- /*reid_blocks=*/"2077075229;1122849309",
- /*reid_blocks_salts_ranges=*/base::NumberToString(salt_ranges),
- /*reid_blocks_bits=*/base::NumberToString(bits),
- /*reid_blocks_noise_probabilities=*/base::NumberToString(noise));
-
- ukm::TestAutoSetUkmRecorder test_recorder;
- base::RunLoop run_loop;
- test_recorder.SetOnAddEntryCallback(
- ukm::builders::Identifiability::kEntryName,
- base::BarrierClosure(kNumIterations, run_loop.QuitClosure()));
- blink::test::ScopedIdentifiabilityTestSampleCollector collector;
- ProcessReidRecords(&settings, fixed_token);
- // This should let the async tasks run.
- run_loop.Run();
- const auto& entries = collector.entries();
- bool has_value_0 = false;
- bool has_value_1 = false;
- base::flat_set<uint32_t> reid_results;
- int count = 0;
- for (auto& entry : entries) {
- for (auto& metric : entry.metrics) {
- auto surface = metric.surface;
- if (surface.GetType() ==
- blink::IdentifiableSurface::Type::kReidScoreEstimator) {
- EXPECT_EQ(metric.surface.ToUkmMetricHash(), kExpectedSurface);
- ++count;
- uint64_t hash = static_cast<uint64_t>(metric.value.ToUkmMetricValue());
- uint32_t reid_bits = hash & 0xFFFFFFFF;
- if (noise == 1) {
- // Result should be noise i.e. didn't appear before.
- EXPECT_FALSE(reid_results.contains(reid_bits));
- reid_results.insert(reid_bits);
- } else {
- EXPECT_TRUE(reid_bits == 0 || reid_bits == 1);
- if (reid_bits == 0)
- has_value_0 = true;
- else if (reid_bits == 1)
- has_value_1 = true;
- }
- uint32_t salt = (hash >> 32);
- EXPECT_TRUE((salt >= 0) && (salt < salt_ranges));
- }
- }
- }
- EXPECT_EQ(count, kNumIterations);
- // Since the 1 bit should be random, the probability of it being always 0 or
- // always 1 is 2/(2^kNumIterations), hence it should be negligible.
- if (noise != 1) {
- EXPECT_TRUE(has_value_0);
- EXPECT_TRUE(has_value_1);
- }
-}
-
-INSTANTIATE_TEST_SUITE_P(
- PrivacyBudgetReidScoreEstimatorParameterizedTest,
- PrivacyBudgetReidScoreEstimatorStandaloneTest,
- ::testing::Values(
- /*RandomSaltFixedTokens*/ std::make_tuple(1000000, 1, 0, true),
- /*FixedSaltRandomTokens*/ std::make_tuple(1, 1, 0, false),
- /*AllNoise*/ std::make_tuple(1, 32, 1, true)));
-
-TEST_F(PrivacyBudgetReidScoreEstimatorStandaloneTest, ReportingMultiBlockReid) {
- auto settings = IdentifiabilityStudyGroupSettings::InitFrom(
- /*enabled=*/true,
- /*expected_surface_count=*/0,
- /*surface_budget=*/0,
- /*blocks=*/"",
- /*blocks_weights=*/"",
- /*allowed_random_types=*/"",
- /*reid_blocks=*/
- "2077075229;1122849309;1122849311,1122849310;1122849311,2077075229",
- /*reid_blocks_salts_ranges=*/"1,1000000,1",
- /*reid_blocks_bits=*/"10,1,1",
- /*reid_blocks_noise_probabilities=*/"0,0,0");
-
- ukm::TestAutoSetUkmRecorder test_recorder;
-
- PrivacyBudgetReidScoreEstimator reid_storage(&settings, pref_service());
- reid_storage.Init();
-
- base::RunLoop run_loop;
- test_recorder.SetOnAddEntryCallback(
- ukm::builders::Identifiability::kEntryName,
- BarrierClosure(2u, run_loop.QuitClosure()));
- blink::test::ScopedIdentifiabilityTestSampleCollector collector;
-
- // Process values for the surfaces.
- reid_storage.ProcessForReidScore(kSurface_1, blink::IdentifiableToken(1));
- reid_storage.ProcessForReidScore(kSurface_2, blink::IdentifiableToken(2));
- reid_storage.ProcessForReidScore(kSurface_3, blink::IdentifiableToken(3));
-
- // Get these values using IdentifiableSurface::FromTypeAndToken() with type
- // IdentifiableSurface::Type::kReidScoreEstimator.
- uint64_t expected_surface_key_for_block_0 = 11985663064608009253u;
- uint64_t expected_surface_key_for_block_2 = 17524302200237928997u;
-
- // Get the expected values of Reid hashes. The salt is forced to 0.
- // The surfaces will be sorted in ReidBlockStorage so the hash will be
- // computed based on the surface key order.
- std::vector<uint64_t> tokens_0 = {0, 2, 3, 1};
- std::vector<uint64_t> tokens_2 = {0, 1};
- uint64_t reid_hash_0 = blink::IdentifiabilityDigestOfBytes(
- base::as_bytes(base::make_span(tokens_0)));
- uint64_t reid_hash_2 = blink::IdentifiabilityDigestOfBytes(
- base::as_bytes(base::make_span(tokens_2)));
-
- // Get the lower b bits required.
- uint64_t reid_bits_0 = reid_hash_0 & ((1 << 10) - 1);
- uint64_t reid_bits_2 = reid_hash_2 % 2;
-
- // This should let the async tasks run.
- run_loop.Run();
-
- const auto& entries = collector.entries();
- EXPECT_EQ(entries.size(), 2u);
- EXPECT_EQ(entries[0].metrics[0].surface.ToUkmMetricHash(),
- expected_surface_key_for_block_2);
- uint64_t value_2 =
- static_cast<uint64_t>(entries[0].metrics[0].value.ToUkmMetricValue());
- EXPECT_EQ(value_2, reid_bits_2);
- EXPECT_EQ(entries[1].metrics[0].surface.ToUkmMetricHash(),
- expected_surface_key_for_block_0);
- uint64_t value_0 =
- static_cast<uint64_t>(entries[1].metrics[0].value.ToUkmMetricValue());
- EXPECT_EQ(value_0, reid_bits_0);
-}
-
-TEST_F(PrivacyBudgetReidScoreEstimatorStandaloneTest,
- ReidHashIsReportedOnlyOnce) {
- auto settings = IdentifiabilityStudyGroupSettings::InitFrom(
- /*enabled=*/true,
- /*expected_surface_count=*/0,
- /*surface_budget=*/0,
- /*blocks=*/"",
- /*blocks_weights=*/"",
- /*allowed_random_types=*/"",
- /*reid_blocks=*/"2077075229;1122849309",
- /*reid_blocks_salts_ranges=*/"1000000",
- /*reid_blocks_bits=*/"1",
- /*reid_blocks_noise_probabilities=*/"0");
-
- ukm::TestAutoSetUkmRecorder test_recorder;
-
- {
- PrivacyBudgetReidScoreEstimator reid_storage(&settings, pref_service());
- reid_storage.Init();
-
- {
- base::RunLoop run_loop;
- test_recorder.SetOnAddEntryCallback(
- ukm::builders::Identifiability::kEntryName, run_loop.QuitClosure());
- blink::test::ScopedIdentifiabilityTestSampleCollector collector;
-
- // Process values for 2 surfaces.
- reid_storage.ProcessForReidScore(kSurface_1, blink::IdentifiableToken(1));
- reid_storage.ProcessForReidScore(kSurface_2, blink::IdentifiableToken(2));
-
- // This should let the async tasks run.
- run_loop.Run();
-
- const auto& entries = collector.entries();
- EXPECT_EQ(entries.size(), 1u);
- EXPECT_EQ(entries[0].metrics.size(), 1u);
- EXPECT_EQ(entries[0].metrics[0].surface.ToUkmMetricHash(),
- kExpectedSurface);
- }
-
- // Now check that the reid hash is not reported again if we see again the
- // two surfaces.
- {
- blink::test::ScopedIdentifiabilityTestSampleCollector collector;
-
- reid_storage.ProcessForReidScore(kSurface_1, blink::IdentifiableToken(1));
- reid_storage.ProcessForReidScore(kSurface_2, blink::IdentifiableToken(2));
-
- RunUntilIdle();
- const auto& entries = collector.entries();
- EXPECT_TRUE(entries.empty());
- }
- }
-
- // Even if we instantiate a new PrivacyBudgetReidScoreEstimator, the Reid
- // hash is not reported again because of the information persisted in the
- // PrefService.
- {
- PrivacyBudgetReidScoreEstimator reid_storage(&settings, pref_service());
- reid_storage.Init();
- {
- blink::test::ScopedIdentifiabilityTestSampleCollector collector;
-
- reid_storage.ProcessForReidScore(kSurface_1, blink::IdentifiableToken(1));
- reid_storage.ProcessForReidScore(kSurface_2, blink::IdentifiableToken(2));
-
- RunUntilIdle();
-
- const auto& entries = collector.entries();
- EXPECT_TRUE(entries.empty());
- }
-
- // If we reset the persisted state, then the Reid hash will be reported
- // again.
- reid_storage.ResetPersistedState();
- reid_storage.Init();
-
- {
- base::RunLoop run_loop;
- test_recorder.SetOnAddEntryCallback(
- ukm::builders::Identifiability::kEntryName, run_loop.QuitClosure());
-
- blink::test::ScopedIdentifiabilityTestSampleCollector collector;
- reid_storage.ProcessForReidScore(kSurface_1, blink::IdentifiableToken(1));
- reid_storage.ProcessForReidScore(kSurface_2, blink::IdentifiableToken(2));
-
- run_loop.Run();
-
- const auto& entries = collector.entries();
- EXPECT_EQ(entries.size(), 1u);
- EXPECT_EQ(entries[0].metrics.size(), 1u);
- EXPECT_EQ(entries[0].metrics[0].surface.ToUkmMetricHash(),
- kExpectedSurface);
- }
- }
-}
diff --git a/chrome/browser/privacy_budget/privacy_budget_ukm_entry_filter.cc b/chrome/browser/privacy_budget/privacy_budget_ukm_entry_filter.cc
index 71edf9f..af02e84 100644
--- a/chrome/browser/privacy_budget/privacy_budget_ukm_entry_filter.cc
+++ b/chrome/browser/privacy_budget/privacy_budget_ukm_entry_filter.cc
@@ -46,10 +46,6 @@
blink::IdentifiableSurface::FromMetricHash(metric.first);
const blink::IdentifiableToken token = metric.second;
- // Update the Reid surface storage map.
- identifiability_study_state_->MaybeStoreValueForComputingReidScore(surface,
- token);
-
if (!blink::IdentifiabilityStudySettings::Get()->ShouldSampleSurface(
surface))
return true;