Chromium Code Reviews| 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" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/sha1.h" | 12 #include "base/sha1.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "components/compression/compression_utils.h" | 14 #include "components/compression/compression_utils.h" |
| 15 #include "components/variations/android/variations_seed_bridge.h" | |
|
Alexei Svitkine (slow)
2015/11/12 22:25:29
Put this include in ifdef and put it below the oth
Alexander Agulenko
2015/11/12 22:37:55
Done.
| |
| 15 #include "components/variations/pref_names.h" | 16 #include "components/variations/pref_names.h" |
| 16 #include "components/variations/proto/variations_seed.pb.h" | 17 #include "components/variations/proto/variations_seed.pb.h" |
| 17 #include "crypto/signature_verifier.h" | 18 #include "crypto/signature_verifier.h" |
| 18 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" | 19 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" |
| 19 | 20 |
| 20 namespace variations { | 21 namespace variations { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // Signature verification is disabled on mobile platforms for now, since it | 25 // Signature verification is disabled on mobile platforms for now, since it |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 void VariationsSeedStore::ClearPrefs() { | 353 void VariationsSeedStore::ClearPrefs() { |
| 353 local_state_->ClearPref(prefs::kVariationsCompressedSeed); | 354 local_state_->ClearPref(prefs::kVariationsCompressedSeed); |
| 354 local_state_->ClearPref(prefs::kVariationsSeed); | 355 local_state_->ClearPref(prefs::kVariationsSeed); |
| 355 local_state_->ClearPref(prefs::kVariationsSeedDate); | 356 local_state_->ClearPref(prefs::kVariationsSeedDate); |
| 356 local_state_->ClearPref(prefs::kVariationsSeedSignature); | 357 local_state_->ClearPref(prefs::kVariationsSeedSignature); |
| 357 } | 358 } |
| 358 | 359 |
| 359 #if defined(OS_ANDROID) | 360 #if defined(OS_ANDROID) |
| 360 void VariationsSeedStore::ImportFirstRunJavaSeed() { | 361 void VariationsSeedStore::ImportFirstRunJavaSeed() { |
| 361 DVLOG(1) << "Importing first run seed from Java preferences."; | 362 DVLOG(1) << "Importing first run seed from Java preferences."; |
| 362 if (get_variations_first_run_seed_.is_null()) { | |
| 363 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_FAIL_NO_CALLBACK); | |
| 364 return; | |
| 365 } | |
| 366 | 363 |
| 367 std::string seed_data; | 364 std::string seed_data; |
| 368 std::string seed_signature; | 365 std::string seed_signature; |
| 369 std::string seed_country; | 366 std::string seed_country; |
| 370 get_variations_first_run_seed_.Run(&seed_data, &seed_signature, | 367 std::string response_time; |
| 371 &seed_country); | 368 base::Time current_time; |
| 369 bool is_gzip_compressed; | |
|
Alexei Svitkine (slow)
2015/11/12 22:25:29
Move this right above the time parsing code.
Alexander Agulenko
2015/11/12 22:37:55
Done.
| |
| 370 | |
| 371 android::GetVariationsFirstRunSeed(&seed_data, &seed_signature, &seed_country, | |
| 372 &response_time, &is_gzip_compressed); | |
| 372 if (seed_data.empty()) { | 373 if (seed_data.empty()) { |
| 373 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_FAIL_NO_FIRST_RUN_SEED); | 374 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_FAIL_NO_FIRST_RUN_SEED); |
| 374 return; | 375 return; |
| 375 } | 376 } |
| 377 base::Time::FromString(response_time.c_str(), ¤t_time); | |
|
Alexei Svitkine (slow)
2015/11/12 22:25:29
To match how we do it on the C++ side, this should
Alexander Agulenko
2015/11/12 22:37:55
Done.
| |
| 376 | 378 |
| 377 // TODO(agulenko): Pull actual time from the response. | |
| 378 base::Time current_time = base::Time::Now(); | |
| 379 | |
| 380 // TODO(agulenko): Support gzip compressed seed. | |
| 381 if (!StoreSeedData(seed_data, seed_signature, seed_country, current_time, | 379 if (!StoreSeedData(seed_data, seed_signature, seed_country, current_time, |
| 382 false, false, nullptr)) { | 380 false, is_gzip_compressed, nullptr)) { |
| 383 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_FAIL_STORE_FAILED); | 381 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_FAIL_STORE_FAILED); |
| 384 LOG(WARNING) << "First run variations seed is invalid."; | 382 LOG(WARNING) << "First run variations seed is invalid."; |
| 385 return; | 383 return; |
| 386 } | 384 } |
| 387 // TODO(agulenko): Clear Java prefs. | 385 // TODO(agulenko): Clear Java prefs. |
| 388 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_SUCCESS); | 386 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_SUCCESS); |
| 389 } | 387 } |
| 390 #endif // OS_ANDROID | 388 #endif // OS_ANDROID |
| 391 | 389 |
| 392 bool VariationsSeedStore::ReadSeedData(std::string* seed_data) { | 390 bool VariationsSeedStore::ReadSeedData(std::string* seed_data) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 } | 528 } |
| 531 return true; | 529 return true; |
| 532 } | 530 } |
| 533 | 531 |
| 534 void VariationsSeedStore::ReportUnsupportedSeedFormatError() { | 532 void VariationsSeedStore::ReportUnsupportedSeedFormatError() { |
| 535 RecordSeedStoreHistogram( | 533 RecordSeedStoreHistogram( |
| 536 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT); | 534 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT); |
| 537 } | 535 } |
| 538 | 536 |
| 539 } // namespace variations | 537 } // namespace variations |
| OLD | NEW |