Chromium Code Reviews| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/histogram.h" | |
| 11 #include "base/process/process_info.h" | |
| 12 #include "base/strings/string_number_conversions.h" | |
| 13 #include "base/time/time.h" | |
| 14 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" | |
| 13 #include "chrome/browser/ui/browser_finder.h" | |
| 14 #include "chrome/browser/ui/browser_navigator.h" | |
| 15 #include "chrome/browser/ui/browser_navigator_params.h" | |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/common/url_constants.h" | |
| 18 #include "components/prefs/pref_registry_simple.h" | 19 #include "components/prefs/pref_registry_simple.h" |
| 19 | 20 |
| 20 namespace { | |
| 21 | |
| 22 enum StartupType { | |
| 23 COLD_START, | |
| 24 WARM_START, | |
| 25 WARM_START_FAST, | |
| 26 }; | |
| 27 | |
| 28 // For when an app list show request is received via CommandLine. Indicates | |
| 29 // whether the Profile the app list was previously showing was the SAME, OTHER | |
| 30 // or NONE with respect to the new Profile to show. | |
| 31 enum ProfileLoadState { | |
| 32 PROFILE_LOADED_SAME, | |
| 33 PROFILE_LOADED_OTHER, | |
| 34 PROFILE_LOADED_NONE, | |
| 35 }; | |
| 36 | |
| 37 base::Time GetOriginalProcessStartTime(const base::CommandLine& command_line) { | |
| 38 if (command_line.HasSwitch(switches::kOriginalProcessStartTime)) { | |
| 39 std::string start_time_string = | |
| 40 command_line.GetSwitchValueASCII(switches::kOriginalProcessStartTime); | |
| 41 int64_t remote_start_time; | |
| 42 base::StringToInt64(start_time_string, &remote_start_time); | |
| 43 return base::Time::FromInternalValue(remote_start_time); | |
| 44 } | |
| 45 | |
| 46 // base::CurrentProcessInfo::CreationTime() is only defined on some | |
| 47 // platforms. | |
| 48 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) | |
| 49 return base::CurrentProcessInfo::CreationTime(); | |
| 50 #else | |
| 51 return base::Time(); | |
| 52 #endif | |
| 53 } | |
| 54 | |
| 55 StartupType GetStartupType(const base::CommandLine& command_line) { | |
| 56 // The presence of kOriginalProcessStartTime implies that another process | |
| 57 // has sent us its command line to handle, ie: we are already running. | |
| 58 if (command_line.HasSwitch(switches::kOriginalProcessStartTime)) { | |
| 59 return command_line.HasSwitch(switches::kFastStart) ? | |
| 60 WARM_START_FAST : WARM_START; | |
| 61 } | |
| 62 return COLD_START; | |
| 63 } | |
| 64 | |
| 65 // The time the process that caused the app list to be shown started. This isn't | |
| 66 // necessarily the currently executing process as we may be processing a command | |
| 67 // line given to a short-lived Chrome instance. | |
| 68 int64_t g_original_process_start_time; | |
| 69 | |
| 70 // The type of startup the the current app list show has gone through. | |
| 71 StartupType g_app_show_startup_type; | |
| 72 | |
| 73 // The state of the active app list profile at the most recent launch. | |
| 74 ProfileLoadState g_profile_load_state; | |
| 75 | |
| 76 void RecordFirstPaintTiming() { | |
| 77 base::Time start_time( | |
| 78 base::Time::FromInternalValue(g_original_process_start_time)); | |
| 79 base::TimeDelta elapsed = base::Time::Now() - start_time; | |
| 80 switch (g_app_show_startup_type) { | |
| 81 case COLD_START: | |
| 82 DCHECK_EQ(PROFILE_LOADED_NONE, g_profile_load_state); | |
| 83 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintColdStart", elapsed); | |
| 84 break; | |
| 85 case WARM_START: | |
| 86 // For warm starts, only record showing the same profile. "NONE" should | |
| 87 // only occur in the first 30 seconds after startup. "OTHER" only occurs | |
| 88 // for multi-profile cases. In these cases, timings are also affected by | |
| 89 // whether or not a profile has been loaded from disk, which makes the | |
| 90 // profile load asynchronous and skews results unpredictably. | |
| 91 if (g_profile_load_state == PROFILE_LOADED_SAME) | |
| 92 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintWarmStart", elapsed); | |
| 93 break; | |
| 94 case WARM_START_FAST: | |
| 95 if (g_profile_load_state == PROFILE_LOADED_SAME) { | |
| 96 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintWarmStartFast", | |
| 97 elapsed); | |
| 98 } | |
| 99 break; | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 void RecordStartupInfo(AppListService* service, | |
| 104 const base::CommandLine& command_line, | |
| 105 Profile* launch_profile) { | |
| 106 base::Time start_time = GetOriginalProcessStartTime(command_line); | |
| 107 if (start_time.is_null()) | |
| 108 return; | |
| 109 | |
| 110 base::TimeDelta elapsed = base::Time::Now() - start_time; | |
| 111 StartupType startup_type = GetStartupType(command_line); | |
| 112 switch (startup_type) { | |
| 113 case COLD_START: | |
| 114 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListColdStart", elapsed); | |
| 115 break; | |
| 116 case WARM_START: | |
| 117 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStart", elapsed); | |
| 118 break; | |
| 119 case WARM_START_FAST: | |
| 120 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStartFast", elapsed); | |
| 121 break; | |
| 122 } | |
| 123 | |
| 124 g_original_process_start_time = start_time.ToInternalValue(); | |
| 125 g_app_show_startup_type = startup_type; | |
| 126 | |
| 127 Profile* current_profile = service->GetCurrentAppListProfile(); | |
| 128 if (!current_profile) | |
| 129 g_profile_load_state = PROFILE_LOADED_NONE; | |
| 130 else if (current_profile == launch_profile) | |
| 131 g_profile_load_state = PROFILE_LOADED_SAME; | |
| 132 else | |
| 133 g_profile_load_state = PROFILE_LOADED_OTHER; | |
| 134 | |
| 135 service->SetAppListNextPaintCallback(RecordFirstPaintTiming); | |
| 136 } | |
| 137 | |
| 138 } // namespace | |
| 139 | |
| 140 // static | 21 // static |
| 141 void AppListService::RegisterPrefs(PrefRegistrySimple* registry) { | 22 void AppListService::RegisterPrefs(PrefRegistrySimple* registry) { |
| 142 registry->RegisterInt64Pref(prefs::kLastAppListLaunchPing, 0); | 23 registry->RegisterInt64Pref(prefs::kLastAppListLaunchPing, 0); |
| 143 registry->RegisterIntegerPref(prefs::kAppListLaunchCount, 0); | 24 registry->RegisterIntegerPref(prefs::kAppListLaunchCount, 0); |
| 144 registry->RegisterInt64Pref(prefs::kLastAppListAppLaunchPing, 0); | 25 registry->RegisterInt64Pref(prefs::kLastAppListAppLaunchPing, 0); |
| 145 registry->RegisterIntegerPref(prefs::kAppListAppLaunchCount, 0); | 26 registry->RegisterIntegerPref(prefs::kAppListAppLaunchCount, 0); |
| 146 registry->RegisterStringPref(prefs::kAppListProfile, std::string()); | 27 registry->RegisterStringPref(prefs::kAppListProfile, std::string()); |
| 147 registry->RegisterBooleanPref(prefs::kAppLauncherHasBeenEnabled, false); | 28 registry->RegisterBooleanPref(prefs::kAppLauncherHasBeenEnabled, false); |
| 148 registry->RegisterIntegerPref(prefs::kAppListEnableMethod, | 29 registry->RegisterIntegerPref(prefs::kAppListEnableMethod, |
| 149 ENABLE_NOT_RECORDED); | 30 ENABLE_NOT_RECORDED); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 160 } | 41 } |
| 161 | 42 |
| 162 // static | 43 // static |
| 163 bool AppListService::HandleLaunchCommandLine( | 44 bool AppListService::HandleLaunchCommandLine( |
| 164 const base::CommandLine& command_line, | 45 const base::CommandLine& command_line, |
| 165 Profile* launch_profile) { | 46 Profile* launch_profile) { |
| 166 InitAll(launch_profile, launch_profile->GetPath()); | 47 InitAll(launch_profile, launch_profile->GetPath()); |
| 167 if (!command_line.HasSwitch(switches::kShowAppList)) | 48 if (!command_line.HasSwitch(switches::kShowAppList)) |
| 168 return false; | 49 return false; |
| 169 | 50 |
| 170 AppListService* service = Get(); | 51 Browser* browser = chrome::FindLastActive(); |
| 171 DCHECK(service); | 52 |
| 172 RecordStartupInfo(service, command_line, launch_profile); | 53 chrome::NavigateParams params(browser ? browser->profile() : launch_profile, |
|
tapted
2016/05/17 03:11:13
app_list_service.cc isn't compiled when enable_app
calamity
2016/05/18 01:11:38
Done.
| |
| 173 service->ShowForProfile(launch_profile); | 54 GURL(chrome::kChromeUIAppsURL), |
| 55 ui::PAGE_TRANSITION_AUTO_BOOKMARK); | |
| 56 chrome::Navigate(¶ms); | |
| 174 return true; | 57 return true; |
| 175 } | 58 } |
| OLD | NEW |