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

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

Issue 1058333002: Multi-dimension rappor metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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_service.h" 5 #include "components/rappor/rappor_service.h"
6 6
7 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "components/metrics/metrics_hashes.h" 10 #include "components/metrics/metrics_hashes.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 return GURL(server_url); 45 return GURL(server_url);
46 else 46 else
47 return GURL(kDefaultServerUrl); 47 return GURL(kDefaultServerUrl);
48 } 48 }
49 49
50 const RapporParameters kRapporParametersForType[NUM_RAPPOR_TYPES] = { 50 const RapporParameters kRapporParametersForType[NUM_RAPPOR_TYPES] = {
51 // ETLD_PLUS_ONE_RAPPOR_TYPE 51 // ETLD_PLUS_ONE_RAPPOR_TYPE
52 {128 /* Num cohorts */, 52 {128 /* Num cohorts */,
53 16 /* Bloom filter size bytes */, 53 16 /* Bloom filter size bytes */,
54 2 /* Bloom filter hash count */, 54 2 /* Bloom filter hash count */,
55 0,
55 rappor::PROBABILITY_50 /* Fake data probability */, 56 rappor::PROBABILITY_50 /* Fake data probability */,
56 rappor::PROBABILITY_50 /* Fake one probability */, 57 rappor::PROBABILITY_50 /* Fake one probability */,
57 rappor::PROBABILITY_75 /* One coin probability */, 58 rappor::PROBABILITY_75 /* One coin probability */,
58 rappor::PROBABILITY_25 /* Zero coin probability */, 59 rappor::PROBABILITY_25 /* Zero coin probability */,
59 FINE_LEVEL /* Recording level */}, 60 FINE_LEVEL /* Recording level */},
60 // COARSE_RAPPOR_TYPE 61 // COARSE_RAPPOR_TYPE
61 {128 /* Num cohorts */, 62 {128 /* Num cohorts */,
62 1 /* Bloom filter size bytes */, 63 1 /* Bloom filter size bytes */,
63 2 /* Bloom filter hash count */, 64 2 /* Bloom filter hash count */,
65 0,
64 rappor::PROBABILITY_50 /* Fake data probability */, 66 rappor::PROBABILITY_50 /* Fake data probability */,
65 rappor::PROBABILITY_50 /* Fake one probability */, 67 rappor::PROBABILITY_50 /* Fake one probability */,
66 rappor::PROBABILITY_75 /* One coin probability */, 68 rappor::PROBABILITY_75 /* One coin probability */,
69 rappor::PROBABILITY_25 /* Zero coin probability */,
70 COARSE_LEVEL /* Recording level */},
71 // STRING_W_FLAGS_SB_RAPPOR_TYPE
72 {128 /* Num cohorts */,
73 1 /* Bloom filter size bytes */,
74 2 /* Bloom filter hash count */,
75 1,
76 rappor::PROBABILITY_50 /* Fake data probability */,
77 rappor::PROBABILITY_50 /* Fake one probability */,
78 rappor::PROBABILITY_75 /* One coin probability */,
67 rappor::PROBABILITY_25 /* Zero coin probability */, 79 rappor::PROBABILITY_25 /* Zero coin probability */,
68 COARSE_LEVEL /* Recording level */}, 80 COARSE_LEVEL /* Recording level */},
69 }; 81 };
70 82
71 } // namespace 83 } // namespace
72 84
73 RapporService::RapporService( 85 RapporService::RapporService(
74 PrefService* pref_service, 86 PrefService* pref_service,
75 const base::Callback<bool(void)> is_incognito_callback) 87 const base::Callback<bool(void)> is_incognito_callback)
76 : pref_service_(pref_service), 88 : pref_service_(pref_service),
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 STLDeleteValues(&metrics_map_); 217 STLDeleteValues(&metrics_map_);
206 return true; 218 return true;
207 } 219 }
208 220
209 bool RapporService::IsInitialized() const { 221 bool RapporService::IsInitialized() const {
210 return cohort_ >= 0; 222 return cohort_ >= 0;
211 } 223 }
212 224
213 void RapporService::RecordSample(const std::string& metric_name, 225 void RapporService::RecordSample(const std::string& metric_name,
214 RapporType type, 226 RapporType type,
215 const std::string& sample) { 227 const std::string& str) {
216 // Ignore the sample if the service hasn't started yet. 228 // Ignore the sample if the service hasn't started yet.
217 if (!IsInitialized()) 229 if (!IsInitialized())
218 return; 230 return;
219 DCHECK_LT(type, NUM_RAPPOR_TYPES); 231 DCHECK_LT(type, NUM_RAPPOR_TYPES);
220 const RapporParameters& parameters = kRapporParametersForType[type]; 232 const RapporParameters& parameters = kRapporParametersForType[type];
221 DVLOG(2) << "Recording sample \"" << sample 233 DVLOG(2) << "Recording sample \"" << str
222 << "\" for metric \"" << metric_name 234 << "\" for metric \"" << metric_name
223 << "\" of type: " << type; 235 << "\" of type: " << type;
236 Sample sample;
237 DCHECK_EQ(0, parameters.flag_bytes);
238 SetSampleBits(parameters, cohort_, str, 0, &sample);
239 RecordSampleInternal(metric_name, parameters, sample);
240 }
241
242 void RapporService::RecordStringAndFlags(const std::string& metric_name,
243 RapporType type,
244 const std::string& str,
245 uint64_t flags) {
246 // Ignore the sample if the service hasn't started yet.
247 if (!IsInitialized())
248 return;
249 DCHECK_LT(type, NUM_RAPPOR_TYPES);
250 const RapporParameters& parameters = kRapporParametersForType[type];
251 DVLOG(2) << "Recording sample \"" << str << "\"," << flags
252 << " for metric \"" << metric_name
253 << "\" of type: " << type;
254 Sample sample;
255 SetSampleBits(parameters, cohort_, str, flags, &sample);
224 RecordSampleInternal(metric_name, parameters, sample); 256 RecordSampleInternal(metric_name, parameters, sample);
225 } 257 }
226 258
227 void RapporService::RecordSampleInternal(const std::string& metric_name, 259 void RapporService::RecordSampleInternal(const std::string& metric_name,
228 const RapporParameters& parameters, 260 const RapporParameters& parameters,
229 const std::string& sample) { 261 const Sample& sample) {
230 DCHECK(IsInitialized()); 262 DCHECK(IsInitialized());
231 if (is_incognito_callback_.Run()) { 263 if (is_incognito_callback_.Run()) {
232 DVLOG(2) << "Metric not logged due to incognito mode."; 264 DVLOG(2) << "Metric not logged due to incognito mode.";
233 return; 265 return;
234 } 266 }
235 // Skip this metric if it's reporting level is less than the enabled 267 // Skip this metric if it's reporting level is less than the enabled
236 // reporting level. 268 // reporting level.
237 if (recording_level_ < parameters.recording_level) { 269 if (recording_level_ < parameters.recording_level) {
238 DVLOG(2) << "Metric not logged due to recording_level " 270 DVLOG(2) << "Metric not logged due to recording_level "
239 << recording_level_ << " < " << parameters.recording_level; 271 << recording_level_ << " < " << parameters.recording_level;
240 return; 272 return;
241 } 273 }
242 RapporMetric* metric = LookUpMetric(metric_name, parameters); 274 RapporMetric* metric = LookUpMetric(metric_name, parameters);
243 metric->AddSample(sample); 275 metric->AddSample(sample);
244 } 276 }
245 277
246 RapporMetric* RapporService::LookUpMetric(const std::string& metric_name, 278 RapporMetric* RapporService::LookUpMetric(const std::string& metric_name,
247 const RapporParameters& parameters) { 279 const RapporParameters& parameters) {
248 DCHECK(IsInitialized()); 280 DCHECK(IsInitialized());
249 std::map<std::string, RapporMetric*>::const_iterator it = 281 std::map<std::string, RapporMetric*>::const_iterator it =
250 metrics_map_.find(metric_name); 282 metrics_map_.find(metric_name);
251 if (it != metrics_map_.end()) { 283 if (it != metrics_map_.end()) {
252 RapporMetric* metric = it->second; 284 RapporMetric* metric = it->second;
253 DCHECK_EQ(parameters.ToString(), metric->parameters().ToString()); 285 DCHECK_EQ(parameters.ToString(), metric->parameters().ToString());
254 return metric; 286 return metric;
255 } 287 }
256 288
257 RapporMetric* new_metric = new RapporMetric(metric_name, parameters, cohort_); 289 RapporMetric* new_metric = new RapporMetric(metric_name, parameters);
258 metrics_map_[metric_name] = new_metric; 290 metrics_map_[metric_name] = new_metric;
259 return new_metric; 291 return new_metric;
260 } 292 }
261 293
262 } // namespace rappor 294 } // namespace rappor
OLDNEW
« components/rappor/rappor_service.h ('K') | « components/rappor/rappor_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698