Chromium Code Reviews| Index: chrome/browser/metrics/metrics_service.cc |
| diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc |
| index d3993e1fa182f2188bd7a30ff796f84084ecc585..6025eb315b338bde1a78130004aac6b075f80989 100644 |
| --- a/chrome/browser/metrics/metrics_service.cc |
| +++ b/chrome/browser/metrics/metrics_service.cc |
| @@ -446,11 +446,24 @@ void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) { |
| 0); |
| registry->RegisterIntegerPref(prefs::kStabilityDebuggerPresent, 0); |
| registry->RegisterIntegerPref(prefs::kStabilityDebuggerNotPresent, 0); |
| -#if defined(OS_CHROMEOS) |
| +#if defined(OS_ANDROID) |
| + registry->RegisterIntegerPref(prefs::kStabilityForegroundActivity, |
| + ActivityTypeIds::ACTIVITY_NONE); |
| + registry->RegisterIntegerPref(prefs::kStabilityLaunchedActivityFlags, |
| + ActivityTypeIds::ACTIVITY_NONE); |
| + |
| + registry->RegisterIntegerPref(prefs::kStabilityLaunchCountMainActivity, 0); |
| + registry->RegisterIntegerPref(prefs::kStabilityLaunchCountFullScreenActivity, |
| + 0); |
| + |
| + registry->RegisterIntegerPref(prefs::kStabilityCrashCountMainActivity, 0); |
| + registry->RegisterIntegerPref(prefs::kStabilityCrashCountFullScreenActivity, |
| + 0); |
| +#elif defined(OS_CHROMEOS) |
| registry->RegisterIntegerPref(prefs::kStabilityOtherUserCrashCount, 0); |
| registry->RegisterIntegerPref(prefs::kStabilityKernelCrashCount, 0); |
| registry->RegisterIntegerPref(prefs::kStabilitySystemUncleanShutdownCount, 0); |
| -#endif // OS_CHROMEOS |
| +#endif |
| registry->RegisterStringPref(prefs::kStabilitySavedSystemProfile, |
| std::string()); |
| @@ -483,6 +496,19 @@ void MetricsService::DiscardOldStabilityStats(PrefService* local_state) { |
| local_state->SetInteger(prefs::kStabilityLaunchCount, 0); |
| local_state->SetInteger(prefs::kStabilityCrashCount, 0); |
| +#if defined(OS_ANDROID) |
| + local_state->SetInteger(prefs::kStabilityForegroundActivity, |
| + ActivityTypeIds::ACTIVITY_NONE); |
| + local_state->SetInteger(prefs::kStabilityLaunchedActivityFlags, |
| + ActivityTypeIds::ACTIVITY_NONE); |
| + |
| + local_state->SetInteger(prefs::kStabilityLaunchCountMainActivity, 0); |
| + local_state->SetInteger(prefs::kStabilityLaunchCountFullScreenActivity, 0); |
| + |
| + local_state->SetInteger(prefs::kStabilityCrashCountMainActivity, 0); |
| + local_state->SetInteger(prefs::kStabilityCrashCountFullScreenActivity, 0); |
| +#endif // defined(OS_ANDROID) |
| + |
| local_state->SetInteger(prefs::kStabilityPageLoadCount, 0); |
| local_state->SetInteger(prefs::kStabilityRendererCrashCount, 0); |
| local_state->SetInteger(prefs::kStabilityRendererHangCount, 0); |
| @@ -778,6 +804,22 @@ void MetricsService::RecordCompletedSessionEnd() { |
| RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, true); |
| } |
| +#if defined(OS_ANDROID) |
| +void MetricsService::OnForegroundActivityChanged(ActivityTypeIds::Type type) { |
| + PrefService* pref = g_browser_process->local_state(); |
| + |
| + // Record that the Activity is now in the foreground. |
| + pref->SetInteger(prefs::kStabilityForegroundActivity, type); |
| + |
| + // Record that the Activity was launched. |
| + int launched_activities = |
| + pref->GetInteger(prefs::kStabilityLaunchedActivityFlags) | type; |
| + pref->SetInteger(prefs::kStabilityLaunchedActivityFlags, launched_activities); |
| + |
| + pref->CommitPendingWrite(); |
| +} |
| +#endif // defined(OS_ANDROID) |
| + |
| #if defined(OS_ANDROID) || defined(OS_IOS) |
| void MetricsService::OnAppEnterBackground() { |
| scheduler_->Stop(); |
| @@ -927,6 +969,36 @@ void MetricsService::InitializeMetricsState() { |
| // Stability bookkeeping |
| IncrementPrefValue(prefs::kStabilityLaunchCount); |
| +#if defined(OS_ANDROID) |
| + // Track which Activities were launched by the user. |
| + int launched_activities = |
| + pref->GetInteger(prefs::kStabilityLaunchedActivityFlags); |
| + if (launched_activities & ActivityTypeIds::ACTIVITY_MAIN) { |
| + IncrementPrefValue(prefs::kStabilityLaunchCountMainActivity); |
| + } |
| + if (launched_activities & ActivityTypeIds::ACTIVITY_FULLSCREEN) { |
| + IncrementPrefValue(prefs::kStabilityLaunchCountFullScreenActivity); |
| + } |
| + pref->SetInteger(prefs::kStabilityLaunchedActivityFlags, |
| + ActivityTypeIds::ACTIVITY_NONE); |
| + |
| + // If an Activity was in the foreground when Chrome died, then Chrome was |
| + // improperly shut down. Record it as a crash for that particular Activity. |
| + int foreground = pref->GetInteger(prefs::kStabilityForegroundActivity); |
|
Yaron
2013/12/10 01:48:17
So you'll get onForegroundActivityChanged(ACTIVITY
gone
2013/12/10 01:59:39
Yep:
https://chrome-internal-review.googlesource.c
|
| + switch (foreground) { |
| + case ActivityTypeIds::ACTIVITY_MAIN: |
| + IncrementPrefValue(prefs::kStabilityCrashCountMainActivity); |
| + break; |
| + case ActivityTypeIds::ACTIVITY_FULLSCREEN: |
| + IncrementPrefValue(prefs::kStabilityCrashCountFullScreenActivity); |
| + break; |
| + default: |
| + break; |
| + } |
| + pref->SetInteger(prefs::kStabilityForegroundActivity, |
| + ActivityTypeIds::ACTIVITY_NONE); |
| +#endif // defined(OS_ANDROID) |
| + |
| if (!pref->GetBoolean(prefs::kStabilityExitedCleanly)) { |
| IncrementPrefValue(prefs::kStabilityCrashCount); |
| // Reset flag, and wait until we call LogNeedForCleanShutdown() before |
| @@ -1210,6 +1282,46 @@ void MetricsService::OpenNewLog() { |
| } |
| } |
| +#if defined(OS_ANDROID) |
| +void MetricsService::RecordAndroidStabilityHistograms() { |
| + PrefService* pref = g_browser_process->local_state(); |
| + |
| + // Track which Activities were launched by the user. |
| + int main_launch_count = |
| + pref->GetInteger(prefs::kStabilityLaunchCountMainActivity); |
| + for (int i = 0; i < main_launch_count; ++i) { |
| + UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Android.Activity.LaunchCounts", |
| + ActivityTypeIds::ACTIVITY_MAIN); |
| + } |
| + pref->SetInteger(prefs::kStabilityLaunchCountMainActivity, 0); |
| + |
| + int full_screen_launch_count = |
| + pref->GetInteger(prefs::kStabilityLaunchCountFullScreenActivity); |
| + for (int i = 0; i < full_screen_launch_count; ++i) { |
| + UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Android.Activity.LaunchCounts", |
| + ActivityTypeIds::ACTIVITY_FULLSCREEN); |
| + } |
| + pref->SetInteger(prefs::kStabilityLaunchCountFullScreenActivity, 0); |
| + |
| + // Track which Activities were in the foreground when Chrome died. |
| + int main_crash_count = |
| + pref->GetInteger(prefs::kStabilityCrashCountMainActivity); |
| + for (int i = 0; i < main_crash_count; ++i) { |
| + UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Android.Activity.CrashCounts", |
| + ActivityTypeIds::ACTIVITY_MAIN); |
| + } |
| + pref->SetInteger(prefs::kStabilityCrashCountMainActivity, 0); |
| + |
| + int full_screen_crash_count = |
| + pref->GetInteger(prefs::kStabilityCrashCountFullScreenActivity); |
| + for (int i = 0; i < full_screen_crash_count; ++i) { |
| + UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Android.Activity.CrashCounts", |
| + ActivityTypeIds::ACTIVITY_FULLSCREEN); |
| + } |
| + pref->SetInteger(prefs::kStabilityCrashCountFullScreenActivity, 0); |
| +} |
| +#endif |
| + |
| void MetricsService::CloseCurrentLog() { |
| if (!log_manager_.current_log()) |
| return; |
| @@ -1241,6 +1353,9 @@ void MetricsService::CloseCurrentLog() { |
| current_log->RecordStabilityMetrics(GetIncrementalUptime(pref), |
| MetricsLog::ONGOING_LOG); |
| +#if defined(OS_ANDROID) |
| + RecordAndroidStabilityHistograms(); |
| +#endif |
| RecordCurrentHistograms(); |
| log_manager_.FinishCurrentLog(); |