Chromium Code Reviews| 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> |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 RecordCreateTrialsSeedExpiry(VARIATIONS_SEED_EXPIRY_EXPIRED); | 326 RecordCreateTrialsSeedExpiry(VARIATIONS_SEED_EXPIRY_EXPIRED); |
| 327 return false; | 327 return false; |
| 328 } | 328 } |
| 329 RecordCreateTrialsSeedExpiry(VARIATIONS_SEED_EXPIRY_NOT_EXPIRED); | 329 RecordCreateTrialsSeedExpiry(VARIATIONS_SEED_EXPIRY_NOT_EXPIRED); |
| 330 } | 330 } |
| 331 | 331 |
| 332 const base::Version current_version(version_info::GetVersionNumber()); | 332 const base::Version current_version(version_info::GetVersionNumber()); |
| 333 if (!current_version.IsValid()) | 333 if (!current_version.IsValid()) |
| 334 return false; | 334 return false; |
| 335 | 335 |
| 336 variations::Study_Channel channel = | 336 std::unique_ptr<ClientFilterableState> client_state = |
| 337 GetChannelForVariations(client_->GetChannel()); | 337 GetClientFilterableStateForVersion(current_version); |
| 338 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.UserChannel", channel); | 338 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.UserChannel", client_state->channel); |
| 339 | 339 |
| 340 const std::string latest_country = GetLatestCountry(); | |
| 341 std::unique_ptr<const base::FieldTrial::EntropyProvider> low_entropy_provider( | 340 std::unique_ptr<const base::FieldTrial::EntropyProvider> low_entropy_provider( |
| 342 CreateLowEntropyProvider()); | 341 CreateLowEntropyProvider()); |
| 343 // Note that passing |&ui_string_overrider_| via base::Unretained below is | 342 // Note that passing |&ui_string_overrider_| via base::Unretained below is |
| 344 // safe because the callback is executed synchronously. It is not possible | 343 // safe because the callback is executed synchronously. It is not possible |
| 345 // to pass UIStringOverrider itself to VariationSeedProcesor as variations | 344 // to pass UIStringOverrider itself to VariationSeedProcessor as variations |
| 346 // components should not depends on //ui/base. | 345 // components should not depends on //ui/base. |
| 347 variations::VariationsSeedProcessor().CreateTrialsFromSeed( | 346 variations::VariationsSeedProcessor().CreateTrialsFromSeed( |
| 348 seed, client_->GetApplicationLocale(), | 347 seed, *client_state, |
| 349 GetReferenceDateForExpiryChecks(local_state_), current_version, channel, | |
| 350 GetCurrentFormFactor(), GetHardwareClass(), latest_country, | |
| 351 LoadPermanentConsistencyCountry(current_version, latest_country), | |
| 352 base::Bind(&UIStringOverrider::OverrideUIString, | 348 base::Bind(&UIStringOverrider::OverrideUIString, |
| 353 base::Unretained(&ui_string_overrider_)), | 349 base::Unretained(&ui_string_overrider_)), |
| 354 low_entropy_provider.get(), feature_list); | 350 low_entropy_provider.get(), feature_list); |
| 355 | 351 |
| 356 const base::Time now = base::Time::Now(); | 352 const base::Time now = base::Time::Now(); |
| 357 | 353 |
| 358 // Log the "freshness" of the seed that was just used. The freshness is the | 354 // Log the "freshness" of the seed that was just used. The freshness is the |
| 359 // time between the last successful seed download and now. | 355 // time between the last successful seed download and now. |
| 360 if (last_fetch_time_internal) { | 356 if (last_fetch_time_internal) { |
| 361 const base::TimeDelta delta = | 357 const base::TimeDelta delta = |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 | 616 |
| 621 std::unique_ptr<const base::FieldTrial::EntropyProvider> | 617 std::unique_ptr<const base::FieldTrial::EntropyProvider> |
| 622 VariationsService::CreateLowEntropyProvider() { | 618 VariationsService::CreateLowEntropyProvider() { |
| 623 return state_manager_->CreateLowEntropyProvider(); | 619 return state_manager_->CreateLowEntropyProvider(); |
| 624 } | 620 } |
| 625 | 621 |
| 626 bool VariationsService::LoadSeed(VariationsSeed* seed) { | 622 bool VariationsService::LoadSeed(VariationsSeed* seed) { |
| 627 return seed_store_.LoadSeed(seed); | 623 return seed_store_.LoadSeed(seed); |
| 628 } | 624 } |
| 629 | 625 |
| 626 std::unique_ptr<ClientFilterableState> | |
| 627 VariationsService::GetClientFilterableStateForVersion( | |
| 628 const base::Version& version) { | |
| 629 const std::string latest_country = GetLatestCountry(); | |
|
Alexei Svitkine (slow)
2017/06/07 15:18:08
Nit: Move closer to where it's used - above line 6
Ilya Sherman
2017/06/07 21:50:08
Done.
| |
| 630 | |
| 631 std::unique_ptr<ClientFilterableState> state = | |
| 632 base::MakeUnique<ClientFilterableState>(); | |
| 633 variations::Study::Channel channel = | |
| 634 GetChannelForVariations(client_->GetChannel()); | |
| 635 state->locale = client_->GetApplicationLocale(); | |
| 636 state->reference_date = GetReferenceDateForExpiryChecks(local_state_); | |
| 637 state->version = version; | |
| 638 state->channel = channel; | |
| 639 state->form_factor = GetCurrentFormFactor(); | |
| 640 state->platform = ClientFilterableState::GetCurrentPlatform(); | |
| 641 state->hardware_class = GetHardwareClass(); | |
| 642 state->session_consistency_country = latest_country; | |
| 643 state->permanent_consistency_country = | |
| 644 LoadPermanentConsistencyCountry(version, latest_country); | |
| 645 return state; | |
| 646 } | |
| 647 | |
| 630 void VariationsService::FetchVariationsSeed() { | 648 void VariationsService::FetchVariationsSeed() { |
| 631 DCHECK(thread_checker_.CalledOnValidThread()); | 649 DCHECK(thread_checker_.CalledOnValidThread()); |
| 632 | 650 |
| 633 const web_resource::ResourceRequestAllowedNotifier::State state = | 651 const web_resource::ResourceRequestAllowedNotifier::State state = |
| 634 resource_request_allowed_notifier_->GetResourceRequestsAllowedState(); | 652 resource_request_allowed_notifier_->GetResourceRequestsAllowedState(); |
| 635 RecordRequestsAllowedHistogram(ResourceRequestStateToHistogramValue(state)); | 653 RecordRequestsAllowedHistogram(ResourceRequestStateToHistogramValue(state)); |
| 636 if (state != web_resource::ResourceRequestAllowedNotifier::ALLOWED) { | 654 if (state != web_resource::ResourceRequestAllowedNotifier::ALLOWED) { |
| 637 DVLOG(1) << "Resource requests were not allowed. Waiting for notification."; | 655 DVLOG(1) << "Resource requests were not allowed. Waiting for notification."; |
| 638 return; | 656 return; |
| 639 } | 657 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 | 782 |
| 765 const base::ElapsedTimer timer; | 783 const base::ElapsedTimer timer; |
| 766 | 784 |
| 767 std::unique_ptr<const base::FieldTrial::EntropyProvider> default_provider = | 785 std::unique_ptr<const base::FieldTrial::EntropyProvider> default_provider = |
| 768 state_manager_->CreateDefaultEntropyProvider(); | 786 state_manager_->CreateDefaultEntropyProvider(); |
| 769 std::unique_ptr<const base::FieldTrial::EntropyProvider> low_provider = | 787 std::unique_ptr<const base::FieldTrial::EntropyProvider> low_provider = |
| 770 state_manager_->CreateLowEntropyProvider(); | 788 state_manager_->CreateLowEntropyProvider(); |
| 771 variations::VariationsSeedSimulator seed_simulator(*default_provider, | 789 variations::VariationsSeedSimulator seed_simulator(*default_provider, |
| 772 *low_provider); | 790 *low_provider); |
| 773 | 791 |
| 774 const std::string latest_country = GetLatestCountry(); | 792 std::unique_ptr<ClientFilterableState> client_state = |
| 775 const variations::VariationsSeedSimulator::Result result = | 793 GetClientFilterableStateForVersion(version); |
| 776 seed_simulator.SimulateSeedStudies( | 794 const VariationsSeedSimulator::Result result = |
| 777 *seed, client_->GetApplicationLocale(), | 795 seed_simulator.SimulateSeedStudies(*seed, *client_state); |
| 778 GetReferenceDateForExpiryChecks(local_state_), version, | |
| 779 GetChannelForVariations(client_->GetChannel()), | |
| 780 GetCurrentFormFactor(), GetHardwareClass(), latest_country, | |
| 781 LoadPermanentConsistencyCountry(version, latest_country)); | |
| 782 | 796 |
| 783 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.NormalChanges", | 797 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.NormalChanges", |
| 784 result.normal_group_change_count); | 798 result.normal_group_change_count); |
| 785 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.KillBestEffortChanges", | 799 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.KillBestEffortChanges", |
| 786 result.kill_best_effort_group_change_count); | 800 result.kill_best_effort_group_change_count); |
| 787 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.KillCriticalChanges", | 801 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.KillCriticalChanges", |
| 788 result.kill_critical_group_change_count); | 802 result.kill_critical_group_change_count); |
| 789 | 803 |
| 790 UMA_HISTOGRAM_TIMES("Variations.SimulateSeed.Duration", timer.Elapsed()); | 804 UMA_HISTOGRAM_TIMES("Variations.SimulateSeed.Duration", timer.Elapsed()); |
| 791 | 805 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 928 std::string VariationsService::GetLatestCountry() const { | 942 std::string VariationsService::GetLatestCountry() const { |
| 929 const std::string override_country = | 943 const std::string override_country = |
| 930 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 944 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 931 switches::kVariationsOverrideCountry); | 945 switches::kVariationsOverrideCountry); |
| 932 return !override_country.empty() | 946 return !override_country.empty() |
| 933 ? override_country | 947 ? override_country |
| 934 : local_state_->GetString(prefs::kVariationsCountry); | 948 : local_state_->GetString(prefs::kVariationsCountry); |
| 935 } | 949 } |
| 936 | 950 |
| 937 } // namespace variations | 951 } // namespace variations |
| OLD | NEW |