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

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

Issue 2919223002: [Cleanup] Remove the obsolete variations_seed pref. (Closed)
Patch Set: Fix the test Created 3 years, 6 months 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 server_date_fetched.ToInternalValue()); 300 server_date_fetched.ToInternalValue());
301 } 301 }
302 302
303 std::string VariationsSeedStore::GetInvalidSignature() const { 303 std::string VariationsSeedStore::GetInvalidSignature() const {
304 return invalid_base64_signature_; 304 return invalid_base64_signature_;
305 } 305 }
306 306
307 // static 307 // static
308 void VariationsSeedStore::RegisterPrefs(PrefRegistrySimple* registry) { 308 void VariationsSeedStore::RegisterPrefs(PrefRegistrySimple* registry) {
309 registry->RegisterStringPref(prefs::kVariationsCompressedSeed, std::string()); 309 registry->RegisterStringPref(prefs::kVariationsCompressedSeed, std::string());
310 registry->RegisterStringPref(prefs::kVariationsSeed, std::string());
311 registry->RegisterInt64Pref(prefs::kVariationsSeedDate, 310 registry->RegisterInt64Pref(prefs::kVariationsSeedDate,
312 base::Time().ToInternalValue()); 311 base::Time().ToInternalValue());
313 registry->RegisterStringPref(prefs::kVariationsSeedSignature, std::string()); 312 registry->RegisterStringPref(prefs::kVariationsSeedSignature, std::string());
314 registry->RegisterStringPref(prefs::kVariationsCountry, std::string()); 313 registry->RegisterStringPref(prefs::kVariationsCountry, std::string());
315 } 314 }
316 315
317 VariationsSeedStore::VerifySignatureResult 316 VariationsSeedStore::VerifySignatureResult
318 VariationsSeedStore::VerifySeedSignature( 317 VariationsSeedStore::VerifySeedSignature(
319 const std::string& seed_bytes, 318 const std::string& seed_bytes,
320 const std::string& base64_seed_signature) { 319 const std::string& base64_seed_signature) {
(...skipping 17 matching lines...) Expand all
338 337
339 verifier.VerifyUpdate(reinterpret_cast<const uint8_t*>(seed_bytes.data()), 338 verifier.VerifyUpdate(reinterpret_cast<const uint8_t*>(seed_bytes.data()),
340 seed_bytes.size()); 339 seed_bytes.size());
341 if (verifier.VerifyFinal()) 340 if (verifier.VerifyFinal())
342 return VARIATIONS_SEED_SIGNATURE_VALID; 341 return VARIATIONS_SEED_SIGNATURE_VALID;
343 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED; 342 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED;
344 } 343 }
345 344
346 void VariationsSeedStore::ClearPrefs() { 345 void VariationsSeedStore::ClearPrefs() {
347 local_state_->ClearPref(prefs::kVariationsCompressedSeed); 346 local_state_->ClearPref(prefs::kVariationsCompressedSeed);
348 local_state_->ClearPref(prefs::kVariationsSeed);
349 local_state_->ClearPref(prefs::kVariationsSeedDate); 347 local_state_->ClearPref(prefs::kVariationsSeedDate);
350 local_state_->ClearPref(prefs::kVariationsSeedSignature); 348 local_state_->ClearPref(prefs::kVariationsSeedSignature);
351 } 349 }
352 350
353 #if defined(OS_ANDROID) 351 #if defined(OS_ANDROID)
354 void VariationsSeedStore::ImportFirstRunJavaSeed() { 352 void VariationsSeedStore::ImportFirstRunJavaSeed() {
355 DVLOG(1) << "Importing first run seed from Java preferences."; 353 DVLOG(1) << "Importing first run seed from Java preferences.";
356 354
357 std::string seed_data; 355 std::string seed_data;
358 std::string seed_signature; 356 std::string seed_signature;
(...skipping 21 matching lines...) Expand all
380 LOG(WARNING) << "First run variations seed is invalid."; 378 LOG(WARNING) << "First run variations seed is invalid.";
381 return; 379 return;
382 } 380 }
383 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_SUCCESS); 381 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_SUCCESS);
384 } 382 }
385 #endif // OS_ANDROID 383 #endif // OS_ANDROID
386 384
387 bool VariationsSeedStore::ReadSeedData(std::string* seed_data) { 385 bool VariationsSeedStore::ReadSeedData(std::string* seed_data) {
388 std::string base64_seed_data = 386 std::string base64_seed_data =
389 local_state_->GetString(prefs::kVariationsCompressedSeed); 387 local_state_->GetString(prefs::kVariationsCompressedSeed);
390 const bool is_compressed = !base64_seed_data.empty();
391 // If there's no compressed seed, fall back to the uncompressed one.
392 if (!is_compressed)
393 base64_seed_data = local_state_->GetString(prefs::kVariationsSeed);
394
395 if (base64_seed_data.empty()) { 388 if (base64_seed_data.empty()) {
396 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_EMPTY); 389 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_EMPTY);
397 return false; 390 return false;
398 } 391 }
399 392
400 // If the decode process fails, assume the pref value is corrupt and clear it. 393 // If the decode process fails, assume the pref value is corrupt and clear it.
401 std::string decoded_data; 394 std::string decoded_data;
402 if (!base::Base64Decode(base64_seed_data, &decoded_data)) { 395 if (!base::Base64Decode(base64_seed_data, &decoded_data)) {
403 ClearPrefs(); 396 ClearPrefs();
404 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_CORRUPT_BASE64); 397 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_CORRUPT_BASE64);
405 return false; 398 return false;
406 } 399 }
407 400
408 if (!is_compressed) { 401 if (!compression::GzipUncompress(decoded_data, seed_data)) {
409 seed_data->swap(decoded_data);
410 } else if (!compression::GzipUncompress(decoded_data, seed_data)) {
411 ClearPrefs(); 402 ClearPrefs();
412 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_CORRUPT_GZIP); 403 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_CORRUPT_GZIP);
413 return false; 404 return false;
414 } 405 }
415 406
416 return true; 407 return true;
417 } 408 }
418 409
419 bool VariationsSeedStore::StoreSeedDataNoDelta( 410 bool VariationsSeedStore::StoreSeedDataNoDelta(
420 const std::string& seed_data, 411 const std::string& seed_data,
(...skipping 27 matching lines...) Expand all
448 // Compress the seed before base64-encoding and storing. 439 // Compress the seed before base64-encoding and storing.
449 std::string compressed_seed_data; 440 std::string compressed_seed_data;
450 if (!compression::GzipCompress(seed_data, &compressed_seed_data)) { 441 if (!compression::GzipCompress(seed_data, &compressed_seed_data)) {
451 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_GZIP); 442 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_GZIP);
452 return false; 443 return false;
453 } 444 }
454 445
455 std::string base64_seed_data; 446 std::string base64_seed_data;
456 base::Base64Encode(compressed_seed_data, &base64_seed_data); 447 base::Base64Encode(compressed_seed_data, &base64_seed_data);
457 448
458 // TODO(asvitkine): This pref is no longer being used. Remove it completely
459 // in M45+.
460 local_state_->ClearPref(prefs::kVariationsSeed);
gab 2017/06/06 14:45:03 Since this pref was passed through master_prefs an
Ilya Sherman 2017/06/06 20:22:16 Hmm, that sounds like a bug if this and the other
Ilya Sherman 2017/06/06 21:54:37 Okay, found the docs [1] and then updated them for
461
462 #if defined(OS_ANDROID) 449 #if defined(OS_ANDROID)
463 // If currently we do not have any stored pref then we mark seed storing as 450 // If currently we do not have any stored pref then we mark seed storing as
464 // successful on the Java side of Chrome for Android to avoid repeated seed 451 // successful on the Java side of Chrome for Android to avoid repeated seed
465 // fetches and clear preferences on the Java side. 452 // fetches and clear preferences on the Java side.
466 if (local_state_->GetString(prefs::kVariationsCompressedSeed).empty()) { 453 if (local_state_->GetString(prefs::kVariationsCompressedSeed).empty()) {
467 android::MarkVariationsSeedAsStored(); 454 android::MarkVariationsSeedAsStored();
468 android::ClearJavaFirstRunPrefs(); 455 android::ClearJavaFirstRunPrefs();
469 } 456 }
470 #endif 457 #endif
471 458
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 } 523 }
537 return true; 524 return true;
538 } 525 }
539 526
540 void VariationsSeedStore::ReportUnsupportedSeedFormatError() { 527 void VariationsSeedStore::ReportUnsupportedSeedFormatError() {
541 RecordSeedStoreHistogram( 528 RecordSeedStoreHistogram(
542 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT); 529 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT);
543 } 530 }
544 531
545 } // namespace variations 532 } // namespace variations
OLDNEW
« no previous file with comments | « components/variations/service/variations_service_unittest.cc ('k') | components/variations/variations_seed_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698