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

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

Issue 1417503010: Variations seed is pulled from the Java application on the first launch of Chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor fix: removed debug output 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
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"
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 void VariationsSeedStore::ClearPrefs() { 332 void VariationsSeedStore::ClearPrefs() {
333 local_state_->ClearPref(prefs::kVariationsCompressedSeed); 333 local_state_->ClearPref(prefs::kVariationsCompressedSeed);
334 local_state_->ClearPref(prefs::kVariationsSeed); 334 local_state_->ClearPref(prefs::kVariationsSeed);
335 local_state_->ClearPref(prefs::kVariationsSeedDate); 335 local_state_->ClearPref(prefs::kVariationsSeedDate);
336 local_state_->ClearPref(prefs::kVariationsSeedSignature); 336 local_state_->ClearPref(prefs::kVariationsSeedSignature);
337 } 337 }
338 338
339 bool VariationsSeedStore::ReadSeedData(std::string* seed_data) { 339 bool VariationsSeedStore::ReadSeedData(std::string* seed_data) {
340 std::string base64_seed_data = 340 std::string base64_seed_data =
341 local_state_->GetString(prefs::kVariationsCompressedSeed); 341 local_state_->GetString(prefs::kVariationsCompressedSeed);
342 const bool is_compressed = !base64_seed_data.empty(); 342
343 // ToDo (agulenko): return const identifier back
344 /* const */ bool is_compressed = !base64_seed_data.empty();
345
343 // If there's no compressed seed, fall back to the uncompressed one. 346 // If there's no compressed seed, fall back to the uncompressed one.
344 if (!is_compressed) 347 if (!is_compressed)
345 base64_seed_data = local_state_->GetString(prefs::kVariationsSeed); 348 base64_seed_data = local_state_->GetString(prefs::kVariationsSeed);
346 349
347 if (base64_seed_data.empty()) { 350 if (base64_seed_data.empty()) {
351 #if defined(OS_ANDROID)
352 LOG(WARNING) << "variationsTracker: Trying to read seed from Java side";
Steven Holte 2015/10/28 01:00:18 Move this block of code into a function, e.g. Migr
Alexei Svitkine (slow) 2015/10/28 15:16:38 Agree with Steve. How about naming it ImportJavaSe
Alexander Agulenko 2015/10/28 23:05:09 Done.
353 std::string plain_seed_data = pull_variations_seed_pref_.Run(
354 prefs::kVariationsSeed);
355 std::string seed_signature = pull_variations_seed_pref_.Run(
356 prefs::kVariationsSeedSignature);
357 std::string country_code = pull_variations_seed_pref_.Run(
358 prefs::kVariationsCountry);
359
360 if (plain_seed_data.empty()) {
361 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_EMPTY);
362 return false;
363 }
364
365 // ToDo (agulenko): pull actual time from the response.
Alexei Svitkine (slow) 2015/10/28 15:16:38 Nit: Usual format for these is: TODO(agulenko): P
Alexander Agulenko 2015/10/28 23:05:09 Done.
366 base::Time current_time = base::Time::Now();
367 scoped_ptr<variations::VariationsSeed> seed(new variations::VariationsSeed);
Alexei Svitkine (slow) 2015/10/28 15:16:38 It doesn't seem like you're using |seed| other tha
Alexander Agulenko 2015/10/28 23:05:09 Done.
368
369 // Trying to translated the seed that we pulled from the Java side.
Steven Holte 2015/10/28 01:00:18 translate -> migrate, but moving to a function sho
Alexander Agulenko 2015/10/28 23:05:09 Done.
370 // ToDo(agulenko): replace "true" with real value
Steven Holte 2015/10/28 01:00:18 Nit: All caps TODO
Steven Holte 2015/10/28 01:00:18 Probably TODO: support gzipped seed?
Alexander Agulenko 2015/10/28 23:05:09 Done.
371 if (!StoreSeedData(plain_seed_data, seed_signature, country_code,
372 current_time, false, false, seed.get())) {
373 LOG(WARNING) << "Seed translation failed!";
Steven Holte 2015/10/28 01:00:18 Change to "First run variations seed is invalid"
Alexander Agulenko 2015/10/28 23:05:09 Done.
374 return false;
375 }
Steven Holte 2015/10/28 01:00:18 Add a TODO to clear the Java prefs (regardless if
Alexander Agulenko 2015/10/28 23:05:09 Done.
376
377 base64_seed_data = local_state_->GetString(prefs::kVariationsCompressedSeed) ;
Steven Holte 2015/10/28 01:00:18 To avoid this duplication it's probably better to
Alexander Agulenko 2015/10/28 23:05:09 Done.
378 is_compressed = !base64_seed_data.empty();
379
380 // If there's no compressed seed, fall back to the uncompressed one.
381 if (!is_compressed) {
382 base64_seed_data = local_state_->GetString(prefs::kVariationsSeed);
383 }
384 #else // OS_ANDROID
348 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_EMPTY); 385 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_EMPTY);
349 return false; 386 return false;
387 #endif // OS_ANDROID
350 } 388 }
351 389
352 // If the decode process fails, assume the pref value is corrupt and clear it. 390 // If the decode process fails, assume the pref value is corrupt and clear it.
353 std::string decoded_data; 391 std::string decoded_data;
354 if (!base::Base64Decode(base64_seed_data, &decoded_data)) { 392 if (!base::Base64Decode(base64_seed_data, &decoded_data)) {
355 ClearPrefs(); 393 ClearPrefs();
356 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_CORRUPT_BASE64); 394 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_CORRUPT_BASE64);
357 return false; 395 return false;
358 } 396 }
359 397
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 } 515 }
478 return true; 516 return true;
479 } 517 }
480 518
481 void VariationsSeedStore::ReportUnsupportedSeedFormatError() { 519 void VariationsSeedStore::ReportUnsupportedSeedFormatError() {
482 RecordSeedStoreHistogram( 520 RecordSeedStoreHistogram(
483 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT); 521 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT);
484 } 522 }
485 523
486 } // namespace variations 524 } // namespace variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698