OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/app_list/app_list_service.h" | 5 #include "chrome/browser/ui/app_list/app_list_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/process/process_info.h" | 10 #include "base/process/process_info.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 enum StartupType { | 18 enum StartupType { |
19 COLD_START, | 19 COLD_START, |
20 WARM_START, | 20 WARM_START, |
21 WARM_START_FAST, | 21 WARM_START_FAST, |
22 }; | 22 }; |
23 | 23 |
24 // For when an app list show request is received via CommandLine. Indicates | |
25 // whether the Profile the app list was previously showing was the SAME, OTHER | |
26 // or NONE with respect to the new Profile to show. | |
27 enum ProfileLoadState { | |
28 PROFILE_LOADED_SAME, | |
29 PROFILE_LOADED_OTHER, | |
30 PROFILE_LOADED_NONE, | |
31 }; | |
32 | |
24 base::Time GetOriginalProcessStartTime(const CommandLine& command_line) { | 33 base::Time GetOriginalProcessStartTime(const CommandLine& command_line) { |
25 if (command_line.HasSwitch(switches::kOriginalProcessStartTime)) { | 34 if (command_line.HasSwitch(switches::kOriginalProcessStartTime)) { |
26 std::string start_time_string = | 35 std::string start_time_string = |
27 command_line.GetSwitchValueASCII(switches::kOriginalProcessStartTime); | 36 command_line.GetSwitchValueASCII(switches::kOriginalProcessStartTime); |
28 int64 remote_start_time; | 37 int64 remote_start_time; |
29 base::StringToInt64(start_time_string, &remote_start_time); | 38 base::StringToInt64(start_time_string, &remote_start_time); |
30 return base::Time::FromInternalValue(remote_start_time); | 39 return base::Time::FromInternalValue(remote_start_time); |
31 } | 40 } |
32 | 41 |
33 // base::CurrentProcessInfo::CreationTime() is only defined on some | 42 // base::CurrentProcessInfo::CreationTime() is only defined on some |
(...skipping 16 matching lines...) Expand all Loading... | |
50 } | 59 } |
51 | 60 |
52 // The time the process that caused the app list to be shown started. This isn't | 61 // The time the process that caused the app list to be shown started. This isn't |
53 // necessarily the currently executing process as we may be processing a command | 62 // necessarily the currently executing process as we may be processing a command |
54 // line given to a short-lived Chrome instance. | 63 // line given to a short-lived Chrome instance. |
55 int64 g_original_process_start_time; | 64 int64 g_original_process_start_time; |
56 | 65 |
57 // The type of startup the the current app list show has gone through. | 66 // The type of startup the the current app list show has gone through. |
58 StartupType g_app_show_startup_type; | 67 StartupType g_app_show_startup_type; |
59 | 68 |
60 void RecordStartupInfo(StartupType startup_type, const base::Time& start_time) { | 69 // The state of the active app list profile at the most recent launch. |
70 ProfileLoadState g_profile_load_state; | |
71 | |
72 void RecordStartupInfo(StartupType startup_type, | |
73 const base::Time& start_time, | |
74 Profile* current_profile, | |
75 Profile* launch_profile) { | |
61 g_original_process_start_time = start_time.ToInternalValue(); | 76 g_original_process_start_time = start_time.ToInternalValue(); |
62 g_app_show_startup_type = startup_type; | 77 g_app_show_startup_type = startup_type; |
78 | |
79 if (!current_profile) | |
80 g_profile_load_state = PROFILE_LOADED_NONE; | |
81 else if (current_profile == launch_profile) | |
82 g_profile_load_state = PROFILE_LOADED_SAME; | |
83 else | |
84 g_profile_load_state = PROFILE_LOADED_OTHER; | |
63 } | 85 } |
64 | 86 |
65 void RecordFirstPaintTiming() { | 87 void RecordFirstPaintTiming() { |
66 base::Time start_time( | 88 base::Time start_time( |
67 base::Time::FromInternalValue(g_original_process_start_time)); | 89 base::Time::FromInternalValue(g_original_process_start_time)); |
68 base::TimeDelta elapsed = base::Time::Now() - start_time; | 90 base::TimeDelta elapsed = base::Time::Now() - start_time; |
69 switch (g_app_show_startup_type) { | 91 switch (g_app_show_startup_type) { |
70 case COLD_START: | 92 case COLD_START: |
71 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintColdStart", elapsed); | 93 if (g_profile_load_state == PROFILE_LOADED_NONE) |
Matt Giuca
2014/07/02 07:35:18
nit: Can this just be a DCHECK (avoiding the NOTRE
tapted
2014/07/04 03:00:02
Done.
| |
94 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintColdStart", elapsed); | |
95 else | |
96 NOTREACHED(); | |
72 break; | 97 break; |
73 case WARM_START: | 98 case WARM_START: |
74 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintWarmStart", elapsed); | 99 // For warm starts, only record showing the same profile. "NONE" should |
100 // only occur in the first 30 seconds after startup. "OTHER" only occurs | |
101 // for multi-profile cases. In these cases, timings are also affected by | |
102 // whether or not a profile has been loaded from disk, which makes the | |
103 // profile load asynchronous and skews results unpredictably. | |
104 if (g_profile_load_state == PROFILE_LOADED_SAME) | |
105 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintWarmStart", elapsed); | |
75 break; | 106 break; |
76 case WARM_START_FAST: | 107 case WARM_START_FAST: |
77 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintWarmStartFast", | 108 if (g_profile_load_state == PROFILE_LOADED_SAME) { |
78 elapsed); | 109 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintWarmStartFast", |
110 elapsed); | |
111 } | |
79 break; | 112 break; |
80 } | 113 } |
81 } | 114 } |
82 | 115 |
116 void RecordStartupTimings(AppListService* service, | |
Matt Giuca
2014/07/02 07:35:18
nit: I think it would read nicer if this method wa
tapted
2014/07/04 03:00:02
Done - I think it reads nice that way too, but not
Matt Giuca
2014/07/04 04:37:15
Hmm that's not so nice. I'd be happy if you put it
| |
117 const CommandLine& command_line, | |
Matt Giuca
2014/07/02 07:35:18
Your CL description mentions "RecordShowTimings";
tapted
2014/07/04 03:00:02
Done.
| |
118 Profile* launch_profile) { | |
119 base::Time start_time = GetOriginalProcessStartTime(command_line); | |
120 if (start_time.is_null()) | |
121 return; | |
122 | |
123 base::TimeDelta elapsed = base::Time::Now() - start_time; | |
124 StartupType startup = GetStartupType(command_line); | |
125 switch (startup) { | |
126 case COLD_START: | |
127 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListColdStart", elapsed); | |
128 break; | |
129 case WARM_START: | |
130 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStart", elapsed); | |
131 break; | |
132 case WARM_START_FAST: | |
133 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStartFast", elapsed); | |
134 break; | |
135 } | |
136 | |
137 Profile* current_profile = service->GetCurrentAppListProfile(); | |
138 RecordStartupInfo(startup, start_time, current_profile, launch_profile); | |
139 service->SetAppListNextPaintCallback(RecordFirstPaintTiming); | |
140 } | |
141 | |
83 } // namespace | 142 } // namespace |
84 | 143 |
85 // static | 144 // static |
86 void AppListService::RegisterPrefs(PrefRegistrySimple* registry) { | 145 void AppListService::RegisterPrefs(PrefRegistrySimple* registry) { |
87 registry->RegisterInt64Pref(prefs::kLastAppListLaunchPing, 0); | 146 registry->RegisterInt64Pref(prefs::kLastAppListLaunchPing, 0); |
88 registry->RegisterIntegerPref(prefs::kAppListLaunchCount, 0); | 147 registry->RegisterIntegerPref(prefs::kAppListLaunchCount, 0); |
89 registry->RegisterInt64Pref(prefs::kLastAppListAppLaunchPing, 0); | 148 registry->RegisterInt64Pref(prefs::kLastAppListAppLaunchPing, 0); |
90 registry->RegisterIntegerPref(prefs::kAppListAppLaunchCount, 0); | 149 registry->RegisterIntegerPref(prefs::kAppListAppLaunchCount, 0); |
91 registry->RegisterStringPref(prefs::kAppListProfile, std::string()); | 150 registry->RegisterStringPref(prefs::kAppListProfile, std::string()); |
92 registry->RegisterBooleanPref(prefs::kAppLauncherIsEnabled, false); | 151 registry->RegisterBooleanPref(prefs::kAppLauncherIsEnabled, false); |
93 registry->RegisterBooleanPref(prefs::kAppLauncherHasBeenEnabled, false); | 152 registry->RegisterBooleanPref(prefs::kAppLauncherHasBeenEnabled, false); |
94 registry->RegisterIntegerPref(prefs::kAppListEnableMethod, | 153 registry->RegisterIntegerPref(prefs::kAppListEnableMethod, |
95 ENABLE_NOT_RECORDED); | 154 ENABLE_NOT_RECORDED); |
96 registry->RegisterInt64Pref(prefs::kAppListEnableTime, 0); | 155 registry->RegisterInt64Pref(prefs::kAppListEnableTime, 0); |
97 | 156 |
98 #if defined(OS_MACOSX) | 157 #if defined(OS_MACOSX) |
99 registry->RegisterIntegerPref(prefs::kAppLauncherShortcutVersion, 0); | 158 registry->RegisterIntegerPref(prefs::kAppLauncherShortcutVersion, 0); |
100 #endif | 159 #endif |
101 | 160 |
102 // Identifies whether we should show the app launcher promo or not. | 161 // Identifies whether we should show the app launcher promo or not. |
103 // Note that a field trial also controls the showing, so the promo won't show | 162 // Note that a field trial also controls the showing, so the promo won't show |
104 // unless the pref is set AND the field trial is set to a proper group. | 163 // unless the pref is set AND the field trial is set to a proper group. |
105 registry->RegisterBooleanPref(prefs::kShowAppLauncherPromo, true); | 164 registry->RegisterBooleanPref(prefs::kShowAppLauncherPromo, true); |
106 } | 165 } |
107 | 166 |
108 // static | 167 // static |
109 void AppListService::RecordShowTimings(const CommandLine& command_line) { | 168 bool AppListService::HandleLaunchCommandLine( |
110 base::Time start_time = GetOriginalProcessStartTime(command_line); | 169 const base::CommandLine& command_line, |
111 if (start_time.is_null()) | 170 Profile* launch_profile) { |
112 return; | 171 InitAll(launch_profile); |
172 if (!command_line.HasSwitch(switches::kShowAppList)) | |
173 return false; | |
113 | 174 |
114 base::TimeDelta elapsed = base::Time::Now() - start_time; | 175 // The --show-app-list switch is used for shortcuts on the native desktop. |
115 StartupType startup = GetStartupType(command_line); | 176 AppListService* service = |
116 switch (startup) { | 177 AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE); |
117 case COLD_START: | 178 RecordStartupTimings(service, command_line, launch_profile); |
118 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListColdStart", elapsed); | 179 service->ShowForProfile(launch_profile); |
119 break; | 180 return true; |
120 case WARM_START: | |
121 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStart", elapsed); | |
122 break; | |
123 case WARM_START_FAST: | |
124 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStartFast", elapsed); | |
125 break; | |
126 } | |
127 | |
128 RecordStartupInfo(startup, start_time); | |
129 Get(chrome::HOST_DESKTOP_TYPE_NATIVE)->SetAppListNextPaintCallback( | |
130 RecordFirstPaintTiming); | |
131 } | 181 } |
OLD | NEW |