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_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 Loading... |
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 /* Flag bytes */, |
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 /* Flag bytes */, |
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 */, |
67 rappor::PROBABILITY_25 /* Zero coin probability */, | 69 rappor::PROBABILITY_25 /* Zero coin probability */, |
68 COARSE_LEVEL /* Recording level */}, | 70 COARSE_LEVEL /* Recording level */}, |
69 }; | 71 }; |
70 | 72 |
71 } // namespace | 73 } // namespace |
72 | 74 |
73 RapporService::RapporService( | 75 RapporService::RapporService( |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 RapporMetric* metric = it->second; | 254 RapporMetric* metric = it->second; |
253 DCHECK_EQ(parameters.ToString(), metric->parameters().ToString()); | 255 DCHECK_EQ(parameters.ToString(), metric->parameters().ToString()); |
254 return metric; | 256 return metric; |
255 } | 257 } |
256 | 258 |
257 RapporMetric* new_metric = new RapporMetric(metric_name, parameters, cohort_); | 259 RapporMetric* new_metric = new RapporMetric(metric_name, parameters, cohort_); |
258 metrics_map_[metric_name] = new_metric; | 260 metrics_map_[metric_name] = new_metric; |
259 return new_metric; | 261 return new_metric; |
260 } | 262 } |
261 | 263 |
| 264 scoped_ptr<Sample> RapporService::MakeSampleObj(RapporType type) { |
| 265 DCHECK(IsInitialized()); |
| 266 return scoped_ptr<Sample>( |
| 267 new Sample(cohort_, kRapporParametersForType[type])); |
| 268 } |
| 269 |
| 270 void RapporService::RecordSampleObj(const std::string& metric_name, |
| 271 scoped_ptr<Sample> sample) { |
| 272 if (is_incognito_callback_.Run()) { |
| 273 DVLOG(2) << "Metric not logged due to incognito mode."; |
| 274 return; |
| 275 } |
| 276 // Skip this metric if it's reporting level is less than the enabled |
| 277 // reporting level. |
| 278 if (recording_level_ < sample->parameters().recording_level) { |
| 279 DVLOG(2) << "Metric not logged due to recording_level " |
| 280 << recording_level_ << " < " |
| 281 << sample->parameters().recording_level; |
| 282 return; |
| 283 } |
| 284 sampler_.AddSample(metric_name, sample.Pass()); |
| 285 } |
| 286 |
262 } // namespace rappor | 287 } // namespace rappor |
OLD | NEW |