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

Side by Side Diff: components/variations/service/variations_service.cc

Issue 2924983003: [Variations] Refactor all state used for study filtering into a container struct. (Closed)
Patch Set: A bit more cleanup Created 3 years, 6 months 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 (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
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
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 std::unique_ptr<ClientFilterableState> state =
630 base::MakeUnique<ClientFilterableState>();
631 state->locale = client_->GetApplicationLocale();
632 state->reference_date = GetReferenceDateForExpiryChecks(local_state_);
633 state->version = version;
634 state->channel = GetChannelForVariations(client_->GetChannel());
635 state->form_factor = GetCurrentFormFactor();
636 state->platform = ClientFilterableState::GetCurrentPlatform();
637 state->hardware_class = GetHardwareClass();
638 state->session_consistency_country = GetLatestCountry();
639 state->permanent_consistency_country = LoadPermanentConsistencyCountry(
640 version, state->session_consistency_country);
641 return state;
642 }
643
630 void VariationsService::FetchVariationsSeed() { 644 void VariationsService::FetchVariationsSeed() {
631 DCHECK(thread_checker_.CalledOnValidThread()); 645 DCHECK(thread_checker_.CalledOnValidThread());
632 646
633 const web_resource::ResourceRequestAllowedNotifier::State state = 647 const web_resource::ResourceRequestAllowedNotifier::State state =
634 resource_request_allowed_notifier_->GetResourceRequestsAllowedState(); 648 resource_request_allowed_notifier_->GetResourceRequestsAllowedState();
635 RecordRequestsAllowedHistogram(ResourceRequestStateToHistogramValue(state)); 649 RecordRequestsAllowedHistogram(ResourceRequestStateToHistogramValue(state));
636 if (state != web_resource::ResourceRequestAllowedNotifier::ALLOWED) { 650 if (state != web_resource::ResourceRequestAllowedNotifier::ALLOWED) {
637 DVLOG(1) << "Resource requests were not allowed. Waiting for notification."; 651 DVLOG(1) << "Resource requests were not allowed. Waiting for notification.";
638 return; 652 return;
639 } 653 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 778
765 const base::ElapsedTimer timer; 779 const base::ElapsedTimer timer;
766 780
767 std::unique_ptr<const base::FieldTrial::EntropyProvider> default_provider = 781 std::unique_ptr<const base::FieldTrial::EntropyProvider> default_provider =
768 state_manager_->CreateDefaultEntropyProvider(); 782 state_manager_->CreateDefaultEntropyProvider();
769 std::unique_ptr<const base::FieldTrial::EntropyProvider> low_provider = 783 std::unique_ptr<const base::FieldTrial::EntropyProvider> low_provider =
770 state_manager_->CreateLowEntropyProvider(); 784 state_manager_->CreateLowEntropyProvider();
771 variations::VariationsSeedSimulator seed_simulator(*default_provider, 785 variations::VariationsSeedSimulator seed_simulator(*default_provider,
772 *low_provider); 786 *low_provider);
773 787
774 const std::string latest_country = GetLatestCountry(); 788 std::unique_ptr<ClientFilterableState> client_state =
775 const variations::VariationsSeedSimulator::Result result = 789 GetClientFilterableStateForVersion(version);
776 seed_simulator.SimulateSeedStudies( 790 const VariationsSeedSimulator::Result result =
777 *seed, client_->GetApplicationLocale(), 791 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 792
783 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.NormalChanges", 793 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.NormalChanges",
784 result.normal_group_change_count); 794 result.normal_group_change_count);
785 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.KillBestEffortChanges", 795 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.KillBestEffortChanges",
786 result.kill_best_effort_group_change_count); 796 result.kill_best_effort_group_change_count);
787 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.KillCriticalChanges", 797 UMA_HISTOGRAM_COUNTS_100("Variations.SimulateSeed.KillCriticalChanges",
788 result.kill_critical_group_change_count); 798 result.kill_critical_group_change_count);
789 799
790 UMA_HISTOGRAM_TIMES("Variations.SimulateSeed.Duration", timer.Elapsed()); 800 UMA_HISTOGRAM_TIMES("Variations.SimulateSeed.Duration", timer.Elapsed());
791 801
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 std::string VariationsService::GetLatestCountry() const { 938 std::string VariationsService::GetLatestCountry() const {
929 const std::string override_country = 939 const std::string override_country =
930 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 940 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
931 switches::kVariationsOverrideCountry); 941 switches::kVariationsOverrideCountry);
932 return !override_country.empty() 942 return !override_country.empty()
933 ? override_country 943 ? override_country
934 : local_state_->GetString(prefs::kVariationsCountry); 944 : local_state_->GetString(prefs::kVariationsCountry);
935 } 945 }
936 946
937 } // namespace variations 947 } // namespace variations
OLDNEW
« no previous file with comments | « components/variations/service/variations_service.h ('k') | components/variations/study_filtering.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698