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

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

Issue 1530133005: Refactor VariationsHttpHeaderProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing include to srt_fetcher_win.cc. Created 5 years 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_accessor.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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 235
236 int probability; 236 int probability;
237 // In case specified sampling rate is invalid. 237 // In case specified sampling rate is invalid.
238 if (!base::StringToInt(probability_str, &probability)) 238 if (!base::StringToInt(probability_str, &probability))
239 return true; 239 return true;
240 return base::RandInt(1, 100) <= probability; 240 return base::RandInt(1, 100) <= probability;
241 } 241 }
242 242
243 } // namespace 243 } // namespace
244 244
245
246 SyntheticTrialGroup::SyntheticTrialGroup(uint32 trial, uint32 group) {
247 id.name = trial;
248 id.group = group;
249 }
250
251 SyntheticTrialGroup::~SyntheticTrialGroup() {
252 }
253
254 // static 245 // static
255 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = 246 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ =
256 MetricsService::CLEANLY_SHUTDOWN; 247 MetricsService::CLEANLY_SHUTDOWN;
257 248
258 MetricsService::ExecutionPhase MetricsService::execution_phase_ = 249 MetricsService::ExecutionPhase MetricsService::execution_phase_ =
259 MetricsService::UNINITIALIZED_PHASE; 250 MetricsService::UNINITIALIZED_PHASE;
260 251
261 // static 252 // static
262 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) { 253 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) {
263 DCHECK(IsSingleThreaded()); 254 DCHECK(IsSingleThreaded());
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 local_state_->SetInt64(path, value + 1); 1009 local_state_->SetInt64(path, value + 1);
1019 } 1010 }
1020 1011
1021 bool MetricsService::UmaMetricsProperlyShutdown() { 1012 bool MetricsService::UmaMetricsProperlyShutdown() {
1022 CHECK(clean_shutdown_status_ == CLEANLY_SHUTDOWN || 1013 CHECK(clean_shutdown_status_ == CLEANLY_SHUTDOWN ||
1023 clean_shutdown_status_ == NEED_TO_SHUTDOWN); 1014 clean_shutdown_status_ == NEED_TO_SHUTDOWN);
1024 return clean_shutdown_status_ == CLEANLY_SHUTDOWN; 1015 return clean_shutdown_status_ == CLEANLY_SHUTDOWN;
1025 } 1016 }
1026 1017
1027 void MetricsService::AddSyntheticTrialObserver( 1018 void MetricsService::AddSyntheticTrialObserver(
1028 SyntheticTrialObserver* observer) { 1019 variations::SyntheticTrialObserver* observer) {
1029 synthetic_trial_observer_list_.AddObserver(observer); 1020 synthetic_trial_observer_list_.AddObserver(observer);
1030 if (!synthetic_trial_groups_.empty()) 1021 if (!synthetic_trial_groups_.empty())
1031 observer->OnSyntheticTrialsChanged(synthetic_trial_groups_); 1022 observer->OnSyntheticTrialsChanged(synthetic_trial_groups_);
1032 } 1023 }
1033 1024
1034 void MetricsService::RemoveSyntheticTrialObserver( 1025 void MetricsService::RemoveSyntheticTrialObserver(
1035 SyntheticTrialObserver* observer) { 1026 variations::SyntheticTrialObserver* observer) {
1036 synthetic_trial_observer_list_.RemoveObserver(observer); 1027 synthetic_trial_observer_list_.RemoveObserver(observer);
1037 } 1028 }
1038 1029
1039 void MetricsService::RegisterSyntheticFieldTrial( 1030 void MetricsService::RegisterSyntheticFieldTrial(
1040 const SyntheticTrialGroup& trial) { 1031 const variations::SyntheticTrialGroup& trial) {
1041 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) { 1032 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) {
1042 if (synthetic_trial_groups_[i].id.name == trial.id.name) { 1033 if (synthetic_trial_groups_[i].id.name == trial.id.name) {
1043 if (synthetic_trial_groups_[i].id.group != trial.id.group) { 1034 if (synthetic_trial_groups_[i].id.group != trial.id.group) {
1044 synthetic_trial_groups_[i].id.group = trial.id.group; 1035 synthetic_trial_groups_[i].id.group = trial.id.group;
1045 synthetic_trial_groups_[i].start_time = base::TimeTicks::Now(); 1036 synthetic_trial_groups_[i].start_time = base::TimeTicks::Now();
1046 NotifySyntheticTrialObservers(); 1037 NotifySyntheticTrialObservers();
1047 } 1038 }
1048 return; 1039 return;
1049 } 1040 }
1050 } 1041 }
1051 1042
1052 SyntheticTrialGroup trial_group = trial; 1043 variations::SyntheticTrialGroup trial_group = trial;
1053 trial_group.start_time = base::TimeTicks::Now(); 1044 trial_group.start_time = base::TimeTicks::Now();
1054 synthetic_trial_groups_.push_back(trial_group); 1045 synthetic_trial_groups_.push_back(trial_group);
1055 NotifySyntheticTrialObservers(); 1046 NotifySyntheticTrialObservers();
1056 } 1047 }
1057 1048
1058 void MetricsService::GetCurrentSyntheticFieldTrialsForTesting( 1049 void MetricsService::GetCurrentSyntheticFieldTrialsForTesting(
1059 std::vector<variations::ActiveGroupId>* synthetic_trials) { 1050 std::vector<variations::ActiveGroupId>* synthetic_trials) {
1060 GetSyntheticFieldTrialsOlderThan(base::TimeTicks::Now(), synthetic_trials); 1051 GetSyntheticFieldTrialsOlderThan(base::TimeTicks::Now(), synthetic_trials);
1061 } 1052 }
1062 1053
1063 void MetricsService::RegisterMetricsProvider( 1054 void MetricsService::RegisterMetricsProvider(
1064 scoped_ptr<MetricsProvider> provider) { 1055 scoped_ptr<MetricsProvider> provider) {
1065 DCHECK_EQ(INITIALIZED, state_); 1056 DCHECK_EQ(INITIALIZED, state_);
1066 metrics_providers_.push_back(provider.Pass()); 1057 metrics_providers_.push_back(provider.Pass());
1067 } 1058 }
1068 1059
1069 void MetricsService::CheckForClonedInstall( 1060 void MetricsService::CheckForClonedInstall(
1070 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 1061 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
1071 state_manager_->CheckForClonedInstall(task_runner); 1062 state_manager_->CheckForClonedInstall(task_runner);
1072 } 1063 }
1073 1064
1074 void MetricsService::NotifySyntheticTrialObservers() { 1065 void MetricsService::NotifySyntheticTrialObservers() {
1075 FOR_EACH_OBSERVER(SyntheticTrialObserver, synthetic_trial_observer_list_, 1066 FOR_EACH_OBSERVER(variations::SyntheticTrialObserver,
1067 synthetic_trial_observer_list_,
1076 OnSyntheticTrialsChanged(synthetic_trial_groups_)); 1068 OnSyntheticTrialsChanged(synthetic_trial_groups_));
1077 } 1069 }
1078 1070
1079 void MetricsService::GetSyntheticFieldTrialsOlderThan( 1071 void MetricsService::GetSyntheticFieldTrialsOlderThan(
1080 base::TimeTicks time, 1072 base::TimeTicks time,
1081 std::vector<variations::ActiveGroupId>* synthetic_trials) { 1073 std::vector<variations::ActiveGroupId>* synthetic_trials) {
1082 DCHECK(synthetic_trials); 1074 DCHECK(synthetic_trials);
1083 synthetic_trials->clear(); 1075 synthetic_trials->clear();
1084 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) { 1076 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) {
1085 if (synthetic_trial_groups_[i].start_time <= time) 1077 if (synthetic_trial_groups_[i].start_time <= time)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 base::Time::Now().ToTimeT()); 1135 base::Time::Now().ToTimeT());
1144 } 1136 }
1145 1137
1146 void MetricsService::SkipAndDiscardUpload() { 1138 void MetricsService::SkipAndDiscardUpload() {
1147 log_manager_.DiscardStagedLog(); 1139 log_manager_.DiscardStagedLog();
1148 scheduler_->UploadCancelled(); 1140 scheduler_->UploadCancelled();
1149 log_upload_in_progress_ = false; 1141 log_upload_in_progress_ = false;
1150 } 1142 }
1151 1143
1152 } // namespace metrics 1144 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/metrics_service.h ('k') | components/metrics/metrics_service_accessor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698