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::kStabilityForegroundActivityType, | |
| 17 ActivityTypeIds::ACTIVITY_TYPE_NONE); | |
| 18 registry->RegisterIntegerPref(prefs::kStabilityLaunchedActivityFlags, | |
| 19 ActivityTypeIds::ACTIVITY_FLAG_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_FLAG_MAIN) | |
| 37 IncrementPrefValue(prefs::kStabilityLaunchCountMainActivity); | |
| 38 if (launched_activities & ActivityTypeIds::ACTIVITY_FLAG_FULLSCREEN) | |
| 39 IncrementPrefValue(prefs::kStabilityLaunchCountFullScreenActivity); | |
| 40 pref->SetInteger(prefs::kStabilityLaunchedActivityFlags, | |
| 41 ActivityTypeIds::ACTIVITY_FLAG_NONE); | |
| 42 | |
| 43 // If an Activity was in the foreground when Chrome died, then Chrome was | |
| 44 // improperly shut down. Record it as a crash for that particular Activity. | |
| 45 int foreground = pref->GetInteger(prefs::kStabilityForegroundActivityType); | |
| 46 switch (foreground) { | |
| 47 case ActivityTypeIds::ACTIVITY_TYPE_MAIN: | |
| 48 IncrementPrefValue(prefs::kStabilityCrashCountMainActivity); | |
| 49 break; | |
| 50 case ActivityTypeIds::ACTIVITY_TYPE_FULLSCREEN: | |
| 51 IncrementPrefValue(prefs::kStabilityCrashCountFullScreenActivity); | |
| 52 break; | |
| 53 default: | |
| 54 break; | |
| 55 } | |
| 56 pref->SetInteger(prefs::kStabilityForegroundActivityType, | |
| 57 ActivityTypeIds::ACTIVITY_TYPE_NONE); | |
| 58 } | |
| 59 | |
| 60 void MetricsService::RecordAndroidStabilityHistograms() { | |
| 61 PrefService* pref = g_browser_process->local_state(); | |
| 62 | |
| 63 // Track which Activities were launched by the user. | |
| 64 int main_launch_count = | |
| 65 pref->GetInteger(prefs::kStabilityLaunchCountMainActivity); | |
| 66 for (int i = 0; i < main_launch_count; ++i) { | |
| 67 UMA_HISTOGRAM_ENUMERATION("Chrome.Android.Activity.LaunchCounts", | |
| 68 ActivityTypeIds::ACTIVITY_TYPE_MAIN, | |
| 69 ActivityTypeIds::ACTIVITY_TYPE_MAX_VALUE); | |
| 70 } | |
| 71 pref->SetInteger(prefs::kStabilityLaunchCountMainActivity, 0); | |
| 72 | |
| 73 int full_screen_launch_count = | |
| 74 pref->GetInteger(prefs::kStabilityLaunchCountFullScreenActivity); | |
| 75 for (int i = 0; i < full_screen_launch_count; ++i) { | |
| 76 UMA_HISTOGRAM_ENUMERATION("Chrome.Android.Activity.LaunchCounts", | |
| 77 ActivityTypeIds::ACTIVITY_TYPE_FULLSCREEN, | |
| 78 ActivityTypeIds::ACTIVITY_TYPE_MAX_VALUE); | |
| 79 } | |
| 80 pref->SetInteger(prefs::kStabilityLaunchCountFullScreenActivity, 0); | |
| 81 | |
| 82 // Track which Activities were in the foreground when Chrome died. | |
| 83 int main_crash_count = | |
| 84 pref->GetInteger(prefs::kStabilityCrashCountMainActivity); | |
| 85 for (int i = 0; i < main_crash_count; ++i) { | |
| 86 UMA_HISTOGRAM_ENUMERATION("Chrome.Android.Activity.CrashCounts", | |
| 87 ActivityTypeIds::ACTIVITY_TYPE_MAIN, | |
| 88 ActivityTypeIds::ACTIVITY_TYPE_MAX_VALUE); | |
| 89 } | |
|
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.
| |
| 90 pref->SetInteger(prefs::kStabilityCrashCountMainActivity, 0); | |
| 91 | |
| 92 int full_screen_crash_count = | |
| 93 pref->GetInteger(prefs::kStabilityCrashCountFullScreenActivity); | |
| 94 for (int i = 0; i < full_screen_crash_count; ++i) { | |
| 95 UMA_HISTOGRAM_ENUMERATION("Chrome.Android.Activity.CrashCounts", | |
| 96 ActivityTypeIds::ACTIVITY_TYPE_FULLSCREEN, | |
| 97 ActivityTypeIds::ACTIVITY_TYPE_MAX_VALUE); | |
| 98 } | |
| 99 pref->SetInteger(prefs::kStabilityCrashCountFullScreenActivity, 0); | |
| 100 } | |
| 101 | |
| 102 void MetricsService::OnForegroundActivityChanged(ActivityTypeIds::Type type) { | |
| 103 PrefService* pref = g_browser_process->local_state(); | |
| 104 | |
| 105 // Record that the Activity is now in the foreground. | |
| 106 pref->SetInteger(prefs::kStabilityForegroundActivityType, type); | |
| 107 | |
| 108 // Record that the Activity was launched by ORing its flag representation with | |
| 109 // our record of the other actvities that had launched. | |
| 110 int launched_activities = | |
| 111 pref->GetInteger(prefs::kStabilityLaunchedActivityFlags); | |
| 112 switch (type) { | |
| 113 case ActivityTypeIds::ACTIVITY_TYPE_NONE: | |
| 114 launched_activities |= ActivityTypeIds::ACTIVITY_FLAG_NONE; | |
| 115 break; | |
| 116 case ActivityTypeIds::ACTIVITY_TYPE_MAIN: | |
| 117 launched_activities |= ActivityTypeIds::ACTIVITY_FLAG_MAIN; | |
| 118 break; | |
| 119 case ActivityTypeIds::ACTIVITY_TYPE_FULLSCREEN: | |
| 120 launched_activities |= ActivityTypeIds::ACTIVITY_FLAG_FULLSCREEN; | |
| 121 break; | |
| 122 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.
| |
| 123 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.
| |
| 124 break; | |
| 125 } | |
| 126 pref->SetInteger(prefs::kStabilityLaunchedActivityFlags, launched_activities); | |
| 127 | |
| 128 pref->CommitPendingWrite(); | |
| 129 } | |
| 130 | |
| 131 // static | |
| 132 void MetricsService::DiscardOldStabilityStatsAndroid(PrefService* local_state) { | |
| 133 local_state->SetInteger(prefs::kStabilityForegroundActivityType, | |
| 134 ActivityTypeIds::ACTIVITY_TYPE_NONE); | |
| 135 local_state->SetInteger(prefs::kStabilityLaunchedActivityFlags, | |
| 136 ActivityTypeIds::ACTIVITY_FLAG_NONE); | |
| 137 | |
| 138 local_state->SetInteger(prefs::kStabilityLaunchCountMainActivity, 0); | |
| 139 local_state->SetInteger(prefs::kStabilityLaunchCountFullScreenActivity, 0); | |
| 140 | |
| 141 local_state->SetInteger(prefs::kStabilityCrashCountMainActivity, 0); | |
| 142 local_state->SetInteger(prefs::kStabilityCrashCountFullScreenActivity, 0); | |
| 143 } | |
| OLD | NEW |