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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 void VariationsSeedStore::ClearPrefs() { | 356 void VariationsSeedStore::ClearPrefs() { |
357 local_state_->ClearPref(prefs::kVariationsCompressedSeed); | 357 local_state_->ClearPref(prefs::kVariationsCompressedSeed); |
358 local_state_->ClearPref(prefs::kVariationsSeed); | 358 local_state_->ClearPref(prefs::kVariationsSeed); |
359 local_state_->ClearPref(prefs::kVariationsSeedDate); | 359 local_state_->ClearPref(prefs::kVariationsSeedDate); |
360 local_state_->ClearPref(prefs::kVariationsSeedSignature); | 360 local_state_->ClearPref(prefs::kVariationsSeedSignature); |
361 } | 361 } |
362 | 362 |
363 #if defined(OS_ANDROID) | 363 #if defined(OS_ANDROID) |
364 void VariationsSeedStore::ImportFirstRunJavaSeed() { | 364 void VariationsSeedStore::ImportFirstRunJavaSeed() { |
365 DVLOG(1) << "Importing first run seed from Java preferences."; | 365 DVLOG(1) << "Importing first run seed from Java preferences."; |
366 if (get_variations_first_run_seed_.is_null()) { | |
367 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_FAIL_NO_CALLBACK); | |
368 return; | |
369 } | |
370 | 366 |
371 std::string seed_data; | 367 std::string seed_data; |
372 std::string seed_signature; | 368 std::string seed_signature; |
373 std::string seed_country; | 369 std::string seed_country; |
374 get_variations_first_run_seed_.Run(&seed_data, &seed_signature, | 370 std::string response_date; |
375 &seed_country); | 371 bool is_gzip_compressed; |
| 372 |
| 373 android::GetVariationsFirstRunSeed(&seed_data, &seed_signature, &seed_country, |
| 374 &response_date, &is_gzip_compressed); |
376 if (seed_data.empty()) { | 375 if (seed_data.empty()) { |
377 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_FAIL_NO_FIRST_RUN_SEED); | 376 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_FAIL_NO_FIRST_RUN_SEED); |
378 return; | 377 return; |
379 } | 378 } |
380 | 379 |
381 // TODO(agulenko): Pull actual time from the response. | 380 base::Time current_date; |
382 base::Time current_time = base::Time::Now(); | 381 base::Time::FromUTCString(response_date.c_str(), ¤t_date); |
383 | 382 |
384 // TODO(agulenko): Support gzip compressed seed. | 383 if (!StoreSeedData(seed_data, seed_signature, seed_country, current_date, |
385 if (!StoreSeedData(seed_data, seed_signature, seed_country, current_time, | 384 false, is_gzip_compressed, nullptr)) { |
386 false, false, nullptr)) { | |
387 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_FAIL_STORE_FAILED); | 385 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_FAIL_STORE_FAILED); |
388 LOG(WARNING) << "First run variations seed is invalid."; | 386 LOG(WARNING) << "First run variations seed is invalid."; |
389 return; | 387 return; |
390 } | 388 } |
391 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_SUCCESS); | 389 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_SUCCESS); |
392 } | 390 } |
393 #endif // OS_ANDROID | 391 #endif // OS_ANDROID |
394 | 392 |
395 bool VariationsSeedStore::ReadSeedData(std::string* seed_data) { | 393 bool VariationsSeedStore::ReadSeedData(std::string* seed_data) { |
396 std::string base64_seed_data = | 394 std::string base64_seed_data = |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 } | 541 } |
544 return true; | 542 return true; |
545 } | 543 } |
546 | 544 |
547 void VariationsSeedStore::ReportUnsupportedSeedFormatError() { | 545 void VariationsSeedStore::ReportUnsupportedSeedFormatError() { |
548 RecordSeedStoreHistogram( | 546 RecordSeedStoreHistogram( |
549 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT); | 547 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT); |
550 } | 548 } |
551 | 549 |
552 } // namespace variations | 550 } // namespace variations |
OLD | NEW |