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..8f08071ed8299d50e578bb9ed1cfc5a5ffdc2f03 |
| --- /dev/null |
| +++ b/chrome/browser/metrics/metrics_service_android.cc |
| @@ -0,0 +1,129 @@ |
| +// 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::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); |
| +} |
| + |
| +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_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); |
| + 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); |
| +} |
| + |
| +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_MAIN, |
| + ActivityTypeIds::ACTIVITY_MAX_VALUE); |
|
Ilya Sherman
2013/12/17 02:13:44
It looks like this histogram only has two buckets,
gone
2013/12/18 23:46:01
Split it apart, but it got a bit messy.
Ilya Sherman
2013/12/19 00:36:36
Thanks!
|
| + } |
| + 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_FULLSCREEN, |
| + ActivityTypeIds::ACTIVITY_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_MAIN, |
| + ActivityTypeIds::ACTIVITY_MAX_VALUE); |
| + } |
| + 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_FULLSCREEN, |
| + ActivityTypeIds::ACTIVITY_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::kStabilityForegroundActivity, type); |
| + |
| + // Record that the Activity was launched. |
| + int launched_activities = |
| + pref->GetInteger(prefs::kStabilityLaunchedActivityFlags) | type; |
| + pref->SetInteger(prefs::kStabilityLaunchedActivityFlags, launched_activities); |
| + |
| + pref->CommitPendingWrite(); |
| +} |
| + |
| +// static |
| +void MetricsService::DiscardOldStabilityStatsAndroid(PrefService* local_state) { |
| + 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); |
| +} |