blob: f49f0fda71baa6f2df120d0465215e6f50a1e474 [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
pmonettea98315242016-11-23 21:39:1814#include <memory>
15#include <utility>
pmonette32a5cfb42016-04-11 22:04:4416#include <vector>
17
[email protected]3a3e72c2011-11-29 02:59:3818#include "base/bind.h"
pmonette32a5cfb42016-04-11 22:04:4419#include "base/callback.h"
[email protected]d24c4012009-07-28 01:57:3120#include "base/command_line.h"
[email protected]25a4c1c2013-06-08 04:53:3621#include "base/files/file_enumerator.h"
thestig18dfb7a52014-08-26 10:44:0422#include "base/files/file_util.h"
avi664c07b2015-12-26 02:18:3123#include "base/macros.h"
dcheng4af48582016-04-19 00:29:3524#include "base/memory/ptr_util.h"
pmonette32a5cfb42016-04-11 22:04:4425#include "base/memory/weak_ptr.h"
[email protected]fa1e0e12013-07-18 00:10:1426#include "base/message_loop/message_loop.h"
pmonette32a5cfb42016-04-11 22:04:4427#include "base/metrics/histogram_macros.h"
grtc291eea2016-05-26 15:38:4828#include "base/metrics/user_metrics.h"
29#include "base/metrics/user_metrics_action.h"
[email protected]d24c4012009-07-28 01:57:3130#include "base/path_service.h"
[email protected]24a555b62013-06-10 22:01:1731#include "base/strings/string_util.h"
32#include "base/strings/stringprintf.h"
[email protected]e309f312013-06-07 21:50:0833#include "base/strings/utf_string_conversions.h"
pmonette32a5cfb42016-04-11 22:04:4434#include "base/time/time.h"
35#include "base/timer/timer.h"
[email protected]2d6503982010-10-17 04:41:5436#include "base/win/registry.h"
[email protected]8ee65ba2011-04-12 20:53:2337#include "base/win/scoped_comptr.h"
[email protected]07983302013-01-21 19:41:4438#include "base/win/scoped_propvariant.h"
[email protected]f1024e22012-09-12 07:14:5539#include "base/win/shortcut.h"
[email protected]935aa542010-10-15 01:59:1540#include "base/win/windows_version.h"
[email protected]89d43832013-06-29 20:25:2041#include "chrome/browser/policy/policy_path_parser.h"
pmonette32a5cfb42016-04-11 22:04:4442#include "chrome/browser/shell_integration.h"
[email protected]c9bb06f42010-01-13 23:53:4843#include "chrome/browser/web_applications/web_app.h"
grtc291eea2016-05-26 15:38:4844#include "chrome/browser/win/settings_app_monitor.h"
[email protected]d24c4012009-07-28 01:57:3145#include "chrome/common/chrome_constants.h"
[email protected]12f520c2010-01-06 18:11:1546#include "chrome/common/chrome_paths_internal.h"
[email protected]c9bb06f42010-01-13 23:53:4847#include "chrome/common/chrome_switches.h"
pmonette5057ca3b2016-07-04 16:48:4048#include "chrome/common/shell_handler_win.mojom.h"
49#include "chrome/grit/generated_resources.h"
grtc98803462017-03-08 10:05:0850#include "chrome/install_static/install_util.h"
[email protected]4468a5b2011-05-26 07:48:0251#include "chrome/installer/setup/setup_util.h"
[email protected]d24c4012009-07-28 01:57:3152#include "chrome/installer/util/browser_distribution.h"
53#include "chrome/installer/util/create_reg_key_work_item.h"
[email protected]3f69d6e612012-08-03 18:52:2754#include "chrome/installer/util/install_util.h"
pmonette0c40087a2016-04-21 00:05:1655#include "chrome/installer/util/scoped_user_protocol_entry.h"
[email protected]d24c4012009-07-28 01:57:3156#include "chrome/installer/util/set_reg_value_work_item.h"
57#include "chrome/installer/util/shell_util.h"
58#include "chrome/installer/util/util_constants.h"
59#include "chrome/installer/util/work_item.h"
60#include "chrome/installer/util/work_item_list.h"
pmonette2b1dbee2016-01-08 20:18:5861#include "components/variations/variations_associated_data.h"
[email protected]c38831a12011-10-28 12:44:4962#include "content/public/browser/browser_thread.h"
pmonette5057ca3b2016-07-04 16:48:4063#include "content/public/browser/utility_process_mojo_client.h"
64#include "ui/base/l10n/l10n_util.h"
[email protected]d24c4012009-07-28 01:57:3165
[email protected]631bb742011-11-02 11:29:3966using content::BrowserThread;
67
pmonette9fa59e882016-02-10 00:12:1968namespace shell_integration {
69
[email protected]12f520c2010-01-06 18:11:1570namespace {
71
pmonette9fa59e882016-02-10 00:12:1972// Helper function for GetAppId to generates profile id
[email protected]2f1c09d2011-01-14 14:58:1473// from profile path. "profile_id" is composed of sanitized basenames of
[email protected]12f520c2010-01-06 18:11:1574// user data dir and profile dir joined by a ".".
[email protected]6a72a632013-12-12 22:22:0075base::string16 GetProfileIdFromPath(const base::FilePath& profile_path) {
[email protected]12f520c2010-01-06 18:11:1576 // Return empty string if profile_path is empty
77 if (profile_path.empty())
[email protected]0085863a2013-12-06 21:19:0378 return base::string16();
[email protected]12f520c2010-01-06 18:11:1579
[email protected]650b2d52013-02-10 03:41:4580 base::FilePath default_user_data_dir;
[email protected]12f520c2010-01-06 18:11:1581 // Return empty string if profile_path is in default user data
82 // dir and is the default profile.
83 if (chrome::GetDefaultUserDataDirectory(&default_user_data_dir) &&
84 profile_path.DirName() == default_user_data_dir &&
[email protected]162b5992011-03-15 19:40:4885 profile_path.BaseName().value() ==
[email protected]f911df52013-12-24 23:24:2386 base::ASCIIToUTF16(chrome::kInitialProfile)) {
[email protected]0085863a2013-12-06 21:19:0387 return base::string16();
[email protected]162b5992011-03-15 19:40:4888 }
[email protected]12f520c2010-01-06 18:11:1589
90 // Get joined basenames of user data dir and profile.
[email protected]0085863a2013-12-06 21:19:0391 base::string16 basenames = profile_path.DirName().BaseName().value() +
[email protected]12f520c2010-01-06 18:11:1592 L"." + profile_path.BaseName().value();
93
[email protected]0085863a2013-12-06 21:19:0394 base::string16 profile_id;
[email protected]12f520c2010-01-06 18:11:1595 profile_id.reserve(basenames.size());
96
97 // Generate profile_id from sanitized basenames.
98 for (size_t i = 0; i < basenames.length(); ++i) {
brettwb3413062015-06-24 00:39:0299 if (base::IsAsciiAlpha(basenames[i]) ||
100 base::IsAsciiDigit(basenames[i]) ||
[email protected]12f520c2010-01-06 18:11:15101 basenames[i] == L'.')
102 profile_id += basenames[i];
103 }
104
105 return profile_id;
106}
107
taptedc2c690ab2016-05-25 02:49:03108base::string16 GetAppListAppName() {
109 static const base::char16 kAppListAppNameSuffix[] = L"AppList";
grtc98803462017-03-08 10:05:08110 base::string16 app_name(install_static::GetBaseAppId());
taptedc2c690ab2016-05-25 02:49:03111 app_name.append(kAppListAppNameSuffix);
112 return app_name;
113}
114
[email protected]8ea8f1ef2013-01-06 18:39:03115// Gets expected app id for given Chrome (based on |command_line| and
116// |is_per_user_install|).
avi556c05022014-12-22 23:31:43117base::string16 GetExpectedAppId(const base::CommandLine& command_line,
[email protected]6a72a632013-12-12 22:22:00118 bool is_per_user_install) {
[email protected]b39e32e2013-04-24 08:55:54119 base::FilePath user_data_dir;
120 if (command_line.HasSwitch(switches::kUserDataDir))
121 user_data_dir = command_line.GetSwitchValuePath(switches::kUserDataDir);
122 else
123 chrome::GetDefaultUserDataDirectory(&user_data_dir);
[email protected]89d43832013-06-29 20:25:20124 // Adjust with any policy that overrides any other way to set the path.
125 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir);
[email protected]b39e32e2013-04-24 08:55:54126 DCHECK(!user_data_dir.empty());
[email protected]c9bb06f42010-01-13 23:53:48127
[email protected]b39e32e2013-04-24 08:55:54128 base::FilePath profile_subdir;
129 if (command_line.HasSwitch(switches::kProfileDirectory)) {
130 profile_subdir =
131 command_line.GetSwitchValuePath(switches::kProfileDirectory);
132 } else {
[email protected]f911df52013-12-24 23:24:23133 profile_subdir =
134 base::FilePath(base::ASCIIToUTF16(chrome::kInitialProfile));
[email protected]b39e32e2013-04-24 08:55:54135 }
136 DCHECK(!profile_subdir.empty());
137
138 base::FilePath profile_path = user_data_dir.Append(profile_subdir);
[email protected]0085863a2013-12-06 21:19:03139 base::string16 app_name;
[email protected]c9bb06f42010-01-13 23:53:48140 if (command_line.HasSwitch(switches::kApp)) {
[email protected]f911df52013-12-24 23:24:23141 app_name = base::UTF8ToUTF16(web_app::GenerateApplicationNameFromURL(
[email protected]57ecc4b2010-08-11 03:02:51142 GURL(command_line.GetSwitchValueASCII(switches::kApp))));
[email protected]2f1c09d2011-01-14 14:58:14143 } else if (command_line.HasSwitch(switches::kAppId)) {
[email protected]f911df52013-12-24 23:24:23144 app_name = base::UTF8ToUTF16(
145 web_app::GenerateApplicationNameFromExtensionId(
146 command_line.GetSwitchValueASCII(switches::kAppId)));
taptedc2c690ab2016-05-25 02:49:03147 } else if (command_line.HasSwitch(switches::kShowAppList)) {
148 app_name = GetAppListAppName();
[email protected]c9bb06f42010-01-13 23:53:48149 } else {
grtc98803462017-03-08 10:05:08150 app_name = ShellUtil::GetBrowserModelId(is_per_user_install);
[email protected]c9bb06f42010-01-13 23:53:48151 }
[email protected]b39e32e2013-04-24 08:55:54152 DCHECK(!app_name.empty());
[email protected]c9bb06f42010-01-13 23:53:48153
pmonette9e4c1a82016-04-14 18:15:30154 return win::GetAppModelIdForProfile(app_name, profile_path);
[email protected]c9bb06f42010-01-13 23:53:48155}
156
gab88257b62016-01-15 03:19:19157void MigrateTaskbarPinsCallback() {
[email protected]3a3e72c2011-11-29 02:59:38158 // This should run on the file thread.
thestig00844cea2015-09-08 21:44:52159 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
[email protected]3a3e72c2011-11-29 02:59:38160
161 // Get full path of chrome.
[email protected]650b2d52013-02-10 03:41:45162 base::FilePath chrome_exe;
[email protected]3a3e72c2011-11-29 02:59:38163 if (!PathService::Get(base::FILE_EXE, &chrome_exe))
164 return;
165
gab88257b62016-01-15 03:19:19166 base::FilePath pins_path;
167 if (!PathService::Get(base::DIR_TASKBAR_PINS, &pins_path)) {
168 NOTREACHED();
169 return;
[email protected]3a3e72c2011-11-29 02:59:38170 }
gab88257b62016-01-15 03:19:19171
pmonette9e4c1a82016-04-14 18:15:30172 win::MigrateShortcutsInPathInternal(chrome_exe, pins_path);
[email protected]3a3e72c2011-11-29 02:59:38173}
174
[email protected]caa05352014-03-01 00:43:05175// Windows 8 introduced a new protocol->executable binding system which cannot
176// be retrieved in the HKCR registry subkey method implemented below. We call
177// AssocQueryString with the new Win8-only flag ASSOCF_IS_PROTOCOL instead.
178base::string16 GetAppForProtocolUsingAssocQuery(const GURL& url) {
thestig11bf74d2014-11-24 20:14:42179 base::string16 url_scheme = base::ASCIIToUTF16(url.scheme());
[email protected]caa05352014-03-01 00:43:05180 // Don't attempt to query protocol association on an empty string.
[email protected]6e84d372014-05-29 23:36:39181 if (url_scheme.empty())
[email protected]caa05352014-03-01 00:43:05182 return base::string16();
183
[email protected]caa05352014-03-01 00:43:05184 // Query AssocQueryString for a human-readable description of the program
185 // that will be invoked given the provided URL spec. This is used only to
186 // populate the external protocol dialog box the user sees when invoking
187 // an unknown external protocol.
188 wchar_t out_buffer[1024];
189 DWORD buffer_size = arraysize(out_buffer);
190 HRESULT hr = AssocQueryString(ASSOCF_IS_PROTOCOL,
191 ASSOCSTR_FRIENDLYAPPNAME,
[email protected]6e84d372014-05-29 23:36:39192 url_scheme.c_str(),
[email protected]caa05352014-03-01 00:43:05193 NULL,
194 out_buffer,
195 &buffer_size);
196 if (FAILED(hr)) {
197 DLOG(WARNING) << "AssocQueryString failed!";
198 return base::string16();
199 }
200 return base::string16(out_buffer);
201}
202
203base::string16 GetAppForProtocolUsingRegistry(const GURL& url) {
dominickn0c9a5062016-10-06 20:49:00204 base::string16 command_to_launch;
205
206 // First, try and extract the application's display name.
207 base::string16 cmd_key_path = base::ASCIIToUTF16(url.scheme());
208 base::win::RegKey cmd_key_name(HKEY_CLASSES_ROOT, cmd_key_path.c_str(),
209 KEY_READ);
210 if (cmd_key_name.ReadValue(NULL, &command_to_launch) == ERROR_SUCCESS &&
211 !command_to_launch.empty()) {
212 return command_to_launch;
[email protected]caa05352014-03-01 00:43:05213 }
dominickn0c9a5062016-10-06 20:49:00214
215 // Otherwise, parse the command line in the registry, and return the basename
216 // of the program path if it exists.
217 cmd_key_path = base::ASCIIToUTF16(url.scheme() + "\\shell\\open\\command");
218 base::win::RegKey cmd_key_exe(HKEY_CLASSES_ROOT, cmd_key_path.c_str(),
219 KEY_READ);
220 if (cmd_key_exe.ReadValue(NULL, &command_to_launch) == ERROR_SUCCESS) {
221 base::CommandLine command_line(
222 base::CommandLine::FromString(command_to_launch));
223 return command_line.GetProgram().BaseName().value();
224 }
225
[email protected]caa05352014-03-01 00:43:05226 return base::string16();
227}
228
pmonette9fa59e882016-02-10 00:12:19229DefaultWebClientState GetDefaultWebClientStateFromShellUtilDefaultState(
230 ShellUtil::DefaultState default_state) {
[email protected]eb63da72012-10-15 20:39:48231 switch (default_state) {
232 case ShellUtil::NOT_DEFAULT:
pmonette9fa59e882016-02-10 00:12:19233 return DefaultWebClientState::NOT_DEFAULT;
[email protected]eb63da72012-10-15 20:39:48234 case ShellUtil::IS_DEFAULT:
pmonette9fa59e882016-02-10 00:12:19235 return DefaultWebClientState::IS_DEFAULT;
[email protected]eb63da72012-10-15 20:39:48236 default:
237 DCHECK_EQ(ShellUtil::UNKNOWN_DEFAULT, default_state);
pmonette9fa59e882016-02-10 00:12:19238 return DefaultWebClientState::UNKNOWN_DEFAULT;
[email protected]eb63da72012-10-15 20:39:48239 }
240}
241
grtc291eea2016-05-26 15:38:48242// A recorder of user actions in the Windows Settings app.
243class DefaultBrowserActionRecorder : public win::SettingsAppMonitor::Delegate {
244 public:
245 // Creates the recorder and the monitor that drives it. |continuation| will be
246 // run once the monitor's initialization completes (regardless of success or
247 // failure).
248 explicit DefaultBrowserActionRecorder(base::Closure continuation)
249 : continuation_(std::move(continuation)), settings_app_monitor_(this) {}
250
251 private:
252 // win::SettingsAppMonitor::Delegate:
253 void OnInitialized(HRESULT result) override {
254 UMA_HISTOGRAM_BOOLEAN("SettingsAppMonitor.InitializationResult",
255 SUCCEEDED(result));
256 if (SUCCEEDED(result)) {
257 base::RecordAction(
258 base::UserMetricsAction("SettingsAppMonitor.Initialized"));
259 }
260 continuation_.Run();
261 continuation_ = base::Closure();
262 }
263
264 void OnAppFocused() override {
265 base::RecordAction(
266 base::UserMetricsAction("SettingsAppMonitor.AppFocused"));
267 }
268
269 void OnChooserInvoked() override {
270 base::RecordAction(
271 base::UserMetricsAction("SettingsAppMonitor.ChooserInvoked"));
272 }
273
274 void OnBrowserChosen(const base::string16& browser_name) override {
275 if (browser_name ==
276 BrowserDistribution::GetDistribution()->GetDisplayName()) {
277 base::RecordAction(
278 base::UserMetricsAction("SettingsAppMonitor.ChromeBrowserChosen"));
279 } else {
280 base::RecordAction(
281 base::UserMetricsAction("SettingsAppMonitor.OtherBrowserChosen"));
282 }
283 }
284
pmonetteb66514b42016-12-07 20:28:39285 void OnPromoFocused() override {
286 base::RecordAction(
287 base::UserMetricsAction("SettingsAppMonitor.PromoFocused"));
288 }
289
290 void OnPromoChoiceMade(bool accept_promo) override {
291 if (accept_promo) {
292 base::RecordAction(
293 base::UserMetricsAction("SettingsAppMonitor.CheckItOut"));
294 } else {
295 base::RecordAction(
296 base::UserMetricsAction("SettingsAppMonitor.SwitchAnyway"));
297 }
298 }
299
grtc291eea2016-05-26 15:38:48300 // A closure to be run once initialization completes.
301 base::Closure continuation_;
302
303 // Monitors user interaction with the Windows Settings app for the sake of
304 // reporting user actions.
305 win::SettingsAppMonitor settings_app_monitor_;
306
307 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserActionRecorder);
308};
309
310// A function bound up in a callback with a DefaultBrowserActionRecorder and
311// a closure to keep the former alive until the time comes to run the latter.
312void OnSettingsAppFinished(
313 std::unique_ptr<DefaultBrowserActionRecorder> recorder,
314 const base::Closure& on_finished_callback) {
315 recorder.reset();
316 on_finished_callback.Run();
317}
318
pmonette32a5cfb42016-04-11 22:04:44319// There is no way to make sure the user is done with the system settings, but a
320// signal that the interaction is finished is needed for UMA. A timer of 2
321// minutes is used as a substitute. The registry keys for the protocol
322// association with an app are also monitored to signal the end of the
323// interaction early when it is clear that the user made a choice (e.g. http
324// and https for default browser).
325//
326// This helper class manages both the timer and the registry watchers and makes
327// sure the callback for the end of the settings interaction is only run once.
328// This class also manages its own lifetime.
329class OpenSystemSettingsHelper {
330 public:
331 // Begin the monitoring and will call |on_finished_callback| when done.
332 // Takes in a null-terminated array of |protocols| whose registry keys must be
pmonette0c40087a2016-04-21 00:05:16333 // watched. The array must contain at least one element.
pmonette32a5cfb42016-04-11 22:04:44334 static void Begin(const wchar_t* const protocols[],
335 const base::Closure& on_finished_callback) {
pmonettec541d942016-06-15 22:08:32336 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
337
338 delete instance_;
339 instance_ = new OpenSystemSettingsHelper(protocols, on_finished_callback);
pmonette32a5cfb42016-04-11 22:04:44340 }
341
342 private:
343 // The reason the settings interaction concluded. Do not modify the ordering
344 // because it is used for UMA.
345 enum ConcludeReason { REGISTRY_WATCHER, TIMEOUT, NUM_CONCLUDE_REASON_TYPES };
346
347 OpenSystemSettingsHelper(const wchar_t* const protocols[],
348 const base::Closure& on_finished_callback)
pmonette0c40087a2016-04-21 00:05:16349 : scoped_user_protocol_entry_(protocols[0]),
350 on_finished_callback_(on_finished_callback),
351 weak_ptr_factory_(this) {
pmonette32a5cfb42016-04-11 22:04:44352 static const wchar_t kUrlAssociationFormat[] =
353 L"SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\"
354 L"%ls\\UserChoice";
355
356 // Remember the start time.
357 start_time_ = base::TimeTicks::Now();
358
359 for (const wchar_t* const* scan = &protocols[0]; *scan != nullptr; ++scan) {
360 AddRegistryKeyWatcher(
361 base::StringPrintf(kUrlAssociationFormat, *scan).c_str());
362 }
363 // Only the watchers that were succesfully initialized are counted.
364 registry_watcher_count_ = registry_key_watchers_.size();
365
366 timer_.Start(
367 FROM_HERE, base::TimeDelta::FromMinutes(2),
368 base::Bind(&OpenSystemSettingsHelper::ConcludeInteraction,
369 weak_ptr_factory_.GetWeakPtr(), ConcludeReason::TIMEOUT));
370 }
371
372 // Called when a change is detected on one of the registry keys being watched.
373 // Note: All types of modification to the registry key will trigger this
374 // function even if the value change is the only one that matters. This
375 // is good enough for now.
376 void OnRegistryKeyChanged() {
377 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
378
379 // Make sure all the registry watchers have fired.
380 if (--registry_watcher_count_ == 0) {
381 UMA_HISTOGRAM_MEDIUM_TIMES(
382 "DefaultBrowser.SettingsInteraction.RegistryWatcherDuration",
383 base::TimeTicks::Now() - start_time_);
384
385 ConcludeInteraction(ConcludeReason::REGISTRY_WATCHER);
386 }
387 }
388
389 // Ends the monitoring with the system settings. Will call
390 // |on_finished_callback_| and then dispose of this class instance to make
391 // sure the callback won't get called subsequently.
392 void ConcludeInteraction(ConcludeReason conclude_reason) {
393 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
394
395 UMA_HISTOGRAM_ENUMERATION(
396 "DefaultBrowser.SettingsInteraction.ConcludeReason", conclude_reason,
397 NUM_CONCLUDE_REASON_TYPES);
398 on_finished_callback_.Run();
pmonettec541d942016-06-15 22:08:32399 delete instance_;
400 instance_ = nullptr;
pmonette32a5cfb42016-04-11 22:04:44401 }
402
403 // Helper function to create a registry watcher for a given |key_path|. Do
404 // nothing on initialization failure.
405 void AddRegistryKeyWatcher(const wchar_t* key_path) {
ricea86fa1dd2016-09-13 05:59:45406 auto reg_key = base::MakeUnique<base::win::RegKey>(HKEY_CURRENT_USER,
407 key_path, KEY_NOTIFY);
pmonette32a5cfb42016-04-11 22:04:44408
409 if (reg_key->Valid() &&
410 reg_key->StartWatching(
411 base::Bind(&OpenSystemSettingsHelper::OnRegistryKeyChanged,
412 weak_ptr_factory_.GetWeakPtr()))) {
413 registry_key_watchers_.push_back(std::move(reg_key));
414 }
415 }
416
pmonettec541d942016-06-15 22:08:32417 // Used to make sure only one instance is alive at the same time.
418 static OpenSystemSettingsHelper* instance_;
419
pmonette0c40087a2016-04-21 00:05:16420 // This is needed to make sure that Windows displays an entry for the protocol
421 // inside the "Choose default apps by protocol" settings page.
422 ScopedUserProtocolEntry scoped_user_protocol_entry_;
423
pmonette32a5cfb42016-04-11 22:04:44424 // The function to call when the interaction with the system settings is
425 // finished.
426 base::Closure on_finished_callback_;
427
428 // The number of time the registry key watchers must fire.
429 int registry_watcher_count_ = 0;
430
431 // There can be multiple registry key watchers as some settings modify
432 // multiple protocol associations. e.g. Changing the default browser modifies
433 // the http and https associations.
dcheng4af48582016-04-19 00:29:35434 std::vector<std::unique_ptr<base::win::RegKey>> registry_key_watchers_;
pmonette32a5cfb42016-04-11 22:04:44435
436 base::OneShotTimer timer_;
437
438 // Records the time it takes for the final registry watcher to get signaled.
439 base::TimeTicks start_time_;
440
441 // Weak ptrs are used to bind this class to the callbacks of the timer and the
442 // registry watcher. This makes it possible to self-delete after one of the
443 // callbacks is executed to cancel the remaining ones.
444 base::WeakPtrFactory<OpenSystemSettingsHelper> weak_ptr_factory_;
445
446 DISALLOW_COPY_AND_ASSIGN(OpenSystemSettingsHelper);
447};
448
pmonettec541d942016-06-15 22:08:32449OpenSystemSettingsHelper* OpenSystemSettingsHelper::instance_ = nullptr;
450
pmonettea98315242016-11-23 21:39:18451// Helper class to determine if Chrome is pinned to the taskbar. Hides the
452// complexity of managing the lifetime of a UtilityProcessMojoClient.
453class IsPinnedToTaskbarHelper {
454 public:
455 using ResultCallback = win::IsPinnedToTaskbarCallback;
456 using ErrorCallback = win::ConnectionErrorCallback;
457 static void GetState(const ErrorCallback& error_callback,
458 const ResultCallback& result_callback);
459
460 private:
461 IsPinnedToTaskbarHelper(const ErrorCallback& error_callback,
462 const ResultCallback& result_callback);
463
464 void OnConnectionError();
465 void OnIsPinnedToTaskbarResult(bool succeeded, bool is_pinned_to_taskbar);
466
467 content::UtilityProcessMojoClient<chrome::mojom::ShellHandler> shell_handler_;
468
469 ErrorCallback error_callback_;
470 ResultCallback result_callback_;
471
472 DISALLOW_COPY_AND_ASSIGN(IsPinnedToTaskbarHelper);
473};
474
475// static
476void IsPinnedToTaskbarHelper::GetState(const ErrorCallback& error_callback,
477 const ResultCallback& result_callback) {
478 // Self-deleting when the ShellHandler completes.
479 new IsPinnedToTaskbarHelper(error_callback, result_callback);
pmonette5057ca3b2016-07-04 16:48:40480}
481
pmonettea98315242016-11-23 21:39:18482IsPinnedToTaskbarHelper::IsPinnedToTaskbarHelper(
483 const ErrorCallback& error_callback,
484 const ResultCallback& result_callback)
485 : shell_handler_(
486 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_SHELL_HANDLER_NAME)),
487 error_callback_(error_callback),
488 result_callback_(result_callback) {
pmonette83edc1e2016-12-15 17:36:44489 DCHECK(error_callback_);
490 DCHECK(result_callback_);
491
pmonettea98315242016-11-23 21:39:18492 // |shell_handler_| owns the callbacks and is guaranteed to be destroyed
493 // before |this|, therefore making base::Unretained() safe to use.
494 shell_handler_.set_error_callback(base::Bind(
495 &IsPinnedToTaskbarHelper::OnConnectionError, base::Unretained(this)));
496 shell_handler_.set_disable_sandbox();
497 shell_handler_.Start();
498
499 shell_handler_.service()->IsPinnedToTaskbar(
500 base::Bind(&IsPinnedToTaskbarHelper::OnIsPinnedToTaskbarResult,
501 base::Unretained(this)));
502}
503
504void IsPinnedToTaskbarHelper::OnConnectionError() {
505 error_callback_.Run();
506 delete this;
507}
508
509void IsPinnedToTaskbarHelper::OnIsPinnedToTaskbarResult(
pmonette5057ca3b2016-07-04 16:48:40510 bool succeeded,
511 bool is_pinned_to_taskbar) {
pmonettea98315242016-11-23 21:39:18512 result_callback_.Run(succeeded, is_pinned_to_taskbar);
513 delete this;
pmonette5057ca3b2016-07-04 16:48:40514}
515
[email protected]3a3e72c2011-11-29 02:59:38516} // namespace
[email protected]12f520c2010-01-06 18:11:15517
pmonette9fa59e882016-02-10 00:12:19518bool SetAsDefaultBrowser() {
[email protected]650b2d52013-02-10 03:41:45519 base::FilePath chrome_exe;
[email protected]d24c4012009-07-28 01:57:31520 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
521 LOG(ERROR) << "Error getting app exe path";
522 return false;
523 }
524
525 // From UI currently we only allow setting default browser for current user.
[email protected]bf6117c7e2010-12-01 06:00:25526 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
grte76ca2852014-12-05 16:42:10527 if (!ShellUtil::MakeChromeDefault(dist, ShellUtil::CURRENT_USER, chrome_exe,
528 true /* elevate_if_not_admin */)) {
[email protected]d24c4012009-07-28 01:57:31529 LOG(ERROR) << "Chrome could not be set as default browser.";
530 return false;
531 }
532
[email protected]8e96e502010-10-21 20:57:12533 VLOG(1) << "Chrome registered as default browser.";
[email protected]d24c4012009-07-28 01:57:31534 return true;
535}
536
pmonette9fa59e882016-02-10 00:12:19537bool SetAsDefaultProtocolClient(const std::string& protocol) {
[email protected]4468a5b2011-05-26 07:48:02538 if (protocol.empty())
539 return false;
540
[email protected]650b2d52013-02-10 03:41:45541 base::FilePath chrome_exe;
[email protected]4468a5b2011-05-26 07:48:02542 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
543 LOG(ERROR) << "Error getting app exe path";
544 return false;
545 }
546
[email protected]f911df52013-12-24 23:24:23547 base::string16 wprotocol(base::UTF8ToUTF16(protocol));
[email protected]4468a5b2011-05-26 07:48:02548 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
grte76ca2852014-12-05 16:42:10549 if (!ShellUtil::MakeChromeDefaultProtocolClient(dist, chrome_exe,
550 wprotocol)) {
[email protected]4468a5b2011-05-26 07:48:02551 LOG(ERROR) << "Chrome could not be set as default handler for "
552 << protocol << ".";
553 return false;
554 }
555
556 VLOG(1) << "Chrome registered as default handler for " << protocol << ".";
557 return true;
558}
559
pmonette32a5cfb42016-04-11 22:04:44560DefaultWebClientSetPermission GetDefaultWebClientSetPermission() {
pmonette034a03d92015-10-02 21:04:27561 BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
562 if (distribution->GetDefaultBrowserControlPolicy() !=
563 BrowserDistribution::DEFAULT_BROWSER_FULL_CONTROL)
564 return SET_DEFAULT_NOT_ALLOWED;
pmonette034a03d92015-10-02 21:04:27565 if (ShellUtil::CanMakeChromeDefaultUnattended())
566 return SET_DEFAULT_UNATTENDED;
pmonette32a5cfb42016-04-11 22:04:44567 // Windows 8 and 10 both introduced a new way to set the default web client
568 // which require user interaction.
pmonettef89ac7c72015-10-06 03:22:01569 return SET_DEFAULT_INTERACTIVE;
pmonette034a03d92015-10-02 21:04:27570}
571
pmonette9fa59e882016-02-10 00:12:19572bool IsElevationNeededForSettingDefaultProtocolClient() {
pmonette868ca642015-09-02 14:34:02573 return base::win::GetVersion() < base::win::VERSION_WIN8;
574}
575
pmonette9fa59e882016-02-10 00:12:19576base::string16 GetApplicationNameForProtocol(const GURL& url) {
benwellsd0c67aa2016-07-28 02:57:20577 base::string16 application_name;
578 // Windows 8 or above has a new protocol association query.
579 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
580 application_name = GetAppForProtocolUsingAssocQuery(url);
581 if (!application_name.empty())
582 return application_name;
583 }
584
585 return GetAppForProtocolUsingRegistry(url);
[email protected]42dc9402013-01-30 07:54:20586}
587
pmonette9fa59e882016-02-10 00:12:19588DefaultWebClientState GetDefaultBrowser() {
pmonette034a03d92015-10-02 21:04:27589 return GetDefaultWebClientStateFromShellUtilDefaultState(
590 ShellUtil::GetChromeDefaultState());
591}
592
[email protected]d24c4012009-07-28 01:57:31593// There is no reliable way to say which browser is default on a machine (each
594// browser can have some of the protocols/shortcuts). So we look for only HTTP
595// protocol handler. Even this handler is located at different places in
596// registry on XP and Vista:
597// - HKCR\http\shell\open\command (XP)
598// - HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\
599// http\UserChoice (Vista)
thakise4a02ff32016-09-20 17:00:42600// This method checks if Firefox is default browser by checking these
[email protected]d24c4012009-07-28 01:57:31601// locations and returns true if Firefox traces are found there. In case of
602// error (or if Firefox is not found)it returns the default value which
603// is false.
pmonette9fa59e882016-02-10 00:12:19604bool IsFirefoxDefaultBrowser() {
[email protected]d24c4012009-07-28 01:57:31605 bool ff_default = false;
[email protected]935aa542010-10-15 01:59:15606 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
[email protected]0085863a2013-12-06 21:19:03607 base::string16 app_cmd;
[email protected]2d6503982010-10-17 04:41:54608 base::win::RegKey key(HKEY_CURRENT_USER,
609 ShellUtil::kRegVistaUrlPrefs, KEY_READ);
[email protected]e06f4d52011-01-19 07:28:46610 if (key.Valid() && (key.ReadValue(L"Progid", &app_cmd) == ERROR_SUCCESS) &&
[email protected]d24c4012009-07-28 01:57:31611 app_cmd == L"FirefoxURL")
612 ff_default = true;
613 } else {
[email protected]0085863a2013-12-06 21:19:03614 base::string16 key_path(L"http");
[email protected]d24c4012009-07-28 01:57:31615 key_path.append(ShellUtil::kRegShellOpen);
[email protected]2d6503982010-10-17 04:41:54616 base::win::RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ);
[email protected]0085863a2013-12-06 21:19:03617 base::string16 app_cmd;
[email protected]e06f4d52011-01-19 07:28:46618 if (key.Valid() && (key.ReadValue(L"", &app_cmd) == ERROR_SUCCESS) &&
[email protected]cb1f4ac2014-08-07 16:55:42619 base::string16::npos !=
brettwfce8d192015-08-10 19:07:51620 base::ToLowerASCII(app_cmd).find(L"firefox"))
[email protected]d24c4012009-07-28 01:57:31621 ff_default = true;
622 }
623 return ff_default;
624}
[email protected]12f520c2010-01-06 18:11:15625
pmonette9fa59e882016-02-10 00:12:19626DefaultWebClientState IsDefaultProtocolClient(const std::string& protocol) {
pmonette034a03d92015-10-02 21:04:27627 return GetDefaultWebClientStateFromShellUtilDefaultState(
628 ShellUtil::GetChromeDefaultProtocolClientState(
629 base::UTF8ToUTF16(protocol)));
630}
631
pmonette9e4c1a82016-04-14 18:15:30632namespace win {
633
634bool SetAsDefaultBrowserUsingIntentPicker() {
635 base::FilePath chrome_exe;
636 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
637 NOTREACHED() << "Error getting app exe path";
638 return false;
639 }
640
641 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
642 if (!ShellUtil::ShowMakeChromeDefaultSystemUI(dist, chrome_exe)) {
643 LOG(ERROR) << "Failed to launch the set-default-browser Windows UI.";
644 return false;
645 }
646
647 VLOG(1) << "Set-default-browser Windows UI completed.";
648 return true;
649}
650
651void SetAsDefaultBrowserUsingSystemSettings(
652 const base::Closure& on_finished_callback) {
653 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
654
655 base::FilePath chrome_exe;
656 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
657 NOTREACHED() << "Error getting app exe path";
658 on_finished_callback.Run();
659 return;
660 }
661
grtc291eea2016-05-26 15:38:48662 // Create an action recorder that will open the settings app once it has
663 // initialized.
664 std::unique_ptr<DefaultBrowserActionRecorder> recorder(
665 new DefaultBrowserActionRecorder(base::Bind(
666 base::IgnoreResult(&ShellUtil::ShowMakeChromeDefaultSystemUI),
667 base::Unretained(BrowserDistribution::GetDistribution()),
668 chrome_exe)));
pmonette9e4c1a82016-04-14 18:15:30669
grtc291eea2016-05-26 15:38:48670 // The helper manages its own lifetime. Bind the action recorder
671 // into the finished callback to keep it alive throughout the
672 // interaction.
673 static const wchar_t* const kProtocols[] = {L"http", L"https", nullptr};
674 OpenSystemSettingsHelper::Begin(
675 kProtocols, base::Bind(&OnSettingsAppFinished, base::Passed(&recorder),
676 on_finished_callback));
pmonette9e4c1a82016-04-14 18:15:30677}
678
679bool SetAsDefaultProtocolClientUsingIntentPicker(const std::string& protocol) {
680 base::FilePath chrome_exe;
681 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
682 NOTREACHED() << "Error getting app exe path";
683 return false;
684 }
685
686 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
687 base::string16 wprotocol(base::UTF8ToUTF16(protocol));
688 if (!ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe,
689 wprotocol)) {
690 LOG(ERROR) << "Failed to launch the set-default-client Windows UI.";
691 return false;
692 }
693
694 VLOG(1) << "Set-default-client Windows UI completed.";
695 return true;
696}
697
pmonette0c40087a2016-04-21 00:05:16698void SetAsDefaultProtocolClientUsingSystemSettings(
699 const std::string& protocol,
700 const base::Closure& on_finished_callback) {
701 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
702
703 base::FilePath chrome_exe;
704 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
705 NOTREACHED() << "Error getting app exe path";
706 on_finished_callback.Run();
707 return;
708 }
709
710 // The helper manages its own lifetime.
711 base::string16 wprotocol(base::UTF8ToUTF16(protocol));
712 const wchar_t* const kProtocols[] = {wprotocol.c_str(), nullptr};
713 OpenSystemSettingsHelper::Begin(kProtocols, on_finished_callback);
714
715 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
716 ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe,
717 wprotocol);
718}
719
pmonette9fa59e882016-02-10 00:12:19720base::string16 GetAppModelIdForProfile(const base::string16& app_name,
721 const base::FilePath& profile_path) {
[email protected]d2065e062013-12-12 23:49:52722 std::vector<base::string16> components;
[email protected]a0448002012-06-19 04:32:10723 components.push_back(app_name);
[email protected]0085863a2013-12-06 21:19:03724 const base::string16 profile_id(GetProfileIdFromPath(profile_path));
[email protected]a0448002012-06-19 04:32:10725 if (!profile_id.empty())
726 components.push_back(profile_id);
727 return ShellUtil::BuildAppModelId(components);
[email protected]12f520c2010-01-06 18:11:15728}
729
pmonette9fa59e882016-02-10 00:12:19730base::string16 GetChromiumModelIdForProfile(
[email protected]650b2d52013-02-10 03:41:45731 const base::FilePath& profile_path) {
[email protected]a0448002012-06-19 04:32:10732 return GetAppModelIdForProfile(
grtc98803462017-03-08 10:05:08733 ShellUtil::GetBrowserModelId(InstallUtil::IsPerUserInstall()),
[email protected]786799692012-09-26 14:16:48734 profile_path);
[email protected]12f520c2010-01-06 18:11:15735}
[email protected]c9bb06f42010-01-13 23:53:48736
pmonette9fa59e882016-02-10 00:12:19737void MigrateTaskbarPins() {
[email protected]935aa542010-10-15 01:59:15738 if (base::win::GetVersion() < base::win::VERSION_WIN7)
[email protected]c9bb06f42010-01-13 23:53:48739 return;
740
[email protected]81fcf952012-11-26 22:25:14741 // This needs to happen eventually (e.g. so that the appid is fixed and the
742 // run-time Chrome icon is merged with the taskbar shortcut), but this is not
743 // urgent and shouldn't delay Chrome startup.
gab88257b62016-01-15 03:19:19744 static const int64_t kMigrateTaskbarPinsDelaySeconds = 15;
[email protected]81fcf952012-11-26 22:25:14745 BrowserThread::PostDelayedTask(
[email protected]3a3e72c2011-11-29 02:59:38746 BrowserThread::FILE, FROM_HERE,
gab88257b62016-01-15 03:19:19747 base::Bind(&MigrateTaskbarPinsCallback),
748 base::TimeDelta::FromSeconds(kMigrateTaskbarPinsDelaySeconds));
[email protected]c9bb06f42010-01-13 23:53:48749}
[email protected]43903b82012-06-01 05:26:23750
pmonettea98315242016-11-23 21:39:18751void GetIsPinnedToTaskbarState(
752 const ConnectionErrorCallback& on_error_callback,
753 const IsPinnedToTaskbarCallback& result_callback) {
754 IsPinnedToTaskbarHelper::GetState(on_error_callback, result_callback);
pmonette5057ca3b2016-07-04 16:48:40755}
756
pmonette9fa59e882016-02-10 00:12:19757int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe,
758 const base::FilePath& path) {
[email protected]8ea8f1ef2013-01-06 18:39:03759 DCHECK(base::win::GetVersion() >= base::win::VERSION_WIN7);
760
761 // Enumerate all pinned shortcuts in the given path directly.
[email protected]25a4c1c2013-06-08 04:53:36762 base::FileEnumerator shortcuts_enum(
[email protected]8ea8f1ef2013-01-06 18:39:03763 path, false, // not recursive
[email protected]25a4c1c2013-06-08 04:53:36764 base::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk"));
[email protected]8ea8f1ef2013-01-06 18:39:03765
grt973412f2017-02-25 08:04:21766 bool is_per_user_install = InstallUtil::IsPerUserInstall();
[email protected]8ea8f1ef2013-01-06 18:39:03767
768 int shortcuts_migrated = 0;
[email protected]650b2d52013-02-10 03:41:45769 base::FilePath target_path;
[email protected]0085863a2013-12-06 21:19:03770 base::string16 arguments;
[email protected]07983302013-01-21 19:41:44771 base::win::ScopedPropVariant propvariant;
[email protected]650b2d52013-02-10 03:41:45772 for (base::FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty();
[email protected]8ea8f1ef2013-01-06 18:39:03773 shortcut = shortcuts_enum.Next()) {
774 // TODO(gab): Use ProgramCompare instead of comparing FilePaths below once
775 // it is fixed to work with FilePaths with spaces.
776 if (!base::win::ResolveShortcut(shortcut, &target_path, &arguments) ||
777 chrome_exe != target_path) {
778 continue;
779 }
avi556c05022014-12-22 23:31:43780 base::CommandLine command_line(
781 base::CommandLine::FromString(base::StringPrintf(
782 L"\"%ls\" %ls", target_path.value().c_str(), arguments.c_str())));
[email protected]8ea8f1ef2013-01-06 18:39:03783
784 // Get the expected AppId for this Chrome shortcut.
[email protected]0085863a2013-12-06 21:19:03785 base::string16 expected_app_id(
[email protected]8ea8f1ef2013-01-06 18:39:03786 GetExpectedAppId(command_line, is_per_user_install));
787 if (expected_app_id.empty())
788 continue;
789
790 // Load the shortcut.
791 base::win::ScopedComPtr<IShellLink> shell_link;
792 base::win::ScopedComPtr<IPersistFile> persist_file;
793 if (FAILED(shell_link.CreateInstance(CLSID_ShellLink, NULL,
794 CLSCTX_INPROC_SERVER)) ||
dcheng81762e02014-11-21 21:22:28795 FAILED(persist_file.QueryFrom(shell_link.get())) ||
[email protected]8ea8f1ef2013-01-06 18:39:03796 FAILED(persist_file->Load(shortcut.value().c_str(), STGM_READ))) {
797 DLOG(WARNING) << "Failed loading shortcut at " << shortcut.value();
798 continue;
799 }
800
801 // Any properties that need to be updated on the shortcut will be stored in
802 // |updated_properties|.
803 base::win::ShortcutProperties updated_properties;
804
805 // Validate the existing app id for the shortcut.
806 base::win::ScopedComPtr<IPropertyStore> property_store;
[email protected]07983302013-01-21 19:41:44807 propvariant.Reset();
dcheng81762e02014-11-21 21:22:28808 if (FAILED(property_store.QueryFrom(shell_link.get())) ||
809 property_store->GetValue(PKEY_AppUserModel_ID, propvariant.Receive()) !=
810 S_OK) {
[email protected]8ea8f1ef2013-01-06 18:39:03811 // When in doubt, prefer not updating the shortcut.
812 NOTREACHED();
813 continue;
[email protected]8ea8f1ef2013-01-06 18:39:03814 } else {
[email protected]07983302013-01-21 19:41:44815 switch (propvariant.get().vt) {
816 case VT_EMPTY:
817 // If there is no app_id set, set our app_id if one is expected.
818 if (!expected_app_id.empty())
819 updated_properties.set_app_id(expected_app_id);
820 break;
821 case VT_LPWSTR:
[email protected]0085863a2013-12-06 21:19:03822 if (expected_app_id != base::string16(propvariant.get().pwszVal))
[email protected]07983302013-01-21 19:41:44823 updated_properties.set_app_id(expected_app_id);
824 break;
825 default:
826 NOTREACHED();
827 continue;
[email protected]8ea8f1ef2013-01-06 18:39:03828 }
829 }
830
gab88257b62016-01-15 03:19:19831 // Clear dual_mode property from any shortcuts that previously had it (it
832 // was only ever installed on shortcuts with the
833 // |default_chromium_model_id|).
[email protected]0085863a2013-12-06 21:19:03834 base::string16 default_chromium_model_id(
grtc98803462017-03-08 10:05:08835 ShellUtil::GetBrowserModelId(is_per_user_install));
gab88257b62016-01-15 03:19:19836 if (expected_app_id == default_chromium_model_id) {
[email protected]07983302013-01-21 19:41:44837 propvariant.Reset();
[email protected]8ea8f1ef2013-01-06 18:39:03838 if (property_store->GetValue(PKEY_AppUserModel_IsDualMode,
[email protected]07983302013-01-21 19:41:44839 propvariant.Receive()) != S_OK) {
[email protected]8ea8f1ef2013-01-06 18:39:03840 // When in doubt, prefer to not update the shortcut.
841 NOTREACHED();
842 continue;
gab38d242d4d2016-01-14 20:38:12843 }
844 if (propvariant.get().vt == VT_BOOL &&
845 !!propvariant.get().boolVal) {
846 updated_properties.set_dual_mode(false);
[email protected]8ea8f1ef2013-01-06 18:39:03847 }
848 }
849
850 persist_file.Release();
851 shell_link.Release();
852
853 // Update the shortcut if some of its properties need to be updated.
854 if (updated_properties.options &&
855 base::win::CreateOrUpdateShortcutLink(
856 shortcut, updated_properties,
857 base::win::SHORTCUT_UPDATE_EXISTING)) {
858 ++shortcuts_migrated;
859 }
860 }
861 return shortcuts_migrated;
862}
863
pmonette32a5cfb42016-04-11 22:04:44864} // namespace win
865
pmonette9fa59e882016-02-10 00:12:19866} // namespace shell_integration