Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/rappor/rappor_metric.h" | 5 #include "components/rappor/rappor_metric.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 | 9 |
| 10 namespace rappor { | 10 namespace rappor { |
| 11 | 11 |
| 12 RapporMetric::RapporMetric(const std::string& metric_name, | 12 RapporMetric::RapporMetric(const std::string& metric_name, |
| 13 const RapporParameters& parameters, | 13 const RapporParameters& parameters, |
| 14 int32_t cohort_seed) | 14 int32_t cohort_seed) |
| 15 : metric_name_(metric_name), | 15 : metric_name_(metric_name), |
| 16 parameters_(parameters), | 16 parameters_(parameters), |
| 17 sample_count_(0), | 17 sample_count_(0), |
| 18 bloom_filter_(parameters.bloom_filter_size_bytes, | 18 bloom_filter_(parameters.bloom_filter_size_bytes, |
| 19 parameters.bloom_filter_hash_function_count, | 19 parameters.bloom_filter_hash_function_count, |
| 20 (cohort_seed % parameters.num_cohorts) * | 20 (cohort_seed % parameters.num_cohorts) * |
| 21 parameters.bloom_filter_hash_function_count) { | 21 parameters.bloom_filter_hash_function_count) { |
| 22 DCHECK_GE(cohort_seed, 0); | 22 DCHECK_GE(cohort_seed, 0); |
| 23 DCHECK_LT(cohort_seed, RapporParameters::kMaxCohorts); | 23 DCHECK_LT(cohort_seed, RapporParameters::kMaxCohorts); |
| 24 DCHECK_EQ(RapporParameters::kMaxCohorts % parameters.num_cohorts, 0); | |
|
jwd
2014/10/03 19:53:03
Can you add a comment about this in rappor_paramet
Steven Holte
2014/10/03 20:09:23
Done.
| |
| 24 } | 25 } |
| 25 | 26 |
| 26 RapporMetric::~RapporMetric() {} | 27 RapporMetric::~RapporMetric() {} |
| 27 | 28 |
| 28 void RapporMetric::AddSample(const std::string& str) { | 29 void RapporMetric::AddSample(const std::string& str) { |
| 29 ++sample_count_; | 30 ++sample_count_; |
| 30 // Replace the previous sample with a 1 in sample_count_ chance so that each | 31 // Replace the previous sample with a 1 in sample_count_ chance so that each |
| 31 // sample has equal probability of being reported. | 32 // sample has equal probability of being reported. |
| 32 if (base::RandGenerator(sample_count_) == 0) { | 33 if (base::RandGenerator(sample_count_) == 0) { |
| 33 bloom_filter_.SetString(str); | 34 bloom_filter_.SetString(str); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 64 // the outcome of flipping a zero coin for the zero bits in that data, and of | 65 // the outcome of flipping a zero coin for the zero bits in that data, and of |
| 65 // flipping a one coin for the one bits in that data, as the final report. | 66 // flipping a one coin for the one bits in that data, as the final report. |
| 66 return *ByteVectorMerge(*fake_and_redacted_bits, zero_coins, &one_coins); | 67 return *ByteVectorMerge(*fake_and_redacted_bits, zero_coins, &one_coins); |
| 67 } | 68 } |
| 68 | 69 |
| 69 void RapporMetric::SetBytesForTesting(const ByteVector& bytes) { | 70 void RapporMetric::SetBytesForTesting(const ByteVector& bytes) { |
| 70 bloom_filter_.SetBytesForTesting(bytes); | 71 bloom_filter_.SetBytesForTesting(bytes); |
| 71 } | 72 } |
| 72 | 73 |
| 73 } // namespace rappor | 74 } // namespace rappor |
| OLD | NEW |