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/variations/variations_seed_store.h" | 5 #include "components/variations/variations_seed_store.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
9 #include "base/numerics/safe_math.h" | 9 #include "base/numerics/safe_math.h" |
10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 VariationsSeedStore::VariationsSeedStore(PrefService* local_state) | 145 VariationsSeedStore::VariationsSeedStore(PrefService* local_state) |
146 : local_state_(local_state), seed_has_country_code_(false) { | 146 : local_state_(local_state), seed_has_country_code_(false) { |
147 } | 147 } |
148 | 148 |
149 VariationsSeedStore::~VariationsSeedStore() { | 149 VariationsSeedStore::~VariationsSeedStore() { |
150 } | 150 } |
151 | 151 |
152 bool VariationsSeedStore::LoadSeed(variations::VariationsSeed* seed) { | 152 bool VariationsSeedStore::LoadSeed(variations::VariationsSeed* seed) { |
153 invalid_base64_signature_.clear(); | 153 invalid_base64_signature_.clear(); |
154 | 154 |
155 if (!local_state_->HasPrefPath(prefs::kVariationsSeedSignature)) | |
156 ImportFirstRunJavaSeed(); | |
157 | |
155 std::string seed_data; | 158 std::string seed_data; |
156 if (!ReadSeedData(&seed_data)) | 159 if (!ReadSeedData(&seed_data)) |
157 return false; | 160 return false; |
158 | 161 |
159 const std::string base64_seed_signature = | 162 const std::string base64_seed_signature = |
160 local_state_->GetString(prefs::kVariationsSeedSignature); | 163 local_state_->GetString(prefs::kVariationsSeedSignature); |
161 const VerifySignatureResult result = | 164 const VerifySignatureResult result = |
162 VerifySeedSignature(seed_data, base64_seed_signature); | 165 VerifySeedSignature(seed_data, base64_seed_signature); |
163 if (result != VARIATIONS_SEED_SIGNATURE_ENUM_SIZE) { | 166 if (result != VARIATIONS_SEED_SIGNATURE_ENUM_SIZE) { |
164 UMA_HISTOGRAM_ENUMERATION("Variations.LoadSeedSignature", result, | 167 UMA_HISTOGRAM_ENUMERATION("Variations.LoadSeedSignature", result, |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED; | 332 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED; |
330 } | 333 } |
331 | 334 |
332 void VariationsSeedStore::ClearPrefs() { | 335 void VariationsSeedStore::ClearPrefs() { |
333 local_state_->ClearPref(prefs::kVariationsCompressedSeed); | 336 local_state_->ClearPref(prefs::kVariationsCompressedSeed); |
334 local_state_->ClearPref(prefs::kVariationsSeed); | 337 local_state_->ClearPref(prefs::kVariationsSeed); |
335 local_state_->ClearPref(prefs::kVariationsSeedDate); | 338 local_state_->ClearPref(prefs::kVariationsSeedDate); |
336 local_state_->ClearPref(prefs::kVariationsSeedSignature); | 339 local_state_->ClearPref(prefs::kVariationsSeedSignature); |
337 } | 340 } |
338 | 341 |
342 void VariationsSeedStore::ImportFirstRunJavaSeed() { | |
343 LOG(WARNING) << "variationsTracker: Trying to read seed from Java side"; | |
Steven Holte
2015/10/29 01:37:12
Remove or change this to
DVLOG(1) << "Importing f
Alexander Agulenko
2015/11/02 22:55:33
Done.
| |
344 std::string seed_data, seed_signature, seed_country; | |
Alexei Svitkine (slow)
2015/10/29 15:04:12
Nit: 1 param per line.
Alexander Agulenko
2015/11/02 22:55:33
Done.
| |
345 get_variations_first_run_seed_.Run(&seed_data, &seed_signature, | |
346 &seed_country); | |
347 | |
348 if (seed_data.empty()) { | |
349 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_EMPTY); | |
Steven Holte
2015/10/29 01:37:12
This should already get recorded by ReadSeedData (
Alexander Agulenko
2015/11/02 22:55:33
Done.
| |
350 return; | |
351 } | |
352 | |
353 // TODO (agulenko): Pull actual time from the response. | |
354 base::Time current_time = base::Time::Now(); | |
355 | |
356 // TODO(agulenko): Support gzip compressed seed. | |
357 if (!StoreSeedData(seed_data, seed_signature, seed_country, | |
358 current_time, false, false, nullptr)) { | |
359 LOG(WARNING) << "First run variations seed is invalid."; | |
360 return; | |
361 } | |
362 // TODO(agulenko): Clear Java prefs. | |
363 } | |
364 | |
339 bool VariationsSeedStore::ReadSeedData(std::string* seed_data) { | 365 bool VariationsSeedStore::ReadSeedData(std::string* seed_data) { |
340 std::string base64_seed_data = | 366 std::string base64_seed_data = |
341 local_state_->GetString(prefs::kVariationsCompressedSeed); | 367 local_state_->GetString(prefs::kVariationsCompressedSeed); |
368 | |
Alexei Svitkine (slow)
2015/10/29 15:04:12
Nit: Remove extra diff here, same on line 370.
Alexander Agulenko
2015/11/02 22:55:33
Done.
| |
342 const bool is_compressed = !base64_seed_data.empty(); | 369 const bool is_compressed = !base64_seed_data.empty(); |
370 | |
343 // If there's no compressed seed, fall back to the uncompressed one. | 371 // If there's no compressed seed, fall back to the uncompressed one. |
344 if (!is_compressed) | 372 if (!is_compressed) |
345 base64_seed_data = local_state_->GetString(prefs::kVariationsSeed); | 373 base64_seed_data = local_state_->GetString(prefs::kVariationsSeed); |
346 | 374 |
347 if (base64_seed_data.empty()) { | 375 if (base64_seed_data.empty()) { |
348 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_EMPTY); | 376 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_EMPTY); |
349 return false; | 377 return false; |
350 } | 378 } |
351 | 379 |
352 // If the decode process fails, assume the pref value is corrupt and clear it. | 380 // If the decode process fails, assume the pref value is corrupt and clear it. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 } | 505 } |
478 return true; | 506 return true; |
479 } | 507 } |
480 | 508 |
481 void VariationsSeedStore::ReportUnsupportedSeedFormatError() { | 509 void VariationsSeedStore::ReportUnsupportedSeedFormatError() { |
482 RecordSeedStoreHistogram( | 510 RecordSeedStoreHistogram( |
483 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT); | 511 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT); |
484 } | 512 } |
485 | 513 |
486 } // namespace variations | 514 } // namespace variations |
OLD | NEW |