| 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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 base::Bind(&MetricsService::StartScheduledUpload, | 318 base::Bind(&MetricsService::StartScheduledUpload, |
| 319 self_ptr_factory_.GetWeakPtr()); | 319 self_ptr_factory_.GetWeakPtr()); |
| 320 scheduler_.reset( | 320 scheduler_.reset( |
| 321 new MetricsReportingScheduler( | 321 new MetricsReportingScheduler( |
| 322 upload_callback, | 322 upload_callback, |
| 323 // MetricsServiceClient outlives MetricsService, and | 323 // MetricsServiceClient outlives MetricsService, and |
| 324 // MetricsReportingScheduler is tied to the lifetime of |this|. | 324 // MetricsReportingScheduler is tied to the lifetime of |this|. |
| 325 base::Bind(&MetricsServiceClient::GetStandardUploadInterval, | 325 base::Bind(&MetricsServiceClient::GetStandardUploadInterval, |
| 326 base::Unretained(client_)))); | 326 base::Unretained(client_)))); |
| 327 | 327 |
| 328 for (size_t i = 0; i < metrics_providers_.size(); ++i) | 328 for (MetricsProvider* provider : metrics_providers_) |
| 329 metrics_providers_[i]->Init(); | 329 provider->Init(); |
| 330 } | 330 } |
| 331 | 331 |
| 332 void MetricsService::Start() { | 332 void MetricsService::Start() { |
| 333 HandleIdleSinceLastTransmission(false); | 333 HandleIdleSinceLastTransmission(false); |
| 334 EnableRecording(); | 334 EnableRecording(); |
| 335 EnableReporting(); | 335 EnableReporting(); |
| 336 } | 336 } |
| 337 | 337 |
| 338 void MetricsService::StartRecordingForTests() { | 338 void MetricsService::StartRecordingForTests() { |
| 339 test_mode_active_ = true; | 339 test_mode_active_ = true; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 | 386 |
| 387 if (recording_state_ == ACTIVE) | 387 if (recording_state_ == ACTIVE) |
| 388 return; | 388 return; |
| 389 recording_state_ = ACTIVE; | 389 recording_state_ = ACTIVE; |
| 390 | 390 |
| 391 state_manager_->ForceClientIdCreation(); | 391 state_manager_->ForceClientIdCreation(); |
| 392 client_->SetMetricsClientId(state_manager_->client_id()); | 392 client_->SetMetricsClientId(state_manager_->client_id()); |
| 393 if (!log_manager_.current_log()) | 393 if (!log_manager_.current_log()) |
| 394 OpenNewLog(); | 394 OpenNewLog(); |
| 395 | 395 |
| 396 for (size_t i = 0; i < metrics_providers_.size(); ++i) | 396 for (MetricsProvider* provider : metrics_providers_) |
| 397 metrics_providers_[i]->OnRecordingEnabled(); | 397 provider->OnRecordingEnabled(); |
| 398 | 398 |
| 399 base::RemoveActionCallback(action_callback_); | 399 base::RemoveActionCallback(action_callback_); |
| 400 action_callback_ = base::Bind(&MetricsService::OnUserAction, | 400 action_callback_ = base::Bind(&MetricsService::OnUserAction, |
| 401 base::Unretained(this)); | 401 base::Unretained(this)); |
| 402 base::AddActionCallback(action_callback_); | 402 base::AddActionCallback(action_callback_); |
| 403 } | 403 } |
| 404 | 404 |
| 405 void MetricsService::DisableRecording() { | 405 void MetricsService::DisableRecording() { |
| 406 DCHECK(IsSingleThreaded()); | 406 DCHECK(IsSingleThreaded()); |
| 407 | 407 |
| 408 if (recording_state_ == INACTIVE) | 408 if (recording_state_ == INACTIVE) |
| 409 return; | 409 return; |
| 410 recording_state_ = INACTIVE; | 410 recording_state_ = INACTIVE; |
| 411 | 411 |
| 412 client_->OnRecordingDisabled(); | 412 client_->OnRecordingDisabled(); |
| 413 | 413 |
| 414 base::RemoveActionCallback(action_callback_); | 414 base::RemoveActionCallback(action_callback_); |
| 415 | 415 |
| 416 for (size_t i = 0; i < metrics_providers_.size(); ++i) | 416 for (MetricsProvider* provider : metrics_providers_) |
| 417 metrics_providers_[i]->OnRecordingDisabled(); | 417 provider->OnRecordingDisabled(); |
| 418 | 418 |
| 419 PushPendingLogsToPersistentStorage(); | 419 PushPendingLogsToPersistentStorage(); |
| 420 } | 420 } |
| 421 | 421 |
| 422 bool MetricsService::recording_active() const { | 422 bool MetricsService::recording_active() const { |
| 423 DCHECK(IsSingleThreaded()); | 423 DCHECK(IsSingleThreaded()); |
| 424 return recording_state_ == ACTIVE; | 424 return recording_state_ == ACTIVE; |
| 425 } | 425 } |
| 426 | 426 |
| 427 bool MetricsService::reporting_active() const { | 427 bool MetricsService::reporting_active() const { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 } | 522 } |
| 523 | 523 |
| 524 void MetricsService::RecordBreakpadHasDebugger(bool has_debugger) { | 524 void MetricsService::RecordBreakpadHasDebugger(bool has_debugger) { |
| 525 if (!has_debugger) | 525 if (!has_debugger) |
| 526 IncrementPrefValue(prefs::kStabilityDebuggerNotPresent); | 526 IncrementPrefValue(prefs::kStabilityDebuggerNotPresent); |
| 527 else | 527 else |
| 528 IncrementPrefValue(prefs::kStabilityDebuggerPresent); | 528 IncrementPrefValue(prefs::kStabilityDebuggerPresent); |
| 529 } | 529 } |
| 530 | 530 |
| 531 void MetricsService::ClearSavedStabilityMetrics() { | 531 void MetricsService::ClearSavedStabilityMetrics() { |
| 532 for (size_t i = 0; i < metrics_providers_.size(); ++i) | 532 for (MetricsProvider* provider : metrics_providers_) |
| 533 metrics_providers_[i]->ClearSavedStabilityMetrics(); | 533 provider->ClearSavedStabilityMetrics(); |
| 534 | 534 |
| 535 // Reset the prefs that are managed by MetricsService/MetricsLog directly. | 535 // Reset the prefs that are managed by MetricsService/MetricsLog directly. |
| 536 local_state_->SetInteger(prefs::kStabilityCrashCount, 0); | 536 local_state_->SetInteger(prefs::kStabilityCrashCount, 0); |
| 537 local_state_->SetInteger(prefs::kStabilityExecutionPhase, | 537 local_state_->SetInteger(prefs::kStabilityExecutionPhase, |
| 538 UNINITIALIZED_PHASE); | 538 UNINITIALIZED_PHASE); |
| 539 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); | 539 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
| 540 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); | 540 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); |
| 541 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); | 541 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); |
| 542 } | 542 } |
| 543 | 543 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 const int64_t incremental_time_secs = incremental_uptime->InSeconds(); | 675 const int64_t incremental_time_secs = incremental_uptime->InSeconds(); |
| 676 if (incremental_time_secs > 0) { | 676 if (incremental_time_secs > 0) { |
| 677 int64_t metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); | 677 int64_t metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); |
| 678 metrics_uptime += incremental_time_secs; | 678 metrics_uptime += incremental_time_secs; |
| 679 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); | 679 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); |
| 680 } | 680 } |
| 681 } | 681 } |
| 682 | 682 |
| 683 void MetricsService::NotifyOnDidCreateMetricsLog() { | 683 void MetricsService::NotifyOnDidCreateMetricsLog() { |
| 684 DCHECK(IsSingleThreaded()); | 684 DCHECK(IsSingleThreaded()); |
| 685 for (size_t i = 0; i < metrics_providers_.size(); ++i) | 685 for (MetricsProvider* provider : metrics_providers_) |
| 686 metrics_providers_[i]->OnDidCreateMetricsLog(); | 686 provider->OnDidCreateMetricsLog(); |
| 687 } | 687 } |
| 688 | 688 |
| 689 //------------------------------------------------------------------------------ | 689 //------------------------------------------------------------------------------ |
| 690 // State save methods | 690 // State save methods |
| 691 | 691 |
| 692 void MetricsService::ScheduleNextStateSave() { | 692 void MetricsService::ScheduleNextStateSave() { |
| 693 state_saver_factory_.InvalidateWeakPtrs(); | 693 state_saver_factory_.InvalidateWeakPtrs(); |
| 694 | 694 |
| 695 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 695 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 696 FROM_HERE, base::Bind(&MetricsService::SaveLocalState, | 696 FROM_HERE, base::Bind(&MetricsService::SaveLocalState, |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 scheduler_->UploadFinished(true, log_manager_.has_unsent_logs()); | 864 scheduler_->UploadFinished(true, log_manager_.has_unsent_logs()); |
| 865 return; | 865 return; |
| 866 } | 866 } |
| 867 if (!log_manager_.has_staged_log()) | 867 if (!log_manager_.has_staged_log()) |
| 868 log_manager_.StageNextLogForUpload(); | 868 log_manager_.StageNextLogForUpload(); |
| 869 SendStagedLog(); | 869 SendStagedLog(); |
| 870 } | 870 } |
| 871 | 871 |
| 872 bool MetricsService::ProvidersHaveInitialStabilityMetrics() { | 872 bool MetricsService::ProvidersHaveInitialStabilityMetrics() { |
| 873 // Check whether any metrics provider has initial stability metrics. | 873 // Check whether any metrics provider has initial stability metrics. |
| 874 for (size_t i = 0; i < metrics_providers_.size(); ++i) { | 874 for (MetricsProvider* provider : metrics_providers_) { |
| 875 if (metrics_providers_[i]->HasInitialStabilityMetrics()) | 875 if (provider->HasInitialStabilityMetrics()) |
| 876 return true; | 876 return true; |
| 877 } | 877 } |
| 878 | 878 |
| 879 return false; | 879 return false; |
| 880 } | 880 } |
| 881 | 881 |
| 882 bool MetricsService::PrepareInitialStabilityLog() { | 882 bool MetricsService::PrepareInitialStabilityLog() { |
| 883 DCHECK_EQ(INITIALIZED, state_); | 883 DCHECK_EQ(INITIALIZED, state_); |
| 884 | 884 |
| 885 scoped_ptr<MetricsLog> initial_stability_log( | 885 scoped_ptr<MetricsLog> initial_stability_log( |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 | 1103 |
| 1104 void MetricsService::RecordCurrentEnvironment(MetricsLog* log) { | 1104 void MetricsService::RecordCurrentEnvironment(MetricsLog* log) { |
| 1105 std::vector<variations::ActiveGroupId> synthetic_trials; | 1105 std::vector<variations::ActiveGroupId> synthetic_trials; |
| 1106 GetSyntheticFieldTrialsOlderThan(log->creation_time(), &synthetic_trials); | 1106 GetSyntheticFieldTrialsOlderThan(log->creation_time(), &synthetic_trials); |
| 1107 log->RecordEnvironment(metrics_providers_.get(), synthetic_trials, | 1107 log->RecordEnvironment(metrics_providers_.get(), synthetic_trials, |
| 1108 GetInstallDate(), GetMetricsReportingEnabledDate()); | 1108 GetInstallDate(), GetMetricsReportingEnabledDate()); |
| 1109 } | 1109 } |
| 1110 | 1110 |
| 1111 void MetricsService::RecordCurrentHistograms() { | 1111 void MetricsService::RecordCurrentHistograms() { |
| 1112 DCHECK(log_manager_.current_log()); | 1112 DCHECK(log_manager_.current_log()); |
| 1113 // "true" indicates that StatisticsRecorder should include histograms in | 1113 histogram_snapshot_manager_.StartDeltas(); |
| 1114 // persistent storage. | 1114 // "true" to the begin() call indicates that StatisticsRecorder should include |
| 1115 histogram_snapshot_manager_.PrepareDeltas( | 1115 // histograms held in persistent storage. |
| 1116 base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(), | 1116 auto end = base::StatisticsRecorder::end(); |
| 1117 base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag); | 1117 for (auto it = base::StatisticsRecorder::begin(true); it != end; ++it) { |
| 1118 if ((*it)->flags() & base::Histogram::kUmaTargetedHistogramFlag) |
| 1119 histogram_snapshot_manager_.PrepareDelta(*it); |
| 1120 } |
| 1121 for (MetricsProvider* provider : metrics_providers_) |
| 1122 provider->RecordHistogramSnapshots(&histogram_snapshot_manager_); |
| 1123 histogram_snapshot_manager_.FinishDeltas(); |
| 1118 } | 1124 } |
| 1119 | 1125 |
| 1120 void MetricsService::RecordCurrentStabilityHistograms() { | 1126 void MetricsService::RecordCurrentStabilityHistograms() { |
| 1121 DCHECK(log_manager_.current_log()); | 1127 DCHECK(log_manager_.current_log()); |
| 1122 // "true" indicates that StatisticsRecorder should include histograms in | 1128 // "true" indicates that StatisticsRecorder should include histograms in |
| 1123 // persistent storage. | 1129 // persistent storage. |
| 1124 histogram_snapshot_manager_.PrepareDeltas( | 1130 histogram_snapshot_manager_.PrepareDeltas( |
| 1125 base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(), | 1131 base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(), |
| 1126 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); | 1132 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); |
| 1127 } | 1133 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1155 base::Time::Now().ToTimeT()); | 1161 base::Time::Now().ToTimeT()); |
| 1156 } | 1162 } |
| 1157 | 1163 |
| 1158 void MetricsService::SkipAndDiscardUpload() { | 1164 void MetricsService::SkipAndDiscardUpload() { |
| 1159 log_manager_.DiscardStagedLog(); | 1165 log_manager_.DiscardStagedLog(); |
| 1160 scheduler_->UploadCancelled(); | 1166 scheduler_->UploadCancelled(); |
| 1161 log_upload_in_progress_ = false; | 1167 log_upload_in_progress_ = false; |
| 1162 } | 1168 } |
| 1163 | 1169 |
| 1164 } // namespace metrics | 1170 } // namespace metrics |
| OLD | NEW |