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

Side by Side Diff: components/metrics/metrics_service.cc

Issue 2975273003: Extract SyntheticTrialRegistry from MetricsService (Closed)
Patch Set: asdf Created 3 years, 5 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
« no previous file with comments | « components/metrics/metrics_service.h ('k') | components/metrics/metrics_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 //------------------------------------------------------------------------------ 5 //------------------------------------------------------------------------------
6 // Description of the life cycle of a instance of MetricsService. 6 // Description of the life cycle of a instance of MetricsService.
7 // 7 //
8 // OVERVIEW 8 // OVERVIEW
9 // 9 //
10 // A MetricsService instance is typically created at application startup. It is 10 // A MetricsService instance is typically created at application startup. It is
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 int64_t value = local_state_->GetInt64(path); 838 int64_t value = local_state_->GetInt64(path);
839 local_state_->SetInt64(path, value + 1); 839 local_state_->SetInt64(path, value + 1);
840 } 840 }
841 841
842 bool MetricsService::UmaMetricsProperlyShutdown() { 842 bool MetricsService::UmaMetricsProperlyShutdown() {
843 CHECK(clean_shutdown_status_ == CLEANLY_SHUTDOWN || 843 CHECK(clean_shutdown_status_ == CLEANLY_SHUTDOWN ||
844 clean_shutdown_status_ == NEED_TO_SHUTDOWN); 844 clean_shutdown_status_ == NEED_TO_SHUTDOWN);
845 return clean_shutdown_status_ == CLEANLY_SHUTDOWN; 845 return clean_shutdown_status_ == CLEANLY_SHUTDOWN;
846 } 846 }
847 847
848 void MetricsService::AddSyntheticTrialObserver(
849 variations::SyntheticTrialObserver* observer) {
850 synthetic_trial_observer_list_.AddObserver(observer);
851 if (!synthetic_trial_groups_.empty())
852 observer->OnSyntheticTrialsChanged(synthetic_trial_groups_);
853 }
854
855 void MetricsService::RemoveSyntheticTrialObserver(
856 variations::SyntheticTrialObserver* observer) {
857 synthetic_trial_observer_list_.RemoveObserver(observer);
858 }
859
860 void MetricsService::RegisterSyntheticFieldTrial(
861 const variations::SyntheticTrialGroup& trial) {
862 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) {
863 if (synthetic_trial_groups_[i].id.name == trial.id.name) {
864 if (synthetic_trial_groups_[i].id.group != trial.id.group) {
865 synthetic_trial_groups_[i].id.group = trial.id.group;
866 synthetic_trial_groups_[i].start_time = base::TimeTicks::Now();
867 NotifySyntheticTrialObservers();
868 }
869 return;
870 }
871 }
872
873 variations::SyntheticTrialGroup trial_group = trial;
874 trial_group.start_time = base::TimeTicks::Now();
875 synthetic_trial_groups_.push_back(trial_group);
876 NotifySyntheticTrialObservers();
877 }
878
879 void MetricsService::RegisterSyntheticMultiGroupFieldTrial(
880 uint32_t trial_name_hash,
881 const std::vector<uint32_t>& group_name_hashes) {
882 auto has_same_trial_name =
883 [trial_name_hash](const variations::SyntheticTrialGroup& x) {
884 return x.id.name == trial_name_hash;
885 };
886 synthetic_trial_groups_.erase(
887 std::remove_if(synthetic_trial_groups_.begin(),
888 synthetic_trial_groups_.end(), has_same_trial_name),
889 synthetic_trial_groups_.end());
890
891 if (group_name_hashes.empty())
892 return;
893
894 variations::SyntheticTrialGroup trial_group(trial_name_hash,
895 group_name_hashes[0]);
896 trial_group.start_time = base::TimeTicks::Now();
897 for (uint32_t group_name_hash : group_name_hashes) {
898 // Note: Adding the trial group will copy it, so this re-uses the same
899 // |trial_group| struct for convenience (e.g. so start_time's all match).
900 trial_group.id.group = group_name_hash;
901 synthetic_trial_groups_.push_back(trial_group);
902 }
903 NotifySyntheticTrialObservers();
904 }
905
906 void MetricsService::GetCurrentSyntheticFieldTrialsForTesting(
907 std::vector<variations::ActiveGroupId>* synthetic_trials) {
908 GetSyntheticFieldTrialsOlderThan(base::TimeTicks::Now(), synthetic_trials);
909 }
910
911 void MetricsService::RegisterMetricsProvider( 848 void MetricsService::RegisterMetricsProvider(
912 std::unique_ptr<MetricsProvider> provider) { 849 std::unique_ptr<MetricsProvider> provider) {
913 DCHECK_EQ(INITIALIZED, state_); 850 DCHECK_EQ(INITIALIZED, state_);
914 metrics_providers_.push_back(std::move(provider)); 851 metrics_providers_.push_back(std::move(provider));
915 } 852 }
916 853
917 void MetricsService::CheckForClonedInstall() { 854 void MetricsService::CheckForClonedInstall() {
918 state_manager_->CheckForClonedInstall(); 855 state_manager_->CheckForClonedInstall();
919 } 856 }
920 857
921 void MetricsService::NotifySyntheticTrialObservers() {
922 for (variations::SyntheticTrialObserver& observer :
923 synthetic_trial_observer_list_) {
924 observer.OnSyntheticTrialsChanged(synthetic_trial_groups_);
925 }
926 }
927
928 void MetricsService::GetSyntheticFieldTrialsOlderThan(
929 base::TimeTicks time,
930 std::vector<variations::ActiveGroupId>* synthetic_trials) {
931 DCHECK(synthetic_trials);
932 synthetic_trials->clear();
933 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) {
934 if (synthetic_trial_groups_[i].start_time <= time)
935 synthetic_trials->push_back(synthetic_trial_groups_[i].id);
936 }
937 }
938
939 std::unique_ptr<MetricsLog> MetricsService::CreateLog( 858 std::unique_ptr<MetricsLog> MetricsService::CreateLog(
940 MetricsLog::LogType log_type) { 859 MetricsLog::LogType log_type) {
941 return base::MakeUnique<MetricsLog>(state_manager_->client_id(), session_id_, 860 return base::MakeUnique<MetricsLog>(state_manager_->client_id(), session_id_,
942 log_type, client_, local_state_); 861 log_type, client_, local_state_);
943 } 862 }
944 863
945 void MetricsService::RecordCurrentEnvironment(MetricsLog* log) { 864 void MetricsService::RecordCurrentEnvironment(MetricsLog* log) {
946 DCHECK(client_); 865 DCHECK(client_);
947 std::vector<variations::ActiveGroupId> synthetic_trials; 866 std::vector<variations::ActiveGroupId> synthetic_trials;
948 GetSyntheticFieldTrialsOlderThan(log->creation_time(), &synthetic_trials); 867 GetSyntheticFieldTrialsOlderThan(log->creation_time(), &synthetic_trials);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 // Redundant setting to assure that we always reset this value at shutdown 931 // Redundant setting to assure that we always reset this value at shutdown
1013 // (and that we don't use some alternate path, and not call LogCleanShutdown). 932 // (and that we don't use some alternate path, and not call LogCleanShutdown).
1014 clean_shutdown_status_ = CLEANLY_SHUTDOWN; 933 clean_shutdown_status_ = CLEANLY_SHUTDOWN;
1015 client_->OnLogCleanShutdown(); 934 client_->OnLogCleanShutdown();
1016 state_manager_->clean_exit_beacon()->WriteBeaconValue(true); 935 state_manager_->clean_exit_beacon()->WriteBeaconValue(true);
1017 SetExecutionPhase(ExecutionPhase::SHUTDOWN_COMPLETE, local_state_); 936 SetExecutionPhase(ExecutionPhase::SHUTDOWN_COMPLETE, local_state_);
1018 StabilityMetricsProvider(local_state_).MarkSessionEndCompleted(end_completed); 937 StabilityMetricsProvider(local_state_).MarkSessionEndCompleted(end_completed);
1019 } 938 }
1020 939
1021 } // namespace metrics 940 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/metrics_service.h ('k') | components/metrics/metrics_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698