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

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

Issue 848823002: Fix a bug in RapporService::LoadSecret (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698