Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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/views/app_list/win/app_list_service_win.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 #include <stdint.h> | |
| 9 #include <sstream> | |
| 10 | |
| 11 #include "base/command_line.h" | |
| 12 #include "base/location.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/singleton.h" | |
| 15 #include "base/metrics/histogram.h" | |
| 16 #include "base/path_service.h" | |
| 17 #include "base/single_thread_task_runner.h" | |
| 18 #include "base/strings/utf_string_conversions.h" | |
| 19 #include "base/threading/sequenced_worker_pool.h" | |
| 20 #include "base/threading/thread_task_runner_handle.h" | |
| 21 #include "base/time/time.h" | |
| 22 #include "chrome/browser/browser_process.h" | |
| 23 #include "chrome/browser/browser_shutdown.h" | |
| 24 #include "chrome/browser/platform_util.h" | |
| 25 #include "chrome/browser/profiles/profile.h" | |
| 26 #include "chrome/browser/profiles/profile_manager.h" | |
| 27 #include "chrome/browser/ui/app_list/app_list_util.h" | |
| 28 #include "chrome/browser/ui/views/app_list/win/activation_tracker_win.h" | |
| 29 #include "chrome/browser/ui/views/app_list/win/app_list_controller_delegate_win. h" | |
| 30 #include "chrome/browser/ui/views/app_list/win/app_list_win.h" | |
| 31 #include "chrome/common/channel_info.h" | |
| 32 #include "chrome/common/chrome_constants.h" | |
| 33 #include "chrome/common/chrome_switches.h" | |
| 34 #include "chrome/common/pref_names.h" | |
| 35 #include "chrome/installer/util/browser_distribution.h" | |
| 36 #include "components/prefs/pref_service.h" | |
| 37 #include "components/version_info/version_info.h" | |
| 38 #include "content/public/browser/browser_thread.h" | |
| 39 #include "content/public/common/content_switches.h" | |
| 40 #include "ui/app_list/views/app_list_view.h" | |
| 41 #include "ui/base/ui_base_switches.h" | |
| 42 | |
| 43 #if defined(GOOGLE_CHROME_BUILD) | |
| 44 #include "chrome/installer/util/google_update_settings.h" | |
| 45 #include "chrome/installer/util/install_util.h" | |
| 46 #include "chrome/installer/util/updating_app_registration_data.h" | |
| 47 #include "chrome/installer/util/util_constants.h" | |
| 48 #endif // GOOGLE_CHROME_BUILD | |
| 49 | |
| 50 // static | |
| 51 AppListService* AppListService::Get() { | |
| 52 return AppListServiceWin::GetInstance(); | |
| 53 } | |
| 54 | |
| 55 // static | |
| 56 void AppListService::InitAll(Profile* initial_profile, | |
| 57 const base::FilePath& profile_path) { | |
| 58 AppListServiceWin::GetInstance()->Init(initial_profile); | |
| 59 } | |
| 60 | |
| 61 namespace { | |
| 62 | |
| 63 const int kUnusedAppListNoWarmupDays = 28; | |
| 64 | |
| 65 #if defined(GOOGLE_CHROME_BUILD) | |
| 66 void SetDidRunForNDayActiveStats() { | |
| 67 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | |
| 68 base::FilePath exe_path; | |
| 69 if (!PathService::Get(base::DIR_EXE, &exe_path)) { | |
| 70 NOTREACHED(); | |
| 71 return; | |
| 72 } | |
| 73 bool system_install = !InstallUtil::IsPerUserInstall(exe_path); | |
| 74 // Using Chrome Binary dist: Chrome dist may not exist for the legacy | |
| 75 // App Launcher, and App Launcher dist may be "shadow", which does not | |
| 76 // contain the information needed to determine multi-install. | |
| 77 // Edge case involving Canary: crbug/239163. | |
| 78 BrowserDistribution* chrome_binaries_dist = | |
| 79 BrowserDistribution::GetSpecificDistribution( | |
| 80 BrowserDistribution::CHROME_BINARIES); | |
| 81 if (chrome_binaries_dist && | |
| 82 InstallUtil::IsMultiInstall(chrome_binaries_dist, system_install)) { | |
| 83 UpdatingAppRegistrationData app_launcher_reg_data( | |
| 84 installer::kAppLauncherGuid); | |
| 85 GoogleUpdateSettings::UpdateDidRunStateForApp( | |
|
tapted
2016/07/20 01:15:34
This is the only caller external to google_update_
calamity
2016/07/25 02:34:22
Done.
| |
| 86 app_launcher_reg_data, true /* did_run */); | |
| 87 } | |
| 88 } | |
| 89 #endif // GOOGLE_CHROME_BUILD | |
| 90 | |
| 91 } // namespace | |
| 92 | |
| 93 // static | |
| 94 AppListServiceWin* AppListServiceWin::GetInstance() { | |
| 95 return base::Singleton<AppListServiceWin, | |
| 96 base::LeakySingletonTraits<AppListServiceWin>>::get(); | |
| 97 } | |
| 98 | |
| 99 AppListServiceWin::AppListServiceWin() | |
| 100 : AppListServiceViews(std::unique_ptr<AppListControllerDelegate>( | |
| 101 new AppListControllerDelegateWin(this))) {} | |
| 102 | |
| 103 AppListServiceWin::~AppListServiceWin() { | |
| 104 } | |
| 105 | |
| 106 void AppListServiceWin::ShowForProfile(Profile* requested_profile) { | |
| 107 AppListServiceViews::ShowForProfile(requested_profile); | |
| 108 | |
| 109 #if defined(GOOGLE_CHROME_BUILD) | |
| 110 content::BrowserThread::PostBlockingPoolTask( | |
| 111 FROM_HERE, base::Bind(SetDidRunForNDayActiveStats)); | |
| 112 #endif // GOOGLE_CHROME_BUILD | |
| 113 } | |
| 114 | |
| 115 void AppListServiceWin::OnLoadProfileForWarmup(Profile* initial_profile) { | |
| 116 // App list profiles should not be off-the-record. | |
| 117 DCHECK(!initial_profile->IsOffTheRecord()); | |
| 118 DCHECK(!initial_profile->IsGuestSession()); | |
| 119 | |
| 120 if (!IsWarmupNeeded()) | |
| 121 return; | |
| 122 | |
| 123 base::Time before_warmup(base::Time::Now()); | |
| 124 shower().WarmupForProfile(initial_profile); | |
|
tapted
2016/07/20 01:15:34
I think this is the only caller of WarmupForProfil
calamity
2016/07/25 02:34:22
Done.
| |
| 125 UMA_HISTOGRAM_TIMES("Apps.AppListWarmupDuration", | |
|
tapted
2016/07/20 01:15:34
Mark obsolete in histograms.xml
calamity
2016/07/25 02:34:22
Done.
| |
| 126 base::Time::Now() - before_warmup); | |
| 127 } | |
| 128 | |
| 129 void AppListServiceWin::SetAppListNextPaintCallback(void (*callback)()) { | |
| 130 if (shower().app_list()) | |
| 131 shower().app_list()->SetNextPaintCallback(base::Bind(callback)); | |
|
tapted
2016/07/20 01:15:34
This is the only caller of SetNextPaintCallback()
calamity
2016/07/25 02:34:22
Done.
| |
| 132 else | |
| 133 next_paint_callback_ = base::Bind(callback); | |
| 134 } | |
| 135 | |
| 136 void AppListServiceWin::Init(Profile* initial_profile) { | |
| 137 ScheduleWarmup(); | |
| 138 AppListServiceViews::Init(initial_profile); | |
| 139 } | |
| 140 | |
| 141 void AppListServiceWin::CreateShortcut() { | |
| 142 NOTREACHED(); | |
| 143 } | |
| 144 | |
| 145 void AppListServiceWin::ScheduleWarmup() { | |
| 146 // Post a task to create the app list. This is posted to not impact startup | |
| 147 // time. | |
| 148 /* const */ int kInitWindowDelay = 30; | |
| 149 | |
| 150 // TODO(vadimt): Make kInitWindowDelay const and remove the below switch once | |
| 151 // crbug.com/431326 is fixed. | |
| 152 | |
| 153 // Profiler UMA data is reported only for first 30 sec after browser startup. | |
| 154 // To make all invocations of AppListServiceWin::LoadProfileForWarmup visible | |
| 155 // to the server-side analysis tool, reducing this period to 10 sec in Dev | |
| 156 // builds and Canary, where profiler instrumentations are enabled. | |
| 157 switch (chrome::GetChannel()) { | |
| 158 case version_info::Channel::UNKNOWN: | |
| 159 case version_info::Channel::CANARY: | |
| 160 kInitWindowDelay = 10; | |
| 161 break; | |
| 162 | |
| 163 case version_info::Channel::DEV: | |
| 164 case version_info::Channel::BETA: | |
| 165 case version_info::Channel::STABLE: | |
| 166 // Except on Canary, don't bother scheduling an app launcher warmup when | |
| 167 // it's not already enabled. Always schedule on Canary while collecting | |
| 168 // profiler data (see comment above). | |
| 169 if (!IsAppLauncherEnabled()) | |
| 170 return; | |
| 171 | |
| 172 // Profiler instrumentations are not enabled. | |
| 173 break; | |
| 174 } | |
| 175 | |
| 176 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 177 FROM_HERE, base::Bind(&AppListServiceWin::LoadProfileForWarmup, | |
| 178 base::Unretained(this)), | |
| 179 base::TimeDelta::FromSeconds(kInitWindowDelay)); | |
| 180 } | |
| 181 | |
| 182 bool AppListServiceWin::IsWarmupNeeded() { | |
| 183 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 184 if (!g_browser_process || g_browser_process->IsShuttingDown() || | |
| 185 browser_shutdown::IsTryingToQuit() || | |
| 186 command_line->HasSwitch(switches::kTestType)) { | |
| 187 return false; | |
| 188 } | |
| 189 | |
| 190 // Don't warm up the app list if it hasn't been used for a while. If the last | |
| 191 // launch is unknown, record it as "used" on the first warmup. | |
| 192 PrefService* local_state = g_browser_process->local_state(); | |
| 193 int64_t last_launch_time_pref = | |
| 194 local_state->GetInt64(prefs::kAppListLastLaunchTime); | |
|
tapted
2016/07/20 01:15:34
This is the only getter, so this should be deleted
calamity
2016/07/25 02:34:22
Done.
| |
| 195 if (last_launch_time_pref == 0) | |
| 196 RecordAppListLastLaunch(); | |
| 197 | |
| 198 base::Time last_launch_time = | |
| 199 base::Time::FromInternalValue(last_launch_time_pref); | |
| 200 if (base::Time::Now() - last_launch_time > | |
| 201 base::TimeDelta::FromDays(kUnusedAppListNoWarmupDays)) { | |
| 202 return false; | |
| 203 } | |
| 204 | |
| 205 // We only need to initialize the view if there's no view already created and | |
| 206 // there's no profile loading to be shown. | |
| 207 return !shower().HasView() && !profile_loader().IsAnyProfileLoading(); | |
|
tapted
2016/07/20 01:15:34
hm - I don't think linux calls IsAnyProfileLoading
calamity
2016/07/25 02:34:22
Acknowledged.
| |
| 208 } | |
| 209 | |
| 210 void AppListServiceWin::LoadProfileForWarmup() { | |
| 211 if (!IsWarmupNeeded()) | |
| 212 return; | |
| 213 | |
| 214 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 215 base::FilePath profile_path(GetProfilePath(profile_manager->user_data_dir())); | |
| 216 | |
| 217 profile_loader().LoadProfileInvalidatingOtherLoads( | |
| 218 profile_path, | |
| 219 base::Bind(&AppListServiceWin::OnLoadProfileForWarmup, | |
| 220 base::Unretained(this))); | |
| 221 } | |
| 222 | |
| 223 void AppListServiceWin::OnViewBeingDestroyed() { | |
| 224 activation_tracker_.reset(); | |
| 225 AppListServiceViews::OnViewBeingDestroyed(); | |
| 226 } | |
| 227 | |
| 228 void AppListServiceWin::OnViewCreated() { | |
| 229 if (!next_paint_callback_.is_null()) { | |
| 230 shower().app_list()->SetNextPaintCallback(next_paint_callback_); | |
| 231 next_paint_callback_.Reset(); | |
| 232 } | |
| 233 activation_tracker_.reset(new ActivationTrackerWin(this)); | |
| 234 } | |
| 235 | |
| 236 void AppListServiceWin::OnViewDismissed() { | |
| 237 activation_tracker_->OnViewHidden(); | |
| 238 } | |
| 239 | |
| 240 void AppListServiceWin::MoveNearCursor(app_list::AppListView* view) { | |
| 241 AppListWin::MoveNearCursor(view); | |
| 242 } | |
| OLD | NEW |