OLD | NEW |
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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 // MetricsServiceClient outlives MetricsService, and | 328 // MetricsServiceClient outlives MetricsService, and |
329 // MetricsReportingScheduler is tied to the lifetime of |this|. | 329 // MetricsReportingScheduler is tied to the lifetime of |this|. |
330 base::Bind(&MetricsServiceClient::GetStandardUploadInterval, | 330 base::Bind(&MetricsServiceClient::GetStandardUploadInterval, |
331 base::Unretained(client_)))); | 331 base::Unretained(client_)))); |
332 } | 332 } |
333 | 333 |
334 void MetricsService::Start() { | 334 void MetricsService::Start() { |
335 HandleIdleSinceLastTransmission(false); | 335 HandleIdleSinceLastTransmission(false); |
336 EnableRecording(); | 336 EnableRecording(); |
337 EnableReporting(); | 337 EnableReporting(); |
| 338 |
| 339 FOR_EACH_OBSERVER(MetricsServiceObserver, |
| 340 metrics_service_observer_list_, |
| 341 OnMetricsServiceStart()); |
338 } | 342 } |
339 | 343 |
340 void MetricsService::StartRecordingForTests() { | 344 void MetricsService::StartRecordingForTests() { |
341 test_mode_active_ = true; | 345 test_mode_active_ = true; |
342 EnableRecording(); | 346 EnableRecording(); |
343 DisableReporting(); | 347 DisableReporting(); |
344 } | 348 } |
345 | 349 |
346 void MetricsService::Stop() { | 350 void MetricsService::Stop() { |
| 351 FOR_EACH_OBSERVER(MetricsServiceObserver, |
| 352 metrics_service_observer_list_, |
| 353 OnMetricsServiceStop()); |
| 354 |
347 HandleIdleSinceLastTransmission(false); | 355 HandleIdleSinceLastTransmission(false); |
348 DisableReporting(); | 356 DisableReporting(); |
349 DisableRecording(); | 357 DisableRecording(); |
350 } | 358 } |
351 | 359 |
352 void MetricsService::EnableReporting() { | 360 void MetricsService::EnableReporting() { |
353 if (reporting_active_) | 361 if (reporting_active_) |
354 return; | 362 return; |
355 reporting_active_ = true; | 363 reporting_active_ = true; |
356 StartSchedulerIfNecessary(); | 364 StartSchedulerIfNecessary(); |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 synthetic_trial_observer_list_.AddObserver(observer); | 1037 synthetic_trial_observer_list_.AddObserver(observer); |
1030 if (!synthetic_trial_groups_.empty()) | 1038 if (!synthetic_trial_groups_.empty()) |
1031 observer->OnSyntheticTrialsChanged(synthetic_trial_groups_); | 1039 observer->OnSyntheticTrialsChanged(synthetic_trial_groups_); |
1032 } | 1040 } |
1033 | 1041 |
1034 void MetricsService::RemoveSyntheticTrialObserver( | 1042 void MetricsService::RemoveSyntheticTrialObserver( |
1035 SyntheticTrialObserver* observer) { | 1043 SyntheticTrialObserver* observer) { |
1036 synthetic_trial_observer_list_.RemoveObserver(observer); | 1044 synthetic_trial_observer_list_.RemoveObserver(observer); |
1037 } | 1045 } |
1038 | 1046 |
| 1047 void MetricsService::AddObserver(MetricsServiceObserver* observer) { |
| 1048 metrics_service_observer_list_.AddObserver(observer); |
| 1049 } |
| 1050 |
| 1051 void MetricsService::RemoveObserver(MetricsServiceObserver* observer) { |
| 1052 metrics_service_observer_list_.RemoveObserver(observer); |
| 1053 } |
| 1054 |
1039 void MetricsService::RegisterSyntheticFieldTrial( | 1055 void MetricsService::RegisterSyntheticFieldTrial( |
1040 const SyntheticTrialGroup& trial) { | 1056 const SyntheticTrialGroup& trial) { |
1041 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) { | 1057 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) { |
1042 if (synthetic_trial_groups_[i].id.name == trial.id.name) { | 1058 if (synthetic_trial_groups_[i].id.name == trial.id.name) { |
1043 if (synthetic_trial_groups_[i].id.group != trial.id.group) { | 1059 if (synthetic_trial_groups_[i].id.group != trial.id.group) { |
1044 synthetic_trial_groups_[i].id.group = trial.id.group; | 1060 synthetic_trial_groups_[i].id.group = trial.id.group; |
1045 synthetic_trial_groups_[i].start_time = base::TimeTicks::Now(); | 1061 synthetic_trial_groups_[i].start_time = base::TimeTicks::Now(); |
1046 NotifySyntheticTrialObservers(); | 1062 NotifySyntheticTrialObservers(); |
1047 } | 1063 } |
1048 return; | 1064 return; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 base::Time::Now().ToTimeT()); | 1154 base::Time::Now().ToTimeT()); |
1139 } | 1155 } |
1140 | 1156 |
1141 void MetricsService::SkipAndDiscardUpload() { | 1157 void MetricsService::SkipAndDiscardUpload() { |
1142 log_manager_.DiscardStagedLog(); | 1158 log_manager_.DiscardStagedLog(); |
1143 scheduler_->UploadCancelled(); | 1159 scheduler_->UploadCancelled(); |
1144 log_upload_in_progress_ = false; | 1160 log_upload_in_progress_ = false; |
1145 } | 1161 } |
1146 | 1162 |
1147 } // namespace metrics | 1163 } // namespace metrics |
OLD | NEW |