app_list_service.cc revision 23730a6e56a168d1879203e4b3819bb36e3d8f1f
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/ui/app_list/app_list_service.h" 6 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" 15 16namespace { 17 18enum StartupType { 19 COLD_START, 20 WARM_START, 21 WARM_START_FAST, 22}; 23 24base::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); 31 } 32 33// base::CurrentProcessInfo::CreationTime() is only defined on some 34// platforms. 35#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) 36 return base::CurrentProcessInfo::CreationTime(); 37#else 38 return base::Time(); 39#endif 40} 41 42StartupType GetStartupType(const CommandLine& command_line) { 43 // The presence of kOriginalProcessStartTime implies that another process 44 // has sent us its command line to handle, ie: we are already running. 45 if (command_line.HasSwitch(switches::kOriginalProcessStartTime)) { 46 return command_line.HasSwitch(switches::kFastStart) ? 47 WARM_START_FAST : WARM_START; 48 } 49 return COLD_START; 50} 51 52// 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 54// line given to a short-lived Chrome instance. 55int64 g_original_process_start_time; 56 57// The type of startup the the current app list show has gone through. 58StartupType g_app_show_startup_type; 59 60void RecordStartupInfo(StartupType startup_type, const base::Time& start_time) { 61 g_original_process_start_time = start_time.ToInternalValue(); 62 g_app_show_startup_type = startup_type; 63} 64 65void RecordFirstPaintTiming() { 66 base::Time start_time( 67 base::Time::FromInternalValue(g_original_process_start_time)); 68 base::TimeDelta elapsed = base::Time::Now() - start_time; 69 switch (g_app_show_startup_type) { 70 case COLD_START: 71 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintColdStart", elapsed); 72 break; 73 case WARM_START: 74 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintWarmStart", elapsed); 75 break; 76 case WARM_START_FAST: 77 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintWarmStartFast", 78 elapsed); 79 break; 80 } 81} 82 83} // namespace 84 85// static 86void AppListService::RegisterPrefs(PrefRegistrySimple* registry) { 87 registry->RegisterInt64Pref(prefs::kLastAppListLaunchPing, 0); 88 registry->RegisterIntegerPref(prefs::kAppListLaunchCount, 0); 89 registry->RegisterInt64Pref(prefs::kLastAppListAppLaunchPing, 0); 90 registry->RegisterIntegerPref(prefs::kAppListAppLaunchCount, 0); 91 registry->RegisterStringPref(prefs::kAppListProfile, std::string()); 92 registry->RegisterBooleanPref(prefs::kRestartWithAppList, false); 93 registry->RegisterBooleanPref(prefs::kAppLauncherIsEnabled, false); 94 registry->RegisterBooleanPref(prefs::kAppLauncherHasBeenEnabled, false); 95 registry->RegisterIntegerPref(prefs::kAppListEnableMethod, 96 ENABLE_NOT_RECORDED); 97 registry->RegisterInt64Pref(prefs::kAppListEnableTime, 0); 98 99#if defined(OS_MACOSX) 100 registry->RegisterIntegerPref(prefs::kAppLauncherShortcutVersion, 0); 101#endif 102 103 // Identifies whether we should show the app launcher promo or not. 104 // Note that a field trial also controls the showing, so the promo won't show 105 // unless the pref is set AND the field trial is set to a proper group. 106 registry->RegisterBooleanPref(prefs::kShowAppLauncherPromo, true); 107} 108 109// static 110void AppListService::RecordShowTimings(const CommandLine& command_line) { 111 base::Time start_time = GetOriginalProcessStartTime(command_line); 112 if (start_time.is_null()) 113 return; 114 115 base::TimeDelta elapsed = base::Time::Now() - start_time; 116 StartupType startup = GetStartupType(command_line); 117 switch (startup) { 118 case COLD_START: 119 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListColdStart", elapsed); 120 break; 121 case WARM_START: 122 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStart", elapsed); 123 break; 124 case WARM_START_FAST: 125 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStartFast", elapsed); 126 break; 127 } 128 129 RecordStartupInfo(startup, start_time); 130 Get(chrome::HOST_DESKTOP_TYPE_NATIVE)->SetAppListNextPaintCallback( 131 RecordFirstPaintTiming); 132} 133