Chromium Code Reviews| Index: chrome/browser/metrics/metrics_service_android.cc |
| diff --git a/chrome/browser/metrics/metrics_service_android.cc b/chrome/browser/metrics/metrics_service_android.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4b6676d984369c27f606095caa2972593a81ba46 |
| --- /dev/null |
| +++ b/chrome/browser/metrics/metrics_service_android.cc |
| @@ -0,0 +1,143 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/metrics/metrics_service.h" |
| + |
| +#include "base/metrics/histogram.h" |
| +#include "base/prefs/pref_registry_simple.h" |
| +#include "base/prefs/pref_service.h" |
| +#include "chrome/browser/android/activity_type_ids.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/common/pref_names.h" |
| + |
| +// static |
| +void MetricsService::RegisterPrefsAndroid(PrefRegistrySimple* registry) { |
| + registry->RegisterIntegerPref(prefs::kStabilityForegroundActivityType, |
| + ActivityTypeIds::ACTIVITY_TYPE_NONE); |
| + registry->RegisterIntegerPref(prefs::kStabilityLaunchedActivityFlags, |
| + ActivityTypeIds::ACTIVITY_FLAG_NONE); |
| + |
| + registry->RegisterIntegerPref(prefs::kStabilityLaunchCountMainActivity, 0); |
| + registry->RegisterIntegerPref(prefs::kStabilityLaunchCountFullScreenActivity, |
| + 0); |
| + |
| + registry->RegisterIntegerPref(prefs::kStabilityCrashCountMainActivity, 0); |
| + registry->RegisterIntegerPref(prefs::kStabilityCrashCountFullScreenActivity, |
| + 0); |
| +} |
| + |
| +void MetricsService::RecordAndroidStabilityPrefs() { |
| + PrefService* pref = g_browser_process->local_state(); |
| + |
| + // Track which Activities were launched by the user. |
| + int launched_activities = |
| + pref->GetInteger(prefs::kStabilityLaunchedActivityFlags); |
| + if (launched_activities & ActivityTypeIds::ACTIVITY_FLAG_MAIN) |
| + IncrementPrefValue(prefs::kStabilityLaunchCountMainActivity); |
| + if (launched_activities & ActivityTypeIds::ACTIVITY_FLAG_FULLSCREEN) |
| + IncrementPrefValue(prefs::kStabilityLaunchCountFullScreenActivity); |
| + pref->SetInteger(prefs::kStabilityLaunchedActivityFlags, |
| + ActivityTypeIds::ACTIVITY_FLAG_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::kStabilityForegroundActivityType); |
| + switch (foreground) { |
| + case ActivityTypeIds::ACTIVITY_TYPE_MAIN: |
| + IncrementPrefValue(prefs::kStabilityCrashCountMainActivity); |
| + break; |
| + case ActivityTypeIds::ACTIVITY_TYPE_FULLSCREEN: |
| + IncrementPrefValue(prefs::kStabilityCrashCountFullScreenActivity); |
| + break; |
| + default: |
| + break; |
| + } |
| + pref->SetInteger(prefs::kStabilityForegroundActivityType, |
| + ActivityTypeIds::ACTIVITY_TYPE_NONE); |
| +} |
| + |
| +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_ENUMERATION("Chrome.Android.Activity.LaunchCounts", |
| + ActivityTypeIds::ACTIVITY_TYPE_MAIN, |
| + ActivityTypeIds::ACTIVITY_TYPE_MAX_VALUE); |
| + } |
| + 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_ENUMERATION("Chrome.Android.Activity.LaunchCounts", |
| + ActivityTypeIds::ACTIVITY_TYPE_FULLSCREEN, |
| + ActivityTypeIds::ACTIVITY_TYPE_MAX_VALUE); |
| + } |
| + 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_ENUMERATION("Chrome.Android.Activity.CrashCounts", |
| + ActivityTypeIds::ACTIVITY_TYPE_MAIN, |
| + ActivityTypeIds::ACTIVITY_TYPE_MAX_VALUE); |
| + } |
|
Ilya Sherman
2013/12/19 00:36:37
Please add the new histograms to histograms.xml as
gone
2013/12/20 19:24:37
Done.
|
| + 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_ENUMERATION("Chrome.Android.Activity.CrashCounts", |
| + ActivityTypeIds::ACTIVITY_TYPE_FULLSCREEN, |
| + ActivityTypeIds::ACTIVITY_TYPE_MAX_VALUE); |
| + } |
| + pref->SetInteger(prefs::kStabilityCrashCountFullScreenActivity, 0); |
| +} |
| + |
| +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::kStabilityForegroundActivityType, type); |
| + |
| + // Record that the Activity was launched by ORing its flag representation with |
| + // our record of the other actvities that had launched. |
| + int launched_activities = |
| + pref->GetInteger(prefs::kStabilityLaunchedActivityFlags); |
| + switch (type) { |
| + case ActivityTypeIds::ACTIVITY_TYPE_NONE: |
| + launched_activities |= ActivityTypeIds::ACTIVITY_FLAG_NONE; |
| + break; |
| + case ActivityTypeIds::ACTIVITY_TYPE_MAIN: |
| + launched_activities |= ActivityTypeIds::ACTIVITY_FLAG_MAIN; |
| + break; |
| + case ActivityTypeIds::ACTIVITY_TYPE_FULLSCREEN: |
| + launched_activities |= ActivityTypeIds::ACTIVITY_FLAG_FULLSCREEN; |
| + break; |
| + default: |
|
Ilya Sherman
2013/12/19 00:36:37
Please replace the default case with an explicit "
gone
2013/12/20 19:24:37
Done.
|
| + DCHECK(false) << "Unknown activity type encountered: " << type; |
|
Ilya Sherman
2013/12/19 00:36:37
nit: DCHECK(false) -> NOTREACHED()
gone
2013/12/20 19:24:37
Done.
|
| + break; |
| + } |
| + pref->SetInteger(prefs::kStabilityLaunchedActivityFlags, launched_activities); |
| + |
| + pref->CommitPendingWrite(); |
| +} |
| + |
| +// static |
| +void MetricsService::DiscardOldStabilityStatsAndroid(PrefService* local_state) { |
| + local_state->SetInteger(prefs::kStabilityForegroundActivityType, |
| + ActivityTypeIds::ACTIVITY_TYPE_NONE); |
| + local_state->SetInteger(prefs::kStabilityLaunchedActivityFlags, |
| + ActivityTypeIds::ACTIVITY_FLAG_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); |
| +} |