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 defined(OS_ANDROID) | |
156 if (!local_state_->HasPrefPath(prefs::kVariationsSeedSignature)) | |
157 ImportFirstRunJavaSeed(); | |
Bernhard Bauer
2015/11/03 09:44:49
Indent.
Alexander Agulenko
2015/11/04 08:00:59
Done.
| |
158 #endif // OS_ANDROID | |
159 | |
155 std::string seed_data; | 160 std::string seed_data; |
156 if (!ReadSeedData(&seed_data)) | 161 if (!ReadSeedData(&seed_data)) |
157 return false; | 162 return false; |
158 | 163 |
159 const std::string base64_seed_signature = | 164 const std::string base64_seed_signature = |
160 local_state_->GetString(prefs::kVariationsSeedSignature); | 165 local_state_->GetString(prefs::kVariationsSeedSignature); |
161 const VerifySignatureResult result = | 166 const VerifySignatureResult result = |
162 VerifySeedSignature(seed_data, base64_seed_signature); | 167 VerifySeedSignature(seed_data, base64_seed_signature); |
163 if (result != VARIATIONS_SEED_SIGNATURE_ENUM_SIZE) { | 168 if (result != VARIATIONS_SEED_SIGNATURE_ENUM_SIZE) { |
164 UMA_HISTOGRAM_ENUMERATION("Variations.LoadSeedSignature", result, | 169 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; | 334 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED; |
330 } | 335 } |
331 | 336 |
332 void VariationsSeedStore::ClearPrefs() { | 337 void VariationsSeedStore::ClearPrefs() { |
333 local_state_->ClearPref(prefs::kVariationsCompressedSeed); | 338 local_state_->ClearPref(prefs::kVariationsCompressedSeed); |
334 local_state_->ClearPref(prefs::kVariationsSeed); | 339 local_state_->ClearPref(prefs::kVariationsSeed); |
335 local_state_->ClearPref(prefs::kVariationsSeedDate); | 340 local_state_->ClearPref(prefs::kVariationsSeedDate); |
336 local_state_->ClearPref(prefs::kVariationsSeedSignature); | 341 local_state_->ClearPref(prefs::kVariationsSeedSignature); |
337 } | 342 } |
338 | 343 |
344 #if defined(OS_ANDROID) | |
345 void VariationsSeedStore::ImportFirstRunJavaSeed() { | |
346 DVLOG(1) << "Importing first run seed from Java preferences."; | |
347 std::string seed_data; | |
348 std::string seed_signature; | |
349 std::string seed_country; | |
350 get_variations_first_run_seed_.Run(&seed_data, &seed_signature, | |
351 &seed_country); | |
352 | |
353 if (seed_data.empty()) { | |
354 // TODO(agulenko): add a new UMA histogram for the state of failing | |
355 // to import seed from Java preferences during Chrome first run. | |
356 return; | |
357 } | |
358 | |
359 // TODO(agulenko): Pull actual time from the response. | |
360 base::Time current_time = base::Time::Now(); | |
361 | |
362 // TODO(agulenko): Support gzip compressed seed. | |
363 if (!StoreSeedData(seed_data, seed_signature, seed_country, | |
364 current_time, false, false, nullptr)) { | |
365 LOG(WARNING) << "First run variations seed is invalid."; | |
366 return; | |
367 } | |
368 // TODO(agulenko): Clear Java prefs. | |
369 } | |
370 #endif // OS_ANDROID | |
371 | |
339 bool VariationsSeedStore::ReadSeedData(std::string* seed_data) { | 372 bool VariationsSeedStore::ReadSeedData(std::string* seed_data) { |
340 std::string base64_seed_data = | 373 std::string base64_seed_data = |
341 local_state_->GetString(prefs::kVariationsCompressedSeed); | 374 local_state_->GetString(prefs::kVariationsCompressedSeed); |
342 const bool is_compressed = !base64_seed_data.empty(); | 375 const bool is_compressed = !base64_seed_data.empty(); |
343 // If there's no compressed seed, fall back to the uncompressed one. | 376 // If there's no compressed seed, fall back to the uncompressed one. |
344 if (!is_compressed) | 377 if (!is_compressed) |
345 base64_seed_data = local_state_->GetString(prefs::kVariationsSeed); | 378 base64_seed_data = local_state_->GetString(prefs::kVariationsSeed); |
346 | 379 |
347 if (base64_seed_data.empty()) { | 380 if (base64_seed_data.empty()) { |
348 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_EMPTY); | 381 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_EMPTY); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 } | 510 } |
478 return true; | 511 return true; |
479 } | 512 } |
480 | 513 |
481 void VariationsSeedStore::ReportUnsupportedSeedFormatError() { | 514 void VariationsSeedStore::ReportUnsupportedSeedFormatError() { |
482 RecordSeedStoreHistogram( | 515 RecordSeedStoreHistogram( |
483 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT); | 516 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT); |
484 } | 517 } |
485 | 518 |
486 } // namespace variations | 519 } // namespace variations |
OLD | NEW |