Index: chrome/installer/util/shell_util.cc |
diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc |
index 273c7f0324170eda2e0fbd7b474fd1c4ac6dc724..e88498ad9da281ccaf5862b94d9c83b22243f817 100644 |
--- a/chrome/installer/util/shell_util.cc |
+++ b/chrome/installer/util/shell_util.cc |
@@ -1207,21 +1207,23 @@ bool ShortcutOpDelete(const base::FilePath& shortcut_path) { |
bool ShortcutOpUpdate(const base::win::ShortcutProperties& shortcut_properties, |
const base::FilePath& shortcut_path) { |
bool ret = base::win::CreateOrUpdateShortcutLink( |
- shortcut_path, shortcut_properties, base::win::SHORTCUT_REPLACE_EXISTING); |
+ shortcut_path, shortcut_properties, base::win::SHORTCUT_UPDATE_EXISTING); |
LOG_IF(ERROR, !ret) << "Failed to update " << shortcut_path.value(); |
return ret; |
} |
// {|location|, |dist|, |level|} determine |shortcut_folder|. |
-// Applies |shortcut_operation| to each shortcut in |shortcut_folder| that |
-// targets |target_exe|. |
+// Applies |shortcut_operation| to shortcuts in |shortcut_folder| that |
+// targets |target_exe|, and have filenames matching |filename_filter|. |
// Returns true if all operations are successful. All intended operations are |
// attempted even if failures occur. |
-bool BatchShortcutAction(const FileOperationCallback& shortcut_operation, |
- ShellUtil::ShortcutLocation location, |
- BrowserDistribution* dist, |
- ShellUtil::ShellChange level, |
- const base::FilePath& target_exe) { |
+bool BatchShortcutActionFilteredByName( |
+ const FileOperationCallback& shortcut_operation, |
+ ShellUtil::ShortcutLocation location, |
+ BrowserDistribution* dist, |
+ ShellUtil::ShellChange level, |
+ const base::FilePath& target_exe, |
+ const string16& filename_filter) { |
DCHECK(!shortcut_operation.is_null()); |
base::FilePath shortcut_folder; |
if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { |
@@ -1233,24 +1235,35 @@ bool BatchShortcutAction(const FileOperationCallback& shortcut_operation, |
InstallUtil::ProgramCompare target_compare(target_exe); |
file_util::FileEnumerator enumerator( |
shortcut_folder, false, file_util::FileEnumerator::FILES, |
- string16(L"*") + installer::kLnkExt); |
- base::FilePath target_path; |
- for (base::FilePath shortcut_path = enumerator.Next(); |
- !shortcut_path.empty(); |
- shortcut_path = enumerator.Next()) { |
- if (base::win::ResolveShortcut(shortcut_path, &target_path, NULL)) { |
- if (target_compare.EvaluatePath(target_path) && |
- !shortcut_operation.Run(shortcut_path)) { |
+ filename_filter); |
+ base::FilePath original_target_exe; |
+ for (base::FilePath shortcut_file = enumerator.Next(); |
+ !shortcut_file.empty(); |
+ shortcut_file = enumerator.Next()) { |
+ if (base::win::ResolveShortcut(shortcut_file, &original_target_exe, NULL)) { |
+ if (target_compare.EvaluatePath(original_target_exe) && |
+ !shortcut_operation.Run(shortcut_file)) { |
success = false; |
} |
} else { |
- LOG(ERROR) << "Cannot resolve shortcut at " << shortcut_path.value(); |
+ LOG(ERROR) << "Cannot resolve shortcut at " << shortcut_file.value(); |
success = false; |
} |
} |
return success; |
} |
+// Adaptor to FilteredBatchShortcutAction(), to process all files. |
gab
2013/05/15 22:42:20
Remove comma.
huangs
2013/05/17 20:59:24
Done.
|
+bool BatchShortcutAction(const FileOperationCallback& shortcut_operation, |
+ ShellUtil::ShortcutLocation location, |
+ BrowserDistribution* dist, |
+ ShellUtil::ShellChange level, |
+ const base::FilePath& target_exe) { |
+ return BatchShortcutActionFilteredByName( |
+ shortcut_operation, location, dist, level, target_exe, |
+ string16(L"*") + installer::kLnkExt); |
+} |
+ |
// Removes folder spsecified by {|location|, |dist|, |level|}. |
bool RemoveShortcutFolder(ShellUtil::ShortcutLocation location, |
BrowserDistribution* dist, |
@@ -1348,6 +1361,8 @@ bool ShellUtil::ShortcutLocationIsSupported( |
return true; |
case SHORTCUT_LOCATION_START_MENU: |
return true; |
+ case SHORTCUT_LOCATION_START_MENU_ROOT: |
+ return true; |
case SHORTCUT_LOCATION_TASKBAR_PINS: |
return base::win::GetVersion() >= base::win::VERSION_WIN7; |
case SHORTCUT_LOCATION_APP_SHORTCUTS: |
@@ -1379,6 +1394,10 @@ bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location, |
base::DIR_COMMON_START_MENU; |
add_folder_for_dist = true; |
break; |
+ case SHORTCUT_LOCATION_START_MENU_ROOT: |
gab
2013/05/15 22:42:20
Coordinate with https://codereview.chromium.org/13
huangs
2013/05/17 20:59:24
Deleted for now.
|
+ dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
+ base::DIR_COMMON_START_MENU; |
+ break; |
case SHORTCUT_LOCATION_TASKBAR_PINS: |
dir_key = base::DIR_TASKBAR_PINS; |
break; |
@@ -1397,7 +1416,7 @@ bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location, |
} |
if (add_folder_for_dist) |
- *path = path->Append(dist->GetAppShortCutName()); |
+ *path = path->Append(dist->GetAppShortCutFolderName()); |
return true; |
} |
@@ -1410,7 +1429,8 @@ bool ShellUtil::CreateOrUpdateShortcut( |
// Explicitly whitelist locations to which this is applicable. |
if (location != SHORTCUT_LOCATION_DESKTOP && |
location != SHORTCUT_LOCATION_QUICK_LAUNCH && |
- location != SHORTCUT_LOCATION_START_MENU) { |
+ location != SHORTCUT_LOCATION_START_MENU && |
+ location != SHORTCUT_LOCATION_START_MENU_ROOT) { |
NOTREACHED(); |
return false; |
} |
@@ -1998,6 +2018,7 @@ bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location, |
return BatchShortcutAction(base::Bind(&ShortcutOpUnpin), location, dist, |
level, target_exe); |
+ case SHORTCUT_LOCATION_START_MENU_ROOT: // For emphasis; falls through. |
gab
2013/05/15 22:42:20
See https://codereview.chromium.org/13864015/ (I t
huangs
2013/05/17 20:59:24
Deleted.
|
default: |
return BatchShortcutAction(base::Bind(&ShortcutOpDelete), location, dist, |
level, target_exe); |
@@ -2020,6 +2041,26 @@ bool ShellUtil::UpdateShortcuts( |
location, dist, level, target_exe); |
} |
+// static |
+bool ShellUtil::UpdateShortcutsFilteredByName( |
+ ShellUtil::ShortcutLocation location, |
+ BrowserDistribution* dist, |
+ ShellChange level, |
+ const string16& name_filter, |
+ const base::FilePath& target_exe, |
+ const ShellUtil::ShortcutProperties& properties) { |
+ DCHECK(EndsWith(name_filter, installer::kLnkExt, false)); |
+ |
+ if (!ShellUtil::ShortcutLocationIsSupported(location)) |
+ return true; // Vacuous success. |
+ |
+ base::win::ShortcutProperties shortcut_properties( |
+ TranslateShortcutProperties(properties)); |
+ return BatchShortcutActionFilteredByName( |
+ base::Bind(&ShortcutOpUpdate, shortcut_properties), |
+ location, dist, level, target_exe, name_filter); |
+} |
+ |
bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { |
// Use a thread-safe cache for the user's suffix. |
static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = |