OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/service/variations_service.h" | 5 #include "components/variations/service/variations_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> |
11 | 12 |
12 #include "base/build_time.h" | 13 #include "base/build_time.h" |
13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
15 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
16 #include "base/metrics/sparse_histogram.h" | 17 #include "base/metrics/sparse_histogram.h" |
17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
18 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
19 #include "base/task_runner_util.h" | 20 #include "base/task_runner_util.h" |
20 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 330 } |
330 | 331 |
331 const base::Version current_version(version_info::GetVersionNumber()); | 332 const base::Version current_version(version_info::GetVersionNumber()); |
332 if (!current_version.IsValid()) | 333 if (!current_version.IsValid()) |
333 return false; | 334 return false; |
334 | 335 |
335 variations::Study_Channel channel = | 336 variations::Study_Channel channel = |
336 GetChannelForVariations(client_->GetChannel()); | 337 GetChannelForVariations(client_->GetChannel()); |
337 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.UserChannel", channel); | 338 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.UserChannel", channel); |
338 | 339 |
339 const std::string latest_country = | 340 const std::string latest_country = GetLatestCountry(); |
340 local_state_->GetString(prefs::kVariationsCountry); | |
341 | |
342 std::unique_ptr<const base::FieldTrial::EntropyProvider> low_entropy_provider( | 341 std::unique_ptr<const base::FieldTrial::EntropyProvider> low_entropy_provider( |
343 CreateLowEntropyProvider()); | 342 CreateLowEntropyProvider()); |
344 // Note that passing |&ui_string_overrider_| via base::Unretained below is | 343 // Note that passing |&ui_string_overrider_| via base::Unretained below is |
345 // safe because the callback is executed synchronously. It is not possible | 344 // safe because the callback is executed synchronously. It is not possible |
346 // to pass UIStringOverrider itself to VariationSeedProcesor as variations | 345 // to pass UIStringOverrider itself to VariationSeedProcesor as variations |
347 // components should not depends on //ui/base. | 346 // components should not depends on //ui/base. |
348 variations::VariationsSeedProcessor().CreateTrialsFromSeed( | 347 variations::VariationsSeedProcessor().CreateTrialsFromSeed( |
349 seed, client_->GetApplicationLocale(), | 348 seed, client_->GetApplicationLocale(), |
350 GetReferenceDateForExpiryChecks(local_state_), current_version, channel, | 349 GetReferenceDateForExpiryChecks(local_state_), current_version, channel, |
351 GetCurrentFormFactor(), GetHardwareClass(), latest_country, | 350 GetCurrentFormFactor(), GetHardwareClass(), latest_country, |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 | 772 |
774 const base::ElapsedTimer timer; | 773 const base::ElapsedTimer timer; |
775 | 774 |
776 std::unique_ptr<const base::FieldTrial::EntropyProvider> default_provider = | 775 std::unique_ptr<const base::FieldTrial::EntropyProvider> default_provider = |
777 state_manager_->CreateDefaultEntropyProvider(); | 776 state_manager_->CreateDefaultEntropyProvider(); |
778 std::unique_ptr<const base::FieldTrial::EntropyProvider> low_provider = | 777 std::unique_ptr<const base::FieldTrial::EntropyProvider> low_provider = |
779 state_manager_->CreateLowEntropyProvider(); | 778 state_manager_->CreateLowEntropyProvider(); |
780 variations::VariationsSeedSimulator seed_simulator(*default_provider, | 779 variations::VariationsSeedSimulator seed_simulator(*default_provider, |
781 *low_provider); | 780 *low_provider); |
782 | 781 |
783 const std::string latest_country = | 782 const std::string latest_country = GetLatestCountry(); |
784 local_state_->GetString(prefs::kVariationsCountry); | |
785 const variations::VariationsSeedSimulator::Result result = | 783 const variations::VariationsSeedSimulator::Result result = |
786 seed_simulator.SimulateSeedStudies( | 784 seed_simulator.SimulateSeedStudies( |
787 *seed, client_->GetApplicationLocale(), | 785 *seed, client_->GetApplicationLocale(), |
788 GetReferenceDateForExpiryChecks(local_state_), version, | 786 GetReferenceDateForExpiryChecks(local_state_), version, |
789 GetChannelForVariations(client_->GetChannel()), | 787 GetChannelForVariations(client_->GetChannel()), |
790 GetCurrentFormFactor(), GetHardwareClass(), latest_country, | 788 GetCurrentFormFactor(), GetHardwareClass(), latest_country, |
791 LoadPermanentConsistencyCountry(version, latest_country)); | 789 LoadPermanentConsistencyCountry(version, latest_country)); |
792 | 790 |
793 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.NormalChanges", | 791 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.NormalChanges", |
794 result.normal_group_change_count); | 792 result.normal_group_change_count); |
(...skipping 21 matching lines...) Expand all Loading... |
816 DCHECK(thread_checker_.CalledOnValidThread()); | 814 DCHECK(thread_checker_.CalledOnValidThread()); |
817 return seed_store_.GetInvalidSignature(); | 815 return seed_store_.GetInvalidSignature(); |
818 } | 816 } |
819 | 817 |
820 std::string VariationsService::LoadPermanentConsistencyCountry( | 818 std::string VariationsService::LoadPermanentConsistencyCountry( |
821 const base::Version& version, | 819 const base::Version& version, |
822 const std::string& latest_country) { | 820 const std::string& latest_country) { |
823 DCHECK(thread_checker_.CalledOnValidThread()); | 821 DCHECK(thread_checker_.CalledOnValidThread()); |
824 DCHECK(version.IsValid()); | 822 DCHECK(version.IsValid()); |
825 | 823 |
| 824 const std::string override_country = |
| 825 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 826 switches::kVariationsOverrideCountry); |
| 827 if (!override_country.empty()) |
| 828 return override_country; |
| 829 |
826 const base::ListValue* list_value = | 830 const base::ListValue* list_value = |
827 local_state_->GetList(prefs::kVariationsPermanentConsistencyCountry); | 831 local_state_->GetList(prefs::kVariationsPermanentConsistencyCountry); |
828 std::string stored_version_string; | 832 std::string stored_version_string; |
829 std::string stored_country; | 833 std::string stored_country; |
830 | 834 |
831 // Determine if the saved pref value is present and valid. | 835 // Determine if the saved pref value is present and valid. |
832 const bool is_pref_empty = list_value->empty(); | 836 const bool is_pref_empty = list_value->empty(); |
833 const bool is_pref_valid = list_value->GetSize() == 2 && | 837 const bool is_pref_valid = list_value->GetSize() == 2 && |
834 list_value->GetString(0, &stored_version_string) && | 838 list_value->GetString(0, &stored_version_string) && |
835 list_value->GetString(1, &stored_country) && | 839 list_value->GetString(1, &stored_country) && |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 | 927 |
924 if (got_stored_country && stored_country == country_override) | 928 if (got_stored_country && stored_country == country_override) |
925 return false; | 929 return false; |
926 | 930 |
927 base::Version version(version_info::GetVersionNumber()); | 931 base::Version version(version_info::GetVersionNumber()); |
928 StorePermanentCountry(version, country_override); | 932 StorePermanentCountry(version, country_override); |
929 return true; | 933 return true; |
930 } | 934 } |
931 | 935 |
932 std::string VariationsService::GetLatestCountry() const { | 936 std::string VariationsService::GetLatestCountry() const { |
933 return local_state_->GetString(prefs::kVariationsCountry); | 937 const std::string override_country = |
| 938 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 939 switches::kVariationsOverrideCountry); |
| 940 return !override_country.empty() |
| 941 ? override_country |
| 942 : local_state_->GetString(prefs::kVariationsCountry); |
934 } | 943 } |
935 | 944 |
936 } // namespace variations | 945 } // namespace variations |
OLD | NEW |