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/sparse_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 void MetricsService::OnForegroundActivityChanged(ActivityTypeIds::Type type) { | |
| 15 PrefService* pref = g_browser_process->local_state(); | |
| 16 | |
| 17 // Record that the Activity is now in the foreground. | |
| 18 pref->SetInteger(prefs::kStabilityForegroundActivity, type); | |
| 19 | |
| 20 // Record that the Activity was launched. | |
| 21 int launched_activities = | |
| 22 pref->GetInteger(prefs::kStabilityLaunchedActivityFlags) | type; | |
| 23 pref->SetInteger(prefs::kStabilityLaunchedActivityFlags, launched_activities); | |
| 24 | |
| 25 pref->CommitPendingWrite(); | |
| 26 } | |
|
Ilya Sherman
2013/12/16 23:54:59
nit: Please arrange this method in the same order
gone
2013/12/17 01:34:31
Done.
| |
| 27 | |
| 28 // static | |
| 29 void MetricsService::RegisterPrefsAndroid(PrefRegistrySimple* registry) { | |
| 30 registry->RegisterIntegerPref(prefs::kStabilityForegroundActivity, | |
| 31 ActivityTypeIds::ACTIVITY_NONE); | |
| 32 registry->RegisterIntegerPref(prefs::kStabilityLaunchedActivityFlags, | |
| 33 ActivityTypeIds::ACTIVITY_NONE); | |
| 34 | |
| 35 registry->RegisterIntegerPref(prefs::kStabilityLaunchCountMainActivity, 0); | |
| 36 registry->RegisterIntegerPref(prefs::kStabilityLaunchCountFullScreenActivity, | |
| 37 0); | |
| 38 | |
| 39 registry->RegisterIntegerPref(prefs::kStabilityCrashCountMainActivity, 0); | |
| 40 registry->RegisterIntegerPref(prefs::kStabilityCrashCountFullScreenActivity, | |
| 41 0); | |
| 42 } | |
| 43 | |
| 44 // static | |
| 45 void MetricsService::DiscardOldStabilityStatsAndroid(PrefService* local_state) { | |
| 46 local_state->SetInteger(prefs::kStabilityForegroundActivity, | |
| 47 ActivityTypeIds::ACTIVITY_NONE); | |
| 48 local_state->SetInteger(prefs::kStabilityLaunchedActivityFlags, | |
| 49 ActivityTypeIds::ACTIVITY_NONE); | |
| 50 | |
| 51 local_state->SetInteger(prefs::kStabilityLaunchCountMainActivity, 0); | |
| 52 local_state->SetInteger(prefs::kStabilityLaunchCountFullScreenActivity, 0); | |
| 53 | |
| 54 local_state->SetInteger(prefs::kStabilityCrashCountMainActivity, 0); | |
| 55 local_state->SetInteger(prefs::kStabilityCrashCountFullScreenActivity, 0); | |
| 56 } | |
| 57 | |
| 58 void MetricsService::RecordAndroidStabilityPrefs() { | |
| 59 PrefService* pref = g_browser_process->local_state(); | |
| 60 DCHECK(pref); | |
|
Ilya Sherman
2013/12/16 23:54:59
nit: No need for this, since you directly access t
gone
2013/12/17 01:34:31
Done.
| |
| 61 | |
| 62 // Track which Activities were launched by the user. | |
| 63 int launched_activities = | |
| 64 pref->GetInteger(prefs::kStabilityLaunchedActivityFlags); | |
| 65 if (launched_activities & ActivityTypeIds::ACTIVITY_MAIN) { | |
| 66 IncrementPrefValue(prefs::kStabilityLaunchCountMainActivity); | |
| 67 } | |
|
Ilya Sherman
2013/12/16 23:54:59
nit: No need for curly braces.
gone
2013/12/17 01:34:31
Done.
| |
| 68 if (launched_activities & ActivityTypeIds::ACTIVITY_FULLSCREEN) { | |
| 69 IncrementPrefValue(prefs::kStabilityLaunchCountFullScreenActivity); | |
| 70 } | |
|
Ilya Sherman
2013/12/16 23:54:59
nit: No need for curly braces.
gone
2013/12/17 01:34:31
Done.
| |
| 71 pref->SetInteger(prefs::kStabilityLaunchedActivityFlags, | |
| 72 ActivityTypeIds::ACTIVITY_NONE); | |
| 73 | |
| 74 // If an Activity was in the foreground when Chrome died, then Chrome was | |
| 75 // improperly shut down. Record it as a crash for that particular Activity. | |
| 76 int foreground = pref->GetInteger(prefs::kStabilityForegroundActivity); | |
| 77 switch (foreground) { | |
| 78 case ActivityTypeIds::ACTIVITY_MAIN: | |
| 79 IncrementPrefValue(prefs::kStabilityCrashCountMainActivity); | |
| 80 break; | |
| 81 case ActivityTypeIds::ACTIVITY_FULLSCREEN: | |
| 82 IncrementPrefValue(prefs::kStabilityCrashCountFullScreenActivity); | |
| 83 break; | |
| 84 default: | |
| 85 break; | |
| 86 } | |
| 87 pref->SetInteger(prefs::kStabilityForegroundActivity, | |
| 88 ActivityTypeIds::ACTIVITY_NONE); | |
| 89 } | |
| 90 | |
| 91 void MetricsService::RecordAndroidStabilityHistograms() { | |
| 92 PrefService* pref = g_browser_process->local_state(); | |
| 93 | |
| 94 // Track which Activities were launched by the user. | |
| 95 int main_launch_count = | |
| 96 pref->GetInteger(prefs::kStabilityLaunchCountMainActivity); | |
| 97 for (int i = 0; i < main_launch_count; ++i) { | |
| 98 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Android.Activity.LaunchCounts", | |
| 99 ActivityTypeIds::ACTIVITY_MAIN); | |
| 100 } | |
|
Ilya Sherman
2013/12/16 23:54:59
This is somewhat inefficient. Any reason not to u
gone
2013/12/17 00:17:28
No reason other than I'm not familiar with all the
Ilya Sherman
2013/12/17 00:32:22
An enumerated histogram should be fine for that.
gone
2013/12/17 01:34:31
I think I've adjusted for that use case now.
| |
| 101 pref->SetInteger(prefs::kStabilityLaunchCountMainActivity, 0); | |
| 102 | |
| 103 int full_screen_launch_count = | |
| 104 pref->GetInteger(prefs::kStabilityLaunchCountFullScreenActivity); | |
| 105 for (int i = 0; i < full_screen_launch_count; ++i) { | |
| 106 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Android.Activity.LaunchCounts", | |
| 107 ActivityTypeIds::ACTIVITY_FULLSCREEN); | |
| 108 } | |
| 109 pref->SetInteger(prefs::kStabilityLaunchCountFullScreenActivity, 0); | |
| 110 | |
| 111 // Track which Activities were in the foreground when Chrome died. | |
| 112 int main_crash_count = | |
| 113 pref->GetInteger(prefs::kStabilityCrashCountMainActivity); | |
| 114 for (int i = 0; i < main_crash_count; ++i) { | |
| 115 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Android.Activity.CrashCounts", | |
| 116 ActivityTypeIds::ACTIVITY_MAIN); | |
| 117 } | |
| 118 pref->SetInteger(prefs::kStabilityCrashCountMainActivity, 0); | |
| 119 | |
| 120 int full_screen_crash_count = | |
| 121 pref->GetInteger(prefs::kStabilityCrashCountFullScreenActivity); | |
| 122 for (int i = 0; i < full_screen_crash_count; ++i) { | |
| 123 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Android.Activity.CrashCounts", | |
| 124 ActivityTypeIds::ACTIVITY_FULLSCREEN); | |
| 125 } | |
| 126 pref->SetInteger(prefs::kStabilityCrashCountFullScreenActivity, 0); | |
| 127 } | |
| OLD | NEW |