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/base64.h" | 7 #include "base/base64.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 DVLOG(2) << "Selected a new Rappor cohort: " << cohort; | 203 DVLOG(2) << "Selected a new Rappor cohort: " << cohort; |
204 pref_service_->SetInteger(prefs::kRapporCohortSeed, cohort); | 204 pref_service_->SetInteger(prefs::kRapporCohortSeed, cohort); |
205 return cohort; | 205 return cohort; |
206 } | 206 } |
207 | 207 |
208 std::string RapporService::LoadSecret() { | 208 std::string RapporService::LoadSecret() { |
209 std::string secret; | 209 std::string secret; |
210 std::string secret_base64 = pref_service_->GetString(prefs::kRapporSecret); | 210 std::string secret_base64 = pref_service_->GetString(prefs::kRapporSecret); |
211 if (!secret_base64.empty()) { | 211 if (!secret_base64.empty()) { |
212 bool decoded = base::Base64Decode(secret_base64, &secret); | 212 bool decoded = base::Base64Decode(secret_base64, &secret); |
213 if (decoded && secret_.size() == HmacByteVectorGenerator::kEntropyInputSize) | 213 if (decoded && secret.size() == HmacByteVectorGenerator::kEntropyInputSize) |
214 return secret; | 214 return secret; |
215 // If the preference fails to decode, or is the wrong size, it must be | 215 // If the preference fails to decode, or is the wrong size, it must be |
216 // corrupt, so continue as though it didn't exist yet and generate a new | 216 // corrupt, so continue as though it didn't exist yet and generate a new |
217 // one. | 217 // one. |
218 } | 218 } |
219 | 219 |
220 DVLOG(2) << "Generated a new Rappor secret."; | 220 DVLOG(2) << "Generated a new Rappor secret."; |
221 secret = HmacByteVectorGenerator::GenerateEntropyInput(); | 221 secret = HmacByteVectorGenerator::GenerateEntropyInput(); |
222 base::Base64Encode(secret, &secret_base64); | 222 base::Base64Encode(secret, &secret_base64); |
223 pref_service_->SetString(prefs::kRapporSecret, secret_base64); | 223 pref_service_->SetString(prefs::kRapporSecret, secret_base64); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 DCHECK_EQ(parameters.ToString(), metric->parameters().ToString()); | 294 DCHECK_EQ(parameters.ToString(), metric->parameters().ToString()); |
295 return metric; | 295 return metric; |
296 } | 296 } |
297 | 297 |
298 RapporMetric* new_metric = new RapporMetric(metric_name, parameters, cohort_); | 298 RapporMetric* new_metric = new RapporMetric(metric_name, parameters, cohort_); |
299 metrics_map_[metric_name] = new_metric; | 299 metrics_map_[metric_name] = new_metric; |
300 return new_metric; | 300 return new_metric; |
301 } | 301 } |
302 | 302 |
303 } // namespace rappor | 303 } // namespace rappor |
OLD | NEW |