blob: 27610f8c3fdce28d5aaff8e536f4de39d4c0bf4e [file] [log] [blame]
[email protected]b6b72222012-02-11 02:04:131// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d24c4012009-07-28 01:57:312// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
pmonette32a5cfb42016-04-11 22:04:445#include "chrome/browser/shell_integration_win.h"
[email protected]d24c4012009-07-28 01:57:316
7#include <windows.h>
[email protected]caa05352014-03-01 00:43:058#include <shlwapi.h>
[email protected]d24c4012009-07-28 01:57:319#include <shobjidl.h>
thestig18dfb7a52014-08-26 10:44:0410#include <propkey.h> // Needs to come after shobjidl.h.
avi664c07b2015-12-26 02:18:3111#include <stddef.h>
12#include <stdint.h>
[email protected]d24c4012009-07-28 01:57:3113
pmonette32a5cfb42016-04-11 22:04:4414#include <vector>
15
[email protected]3a3e72c2011-11-29 02:59:3816#include "base/bind.h"
pmonette32a5cfb42016-04-11 22:04:4417#include "base/callback.h"
[email protected]d24c4012009-07-28 01:57:3118#include "base/command_line.h"
[email protected]25a4c1c2013-06-08 04:53:3619#include "base/files/file_enumerator.h"
thestig18dfb7a52014-08-26 10:44:0420#include "base/files/file_util.h"
avi664c07b2015-12-26 02:18:3121#include "base/macros.h"
dcheng4af48582016-04-19 00:29:3522#include "base/memory/ptr_util.h"
pmonette32a5cfb42016-04-11 22:04:4423#include "base/memory/weak_ptr.h"
[email protected]fa1e0e12013-07-18 00:10:1424#include "base/message_loop/message_loop.h"
pmonette32a5cfb42016-04-11 22:04:4425#include "base/metrics/histogram_macros.h"
grtc291eea2016-05-26 15:38:4826#include "base/metrics/user_metrics.h"
27#include "base/metrics/user_metrics_action.h"
[email protected]d24c4012009-07-28 01:57:3128#include "base/path_service.h"
[email protected]24a555b62013-06-10 22:01:1729#include "base/strings/string_util.h"
30#include "base/strings/stringprintf.h"
[email protected]e309f312013-06-07 21:50:0831#include "base/strings/utf_string_conversions.h"
pmonette32a5cfb42016-04-11 22:04:4432#include "base/time/time.h"
33#include "base/timer/timer.h"
[email protected]2d6503982010-10-17 04:41:5434#include "base/win/registry.h"
[email protected]8ee65ba2011-04-12 20:53:2335#include "base/win/scoped_comptr.h"
[email protected]07983302013-01-21 19:41:4436#include "base/win/scoped_propvariant.h"
[email protected]f1024e22012-09-12 07:14:5537#include "base/win/shortcut.h"
[email protected]935aa542010-10-15 01:59:1538#include "base/win/windows_version.h"
[email protected]89d43832013-06-29 20:25:2039#include "chrome/browser/policy/policy_path_parser.h"
pmonette32a5cfb42016-04-11 22:04:4440#include "chrome/browser/shell_integration.h"
[email protected]c9bb06f42010-01-13 23:53:4841#include "chrome/browser/web_applications/web_app.h"
grtc291eea2016-05-26 15:38:4842#include "chrome/browser/win/settings_app_monitor.h"
[email protected]d24c4012009-07-28 01:57:3143#include "chrome/common/chrome_constants.h"
[email protected]12f520c2010-01-06 18:11:1544#include "chrome/common/chrome_paths_internal.h"
[email protected]c9bb06f42010-01-13 23:53:4845#include "chrome/common/chrome_switches.h"
pmonette5057ca3b2016-07-04 16:48:4046#include "chrome/common/shell_handler_win.mojom.h"
47#include "chrome/grit/generated_resources.h"
[email protected]4468a5b2011-05-26 07:48:0248#include "chrome/installer/setup/setup_util.h"
[email protected]d24c4012009-07-28 01:57:3149#include "chrome/installer/util/browser_distribution.h"
50#include "chrome/installer/util/create_reg_key_work_item.h"
[email protected]3f69d6e612012-08-03 18:52:2751#include "chrome/installer/util/install_util.h"
pmonette0c40087a2016-04-21 00:05:1652#include "chrome/installer/util/scoped_user_protocol_entry.h"
[email protected]d24c4012009-07-28 01:57:3153#include "chrome/installer/util/set_reg_value_work_item.h"
54#include "chrome/installer/util/shell_util.h"
55#include "chrome/installer/util/util_constants.h"
56#include "chrome/installer/util/work_item.h"
57#include "chrome/installer/util/work_item_list.h"
pmonette2b1dbee2016-01-08 20:18:5858#include "components/variations/variations_associated_data.h"
[email protected]c38831a12011-10-28 12:44:4959#include "content/public/browser/browser_thread.h"
pmonette5057ca3b2016-07-04 16:48:4060#include "content/public/browser/utility_process_mojo_client.h"
61#include "ui/base/l10n/l10n_util.h"
[email protected]d24c4012009-07-28 01:57:3162
[email protected]631bb742011-11-02 11:29:3963using content::BrowserThread;
64
pmonette9fa59e882016-02-10 00:12:1965namespace shell_integration {
66
[email protected]12f520c2010-01-06 18:11:1567namespace {
68
pmonette9fa59e882016-02-10 00:12:1969// Helper function for GetAppId to generates profile id
[email protected]2f1c09d2011-01-14 14:58:1470// from profile path. "profile_id" is composed of sanitized basenames of
[email protected]12f520c2010-01-06 18:11:1571// user data dir and profile dir joined by a ".".
[email protected]6a72a632013-12-12 22:22:0072base::string16 GetProfileIdFromPath(const base::FilePath& profile_path) {
[email protected]12f520c2010-01-06 18:11:1573 // Return empty string if profile_path is empty
74 if (profile_path.empty())
[email protected]0085863a2013-12-06 21:19:0375 return base::string16();
[email protected]12f520c2010-01-06 18:11:1576
[email protected]650b2d52013-02-10 03:41:4577 base::FilePath default_user_data_dir;
[email protected]12f520c2010-01-06 18:11:1578 // Return empty string if profile_path is in default user data
79 // dir and is the default profile.
80 if (chrome::GetDefaultUserDataDirectory(&default_user_data_dir) &&
81 profile_path.DirName() == default_user_data_dir &&
[email protected]162b5992011-03-15 19:40:4882 profile_path.BaseName().value() ==
[email protected]f911df52013-12-24 23:24:2383 base::ASCIIToUTF16(chrome::kInitialProfile)) {
[email protected]0085863a2013-12-06 21:19:0384 return base::string16();
[email protected]162b5992011-03-15 19:40:4885 }
[email protected]12f520c2010-01-06 18:11:1586
87 // Get joined basenames of user data dir and profile.
[email protected]0085863a2013-12-06 21:19:0388 base::string16 basenames = profile_path.DirName().BaseName().value() +
[email protected]12f520c2010-01-06 18:11:1589 L"." + profile_path.BaseName().value();
90
[email protected]0085863a2013-12-06 21:19:0391 base::string16 profile_id;
[email protected]12f520c2010-01-06 18:11:1592 profile_id.reserve(basenames.size());
93
94 // Generate profile_id from sanitized basenames.
95 for (size_t i = 0; i < basenames.length(); ++i) {
brettwb3413062015-06-24 00:39:0296 if (base::IsAsciiAlpha(basenames[i]) ||
97 base::IsAsciiDigit(basenames[i]) ||
[email protected]12f520c2010-01-06 18:11:1598 basenames[i] == L'.')
99 profile_id += basenames[i];
100 }
101
102 return profile_id;
103}
104
taptedc2c690ab2016-05-25 02:49:03105base::string16 GetAppListAppName() {
106 static const base::char16 kAppListAppNameSuffix[] = L"AppList";
107 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
108 base::string16 app_name(dist->GetBaseAppId());
109 app_name.append(kAppListAppNameSuffix);
110 return app_name;
111}
112
[email protected]8ea8f1ef2013-01-06 18:39:03113// Gets expected app id for given Chrome (based on |command_line| and
114// |is_per_user_install|).
avi556c05022014-12-22 23:31:43115base::string16 GetExpectedAppId(const base::CommandLine& command_line,
[email protected]6a72a632013-12-12 22:22:00116 bool is_per_user_install) {
[email protected]b39e32e2013-04-24 08:55:54117 base::FilePath user_data_dir;
118 if (command_line.HasSwitch(switches::kUserDataDir))
119 user_data_dir = command_line.GetSwitchValuePath(switches::kUserDataDir);
120 else
121 chrome::GetDefaultUserDataDirectory(&user_data_dir);
[email protected]89d43832013-06-29 20:25:20122 // Adjust with any policy that overrides any other way to set the path.
123 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir);
[email protected]b39e32e2013-04-24 08:55:54124 DCHECK(!user_data_dir.empty());
[email protected]c9bb06f42010-01-13 23:53:48125
[email protected]b39e32e2013-04-24 08:55:54126 base::FilePath profile_subdir;
127 if (command_line.HasSwitch(switches::kProfileDirectory)) {
128 profile_subdir =
129 command_line.GetSwitchValuePath(switches::kProfileDirectory);
130 } else {
[email protected]f911df52013-12-24 23:24:23131 profile_subdir =
132 base::FilePath(base::ASCIIToUTF16(chrome::kInitialProfile));
[email protected]b39e32e2013-04-24 08:55:54133 }
134 DCHECK(!profile_subdir.empty());
135
136 base::FilePath profile_path = user_data_dir.Append(profile_subdir);
[email protected]0085863a2013-12-06 21:19:03137 base::string16 app_name;
[email protected]c9bb06f42010-01-13 23:53:48138 if (command_line.HasSwitch(switches::kApp)) {
[email protected]f911df52013-12-24 23:24:23139 app_name = base::UTF8ToUTF16(web_app::GenerateApplicationNameFromURL(
[email protected]57ecc4b2010-08-11 03:02:51140 GURL(command_line.GetSwitchValueASCII(switches::kApp))));
[email protected]2f1c09d2011-01-14 14:58:14141 } else if (command_line.HasSwitch(switches::kAppId)) {
[email protected]f911df52013-12-24 23:24:23142 app_name = base::UTF8ToUTF16(
143 web_app::GenerateApplicationNameFromExtensionId(
144 command_line.GetSwitchValueASCII(switches::kAppId)));
taptedc2c690ab2016-05-25 02:49:03145 } else if (command_line.HasSwitch(switches::kShowAppList)) {
146 app_name = GetAppListAppName();
[email protected]c9bb06f42010-01-13 23:53:48147 } else {
[email protected]a0448002012-06-19 04:32:10148 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
[email protected]8ea8f1ef2013-01-06 18:39:03149 app_name = ShellUtil::GetBrowserModelId(dist, is_per_user_install);
[email protected]c9bb06f42010-01-13 23:53:48150 }
[email protected]b39e32e2013-04-24 08:55:54151 DCHECK(!app_name.empty());
[email protected]c9bb06f42010-01-13 23:53:48152
pmonette9e4c1a82016-04-14 18:15:30153 return win::GetAppModelIdForProfile(app_name, profile_path);
[email protected]c9bb06f42010-01-13 23:53:48154}
155
gab88257b62016-01-15 03:19:19156void MigrateTaskbarPinsCallback() {
[email protected]3a3e72c2011-11-29 02:59:38157 // This should run on the file thread.
thestig00844cea2015-09-08 21:44:52158 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
[email protected]3a3e72c2011-11-29 02:59:38159
160 // Get full path of chrome.
[email protected]650b2d52013-02-10 03:41:45161 base::FilePath chrome_exe;
[email protected]3a3e72c2011-11-29 02:59:38162 if (!PathService::Get(base::FILE_EXE, &chrome_exe))
163 return;
164
gab88257b62016-01-15 03:19:19165 base::FilePath pins_path;
166 if (!PathService::Get(base::DIR_TASKBAR_PINS, &pins_path)) {
167 NOTREACHED();
168 return;
[email protected]3a3e72c2011-11-29 02:59:38169 }
gab88257b62016-01-15 03:19:19170
pmonette9e4c1a82016-04-14 18:15:30171 win::MigrateShortcutsInPathInternal(chrome_exe, pins_path);
[email protected]3a3e72c2011-11-29 02:59:38172}
173
[email protected]caa05352014-03-01 00:43:05174// Windows 8 introduced a new protocol->executable binding system which cannot
175// be retrieved in the HKCR registry subkey method implemented below. We call
176// AssocQueryString with the new Win8-only flag ASSOCF_IS_PROTOCOL instead.
177base::string16 GetAppForProtocolUsingAssocQuery(const GURL& url) {
thestig11bf74d2014-11-24 20:14:42178 base::string16 url_scheme = base::ASCIIToUTF16(url.scheme());
[email protected]caa05352014-03-01 00:43:05179 // Don't attempt to query protocol association on an empty string.
[email protected]6e84d372014-05-29 23:36:39180 if (url_scheme.empty())
[email protected]caa05352014-03-01 00:43:05181 return base::string16();
182
[email protected]caa05352014-03-01 00:43:05183 // Query AssocQueryString for a human-readable description of the program
184 // that will be invoked given the provided URL spec. This is used only to
185 // populate the external protocol dialog box the user sees when invoking
186 // an unknown external protocol.
187 wchar_t out_buffer[1024];
188 DWORD buffer_size = arraysize(out_buffer);
189 HRESULT hr = AssocQueryString(ASSOCF_IS_PROTOCOL,
190 ASSOCSTR_FRIENDLYAPPNAME,
[email protected]6e84d372014-05-29 23:36:39191 url_scheme.c_str(),
[email protected]caa05352014-03-01 00:43:05192 NULL,
193 out_buffer,
194 &buffer_size);
195 if (FAILED(hr)) {
196 DLOG(WARNING) << "AssocQueryString failed!";
197 return base::string16();
198 }
199 return base::string16(out_buffer);
200}
201
202base::string16 GetAppForProtocolUsingRegistry(const GURL& url) {
[email protected]caa05352014-03-01 00:43:05203 const base::string16 cmd_key_path =
thestig11bf74d2014-11-24 20:14:42204 base::ASCIIToUTF16(url.scheme() + "\\shell\\open\\command");
[email protected]caa05352014-03-01 00:43:05205 base::win::RegKey cmd_key(HKEY_CLASSES_ROOT,
206 cmd_key_path.c_str(),
207 KEY_READ);
[email protected]caa05352014-03-01 00:43:05208 base::string16 application_to_launch;
209 if (cmd_key.ReadValue(NULL, &application_to_launch) == ERROR_SUCCESS) {
benwellse84d8392015-08-18 05:23:58210 const base::string16 url_spec =
211 base::ASCIIToUTF16(url.possibly_invalid_spec());
brettwe6dae462015-06-24 20:54:45212 base::ReplaceSubstringsAfterOffset(&application_to_launch,
213 0,
214 L"%1",
benwellse84d8392015-08-18 05:23:58215 url_spec);
[email protected]caa05352014-03-01 00:43:05216 return application_to_launch;
217 }
218 return base::string16();
219}
220
pmonette9fa59e882016-02-10 00:12:19221DefaultWebClientState GetDefaultWebClientStateFromShellUtilDefaultState(
222 ShellUtil::DefaultState default_state) {
[email protected]eb63da72012-10-15 20:39:48223 switch (default_state) {
224 case ShellUtil::NOT_DEFAULT:
pmonette9fa59e882016-02-10 00:12:19225 return DefaultWebClientState::NOT_DEFAULT;
[email protected]eb63da72012-10-15 20:39:48226 case ShellUtil::IS_DEFAULT:
pmonette9fa59e882016-02-10 00:12:19227 return DefaultWebClientState::IS_DEFAULT;
[email protected]eb63da72012-10-15 20:39:48228 default:
229 DCHECK_EQ(ShellUtil::UNKNOWN_DEFAULT, default_state);
pmonette9fa59e882016-02-10 00:12:19230 return DefaultWebClientState::UNKNOWN_DEFAULT;
[email protected]eb63da72012-10-15 20:39:48231 }
232}
233
grtc291eea2016-05-26 15:38:48234// A recorder of user actions in the Windows Settings app.
235class DefaultBrowserActionRecorder : public win::SettingsAppMonitor::Delegate {
236 public:
237 // Creates the recorder and the monitor that drives it. |continuation| will be
238 // run once the monitor's initialization completes (regardless of success or
239 // failure).
240 explicit DefaultBrowserActionRecorder(base::Closure continuation)
241 : continuation_(std::move(continuation)), settings_app_monitor_(this) {}
242
243 private:
244 // win::SettingsAppMonitor::Delegate:
245 void OnInitialized(HRESULT result) override {
246 UMA_HISTOGRAM_BOOLEAN("SettingsAppMonitor.InitializationResult",
247 SUCCEEDED(result));
248 if (SUCCEEDED(result)) {
249 base::RecordAction(
250 base::UserMetricsAction("SettingsAppMonitor.Initialized"));
251 }
252 continuation_.Run();
253 continuation_ = base::Closure();
254 }
255
256 void OnAppFocused() override {
257 base::RecordAction(
258 base::UserMetricsAction("SettingsAppMonitor.AppFocused"));
259 }
260
261 void OnChooserInvoked() override {
262 base::RecordAction(
263 base::UserMetricsAction("SettingsAppMonitor.ChooserInvoked"));
264 }
265
266 void OnBrowserChosen(const base::string16& browser_name) override {
267 if (browser_name ==
268 BrowserDistribution::GetDistribution()->GetDisplayName()) {
269 base::RecordAction(
270 base::UserMetricsAction("SettingsAppMonitor.ChromeBrowserChosen"));
271 } else {
272 base::RecordAction(
273 base::UserMetricsAction("SettingsAppMonitor.OtherBrowserChosen"));
274 }
275 }
276
277 // A closure to be run once initialization completes.
278 base::Closure continuation_;
279
280 // Monitors user interaction with the Windows Settings app for the sake of
281 // reporting user actions.
282 win::SettingsAppMonitor settings_app_monitor_;
283
284 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserActionRecorder);
285};
286
287// A function bound up in a callback with a DefaultBrowserActionRecorder and
288// a closure to keep the former alive until the time comes to run the latter.
289void OnSettingsAppFinished(
290 std::unique_ptr<DefaultBrowserActionRecorder> recorder,
291 const base::Closure& on_finished_callback) {
292 recorder.reset();
293 on_finished_callback.Run();
294}
295
pmonette32a5cfb42016-04-11 22:04:44296// There is no way to make sure the user is done with the system settings, but a
297// signal that the interaction is finished is needed for UMA. A timer of 2
298// minutes is used as a substitute. The registry keys for the protocol
299// association with an app are also monitored to signal the end of the
300// interaction early when it is clear that the user made a choice (e.g. http
301// and https for default browser).
302//
303// This helper class manages both the timer and the registry watchers and makes
304// sure the callback for the end of the settings interaction is only run once.
305// This class also manages its own lifetime.
306class OpenSystemSettingsHelper {
307 public:
308 // Begin the monitoring and will call |on_finished_callback| when done.
309 // Takes in a null-terminated array of |protocols| whose registry keys must be
pmonette0c40087a2016-04-21 00:05:16310 // watched. The array must contain at least one element.
pmonette32a5cfb42016-04-11 22:04:44311 static void Begin(const wchar_t* const protocols[],
312 const base::Closure& on_finished_callback) {
pmonettec541d942016-06-15 22:08:32313 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
314
315 delete instance_;
316 instance_ = new OpenSystemSettingsHelper(protocols, on_finished_callback);
pmonette32a5cfb42016-04-11 22:04:44317 }
318
319 private:
320 // The reason the settings interaction concluded. Do not modify the ordering
321 // because it is used for UMA.
322 enum ConcludeReason { REGISTRY_WATCHER, TIMEOUT, NUM_CONCLUDE_REASON_TYPES };
323
324 OpenSystemSettingsHelper(const wchar_t* const protocols[],
325 const base::Closure& on_finished_callback)
pmonette0c40087a2016-04-21 00:05:16326 : scoped_user_protocol_entry_(protocols[0]),
327 on_finished_callback_(on_finished_callback),
328 weak_ptr_factory_(this) {
pmonette32a5cfb42016-04-11 22:04:44329 static const wchar_t kUrlAssociationFormat[] =
330 L"SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\"
331 L"%ls\\UserChoice";
332
333 // Remember the start time.
334 start_time_ = base::TimeTicks::Now();
335
336 for (const wchar_t* const* scan = &protocols[0]; *scan != nullptr; ++scan) {
337 AddRegistryKeyWatcher(
338 base::StringPrintf(kUrlAssociationFormat, *scan).c_str());
339 }
340 // Only the watchers that were succesfully initialized are counted.
341 registry_watcher_count_ = registry_key_watchers_.size();
342
343 timer_.Start(
344 FROM_HERE, base::TimeDelta::FromMinutes(2),
345 base::Bind(&OpenSystemSettingsHelper::ConcludeInteraction,
346 weak_ptr_factory_.GetWeakPtr(), ConcludeReason::TIMEOUT));
347 }
348
349 // Called when a change is detected on one of the registry keys being watched.
350 // Note: All types of modification to the registry key will trigger this
351 // function even if the value change is the only one that matters. This
352 // is good enough for now.
353 void OnRegistryKeyChanged() {
354 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
355
356 // Make sure all the registry watchers have fired.
357 if (--registry_watcher_count_ == 0) {
358 UMA_HISTOGRAM_MEDIUM_TIMES(
359 "DefaultBrowser.SettingsInteraction.RegistryWatcherDuration",
360 base::TimeTicks::Now() - start_time_);
361
362 ConcludeInteraction(ConcludeReason::REGISTRY_WATCHER);
363 }
364 }
365
366 // Ends the monitoring with the system settings. Will call
367 // |on_finished_callback_| and then dispose of this class instance to make
368 // sure the callback won't get called subsequently.
369 void ConcludeInteraction(ConcludeReason conclude_reason) {
370 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
371
372 UMA_HISTOGRAM_ENUMERATION(
373 "DefaultBrowser.SettingsInteraction.ConcludeReason", conclude_reason,
374 NUM_CONCLUDE_REASON_TYPES);
375 on_finished_callback_.Run();
pmonettec541d942016-06-15 22:08:32376 delete instance_;
377 instance_ = nullptr;
pmonette32a5cfb42016-04-11 22:04:44378 }
379
380 // Helper function to create a registry watcher for a given |key_path|. Do
381 // nothing on initialization failure.
382 void AddRegistryKeyWatcher(const wchar_t* key_path) {
ricea86fa1dd2016-09-13 05:59:45383 auto reg_key = base::MakeUnique<base::win::RegKey>(HKEY_CURRENT_USER,
384 key_path, KEY_NOTIFY);
pmonette32a5cfb42016-04-11 22:04:44385
386 if (reg_key->Valid() &&
387 reg_key->StartWatching(
388 base::Bind(&OpenSystemSettingsHelper::OnRegistryKeyChanged,
389 weak_ptr_factory_.GetWeakPtr()))) {
390 registry_key_watchers_.push_back(std::move(reg_key));
391 }
392 }
393
pmonettec541d942016-06-15 22:08:32394 // Used to make sure only one instance is alive at the same time.
395 static OpenSystemSettingsHelper* instance_;
396
pmonette0c40087a2016-04-21 00:05:16397 // This is needed to make sure that Windows displays an entry for the protocol
398 // inside the "Choose default apps by protocol" settings page.
399 ScopedUserProtocolEntry scoped_user_protocol_entry_;
400
pmonette32a5cfb42016-04-11 22:04:44401 // The function to call when the interaction with the system settings is
402 // finished.
403 base::Closure on_finished_callback_;
404
405 // The number of time the registry key watchers must fire.
406 int registry_watcher_count_ = 0;
407
408 // There can be multiple registry key watchers as some settings modify
409 // multiple protocol associations. e.g. Changing the default browser modifies
410 // the http and https associations.
dcheng4af48582016-04-19 00:29:35411 std::vector<std::unique_ptr<base::win::RegKey>> registry_key_watchers_;
pmonette32a5cfb42016-04-11 22:04:44412
413 base::OneShotTimer timer_;
414
415 // Records the time it takes for the final registry watcher to get signaled.
416 base::TimeTicks start_time_;
417
418 // Weak ptrs are used to bind this class to the callbacks of the timer and the
419 // registry watcher. This makes it possible to self-delete after one of the
420 // callbacks is executed to cancel the remaining ones.
421 base::WeakPtrFactory<OpenSystemSettingsHelper> weak_ptr_factory_;
422
423 DISALLOW_COPY_AND_ASSIGN(OpenSystemSettingsHelper);
424};
425
pmonettec541d942016-06-15 22:08:32426OpenSystemSettingsHelper* OpenSystemSettingsHelper::instance_ = nullptr;
427
pmonette5057ca3b2016-07-04 16:48:40428void RecordPinnedToTaskbarProcessError(bool error) {
429 UMA_HISTOGRAM_BOOLEAN("Windows.IsPinnedToTaskbar.ProcessError", error);
430}
431
432// Record the UMA histogram when a response is received. The callback that binds
433// to this function holds a reference to the ShellHandlerClient to keep it alive
434// until invokation.
435void OnIsPinnedToTaskbarResult(
436 content::UtilityProcessMojoClient<mojom::ShellHandler>* client,
437 bool succeeded,
438 bool is_pinned_to_taskbar) {
439 // Clean up the utility process.
440 delete client;
441
442 RecordPinnedToTaskbarProcessError(false);
443
444 enum Result { NOT_PINNED, PINNED, FAILURE, NUM_RESULTS };
445
446 Result result = FAILURE;
447 if (succeeded)
448 result = is_pinned_to_taskbar ? PINNED : NOT_PINNED;
449 UMA_HISTOGRAM_ENUMERATION("Windows.IsPinnedToTaskbar", result, NUM_RESULTS);
450}
451
452// Called when a connection error happen with the shell handler process. A call
453// to this function is mutially exclusive with a call to
454// OnIsPinnedToTaskbarResult().
455void OnShellHandlerConnectionError(
456 content::UtilityProcessMojoClient<mojom::ShellHandler>* client) {
457 // Clean up the utility process.
458 delete client;
459
460 RecordPinnedToTaskbarProcessError(true);
461}
462
[email protected]3a3e72c2011-11-29 02:59:38463} // namespace
[email protected]12f520c2010-01-06 18:11:15464
pmonette9fa59e882016-02-10 00:12:19465bool SetAsDefaultBrowser() {
[email protected]650b2d52013-02-10 03:41:45466 base::FilePath chrome_exe;
[email protected]d24c4012009-07-28 01:57:31467 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
468 LOG(ERROR) << "Error getting app exe path";
469 return false;
470 }
471
472 // From UI currently we only allow setting default browser for current user.
[email protected]bf6117c7e2010-12-01 06:00:25473 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
grte76ca2852014-12-05 16:42:10474 if (!ShellUtil::MakeChromeDefault(dist, ShellUtil::CURRENT_USER, chrome_exe,
475 true /* elevate_if_not_admin */)) {
[email protected]d24c4012009-07-28 01:57:31476 LOG(ERROR) << "Chrome could not be set as default browser.";
477 return false;
478 }
479
[email protected]8e96e502010-10-21 20:57:12480 VLOG(1) << "Chrome registered as default browser.";
[email protected]d24c4012009-07-28 01:57:31481 return true;
482}
483
pmonette9fa59e882016-02-10 00:12:19484bool SetAsDefaultProtocolClient(const std::string& protocol) {
[email protected]4468a5b2011-05-26 07:48:02485 if (protocol.empty())
486 return false;
487
[email protected]650b2d52013-02-10 03:41:45488 base::FilePath chrome_exe;
[email protected]4468a5b2011-05-26 07:48:02489 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
490 LOG(ERROR) << "Error getting app exe path";
491 return false;
492 }
493
[email protected]f911df52013-12-24 23:24:23494 base::string16 wprotocol(base::UTF8ToUTF16(protocol));
[email protected]4468a5b2011-05-26 07:48:02495 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
grte76ca2852014-12-05 16:42:10496 if (!ShellUtil::MakeChromeDefaultProtocolClient(dist, chrome_exe,
497 wprotocol)) {
[email protected]4468a5b2011-05-26 07:48:02498 LOG(ERROR) << "Chrome could not be set as default handler for "
499 << protocol << ".";
500 return false;
501 }
502
503 VLOG(1) << "Chrome registered as default handler for " << protocol << ".";
504 return true;
505}
506
pmonette32a5cfb42016-04-11 22:04:44507DefaultWebClientSetPermission GetDefaultWebClientSetPermission() {
pmonette034a03d92015-10-02 21:04:27508 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
509 if (distribution->GetDefaultBrowserControlPolicy() !=
510 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL)
511 return SET_DEFAULT_NOT_ALLOWED;
pmonette034a03d92015-10-02 21:04:27512 if (ShellUtil::CanMakeChromeDefaultUnattended())
513 return SET_DEFAULT_UNATTENDED;
pmonette32a5cfb42016-04-11 22:04:44514 // Windows 8 and 10 both introduced a new way to set the default web client
515 // which require user interaction.
pmonettef89ac7c72015-10-06 03:22:01516 return SET_DEFAULT_INTERACTIVE;
pmonette034a03d92015-10-02 21:04:27517}
518
pmonette9fa59e882016-02-10 00:12:19519bool IsElevationNeededForSettingDefaultProtocolClient() {
pmonette868ca642015-09-02 14:34:02520 return base::win::GetVersion() < base::win::VERSION_WIN8;
521}
522
pmonette9fa59e882016-02-10 00:12:19523base::string16 GetApplicationNameForProtocol(const GURL& url) {
benwellsd0c67aa2016-07-28 02:57:20524 base::string16 application_name;
525 // Windows 8 or above has a new protocol association query.
526 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
527 application_name = GetAppForProtocolUsingAssocQuery(url);
528 if (!application_name.empty())
529 return application_name;
530 }
531
532 return GetAppForProtocolUsingRegistry(url);
[email protected]42dc9402013-01-30 07:54:20533}
534
pmonette9fa59e882016-02-10 00:12:19535DefaultWebClientState GetDefaultBrowser() {
pmonette034a03d92015-10-02 21:04:27536 return GetDefaultWebClientStateFromShellUtilDefaultState(
537 ShellUtil::GetChromeDefaultState());
538}
539
[email protected]d24c4012009-07-28 01:57:31540// There is no reliable way to say which browser is default on a machine (each
541// browser can have some of the protocols/shortcuts). So we look for only HTTP
542// protocol handler. Even this handler is located at different places in
543// registry on XP and Vista:
544// - HKCR\http\shell\open\command (XP)
545// - HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\
546// http\UserChoice (Vista)
547// This method checks if Firefox is defualt browser by checking these
548// locations and returns true if Firefox traces are found there. In case of
549// error (or if Firefox is not found)it returns the default value which
550// is false.
pmonette9fa59e882016-02-10 00:12:19551bool IsFirefoxDefaultBrowser() {
[email protected]d24c4012009-07-28 01:57:31552 bool ff_default = false;
[email protected]935aa542010-10-15 01:59:15553 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
[email protected]0085863a2013-12-06 21:19:03554 base::string16 app_cmd;
[email protected]2d6503982010-10-17 04:41:54555 base::win::RegKey key(HKEY_CURRENT_USER,
556 ShellUtil::kRegVistaUrlPrefs, KEY_READ);
[email protected]e06f4d52011-01-19 07:28:46557 if (key.Valid() && (key.ReadValue(L"Progid", &app_cmd) == ERROR_SUCCESS) &&
[email protected]d24c4012009-07-28 01:57:31558 app_cmd == L"FirefoxURL")
559 ff_default = true;
560 } else {
[email protected]0085863a2013-12-06 21:19:03561 base::string16 key_path(L"http");
[email protected]d24c4012009-07-28 01:57:31562 key_path.append(ShellUtil::kRegShellOpen);
[email protected]2d6503982010-10-17 04:41:54563 base::win::RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ);
[email protected]0085863a2013-12-06 21:19:03564 base::string16 app_cmd;
[email protected]e06f4d52011-01-19 07:28:46565 if (key.Valid() && (key.ReadValue(L"", &app_cmd) == ERROR_SUCCESS) &&
[email protected]cb1f4ac2014-08-07 16:55:42566 base::string16::npos !=
brettwfce8d192015-08-10 19:07:51567 base::ToLowerASCII(app_cmd).find(L"firefox"))
[email protected]d24c4012009-07-28 01:57:31568 ff_default = true;
569 }
570 return ff_default;
571}
[email protected]12f520c2010-01-06 18:11:15572
pmonette9fa59e882016-02-10 00:12:19573DefaultWebClientState IsDefaultProtocolClient(const std::string& protocol) {
pmonette034a03d92015-10-02 21:04:27574 return GetDefaultWebClientStateFromShellUtilDefaultState(
575 ShellUtil::GetChromeDefaultProtocolClientState(
576 base::UTF8ToUTF16(protocol)));
577}
578
pmonette9e4c1a82016-04-14 18:15:30579namespace win {
580
581bool SetAsDefaultBrowserUsingIntentPicker() {
582 base::FilePath chrome_exe;
583 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
584 NOTREACHED() << "Error getting app exe path";
585 return false;
586 }
587
588 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
589 if (!ShellUtil::ShowMakeChromeDefaultSystemUI(dist, chrome_exe)) {
590 LOG(ERROR) << "Failed to launch the set-default-browser Windows UI.";
591 return false;
592 }
593
594 VLOG(1) << "Set-default-browser Windows UI completed.";
595 return true;
596}
597
598void SetAsDefaultBrowserUsingSystemSettings(
599 const base::Closure& on_finished_callback) {
600 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
601
602 base::FilePath chrome_exe;
603 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
604 NOTREACHED() << "Error getting app exe path";
605 on_finished_callback.Run();
606 return;
607 }
608
grtc291eea2016-05-26 15:38:48609 // Create an action recorder that will open the settings app once it has
610 // initialized.
611 std::unique_ptr<DefaultBrowserActionRecorder> recorder(
612 new DefaultBrowserActionRecorder(base::Bind(
613 base::IgnoreResult(&ShellUtil::ShowMakeChromeDefaultSystemUI),
614 base::Unretained(BrowserDistribution::GetDistribution()),
615 chrome_exe)));
pmonette9e4c1a82016-04-14 18:15:30616
grtc291eea2016-05-26 15:38:48617 // The helper manages its own lifetime. Bind the action recorder
618 // into the finished callback to keep it alive throughout the
619 // interaction.
620 static const wchar_t* const kProtocols[] = {L"http", L"https", nullptr};
621 OpenSystemSettingsHelper::Begin(
622 kProtocols, base::Bind(&OnSettingsAppFinished, base::Passed(&recorder),
623 on_finished_callback));
pmonette9e4c1a82016-04-14 18:15:30624}
625
626bool SetAsDefaultProtocolClientUsingIntentPicker(const std::string& protocol) {
627 base::FilePath chrome_exe;
628 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
629 NOTREACHED() << "Error getting app exe path";
630 return false;
631 }
632
633 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
634 base::string16 wprotocol(base::UTF8ToUTF16(protocol));
635 if (!ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe,
636 wprotocol)) {
637 LOG(ERROR) << "Failed to launch the set-default-client Windows UI.";
638 return false;
639 }
640
641 VLOG(1) << "Set-default-client Windows UI completed.";
642 return true;
643}
644
pmonette0c40087a2016-04-21 00:05:16645void SetAsDefaultProtocolClientUsingSystemSettings(
646 const std::string& protocol,
647 const base::Closure& on_finished_callback) {
648 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
649
650 base::FilePath chrome_exe;
651 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
652 NOTREACHED() << "Error getting app exe path";
653 on_finished_callback.Run();
654 return;
655 }
656
657 // The helper manages its own lifetime.
658 base::string16 wprotocol(base::UTF8ToUTF16(protocol));
659 const wchar_t* const kProtocols[] = {wprotocol.c_str(), nullptr};
660 OpenSystemSettingsHelper::Begin(kProtocols, on_finished_callback);
661
662 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
663 ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe,
664 wprotocol);
665}
666
pmonette9fa59e882016-02-10 00:12:19667base::string16 GetAppModelIdForProfile(const base::string16& app_name,
668 const base::FilePath& profile_path) {
[email protected]d2065e062013-12-12 23:49:52669 std::vector<base::string16> components;
[email protected]a0448002012-06-19 04:32:10670 components.push_back(app_name);
[email protected]0085863a2013-12-06 21:19:03671 const base::string16 profile_id(GetProfileIdFromPath(profile_path));
[email protected]a0448002012-06-19 04:32:10672 if (!profile_id.empty())
673 components.push_back(profile_id);
674 return ShellUtil::BuildAppModelId(components);
[email protected]12f520c2010-01-06 18:11:15675}
676
pmonette9fa59e882016-02-10 00:12:19677base::string16 GetChromiumModelIdForProfile(
[email protected]650b2d52013-02-10 03:41:45678 const base::FilePath& profile_path) {
[email protected]a0448002012-06-19 04:32:10679 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
[email protected]650b2d52013-02-10 03:41:45680 base::FilePath chrome_exe;
[email protected]a0448002012-06-19 04:32:10681 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
682 NOTREACHED();
683 return dist->GetBaseAppId();
684 }
685 return GetAppModelIdForProfile(
grte76ca2852014-12-05 16:42:10686 ShellUtil::GetBrowserModelId(dist,
687 InstallUtil::IsPerUserInstall(chrome_exe)),
[email protected]786799692012-09-26 14:16:48688 profile_path);
[email protected]12f520c2010-01-06 18:11:15689}
[email protected]c9bb06f42010-01-13 23:53:48690
pmonette9fa59e882016-02-10 00:12:19691void MigrateTaskbarPins() {
[email protected]935aa542010-10-15 01:59:15692 if (base::win::GetVersion() < base::win::VERSION_WIN7)
[email protected]c9bb06f42010-01-13 23:53:48693 return;
694
[email protected]81fcf952012-11-26 22:25:14695 // This needs to happen eventually (e.g. so that the appid is fixed and the
696 // run-time Chrome icon is merged with the taskbar shortcut), but this is not
697 // urgent and shouldn't delay Chrome startup.
gab88257b62016-01-15 03:19:19698 static const int64_t kMigrateTaskbarPinsDelaySeconds = 15;
[email protected]81fcf952012-11-26 22:25:14699 BrowserThread::PostDelayedTask(
[email protected]3a3e72c2011-11-29 02:59:38700 BrowserThread::FILE, FROM_HERE,
gab88257b62016-01-15 03:19:19701 base::Bind(&MigrateTaskbarPinsCallback),
702 base::TimeDelta::FromSeconds(kMigrateTaskbarPinsDelaySeconds));
[email protected]c9bb06f42010-01-13 23:53:48703}
[email protected]43903b82012-06-01 05:26:23704
pmonette5057ca3b2016-07-04 16:48:40705void RecordIsPinnedToTaskbarHistogram() {
706 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
707
708 // The code to check if Chrome is pinned to the taskbar brings in shell
709 // extensions which can hinder stability so it is executed in a utility
710 // process.
711 content::UtilityProcessMojoClient<mojom::ShellHandler>* client =
712 new content::UtilityProcessMojoClient<mojom::ShellHandler>(
713 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_SHELL_HANDLER_NAME));
714
715 client->set_error_callback(
716 base::Bind(&OnShellHandlerConnectionError, client));
717 client->set_disable_sandbox();
718 client->Start();
719
720 client->service()->IsPinnedToTaskbar(
721 base::Bind(&OnIsPinnedToTaskbarResult, client));
722}
723
pmonette9fa59e882016-02-10 00:12:19724int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe,
725 const base::FilePath& path) {
[email protected]8ea8f1ef2013-01-06 18:39:03726 DCHECK(base::win::GetVersion() >= base::win::VERSION_WIN7);
727
728 // Enumerate all pinned shortcuts in the given path directly.
[email protected]25a4c1c2013-06-08 04:53:36729 base::FileEnumerator shortcuts_enum(
[email protected]8ea8f1ef2013-01-06 18:39:03730 path, false, // not recursive
[email protected]25a4c1c2013-06-08 04:53:36731 base::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk"));
[email protected]8ea8f1ef2013-01-06 18:39:03732
grte76ca2852014-12-05 16:42:10733 bool is_per_user_install = InstallUtil::IsPerUserInstall(chrome_exe);
[email protected]8ea8f1ef2013-01-06 18:39:03734
735 int shortcuts_migrated = 0;
[email protected]650b2d52013-02-10 03:41:45736 base::FilePath target_path;
[email protected]0085863a2013-12-06 21:19:03737 base::string16 arguments;
[email protected]07983302013-01-21 19:41:44738 base::win::ScopedPropVariant propvariant;
[email protected]650b2d52013-02-10 03:41:45739 for (base::FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty();
[email protected]8ea8f1ef2013-01-06 18:39:03740 shortcut = shortcuts_enum.Next()) {
741 // TODO(gab): Use ProgramCompare instead of comparing FilePaths below once
742 // it is fixed to work with FilePaths with spaces.
743 if (!base::win::ResolveShortcut(shortcut, &target_path, &arguments) ||
744 chrome_exe != target_path) {
745 continue;
746 }
avi556c05022014-12-22 23:31:43747 base::CommandLine command_line(
748 base::CommandLine::FromString(base::StringPrintf(
749 L"\"%ls\" %ls", target_path.value().c_str(), arguments.c_str())));
[email protected]8ea8f1ef2013-01-06 18:39:03750
751 // Get the expected AppId for this Chrome shortcut.
[email protected]0085863a2013-12-06 21:19:03752 base::string16 expected_app_id(
[email protected]8ea8f1ef2013-01-06 18:39:03753 GetExpectedAppId(command_line, is_per_user_install));
754 if (expected_app_id.empty())
755 continue;
756
757 // Load the shortcut.
758 base::win::ScopedComPtr<IShellLink> shell_link;
759 base::win::ScopedComPtr<IPersistFile> persist_file;
760 if (FAILED(shell_link.CreateInstance(CLSID_ShellLink, NULL,
761 CLSCTX_INPROC_SERVER)) ||
dcheng81762e02014-11-21 21:22:28762 FAILED(persist_file.QueryFrom(shell_link.get())) ||
[email protected]8ea8f1ef2013-01-06 18:39:03763 FAILED(persist_file->Load(shortcut.value().c_str(), STGM_READ))) {
764 DLOG(WARNING) << "Failed loading shortcut at " << shortcut.value();
765 continue;
766 }
767
768 // Any properties that need to be updated on the shortcut will be stored in
769 // |updated_properties|.
770 base::win::ShortcutProperties updated_properties;
771
772 // Validate the existing app id for the shortcut.
773 base::win::ScopedComPtr<IPropertyStore> property_store;
[email protected]07983302013-01-21 19:41:44774 propvariant.Reset();
dcheng81762e02014-11-21 21:22:28775 if (FAILED(property_store.QueryFrom(shell_link.get())) ||
776 property_store->GetValue(PKEY_AppUserModel_ID, propvariant.Receive()) !=
777 S_OK) {
[email protected]8ea8f1ef2013-01-06 18:39:03778 // When in doubt, prefer not updating the shortcut.
779 NOTREACHED();
780 continue;
[email protected]8ea8f1ef2013-01-06 18:39:03781 } else {
[email protected]07983302013-01-21 19:41:44782 switch (propvariant.get().vt) {
783 case VT_EMPTY:
784 // If there is no app_id set, set our app_id if one is expected.
785 if (!expected_app_id.empty())
786 updated_properties.set_app_id(expected_app_id);
787 break;
788 case VT_LPWSTR:
[email protected]0085863a2013-12-06 21:19:03789 if (expected_app_id != base::string16(propvariant.get().pwszVal))
[email protected]07983302013-01-21 19:41:44790 updated_properties.set_app_id(expected_app_id);
791 break;
792 default:
793 NOTREACHED();
794 continue;
[email protected]8ea8f1ef2013-01-06 18:39:03795 }
796 }
797
gab88257b62016-01-15 03:19:19798 // Clear dual_mode property from any shortcuts that previously had it (it
799 // was only ever installed on shortcuts with the
800 // |default_chromium_model_id|).
[email protected]b39e32e2013-04-24 08:55:54801 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
[email protected]0085863a2013-12-06 21:19:03802 base::string16 default_chromium_model_id(
[email protected]b39e32e2013-04-24 08:55:54803 ShellUtil::GetBrowserModelId(dist, is_per_user_install));
gab88257b62016-01-15 03:19:19804 if (expected_app_id == default_chromium_model_id) {
[email protected]07983302013-01-21 19:41:44805 propvariant.Reset();
[email protected]8ea8f1ef2013-01-06 18:39:03806 if (property_store->GetValue(PKEY_AppUserModel_IsDualMode,
[email protected]07983302013-01-21 19:41:44807 propvariant.Receive()) != S_OK) {
[email protected]8ea8f1ef2013-01-06 18:39:03808 // When in doubt, prefer to not update the shortcut.
809 NOTREACHED();
810 continue;
gab38d242d4d2016-01-14 20:38:12811 }
812 if (propvariant.get().vt == VT_BOOL &&
813 !!propvariant.get().boolVal) {
814 updated_properties.set_dual_mode(false);
[email protected]8ea8f1ef2013-01-06 18:39:03815 }
816 }
817
818 persist_file.Release();
819 shell_link.Release();
820
821 // Update the shortcut if some of its properties need to be updated.
822 if (updated_properties.options &&
823 base::win::CreateOrUpdateShortcutLink(
824 shortcut, updated_properties,
825 base::win::SHORTCUT_UPDATE_EXISTING)) {
826 ++shortcuts_migrated;
827 }
828 }
829 return shortcuts_migrated;
830}
831
pmonette9fa59e882016-02-10 00:12:19832base::FilePath GetStartMenuShortcut(const base::FilePath& chrome_exe) {
[email protected]3f69d6e612012-08-03 18:52:27833 static const int kFolderIds[] = {
834 base::DIR_COMMON_START_MENU,
835 base::DIR_START_MENU,
836 };
837 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
taptedd7ef82ae2016-05-13 01:10:19838 const base::string16 shortcut_name(dist->GetShortcutName() +
839 installer::kLnkExt);
grt2be0cd082015-11-12 15:32:21840 base::FilePath programs_folder;
[email protected]650b2d52013-02-10 03:41:45841 base::FilePath shortcut;
[email protected]3f69d6e612012-08-03 18:52:27842
843 // Check both the common and the per-user Start Menu folders for system-level
844 // installs.
grte76ca2852014-12-05 16:42:10845 size_t folder = InstallUtil::IsPerUserInstall(chrome_exe) ? 1 : 0;
[email protected]3f69d6e612012-08-03 18:52:27846 for (; folder < arraysize(kFolderIds); ++folder) {
grt2be0cd082015-11-12 15:32:21847 if (!PathService::Get(kFolderIds[folder], &programs_folder)) {
[email protected]3f69d6e612012-08-03 18:52:27848 NOTREACHED();
849 continue;
850 }
851
grt2be0cd082015-11-12 15:32:21852 shortcut = programs_folder.Append(shortcut_name);
853 if (base::PathExists(shortcut))
854 return shortcut;
[email protected]3f69d6e612012-08-03 18:52:27855 }
856
[email protected]650b2d52013-02-10 03:41:45857 return base::FilePath();
[email protected]3f69d6e612012-08-03 18:52:27858}
pmonettef89ac7c72015-10-06 03:22:01859
pmonette32a5cfb42016-04-11 22:04:44860} // namespace win
861
pmonette9fa59e882016-02-10 00:12:19862} // namespace shell_integration