Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Unified Diff: components/rappor/rappor_metric.cc

Issue 419683014: Randomly select a single rappor sample when more than one is collected. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/rappor/rappor_metric.h ('k') | components/rappor/rappor_metric_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/rappor/rappor_metric.cc
diff --git a/components/rappor/rappor_metric.cc b/components/rappor/rappor_metric.cc
index b4bd950af9d1741210b81dcdf54bbd893b1b63b2..92765de6e89b79e7c3c02873c2c6403b53fb2fea 100644
--- a/components/rappor/rappor_metric.cc
+++ b/components/rappor/rappor_metric.cc
@@ -5,6 +5,7 @@
#include "components/rappor/rappor_metric.h"
#include "base/logging.h"
+#include "base/rand_util.h"
namespace rappor {
@@ -13,6 +14,7 @@ RapporMetric::RapporMetric(const std::string& metric_name,
int32_t cohort_seed)
: metric_name_(metric_name),
parameters_(parameters),
+ sample_count_(0),
bloom_filter_(parameters.bloom_filter_size_bytes,
parameters.bloom_filter_hash_function_count,
(cohort_seed % parameters.num_cohorts) *
@@ -24,7 +26,12 @@ RapporMetric::RapporMetric(const std::string& metric_name,
RapporMetric::~RapporMetric() {}
void RapporMetric::AddSample(const std::string& str) {
- bloom_filter_.AddString(str);
+ ++sample_count_;
+ // Replace the previous sample with a 1 in sample_count_ chance so that each
+ // sample has equal probability of being reported.
+ if (base::RandGenerator(sample_count_) == 0) {
+ bloom_filter_.SetString(str);
+ }
}
ByteVector RapporMetric::GetReport(const std::string& secret) const {
@@ -59,4 +66,8 @@ ByteVector RapporMetric::GetReport(const std::string& secret) const {
return *ByteVectorMerge(*fake_and_redacted_bits, zero_coins, &one_coins);
}
+void RapporMetric::SetBytesForTesting(const ByteVector& bytes) {
+ bloom_filter_.SetBytesForTesting(bytes);
+}
+
} // namespace rappor
« no previous file with comments | « components/rappor/rappor_metric.h ('k') | components/rappor/rappor_metric_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698