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 16 namespace { 17 18 base::TimeDelta GetTimeFromOriginalProcessStart( 19 const CommandLine& command_line) { 20 std::string start_time_string = 21 command_line.GetSwitchValueASCII(switches::kOriginalProcessStartTime); 22 int64 remote_start_time; 23 base::StringToInt64(start_time_string, &remote_start_time); 24 return base::Time::Now() - base::Time::FromInternalValue(remote_start_time); 25 } 26 27 } // namespace 28 29 // static 30 void AppListService::RegisterPrefs(PrefRegistrySimple* registry) { 31 registry->RegisterInt64Pref(prefs::kLastAppListLaunchPing, 0); 32 registry->RegisterIntegerPref(prefs::kAppListLaunchCount, 0); 33 registry->RegisterInt64Pref(prefs::kLastAppListAppLaunchPing, 0); 34 registry->RegisterIntegerPref(prefs::kAppListAppLaunchCount, 0); 35 registry->RegisterStringPref(prefs::kAppListProfile, std::string()); 36 registry->RegisterBooleanPref(prefs::kRestartWithAppList, false); 37 } 38 39 // static 40 void AppListService::RecordShowTimings(const CommandLine& command_line) { 41 // The presence of kOriginalProcessStartTime implies that another process 42 // has sent us its command line to handle, ie: we are already running. 43 if (command_line.HasSwitch(switches::kOriginalProcessStartTime)) { 44 base::TimeDelta elapsed = GetTimeFromOriginalProcessStart(command_line); 45 if (command_line.HasSwitch(switches::kFastStart)) 46 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStartFast", elapsed); 47 else 48 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStart", elapsed); 49 } else { 50 // base::CurrentProcessInfo::CreationTime() is only defined on some 51 // platforms. 52 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) 53 UMA_HISTOGRAM_LONG_TIMES( 54 "Startup.ShowAppListColdStart", 55 base::Time::Now() - base::CurrentProcessInfo::CreationTime()); 56 #endif 57 } 58 } 59