| 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
|
|
|