| 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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 const base::Version current_version(version_info::GetVersionNumber()); | 329 const base::Version current_version(version_info::GetVersionNumber()); |
| 330 if (!current_version.IsValid()) | 330 if (!current_version.IsValid()) |
| 331 return false; | 331 return false; |
| 332 | 332 |
| 333 variations::Study_Channel channel = | 333 variations::Study_Channel channel = |
| 334 GetChannelForVariations(client_->GetChannel()); | 334 GetChannelForVariations(client_->GetChannel()); |
| 335 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.UserChannel", channel); | 335 UMA_HISTOGRAM_SPARSE_SLOWLY("Variations.UserChannel", channel); |
| 336 | 336 |
| 337 const std::string latest_country = | 337 const std::string latest_country = |
| 338 local_state_->GetString(prefs::kVariationsCountry); | 338 local_state_->GetString(prefs::kVariationsCountry); |
| 339 |
| 340 std::unique_ptr<const base::FieldTrial::EntropyProvider> low_entropy_provider( |
| 341 CreateLowEntropyProvider()); |
| 339 // Note that passing |&ui_string_overrider_| via base::Unretained below is | 342 // Note that passing |&ui_string_overrider_| via base::Unretained below is |
| 340 // safe because the callback is executed synchronously. It is not possible | 343 // safe because the callback is executed synchronously. It is not possible |
| 341 // to pass UIStringOverrider itself to VariationSeedProcesor as variations | 344 // to pass UIStringOverrider itself to VariationSeedProcesor as variations |
| 342 // components should not depends on //ui/base. | 345 // components should not depends on //ui/base. |
| 343 variations::VariationsSeedProcessor().CreateTrialsFromSeed( | 346 variations::VariationsSeedProcessor().CreateTrialsFromSeed( |
| 344 seed, client_->GetApplicationLocale(), | 347 seed, client_->GetApplicationLocale(), |
| 345 GetReferenceDateForExpiryChecks(local_state_), current_version, channel, | 348 GetReferenceDateForExpiryChecks(local_state_), current_version, channel, |
| 346 GetCurrentFormFactor(), GetHardwareClass(), latest_country, | 349 GetCurrentFormFactor(), GetHardwareClass(), latest_country, |
| 347 LoadPermanentConsistencyCountry(current_version, latest_country), | 350 LoadPermanentConsistencyCountry(current_version, latest_country), |
| 348 base::Bind(&UIStringOverrider::OverrideUIString, | 351 base::Bind(&UIStringOverrider::OverrideUIString, |
| 349 base::Unretained(&ui_string_overrider_)), | 352 base::Unretained(&ui_string_overrider_)), |
| 350 feature_list); | 353 low_entropy_provider.get(), feature_list); |
| 351 | 354 |
| 352 const base::Time now = base::Time::Now(); | 355 const base::Time now = base::Time::Now(); |
| 353 | 356 |
| 354 // Log the "freshness" of the seed that was just used. The freshness is the | 357 // Log the "freshness" of the seed that was just used. The freshness is the |
| 355 // time between the last successful seed download and now. | 358 // time between the last successful seed download and now. |
| 356 if (last_fetch_time_internal) { | 359 if (last_fetch_time_internal) { |
| 357 const base::TimeDelta delta = | 360 const base::TimeDelta delta = |
| 358 now - base::Time::FromInternalValue(last_fetch_time_internal); | 361 now - base::Time::FromInternalValue(last_fetch_time_internal); |
| 359 // Log the value in number of minutes. | 362 // Log the value in number of minutes. |
| 360 UMA_HISTOGRAM_CUSTOM_COUNTS("Variations.SeedFreshness", delta.InMinutes(), | 363 UMA_HISTOGRAM_CUSTOM_COUNTS("Variations.SeedFreshness", delta.InMinutes(), |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 return true; | 591 return true; |
| 589 | 592 |
| 590 base::PostTaskAndReplyWithResult( | 593 base::PostTaskAndReplyWithResult( |
| 591 client_->GetBlockingPool(), FROM_HERE, | 594 client_->GetBlockingPool(), FROM_HERE, |
| 592 client_->GetVersionForSimulationCallback(), | 595 client_->GetVersionForSimulationCallback(), |
| 593 base::Bind(&VariationsService::PerformSimulationWithVersion, | 596 base::Bind(&VariationsService::PerformSimulationWithVersion, |
| 594 weak_ptr_factory_.GetWeakPtr(), base::Passed(&seed))); | 597 weak_ptr_factory_.GetWeakPtr(), base::Passed(&seed))); |
| 595 return true; | 598 return true; |
| 596 } | 599 } |
| 597 | 600 |
| 601 std::unique_ptr<const base::FieldTrial::EntropyProvider> |
| 602 VariationsService::CreateLowEntropyProvider() { |
| 603 return state_manager_->CreateLowEntropyProvider(); |
| 604 } |
| 605 |
| 598 bool VariationsService::LoadSeed(VariationsSeed* seed) { | 606 bool VariationsService::LoadSeed(VariationsSeed* seed) { |
| 599 return seed_store_.LoadSeed(seed); | 607 return seed_store_.LoadSeed(seed); |
| 600 } | 608 } |
| 601 | 609 |
| 602 void VariationsService::FetchVariationsSeed() { | 610 void VariationsService::FetchVariationsSeed() { |
| 603 DCHECK(thread_checker_.CalledOnValidThread()); | 611 DCHECK(thread_checker_.CalledOnValidThread()); |
| 604 | 612 |
| 605 const web_resource::ResourceRequestAllowedNotifier::State state = | 613 const web_resource::ResourceRequestAllowedNotifier::State state = |
| 606 resource_request_allowed_notifier_->GetResourceRequestsAllowedState(); | 614 resource_request_allowed_notifier_->GetResourceRequestsAllowedState(); |
| 607 RecordRequestsAllowedHistogram(ResourceRequestStateToHistogramValue(state)); | 615 RecordRequestsAllowedHistogram(ResourceRequestStateToHistogramValue(state)); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 void VariationsService::PerformSimulationWithVersion( | 740 void VariationsService::PerformSimulationWithVersion( |
| 733 std::unique_ptr<variations::VariationsSeed> seed, | 741 std::unique_ptr<variations::VariationsSeed> seed, |
| 734 const base::Version& version) { | 742 const base::Version& version) { |
| 735 DCHECK(thread_checker_.CalledOnValidThread()); | 743 DCHECK(thread_checker_.CalledOnValidThread()); |
| 736 | 744 |
| 737 if (!version.IsValid()) | 745 if (!version.IsValid()) |
| 738 return; | 746 return; |
| 739 | 747 |
| 740 const base::ElapsedTimer timer; | 748 const base::ElapsedTimer timer; |
| 741 | 749 |
| 742 std::unique_ptr<const base::FieldTrial::EntropyProvider> entropy_provider = | 750 std::unique_ptr<const base::FieldTrial::EntropyProvider> default_provider = |
| 743 state_manager_->CreateEntropyProvider(); | 751 state_manager_->CreateDefaultEntropyProvider(); |
| 744 variations::VariationsSeedSimulator seed_simulator(*entropy_provider); | 752 std::unique_ptr<const base::FieldTrial::EntropyProvider> low_provider = |
| 753 state_manager_->CreateLowEntropyProvider(); |
| 754 variations::VariationsSeedSimulator seed_simulator(*default_provider, |
| 755 *low_provider); |
| 745 | 756 |
| 746 const std::string latest_country = | 757 const std::string latest_country = |
| 747 local_state_->GetString(prefs::kVariationsCountry); | 758 local_state_->GetString(prefs::kVariationsCountry); |
| 748 const variations::VariationsSeedSimulator::Result result = | 759 const variations::VariationsSeedSimulator::Result result = |
| 749 seed_simulator.SimulateSeedStudies( | 760 seed_simulator.SimulateSeedStudies( |
| 750 *seed, client_->GetApplicationLocale(), | 761 *seed, client_->GetApplicationLocale(), |
| 751 GetReferenceDateForExpiryChecks(local_state_), version, | 762 GetReferenceDateForExpiryChecks(local_state_), version, |
| 752 GetChannelForVariations(client_->GetChannel()), | 763 GetChannelForVariations(client_->GetChannel()), |
| 753 GetCurrentFormFactor(), GetHardwareClass(), latest_country, | 764 GetCurrentFormFactor(), GetHardwareClass(), latest_country, |
| 754 LoadPermanentConsistencyCountry(version, latest_country)); | 765 LoadPermanentConsistencyCountry(version, latest_country)); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 | 897 |
| 887 if (got_stored_country && stored_country == country_override) | 898 if (got_stored_country && stored_country == country_override) |
| 888 return false; | 899 return false; |
| 889 | 900 |
| 890 base::Version version(version_info::GetVersionNumber()); | 901 base::Version version(version_info::GetVersionNumber()); |
| 891 StorePermanentCountry(version, country_override); | 902 StorePermanentCountry(version, country_override); |
| 892 return true; | 903 return true; |
| 893 } | 904 } |
| 894 | 905 |
| 895 } // namespace variations | 906 } // namespace variations |
| OLD | NEW |