Chromium Code Reviews| Index: components/rappor/rappor_metric.cc |
| diff --git a/components/rappor/rappor_metric.cc b/components/rappor/rappor_metric.cc |
| index b4bd950af9d1741210b81dcdf54bbd893b1b63b2..c4c683d77a770a4f03286426d1cccf9d3c0f3a8e 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 { |
| @@ -24,7 +25,13 @@ RapporMetric::RapporMetric(const std::string& metric_name, |
| RapporMetric::~RapporMetric() {} |
| void RapporMetric::AddSample(const std::string& str) { |
| - bloom_filter_.AddString(str); |
| + ++sample_count; |
|
Alexei Svitkine (slow)
2014/07/30 17:12:47
Should be sample_count_, not sample_count.
Steven Holte
2014/08/04 23:30:26
Done.
|
| + // Replace the previous sample with a 1 in sample_count chance so that each |
|
Alexei Svitkine (slow)
2014/07/30 17:12:47
Nit: sample_count_.
Steven Holte
2014/08/04 23:30:26
Done.
|
| + // sample has equal probability of being reported. |
| + if (base::RandGenerator(sample_count) == 0) { |
| + bloom_filter_.Clear(); |
| + bloom_filter_.AddString(str); |
|
Alexei Svitkine (slow)
2014/07/30 17:12:47
Any reason why we can't just change AddString() to
Steven Holte
2014/08/04 23:30:26
Done.
|
| + } |
| } |
| 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 |