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

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

Issue 688973004: Plumbing for variations headers from synthetic field trials. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Expose another hashed API in variations_associated_data.h Created 6 years, 1 month 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 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 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 int64 value = local_state_->GetInt64(path); 1131 int64 value = local_state_->GetInt64(path);
1132 local_state_->SetInt64(path, value + 1); 1132 local_state_->SetInt64(path, value + 1);
1133 } 1133 }
1134 1134
1135 bool MetricsService::UmaMetricsProperlyShutdown() { 1135 bool MetricsService::UmaMetricsProperlyShutdown() {
1136 CHECK(clean_shutdown_status_ == CLEANLY_SHUTDOWN || 1136 CHECK(clean_shutdown_status_ == CLEANLY_SHUTDOWN ||
1137 clean_shutdown_status_ == NEED_TO_SHUTDOWN); 1137 clean_shutdown_status_ == NEED_TO_SHUTDOWN);
1138 return clean_shutdown_status_ == CLEANLY_SHUTDOWN; 1138 return clean_shutdown_status_ == CLEANLY_SHUTDOWN;
1139 } 1139 }
1140 1140
1141 void MetricsService::AddSyntheticTrialObserver(
1142 SyntheticTrialObserver* observer) {
1143 synthetic_trial_observer_list_.AddObserver(observer);
1144 if (!synthetic_trial_groups_.empty())
1145 observer->OnSyntheticTrialsChanged(synthetic_trial_groups_);
1146 }
1147
1148 void MetricsService::RemoveSyntheticTrialObserver(
1149 SyntheticTrialObserver* observer) {
1150 synthetic_trial_observer_list_.RemoveObserver(observer);
1151 }
1152
1141 void MetricsService::RegisterSyntheticFieldTrial( 1153 void MetricsService::RegisterSyntheticFieldTrial(
1142 const SyntheticTrialGroup& trial) { 1154 const SyntheticTrialGroup& trial) {
1143 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) { 1155 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) {
1144 if (synthetic_trial_groups_[i].id.name == trial.id.name) { 1156 if (synthetic_trial_groups_[i].id.name == trial.id.name) {
1145 if (synthetic_trial_groups_[i].id.group != trial.id.group) { 1157 if (synthetic_trial_groups_[i].id.group != trial.id.group) {
1146 synthetic_trial_groups_[i].id.group = trial.id.group; 1158 synthetic_trial_groups_[i].id.group = trial.id.group;
1147 synthetic_trial_groups_[i].start_time = base::TimeTicks::Now(); 1159 synthetic_trial_groups_[i].start_time = base::TimeTicks::Now();
1160 NotifySyntheticTrialObservers();
1148 } 1161 }
1149 return; 1162 return;
1150 } 1163 }
1151 } 1164 }
1152 1165
1153 SyntheticTrialGroup trial_group = trial; 1166 SyntheticTrialGroup trial_group = trial;
1154 trial_group.start_time = base::TimeTicks::Now(); 1167 trial_group.start_time = base::TimeTicks::Now();
1155 synthetic_trial_groups_.push_back(trial_group); 1168 synthetic_trial_groups_.push_back(trial_group);
1169 NotifySyntheticTrialObservers();
1156 } 1170 }
1157 1171
1158 void MetricsService::RegisterMetricsProvider( 1172 void MetricsService::RegisterMetricsProvider(
1159 scoped_ptr<MetricsProvider> provider) { 1173 scoped_ptr<MetricsProvider> provider) {
1160 DCHECK_EQ(INITIALIZED, state_); 1174 DCHECK_EQ(INITIALIZED, state_);
1161 metrics_providers_.push_back(provider.release()); 1175 metrics_providers_.push_back(provider.release());
1162 } 1176 }
1163 1177
1164 void MetricsService::CheckForClonedInstall( 1178 void MetricsService::CheckForClonedInstall(
1165 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 1179 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
1166 state_manager_->CheckForClonedInstall(task_runner); 1180 state_manager_->CheckForClonedInstall(task_runner);
1167 } 1181 }
1168 1182
1183 void MetricsService::NotifySyntheticTrialObservers() {
1184 FOR_EACH_OBSERVER(SyntheticTrialObserver, synthetic_trial_observer_list_,
1185 OnSyntheticTrialsChanged(synthetic_trial_groups_));
1186 }
1187
1169 void MetricsService::GetCurrentSyntheticFieldTrials( 1188 void MetricsService::GetCurrentSyntheticFieldTrials(
1170 std::vector<variations::ActiveGroupId>* synthetic_trials) { 1189 std::vector<variations::ActiveGroupId>* synthetic_trials) {
1171 DCHECK(synthetic_trials); 1190 DCHECK(synthetic_trials);
1172 synthetic_trials->clear(); 1191 synthetic_trials->clear();
1173 const MetricsLog* current_log = log_manager_.current_log(); 1192 const MetricsLog* current_log = log_manager_.current_log();
1174 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) { 1193 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) {
1175 if (synthetic_trial_groups_[i].start_time <= current_log->creation_time()) 1194 if (synthetic_trial_groups_[i].start_time <= current_log->creation_time())
1176 synthetic_trials->push_back(synthetic_trial_groups_[i].id); 1195 synthetic_trials->push_back(synthetic_trial_groups_[i].id);
1177 } 1196 }
1178 } 1197 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 local_state_->SetBoolean(path, value); 1251 local_state_->SetBoolean(path, value);
1233 RecordCurrentState(local_state_); 1252 RecordCurrentState(local_state_);
1234 } 1253 }
1235 1254
1236 void MetricsService::RecordCurrentState(PrefService* pref) { 1255 void MetricsService::RecordCurrentState(PrefService* pref) {
1237 pref->SetInt64(prefs::kStabilityLastTimestampSec, 1256 pref->SetInt64(prefs::kStabilityLastTimestampSec,
1238 base::Time::Now().ToTimeT()); 1257 base::Time::Now().ToTimeT());
1239 } 1258 }
1240 1259
1241 } // namespace metrics 1260 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698