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

Side by Side Diff: components/rappor/rappor_metric.cc

Issue 509203002: Create a mechanism for reporting rappor metrics from non-UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 unified diff | Download patch
OLDNEW
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 // Since cohort_seed is in the range [0, kMaxCohorts), num_cohorts should
25 // divide kMaxCohorts for each cohort to have equal weight.
26 DCHECK_EQ(RapporParameters::kMaxCohorts % parameters.num_cohorts, 0);
Alexei Svitkine (slow) 2014/10/03 20:28:50 Nit: Expected value goes on the left for DCHECK_EQ
Steven Holte 2014/10/03 21:41:11 Done.
24 } 27 }
25 28
26 RapporMetric::~RapporMetric() {} 29 RapporMetric::~RapporMetric() {}
27 30
28 void RapporMetric::AddSample(const std::string& str) { 31 void RapporMetric::AddSample(const std::string& str) {
29 ++sample_count_; 32 ++sample_count_;
30 // Replace the previous sample with a 1 in sample_count_ chance so that each 33 // Replace the previous sample with a 1 in sample_count_ chance so that each
31 // sample has equal probability of being reported. 34 // sample has equal probability of being reported.
32 if (base::RandGenerator(sample_count_) == 0) { 35 if (base::RandGenerator(sample_count_) == 0) {
33 bloom_filter_.SetString(str); 36 bloom_filter_.SetString(str);
(...skipping 30 matching lines...) Expand all
64 // the outcome of flipping a zero coin for the zero bits in that data, and of 67 // 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. 68 // 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); 69 return *ByteVectorMerge(*fake_and_redacted_bits, zero_coins, &one_coins);
67 } 70 }
68 71
69 void RapporMetric::SetBytesForTesting(const ByteVector& bytes) { 72 void RapporMetric::SetBytesForTesting(const ByteVector& bytes) {
70 bloom_filter_.SetBytesForTesting(bytes); 73 bloom_filter_.SetBytesForTesting(bytes);
71 } 74 }
72 75
73 } // namespace rappor 76 } // namespace rappor
OLDNEW
« no previous file with comments | « no previous file | components/rappor/rappor_parameters.h » ('j') | components/rappor/rappor_service.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698