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.
5 #include "chrome/browser/ui/app_list/app_list_service.h"
7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h"
9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/process/process_info.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/time/time.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/pref_names.h"
24 base::Time
GetOriginalProcessStartTime(const CommandLine
& command_line
) {
25 if (command_line
.HasSwitch(switches::kOriginalProcessStartTime
)) {
26 std::string start_time_string
=
27 command_line
.GetSwitchValueASCII(switches::kOriginalProcessStartTime
);
28 int64 remote_start_time
;
29 base::StringToInt64(start_time_string
, &remote_start_time
);
30 return base::Time::FromInternalValue(remote_start_time
);
33 // base::CurrentProcessInfo::CreationTime() is only defined on some
35 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
36 return base::CurrentProcessInfo::CreationTime();
41 StartupType
GetStartupType(const CommandLine
& command_line
) {
42 // The presence of kOriginalProcessStartTime implies that another process
43 // has sent us its command line to handle, ie: we are already running.
44 if (command_line
.HasSwitch(switches::kOriginalProcessStartTime
)) {
45 return command_line
.HasSwitch(switches::kFastStart
) ?
46 WARM_START_FAST
: WARM_START
;
51 // The time the process that caused the app list to be shown started. This isn't
52 // necessarily the currently executing process as we may be processing a command
53 // line given to a short-lived Chrome instance.
54 int64 g_original_process_start_time
;
56 // The type of startup the the current app list show has gone through.
57 StartupType g_app_show_startup_type
;
59 void RecordStartupInfo(StartupType startup_type
, const base::Time
& start_time
) {
60 g_original_process_start_time
= start_time
.ToInternalValue();
61 g_app_show_startup_type
= startup_type
;
64 void RecordFirstPaintTiming() {
65 base::Time
start_time(
66 base::Time::FromInternalValue(g_original_process_start_time
));
67 base::TimeDelta elapsed
= base::Time::Now() - start_time
;
68 switch (g_app_show_startup_type
) {
70 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintColdStart", elapsed
);
73 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintWarmStart", elapsed
);
76 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintWarmStartFast",
85 void AppListService::RegisterPrefs(PrefRegistrySimple
* registry
) {
86 registry
->RegisterInt64Pref(prefs::kLastAppListLaunchPing
, 0);
87 registry
->RegisterIntegerPref(prefs::kAppListLaunchCount
, 0);
88 registry
->RegisterInt64Pref(prefs::kLastAppListAppLaunchPing
, 0);
89 registry
->RegisterIntegerPref(prefs::kAppListAppLaunchCount
, 0);
90 registry
->RegisterStringPref(prefs::kAppListProfile
, std::string());
91 registry
->RegisterBooleanPref(prefs::kRestartWithAppList
, false);
92 registry
->RegisterBooleanPref(prefs::kAppLauncherIsEnabled
, false);
93 registry
->RegisterBooleanPref(prefs::kAppLauncherHasBeenEnabled
, false);
95 #if defined(OS_MACOSX)
96 registry
->RegisterIntegerPref(prefs::kAppLauncherShortcutVersion
, 0);
99 // Identifies whether we should show the app launcher promo or not.
100 // Note that a field trial also controls the showing, so the promo won't show
101 // unless the pref is set AND the field trial is set to a proper group.
102 registry
->RegisterBooleanPref(prefs::kShowAppLauncherPromo
, true);
106 void AppListService::RecordShowTimings(const CommandLine
& command_line
) {
107 base::Time start_time
= GetOriginalProcessStartTime(command_line
);
108 if (start_time
.is_null())
111 base::TimeDelta elapsed
= base::Time::Now() - start_time
;
112 StartupType startup
= GetStartupType(command_line
);
115 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListColdStart", elapsed
);
118 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStart", elapsed
);
120 case WARM_START_FAST
:
121 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStartFast", elapsed
);
125 RecordStartupInfo(startup
, start_time
);
126 Get(chrome::HOST_DESKTOP_TYPE_NATIVE
)->SetAppListNextPaintCallback(
127 RecordFirstPaintTiming
);