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

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

Issue 1438123002: Removed callbacks to JNI functions + added gzip compressed seed support & pulling response time (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implemented the rest TODOs: pulling time from response and GZIP compressed seed support 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"
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"
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // The server date is earlier than the stored date, and they are from 137 // The server date is earlier than the stored date, and they are from
137 // different UTC days, so |server_seed_date| is a valid new day. 138 // different UTC days, so |server_seed_date| is a valid new day.
138 return SEED_DATE_NEW_DAY; 139 return SEED_DATE_NEW_DAY;
139 } 140 }
140 return SEED_DATE_SAME_DAY; 141 return SEED_DATE_SAME_DAY;
141 } 142 }
142 143
143 #if defined(OS_ANDROID) 144 #if defined(OS_ANDROID)
144 enum FirstRunResult { 145 enum FirstRunResult {
145 FIRST_RUN_SEED_IMPORT_SUCCESS, 146 FIRST_RUN_SEED_IMPORT_SUCCESS,
146 FIRST_RUN_SEED_IMPORT_FAIL_NO_CALLBACK,
Alexei Svitkine (slow) 2015/11/12 16:26:55 Keep this entry.
Alexander Agulenko 2015/11/12 20:06:42 Done.
147 FIRST_RUN_SEED_IMPORT_FAIL_NO_FIRST_RUN_SEED, 147 FIRST_RUN_SEED_IMPORT_FAIL_NO_FIRST_RUN_SEED,
148 FIRST_RUN_SEED_IMPORT_FAIL_STORE_FAILED, 148 FIRST_RUN_SEED_IMPORT_FAIL_STORE_FAILED,
149 FIRST_RUN_RESULT_ENUM_SIZE, 149 FIRST_RUN_RESULT_ENUM_SIZE,
150 }; 150 };
151 151
152 void RecordFirstRunResult(FirstRunResult result) { 152 void RecordFirstRunResult(FirstRunResult result) {
153 UMA_HISTOGRAM_ENUMERATION("Variations.FirstRunResult", result, 153 UMA_HISTOGRAM_ENUMERATION("Variations.FirstRunResult", result,
154 FIRST_RUN_RESULT_ENUM_SIZE); 154 FIRST_RUN_RESULT_ENUM_SIZE);
155 } 155 }
156 #endif // OS_ANDROID 156 #endif // OS_ANDROID
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 void VariationsSeedStore::ClearPrefs() { 352 void VariationsSeedStore::ClearPrefs() {
353 local_state_->ClearPref(prefs::kVariationsCompressedSeed); 353 local_state_->ClearPref(prefs::kVariationsCompressedSeed);
354 local_state_->ClearPref(prefs::kVariationsSeed); 354 local_state_->ClearPref(prefs::kVariationsSeed);
355 local_state_->ClearPref(prefs::kVariationsSeedDate); 355 local_state_->ClearPref(prefs::kVariationsSeedDate);
356 local_state_->ClearPref(prefs::kVariationsSeedSignature); 356 local_state_->ClearPref(prefs::kVariationsSeedSignature);
357 } 357 }
358 358
359 #if defined(OS_ANDROID) 359 #if defined(OS_ANDROID)
360 void VariationsSeedStore::ImportFirstRunJavaSeed() { 360 void VariationsSeedStore::ImportFirstRunJavaSeed() {
361 DVLOG(1) << "Importing first run seed from Java preferences."; 361 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 362
367 std::string seed_data; 363 std::string seed_data;
368 std::string seed_signature; 364 std::string seed_signature;
369 std::string seed_country; 365 std::string seed_country;
370 get_variations_first_run_seed_.Run(&seed_data, &seed_signature, 366 base::Time current_time;
371 &seed_country); 367 bool is_gzip_compressed;
368
369 android::GetVariationsFirstRunSeed(&seed_data, &seed_signature, &seed_country,
370 &current_time, &is_gzip_compressed);
372 if (seed_data.empty()) { 371 if (seed_data.empty()) {
373 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_FAIL_NO_FIRST_RUN_SEED); 372 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_FAIL_NO_FIRST_RUN_SEED);
374 return; 373 return;
375 } 374 }
376 375
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, 376 if (!StoreSeedData(seed_data, seed_signature, seed_country, current_time,
382 false, false, nullptr)) { 377 false, is_gzip_compressed, nullptr)) {
383 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_FAIL_STORE_FAILED); 378 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_FAIL_STORE_FAILED);
384 LOG(WARNING) << "First run variations seed is invalid."; 379 LOG(WARNING) << "First run variations seed is invalid.";
385 return; 380 return;
386 } 381 }
387 // TODO(agulenko): Clear Java prefs. 382 // TODO(agulenko): Clear Java prefs.
388 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_SUCCESS); 383 RecordFirstRunResult(FIRST_RUN_SEED_IMPORT_SUCCESS);
389 } 384 }
390 #endif // OS_ANDROID 385 #endif // OS_ANDROID
391 386
392 bool VariationsSeedStore::ReadSeedData(std::string* seed_data) { 387 bool VariationsSeedStore::ReadSeedData(std::string* seed_data) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 } 525 }
531 return true; 526 return true;
532 } 527 }
533 528
534 void VariationsSeedStore::ReportUnsupportedSeedFormatError() { 529 void VariationsSeedStore::ReportUnsupportedSeedFormatError() {
535 RecordSeedStoreHistogram( 530 RecordSeedStoreHistogram(
536 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT); 531 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT);
537 } 532 }
538 533
539 } // namespace variations 534 } // namespace variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698