| 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 |
| 69 // The state of the active app list profile at the most recent launch. |
| 70 ProfileLoadState g_profile_load_state; |
| 71 |
| 60 void RecordFirstPaintTiming() { | 72 void RecordFirstPaintTiming() { |
| 61 base::Time start_time( | 73 base::Time start_time( |
| 62 base::Time::FromInternalValue(g_original_process_start_time)); | 74 base::Time::FromInternalValue(g_original_process_start_time)); |
| 63 base::TimeDelta elapsed = base::Time::Now() - start_time; | 75 base::TimeDelta elapsed = base::Time::Now() - start_time; |
| 64 switch (g_app_show_startup_type) { | 76 switch (g_app_show_startup_type) { |
| 65 case COLD_START: | 77 case COLD_START: |
| 78 DCHECK_EQ(PROFILE_LOADED_NONE, g_profile_load_state); |
| 66 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintColdStart", elapsed); | 79 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintColdStart", elapsed); |
| 67 break; | 80 break; |
| 68 case WARM_START: | 81 case WARM_START: |
| 69 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintWarmStart", elapsed); | 82 // For warm starts, only record showing the same profile. "NONE" should |
| 83 // only occur in the first 30 seconds after startup. "OTHER" only occurs |
| 84 // for multi-profile cases. In these cases, timings are also affected by |
| 85 // whether or not a profile has been loaded from disk, which makes the |
| 86 // profile load asynchronous and skews results unpredictably. |
| 87 if (g_profile_load_state == PROFILE_LOADED_SAME) |
| 88 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintWarmStart", elapsed); |
| 70 break; | 89 break; |
| 71 case WARM_START_FAST: | 90 case WARM_START_FAST: |
| 72 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintWarmStartFast", | 91 if (g_profile_load_state == PROFILE_LOADED_SAME) { |
| 73 elapsed); | 92 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintWarmStartFast", |
| 93 elapsed); |
| 94 } |
| 74 break; | 95 break; |
| 75 } | 96 } |
| 76 } | 97 } |
| 77 | 98 |
| 78 void RecordStartupInfo(AppListService* service, | 99 void RecordStartupInfo(AppListService* service, |
| 79 const CommandLine& command_line) { | 100 const CommandLine& command_line, |
| 101 Profile* launch_profile) { |
| 80 base::Time start_time = GetOriginalProcessStartTime(command_line); | 102 base::Time start_time = GetOriginalProcessStartTime(command_line); |
| 81 if (start_time.is_null()) | 103 if (start_time.is_null()) |
| 82 return; | 104 return; |
| 83 | 105 |
| 84 base::TimeDelta elapsed = base::Time::Now() - start_time; | 106 base::TimeDelta elapsed = base::Time::Now() - start_time; |
| 85 StartupType startup_type = GetStartupType(command_line); | 107 StartupType startup_type = GetStartupType(command_line); |
| 86 switch (startup_type) { | 108 switch (startup_type) { |
| 87 case COLD_START: | 109 case COLD_START: |
| 88 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListColdStart", elapsed); | 110 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListColdStart", elapsed); |
| 89 break; | 111 break; |
| 90 case WARM_START: | 112 case WARM_START: |
| 91 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStart", elapsed); | 113 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStart", elapsed); |
| 92 break; | 114 break; |
| 93 case WARM_START_FAST: | 115 case WARM_START_FAST: |
| 94 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStartFast", elapsed); | 116 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStartFast", elapsed); |
| 95 break; | 117 break; |
| 96 } | 118 } |
| 97 | 119 |
| 98 g_original_process_start_time = start_time.ToInternalValue(); | 120 g_original_process_start_time = start_time.ToInternalValue(); |
| 99 g_app_show_startup_type = startup_type; | 121 g_app_show_startup_type = startup_type; |
| 122 |
| 123 Profile* current_profile = service->GetCurrentAppListProfile(); |
| 124 if (!current_profile) |
| 125 g_profile_load_state = PROFILE_LOADED_NONE; |
| 126 else if (current_profile == launch_profile) |
| 127 g_profile_load_state = PROFILE_LOADED_SAME; |
| 128 else |
| 129 g_profile_load_state = PROFILE_LOADED_OTHER; |
| 130 |
| 100 service->SetAppListNextPaintCallback(RecordFirstPaintTiming); | 131 service->SetAppListNextPaintCallback(RecordFirstPaintTiming); |
| 101 } | 132 } |
| 102 | 133 |
| 103 } // namespace | 134 } // namespace |
| 104 | 135 |
| 105 // static | 136 // static |
| 106 void AppListService::RegisterPrefs(PrefRegistrySimple* registry) { | 137 void AppListService::RegisterPrefs(PrefRegistrySimple* registry) { |
| 107 registry->RegisterInt64Pref(prefs::kLastAppListLaunchPing, 0); | 138 registry->RegisterInt64Pref(prefs::kLastAppListLaunchPing, 0); |
| 108 registry->RegisterIntegerPref(prefs::kAppListLaunchCount, 0); | 139 registry->RegisterIntegerPref(prefs::kAppListLaunchCount, 0); |
| 109 registry->RegisterInt64Pref(prefs::kLastAppListAppLaunchPing, 0); | 140 registry->RegisterInt64Pref(prefs::kLastAppListAppLaunchPing, 0); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 129 bool AppListService::HandleLaunchCommandLine( | 160 bool AppListService::HandleLaunchCommandLine( |
| 130 const base::CommandLine& command_line, | 161 const base::CommandLine& command_line, |
| 131 Profile* launch_profile) { | 162 Profile* launch_profile) { |
| 132 InitAll(launch_profile); | 163 InitAll(launch_profile); |
| 133 if (!command_line.HasSwitch(switches::kShowAppList)) | 164 if (!command_line.HasSwitch(switches::kShowAppList)) |
| 134 return false; | 165 return false; |
| 135 | 166 |
| 136 // The --show-app-list switch is used for shortcuts on the native desktop. | 167 // The --show-app-list switch is used for shortcuts on the native desktop. |
| 137 AppListService* service = Get(chrome::HOST_DESKTOP_TYPE_NATIVE); | 168 AppListService* service = Get(chrome::HOST_DESKTOP_TYPE_NATIVE); |
| 138 DCHECK(service); | 169 DCHECK(service); |
| 139 RecordStartupInfo(service, command_line); | 170 RecordStartupInfo(service, command_line, launch_profile); |
| 140 service->ShowForProfile(launch_profile); | 171 service->ShowForProfile(launch_profile); |
| 141 return true; | 172 return true; |
| 142 } | 173 } |
| OLD | NEW |