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

Side by Side Diff: components/variations/variations_seed_store.cc

Issue 1447823003: Revert of Implemented clearing Java prefs after pulling variations first run seed from Java to C++ side (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 | « components/variations/android/variations_seed_bridge.cc ('k') | 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/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/pref_names.h" 15 #include "components/variations/pref_names.h"
16 #include "components/variations/proto/variations_seed.pb.h" 16 #include "components/variations/proto/variations_seed.pb.h"
17 #include "crypto/signature_verifier.h" 17 #include "crypto/signature_verifier.h"
18 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" 18 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h"
19 19
20 #if defined(OS_ANDROID)
21 #include "components/variations/android/variations_seed_bridge.h"
22 #endif // OS_ANDROID
23
24 namespace variations { 20 namespace variations {
25 21
26 namespace { 22 namespace {
27 23
28 // Signature verification is disabled on mobile platforms for now, since it 24 // Signature verification is disabled on mobile platforms for now, since it
29 // adds about ~15ms to the startup time on mobile (vs. a couple ms on desktop). 25 // adds about ~15ms to the startup time on mobile (vs. a couple ms on desktop).
30 bool SignatureVerificationEnabled() { 26 bool SignatureVerificationEnabled() {
31 #if defined(OS_IOS) || defined(OS_ANDROID) 27 #if defined(OS_IOS) || defined(OS_ANDROID)
32 return false; 28 return false;
33 #else 29 #else
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 // TODO(agulenko): Pull actual time from the response. 377 // TODO(agulenko): Pull actual time from the response.
382 base::Time current_time = base::Time::Now(); 378 base::Time current_time = base::Time::Now();
383 379
384 // TODO(agulenko): Support gzip compressed seed. 380 // TODO(agulenko): Support gzip compressed seed.
385 if (!StoreSeedData(seed_data, seed_signature, seed_country, current_time, 381 if (!StoreSeedData(seed_data, seed_signature, seed_country, current_time,
386 false, false, nullptr)) { 382 false, false, nullptr)) {
387 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_FAIL_STORE_FAILED); 383 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_FAIL_STORE_FAILED);
388 LOG(WARNING) << "First run variations seed is invalid."; 384 LOG(WARNING) << "First run variations seed is invalid.";
389 return; 385 return;
390 } 386 }
387 // TODO(agulenko): Clear Java prefs.
391 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_SUCCESS); 388 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_SUCCESS);
392 } 389 }
393 #endif // OS_ANDROID 390 #endif // OS_ANDROID
394 391
395 bool VariationsSeedStore::ReadSeedData(std::string* seed_data) { 392 bool VariationsSeedStore::ReadSeedData(std::string* seed_data) {
396 std::string base64_seed_data = 393 std::string base64_seed_data =
397 local_state_->GetString(prefs::kVariationsCompressedSeed); 394 local_state_->GetString(prefs::kVariationsCompressedSeed);
398 const bool is_compressed = !base64_seed_data.empty(); 395 const bool is_compressed = !base64_seed_data.empty();
399 // If there's no compressed seed, fall back to the uncompressed one. 396 // If there's no compressed seed, fall back to the uncompressed one.
400 if (!is_compressed) 397 if (!is_compressed)
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 return false; 457 return false;
461 } 458 }
462 459
463 std::string base64_seed_data; 460 std::string base64_seed_data;
464 base::Base64Encode(compressed_seed_data, &base64_seed_data); 461 base::Base64Encode(compressed_seed_data, &base64_seed_data);
465 462
466 // TODO(asvitkine): This pref is no longer being used. Remove it completely 463 // TODO(asvitkine): This pref is no longer being used. Remove it completely
467 // in M45+. 464 // in M45+.
468 local_state_->ClearPref(prefs::kVariationsSeed); 465 local_state_->ClearPref(prefs::kVariationsSeed);
469 466
470 #if defined(OS_ANDROID)
471 // If currently we do not have any stored pref then we mark seed storing as
472 // successful on the Java side of Chrome for Android to avoid repeated seed
473 // fetches and clear preferences on the Java side.
474 if (local_state_->GetString(prefs::kVariationsCompressedSeed).empty()) {
475 android::MarkVariationsSeedAsStored();
476 android::ClearJavaFirstRunPrefs();
477 }
478 #endif
479
480 // Update the saved country code only if one was returned from the server. 467 // Update the saved country code only if one was returned from the server.
481 // Prefer the country code that was transmitted in the header over the one in 468 // Prefer the country code that was transmitted in the header over the one in
482 // the seed (which is deprecated). 469 // the seed (which is deprecated).
483 if (!country_code.empty()) 470 if (!country_code.empty())
484 local_state_->SetString(prefs::kVariationsCountry, country_code); 471 local_state_->SetString(prefs::kVariationsCountry, country_code);
485 else if (seed.has_country_code()) 472 else if (seed.has_country_code())
486 local_state_->SetString(prefs::kVariationsCountry, seed.country_code()); 473 local_state_->SetString(prefs::kVariationsCountry, seed.country_code());
487 474
488 local_state_->SetString(prefs::kVariationsCompressedSeed, base64_seed_data); 475 local_state_->SetString(prefs::kVariationsCompressedSeed, base64_seed_data);
489 UpdateSeedDateAndLogDayChange(date_fetched); 476 UpdateSeedDateAndLogDayChange(date_fetched);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 530 }
544 return true; 531 return true;
545 } 532 }
546 533
547 void VariationsSeedStore::ReportUnsupportedSeedFormatError() { 534 void VariationsSeedStore::ReportUnsupportedSeedFormatError() {
548 RecordSeedStoreHistogram( 535 RecordSeedStoreHistogram(
549 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT); 536 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT);
550 } 537 }
551 538
552 } // namespace variations 539 } // namespace variations
OLDNEW
« no previous file with comments | « components/variations/android/variations_seed_bridge.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698