| 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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 383 |
| 384 if (recording_state_ == ACTIVE) | 384 if (recording_state_ == ACTIVE) |
| 385 return; | 385 return; |
| 386 recording_state_ = ACTIVE; | 386 recording_state_ = ACTIVE; |
| 387 | 387 |
| 388 state_manager_->ForceClientIdCreation(); | 388 state_manager_->ForceClientIdCreation(); |
| 389 client_->SetMetricsClientId(state_manager_->client_id()); | 389 client_->SetMetricsClientId(state_manager_->client_id()); |
| 390 if (!log_manager_.current_log()) | 390 if (!log_manager_.current_log()) |
| 391 OpenNewLog(); | 391 OpenNewLog(); |
| 392 | 392 |
| 393 for (size_t i = 0; i < metrics_providers_.size(); ++i) | 393 for (auto& provider : metrics_providers_) |
| 394 metrics_providers_[i]->OnRecordingEnabled(); | 394 provider->OnRecordingEnabled(); |
| 395 | 395 |
| 396 base::RemoveActionCallback(action_callback_); | 396 base::RemoveActionCallback(action_callback_); |
| 397 action_callback_ = base::Bind(&MetricsService::OnUserAction, | 397 action_callback_ = base::Bind(&MetricsService::OnUserAction, |
| 398 base::Unretained(this)); | 398 base::Unretained(this)); |
| 399 base::AddActionCallback(action_callback_); | 399 base::AddActionCallback(action_callback_); |
| 400 } | 400 } |
| 401 | 401 |
| 402 void MetricsService::DisableRecording() { | 402 void MetricsService::DisableRecording() { |
| 403 DCHECK(IsSingleThreaded()); | 403 DCHECK(IsSingleThreaded()); |
| 404 | 404 |
| 405 if (recording_state_ == INACTIVE) | 405 if (recording_state_ == INACTIVE) |
| 406 return; | 406 return; |
| 407 recording_state_ = INACTIVE; | 407 recording_state_ = INACTIVE; |
| 408 | 408 |
| 409 client_->OnRecordingDisabled(); | 409 client_->OnRecordingDisabled(); |
| 410 | 410 |
| 411 base::RemoveActionCallback(action_callback_); | 411 base::RemoveActionCallback(action_callback_); |
| 412 | 412 |
| 413 for (size_t i = 0; i < metrics_providers_.size(); ++i) | 413 for (auto& provider : metrics_providers_) |
| 414 metrics_providers_[i]->OnRecordingDisabled(); | 414 provider->OnRecordingDisabled(); |
| 415 | 415 |
| 416 PushPendingLogsToPersistentStorage(); | 416 PushPendingLogsToPersistentStorage(); |
| 417 } | 417 } |
| 418 | 418 |
| 419 bool MetricsService::recording_active() const { | 419 bool MetricsService::recording_active() const { |
| 420 DCHECK(IsSingleThreaded()); | 420 DCHECK(IsSingleThreaded()); |
| 421 return recording_state_ == ACTIVE; | 421 return recording_state_ == ACTIVE; |
| 422 } | 422 } |
| 423 | 423 |
| 424 bool MetricsService::reporting_active() const { | 424 bool MetricsService::reporting_active() const { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 } | 519 } |
| 520 | 520 |
| 521 void MetricsService::RecordBreakpadHasDebugger(bool has_debugger) { | 521 void MetricsService::RecordBreakpadHasDebugger(bool has_debugger) { |
| 522 if (!has_debugger) | 522 if (!has_debugger) |
| 523 IncrementPrefValue(prefs::kStabilityDebuggerNotPresent); | 523 IncrementPrefValue(prefs::kStabilityDebuggerNotPresent); |
| 524 else | 524 else |
| 525 IncrementPrefValue(prefs::kStabilityDebuggerPresent); | 525 IncrementPrefValue(prefs::kStabilityDebuggerPresent); |
| 526 } | 526 } |
| 527 | 527 |
| 528 void MetricsService::ClearSavedStabilityMetrics() { | 528 void MetricsService::ClearSavedStabilityMetrics() { |
| 529 for (size_t i = 0; i < metrics_providers_.size(); ++i) | 529 for (auto& provider : metrics_providers_) |
| 530 metrics_providers_[i]->ClearSavedStabilityMetrics(); | 530 provider->ClearSavedStabilityMetrics(); |
| 531 | 531 |
| 532 // Reset the prefs that are managed by MetricsService/MetricsLog directly. | 532 // Reset the prefs that are managed by MetricsService/MetricsLog directly. |
| 533 local_state_->SetInteger(prefs::kStabilityCrashCount, 0); | 533 local_state_->SetInteger(prefs::kStabilityCrashCount, 0); |
| 534 local_state_->SetInteger(prefs::kStabilityExecutionPhase, | 534 local_state_->SetInteger(prefs::kStabilityExecutionPhase, |
| 535 UNINITIALIZED_PHASE); | 535 UNINITIALIZED_PHASE); |
| 536 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); | 536 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
| 537 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); | 537 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); |
| 538 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); | 538 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); |
| 539 } | 539 } |
| 540 | 540 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 const int64_t incremental_time_secs = incremental_uptime->InSeconds(); | 672 const int64_t incremental_time_secs = incremental_uptime->InSeconds(); |
| 673 if (incremental_time_secs > 0) { | 673 if (incremental_time_secs > 0) { |
| 674 int64_t metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); | 674 int64_t metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); |
| 675 metrics_uptime += incremental_time_secs; | 675 metrics_uptime += incremental_time_secs; |
| 676 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); | 676 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); |
| 677 } | 677 } |
| 678 } | 678 } |
| 679 | 679 |
| 680 void MetricsService::NotifyOnDidCreateMetricsLog() { | 680 void MetricsService::NotifyOnDidCreateMetricsLog() { |
| 681 DCHECK(IsSingleThreaded()); | 681 DCHECK(IsSingleThreaded()); |
| 682 for (size_t i = 0; i < metrics_providers_.size(); ++i) | 682 for (auto& provider : metrics_providers_) |
| 683 metrics_providers_[i]->OnDidCreateMetricsLog(); | 683 provider->OnDidCreateMetricsLog(); |
| 684 } | 684 } |
| 685 | 685 |
| 686 //------------------------------------------------------------------------------ | 686 //------------------------------------------------------------------------------ |
| 687 // State save methods | 687 // State save methods |
| 688 | 688 |
| 689 void MetricsService::ScheduleNextStateSave() { | 689 void MetricsService::ScheduleNextStateSave() { |
| 690 state_saver_factory_.InvalidateWeakPtrs(); | 690 state_saver_factory_.InvalidateWeakPtrs(); |
| 691 | 691 |
| 692 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 692 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 693 FROM_HERE, base::Bind(&MetricsService::SaveLocalState, | 693 FROM_HERE, base::Bind(&MetricsService::SaveLocalState, |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 scheduler_->UploadFinished(true, log_manager_.has_unsent_logs()); | 861 scheduler_->UploadFinished(true, log_manager_.has_unsent_logs()); |
| 862 return; | 862 return; |
| 863 } | 863 } |
| 864 if (!log_manager_.has_staged_log()) | 864 if (!log_manager_.has_staged_log()) |
| 865 log_manager_.StageNextLogForUpload(); | 865 log_manager_.StageNextLogForUpload(); |
| 866 SendStagedLog(); | 866 SendStagedLog(); |
| 867 } | 867 } |
| 868 | 868 |
| 869 bool MetricsService::ProvidersHaveInitialStabilityMetrics() { | 869 bool MetricsService::ProvidersHaveInitialStabilityMetrics() { |
| 870 // Check whether any metrics provider has initial stability metrics. | 870 // Check whether any metrics provider has initial stability metrics. |
| 871 for (size_t i = 0; i < metrics_providers_.size(); ++i) { | 871 for (auto& provider : metrics_providers_) { |
| 872 if (metrics_providers_[i]->HasInitialStabilityMetrics()) | 872 if (provider->HasInitialStabilityMetrics()) |
| 873 return true; | 873 return true; |
| 874 } | 874 } |
| 875 | 875 |
| 876 return false; | 876 return false; |
| 877 } | 877 } |
| 878 | 878 |
| 879 bool MetricsService::PrepareInitialStabilityLog() { | 879 bool MetricsService::PrepareInitialStabilityLog() { |
| 880 DCHECK_EQ(INITIALIZED, state_); | 880 DCHECK_EQ(INITIALIZED, state_); |
| 881 | 881 |
| 882 scoped_ptr<MetricsLog> initial_stability_log( | 882 scoped_ptr<MetricsLog> initial_stability_log( |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 | 1100 |
| 1101 void MetricsService::RecordCurrentEnvironment(MetricsLog* log) { | 1101 void MetricsService::RecordCurrentEnvironment(MetricsLog* log) { |
| 1102 std::vector<variations::ActiveGroupId> synthetic_trials; | 1102 std::vector<variations::ActiveGroupId> synthetic_trials; |
| 1103 GetSyntheticFieldTrialsOlderThan(log->creation_time(), &synthetic_trials); | 1103 GetSyntheticFieldTrialsOlderThan(log->creation_time(), &synthetic_trials); |
| 1104 log->RecordEnvironment(metrics_providers_.get(), synthetic_trials, | 1104 log->RecordEnvironment(metrics_providers_.get(), synthetic_trials, |
| 1105 GetInstallDate(), GetMetricsReportingEnabledDate()); | 1105 GetInstallDate(), GetMetricsReportingEnabledDate()); |
| 1106 } | 1106 } |
| 1107 | 1107 |
| 1108 void MetricsService::RecordCurrentHistograms() { | 1108 void MetricsService::RecordCurrentHistograms() { |
| 1109 DCHECK(log_manager_.current_log()); | 1109 DCHECK(log_manager_.current_log()); |
| 1110 histogram_snapshot_manager_.StartDeltas(); |
| 1111 for (auto& provider : metrics_providers_) |
| 1112 provider->RecordHistogramSnapshots(&histogram_snapshot_manager_); |
| 1113 histogram_snapshot_manager_.FinishDeltas(); |
| 1110 } | 1114 } |
| 1111 | 1115 |
| 1112 void MetricsService::RecordCurrentStabilityHistograms() { | 1116 void MetricsService::RecordCurrentStabilityHistograms() { |
| 1113 DCHECK(log_manager_.current_log()); | 1117 DCHECK(log_manager_.current_log()); |
| 1114 // "true" indicates that StatisticsRecorder should include histograms in | 1118 // "true" indicates that StatisticsRecorder should include histograms in |
| 1115 // persistent storage. | 1119 // persistent storage. |
| 1116 histogram_snapshot_manager_.PrepareDeltas( | 1120 histogram_snapshot_manager_.PrepareDeltas( |
| 1117 base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(), | 1121 base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(), |
| 1118 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); | 1122 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); |
| 1119 } | 1123 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1147 base::Time::Now().ToTimeT()); | 1151 base::Time::Now().ToTimeT()); |
| 1148 } | 1152 } |
| 1149 | 1153 |
| 1150 void MetricsService::SkipAndDiscardUpload() { | 1154 void MetricsService::SkipAndDiscardUpload() { |
| 1151 log_manager_.DiscardStagedLog(); | 1155 log_manager_.DiscardStagedLog(); |
| 1152 scheduler_->UploadCancelled(); | 1156 scheduler_->UploadCancelled(); |
| 1153 log_upload_in_progress_ = false; | 1157 log_upload_in_progress_ = false; |
| 1154 } | 1158 } |
| 1155 | 1159 |
| 1156 } // namespace metrics | 1160 } // namespace metrics |
| OLD | NEW |