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 "chrome/browser/metrics/variations/variations_seed_store.h" | 5 #include "chrome/browser/metrics/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/metrics/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 namespace chrome_variations { | 20 namespace chrome_variations { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Signature verification is disabled on mobile platforms for now, since it | 24 // Signature verification is disabled on mobile platforms for now, since it |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 // If the decode process fails, assume the pref value is corrupt and clear it. | 324 // If the decode process fails, assume the pref value is corrupt and clear it. |
325 std::string decoded_data; | 325 std::string decoded_data; |
326 if (!base::Base64Decode(base64_seed_data, &decoded_data)) { | 326 if (!base::Base64Decode(base64_seed_data, &decoded_data)) { |
327 ClearPrefs(); | 327 ClearPrefs(); |
328 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_CORRUPT_BASE64); | 328 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_CORRUPT_BASE64); |
329 return false; | 329 return false; |
330 } | 330 } |
331 | 331 |
332 if (!is_compressed) { | 332 if (!is_compressed) { |
333 seed_data->swap(decoded_data); | 333 seed_data->swap(decoded_data); |
334 } else if (!metrics::GzipUncompress(decoded_data, seed_data)) { | 334 } else if (!compression::GzipUncompress(decoded_data, seed_data)) { |
335 ClearPrefs(); | 335 ClearPrefs(); |
336 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_CORRUPT_GZIP); | 336 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_CORRUPT_GZIP); |
337 return false; | 337 return false; |
338 } | 338 } |
339 | 339 |
340 return true; | 340 return true; |
341 } | 341 } |
342 | 342 |
343 bool VariationsSeedStore::StoreSeedDataNoDelta( | 343 bool VariationsSeedStore::StoreSeedDataNoDelta( |
344 const std::string& seed_data, | 344 const std::string& seed_data, |
(...skipping 19 matching lines...) Expand all Loading... |
364 UMA_HISTOGRAM_ENUMERATION("Variations.StoreSeedSignature", result, | 364 UMA_HISTOGRAM_ENUMERATION("Variations.StoreSeedSignature", result, |
365 VARIATIONS_SEED_SIGNATURE_ENUM_SIZE); | 365 VARIATIONS_SEED_SIGNATURE_ENUM_SIZE); |
366 if (result != VARIATIONS_SEED_SIGNATURE_VALID) { | 366 if (result != VARIATIONS_SEED_SIGNATURE_VALID) { |
367 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_SIGNATURE); | 367 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_SIGNATURE); |
368 return false; | 368 return false; |
369 } | 369 } |
370 } | 370 } |
371 | 371 |
372 // Compress the seed before base64-encoding and storing. | 372 // Compress the seed before base64-encoding and storing. |
373 std::string compressed_seed_data; | 373 std::string compressed_seed_data; |
374 if (!metrics::GzipCompress(seed_data, &compressed_seed_data)) { | 374 if (!compression::GzipCompress(seed_data, &compressed_seed_data)) { |
375 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_GZIP); | 375 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_GZIP); |
376 return false; | 376 return false; |
377 } | 377 } |
378 | 378 |
379 std::string base64_seed_data; | 379 std::string base64_seed_data; |
380 base::Base64Encode(compressed_seed_data, &base64_seed_data); | 380 base::Base64Encode(compressed_seed_data, &base64_seed_data); |
381 | 381 |
382 // TODO(asvitkine): This pref is no longer being used. Remove it completely | 382 // TODO(asvitkine): This pref is no longer being used. Remove it completely |
383 // in M45+. | 383 // in M45+. |
384 local_state_->ClearPref(prefs::kVariationsSeed); | 384 local_state_->ClearPref(prefs::kVariationsSeed); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 end_offset += length; | 444 end_offset += length; |
445 if (!end_offset.IsValid() || end_offset.ValueOrDie() > existing_data_size) | 445 if (!end_offset.IsValid() || end_offset.ValueOrDie() > existing_data_size) |
446 return false; | 446 return false; |
447 output->append(existing_data, offset, length); | 447 output->append(existing_data, offset, length); |
448 } | 448 } |
449 } | 449 } |
450 return true; | 450 return true; |
451 } | 451 } |
452 | 452 |
453 } // namespace chrome_variations | 453 } // namespace chrome_variations |
OLD | NEW |