Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/metrics/metrics_service.h" | |
| 6 | |
| 7 #include "base/metrics/histogram.h" | |
| 8 #include "base/prefs/pref_registry_simple.h" | |
| 9 #include "base/prefs/pref_service.h" | |
| 10 #include "chrome/browser/android/activity_type_ids.h" | |
| 11 #include "chrome/browser/browser_process.h" | |
| 12 #include "chrome/common/pref_names.h" | |
| 13 | |
| 14 // static | |
| 15 void MetricsService::RegisterPrefsAndroid(PrefRegistrySimple* registry) { | |
| 16 registry->RegisterIntegerPref(prefs::kStabilityForegroundActivity, | |
| 17 ActivityTypeIds::ACTIVITY_NONE); | |
| 18 registry->RegisterIntegerPref(prefs::kStabilityLaunchedActivityFlags, | |
| 19 ActivityTypeIds::ACTIVITY_NONE); | |
| 20 | |
| 21 registry->RegisterIntegerPref(prefs::kStabilityLaunchCountMainActivity, 0); | |
| 22 registry->RegisterIntegerPref(prefs::kStabilityLaunchCountFullScreenActivity, | |
| 23 0); | |
| 24 | |
| 25 registry->RegisterIntegerPref(prefs::kStabilityCrashCountMainActivity, 0); | |
| 26 registry->RegisterIntegerPref(prefs::kStabilityCrashCountFullScreenActivity, | |
| 27 0); | |
| 28 } | |
| 29 | |
| 30 void MetricsService::RecordAndroidStabilityPrefs() { | |
| 31 PrefService* pref = g_browser_process->local_state(); | |
| 32 | |
| 33 // Track which Activities were launched by the user. | |
| 34 int launched_activities = | |
| 35 pref->GetInteger(prefs::kStabilityLaunchedActivityFlags); | |
| 36 if (launched_activities & ActivityTypeIds::ACTIVITY_MAIN) | |
| 37 IncrementPrefValue(prefs::kStabilityLaunchCountMainActivity); | |
| 38 if (launched_activities & ActivityTypeIds::ACTIVITY_FULLSCREEN) | |
| 39 IncrementPrefValue(prefs::kStabilityLaunchCountFullScreenActivity); | |
| 40 | |
| 41 pref->SetInteger(prefs::kStabilityLaunchedActivityFlags, | |
| 42 ActivityTypeIds::ACTIVITY_NONE); | |
| 43 | |
| 44 // If an Activity was in the foreground when Chrome died, then Chrome was | |
| 45 // improperly shut down. Record it as a crash for that particular Activity. | |
| 46 int foreground = pref->GetInteger(prefs::kStabilityForegroundActivity); | |
| 47 switch (foreground) { | |
| 48 case ActivityTypeIds::ACTIVITY_MAIN: | |
| 49 IncrementPrefValue(prefs::kStabilityCrashCountMainActivity); | |
| 50 break; | |
| 51 case ActivityTypeIds::ACTIVITY_FULLSCREEN: | |
| 52 IncrementPrefValue(prefs::kStabilityCrashCountFullScreenActivity); | |
| 53 break; | |
| 54 default: | |
| 55 break; | |
| 56 } | |
| 57 pref->SetInteger(prefs::kStabilityForegroundActivity, | |
| 58 ActivityTypeIds::ACTIVITY_NONE); | |
| 59 } | |
| 60 | |
| 61 void MetricsService::RecordAndroidStabilityHistograms() { | |
| 62 PrefService* pref = g_browser_process->local_state(); | |
| 63 | |
| 64 // Track which Activities were launched by the user. | |
| 65 int main_launch_count = | |
| 66 pref->GetInteger(prefs::kStabilityLaunchCountMainActivity); | |
| 67 for (int i = 0; i < main_launch_count; ++i) { | |
| 68 UMA_HISTOGRAM_ENUMERATION("Chrome.Android.Activity.LaunchCounts", | |
| 69 ActivityTypeIds::ACTIVITY_MAIN, | |
| 70 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!
| |
| 71 } | |
| 72 pref->SetInteger(prefs::kStabilityLaunchCountMainActivity, 0); | |
| 73 | |
| 74 int full_screen_launch_count = | |
| 75 pref->GetInteger(prefs::kStabilityLaunchCountFullScreenActivity); | |
| 76 for (int i = 0; i < full_screen_launch_count; ++i) { | |
| 77 UMA_HISTOGRAM_ENUMERATION("Chrome.Android.Activity.LaunchCounts", | |
| 78 ActivityTypeIds::ACTIVITY_FULLSCREEN, | |
| 79 ActivityTypeIds::ACTIVITY_MAX_VALUE); | |
| 80 } | |
| 81 pref->SetInteger(prefs::kStabilityLaunchCountFullScreenActivity, 0); | |
| 82 | |
| 83 // Track which Activities were in the foreground when Chrome died. | |
| 84 int main_crash_count = | |
| 85 pref->GetInteger(prefs::kStabilityCrashCountMainActivity); | |
| 86 for (int i = 0; i < main_crash_count; ++i) { | |
| 87 UMA_HISTOGRAM_ENUMERATION("Chrome.Android.Activity.CrashCounts", | |
| 88 ActivityTypeIds::ACTIVITY_MAIN, | |
| 89 ActivityTypeIds::ACTIVITY_MAX_VALUE); | |
| 90 } | |
| 91 pref->SetInteger(prefs::kStabilityCrashCountMainActivity, 0); | |
| 92 | |
| 93 int full_screen_crash_count = | |
| 94 pref->GetInteger(prefs::kStabilityCrashCountFullScreenActivity); | |
| 95 for (int i = 0; i < full_screen_crash_count; ++i) { | |
| 96 UMA_HISTOGRAM_ENUMERATION("Chrome.Android.Activity.CrashCounts", | |
| 97 ActivityTypeIds::ACTIVITY_FULLSCREEN, | |
| 98 ActivityTypeIds::ACTIVITY_MAX_VALUE); | |
| 99 } | |
| 100 pref->SetInteger(prefs::kStabilityCrashCountFullScreenActivity, 0); | |
| 101 } | |
| 102 | |
| 103 void MetricsService::OnForegroundActivityChanged(ActivityTypeIds::Type type) { | |
| 104 PrefService* pref = g_browser_process->local_state(); | |
| 105 | |
| 106 // Record that the Activity is now in the foreground. | |
| 107 pref->SetInteger(prefs::kStabilityForegroundActivity, type); | |
| 108 | |
| 109 // Record that the Activity was launched. | |
| 110 int launched_activities = | |
| 111 pref->GetInteger(prefs::kStabilityLaunchedActivityFlags) | type; | |
| 112 pref->SetInteger(prefs::kStabilityLaunchedActivityFlags, launched_activities); | |
| 113 | |
| 114 pref->CommitPendingWrite(); | |
| 115 } | |
| 116 | |
| 117 // static | |
| 118 void MetricsService::DiscardOldStabilityStatsAndroid(PrefService* local_state) { | |
| 119 local_state->SetInteger(prefs::kStabilityForegroundActivity, | |
| 120 ActivityTypeIds::ACTIVITY_NONE); | |
| 121 local_state->SetInteger(prefs::kStabilityLaunchedActivityFlags, | |
| 122 ActivityTypeIds::ACTIVITY_NONE); | |
| 123 | |
| 124 local_state->SetInteger(prefs::kStabilityLaunchCountMainActivity, 0); | |
| 125 local_state->SetInteger(prefs::kStabilityLaunchCountFullScreenActivity, 0); | |
| 126 | |
| 127 local_state->SetInteger(prefs::kStabilityCrashCountMainActivity, 0); | |
| 128 local_state->SetInteger(prefs::kStabilityCrashCountFullScreenActivity, 0); | |
| 129 } | |
| OLD | NEW |