Chromium Code Reviews| Index: chrome/installer/setup/update_per_user_shortcuts_in_location.cc |
| diff --git a/chrome/installer/setup/update_per_user_shortcuts_in_location.cc b/chrome/installer/setup/update_per_user_shortcuts_in_location.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ba3f737e1712ec7254b69af9de4c911313d382ce |
| --- /dev/null |
| +++ b/chrome/installer/setup/update_per_user_shortcuts_in_location.cc |
| @@ -0,0 +1,61 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/installer/setup/update_per_user_shortcuts_in_location.h" |
| + |
| +#include "base/command_line.h" |
|
gab
2016/03/10 06:01:03
Not required?
fdoray
2016/03/10 14:32:46
Done.
|
| +#include "base/files/file_enumerator.h" |
| +#include "base/files/file_path.h" |
| +#include "base/logging.h" |
| +#include "base/strings/string16.h" |
| +#include "base/strings/string_util.h" |
| +#include "base/win/shortcut.h" |
| +#include "chrome/common/chrome_switches.h" |
|
gab
2016/03/10 06:01:03
Which switch is used? I don't see anything requiri
fdoray
2016/03/10 14:32:46
Done.
|
| + |
| +namespace installer { |
| + |
| +void UpdatePerUserShortcutsInLocation( |
| + const ShellUtil::ShortcutLocation shortcut_location, |
| + BrowserDistribution* dist, |
| + const base::FilePath& old_target_path_prefix, |
| + const base::FilePath& old_target_path_suffix, |
| + const base::FilePath& new_target_path) { |
| + base::FilePath shortcut_path; |
| + const bool get_shortcut_path_return = ShellUtil::GetShortcutPath( |
| + shortcut_location, dist, ShellUtil::CURRENT_USER, &shortcut_path); |
| + DCHECK(get_shortcut_path_return); |
| + |
| + bool recursive = false; |
| + |
| + // TODO(fdoray): Modify GetShortcutPath such that it returns |
| + // ...\Quick Launch\User Pinned instead of |
| + // ...\Quick Launch\User Pinned\TaskBar for SHORTCUT_LOCATION_TASKBAR_PINS. |
| + if (shortcut_location == ShellUtil::SHORTCUT_LOCATION_TASKBAR_PINS) { |
| + shortcut_path = shortcut_path.DirName(); |
| + recursive = true; |
| + } |
| + |
| + base::FileEnumerator shortcuts_enum(shortcut_path, recursive, |
| + base::FileEnumerator::FILES); |
| + for (base::FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty(); |
| + shortcut = shortcuts_enum.Next()) { |
| + base::FilePath existing_target_path; |
| + if (!base::win::ResolveShortcut(shortcut, &existing_target_path, nullptr) || |
| + !base::StartsWith(existing_target_path.value(), |
| + old_target_path_prefix.value(), |
| + base::CompareCase::INSENSITIVE_ASCII) || |
| + !base::EndsWith(existing_target_path.value(), |
| + old_target_path_suffix.value(), |
| + base::CompareCase::INSENSITIVE_ASCII)) { |
| + continue; |
| + } |
| + |
| + base::win::ShortcutProperties updated_properties; |
| + updated_properties.set_target(new_target_path); |
| + base::win::CreateOrUpdateShortcutLink(shortcut, updated_properties, |
| + base::win::SHORTCUT_UPDATE_EXISTING); |
| + } |
| +} |
| + |
| +} // namespace installer |