Chromium Code Reviews| Index: chrome/installer/util/shell_util.cc |
| diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc |
| index 4284e67f13f9fe4f51d6ef42acbc833b76c8a127..50f06897187d2f64c2af8babb9451b8225bb2554 100644 |
| --- a/chrome/installer/util/shell_util.cc |
| +++ b/chrome/installer/util/shell_util.cc |
| @@ -1263,14 +1263,34 @@ bool ShortcutOpDelete(const base::FilePath& shortcut_path) { |
| return ret; |
| } |
| -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_UPDATE_EXISTING); |
| - LOG_IF(ERROR, !ret) << "Failed to update " << shortcut_path.value(); |
| - return ret; |
| +bool ShortcutOpRetarget(const base::FilePath& old_target, |
| + const base::FilePath& new_target, |
| + const base::FilePath& shortcut_path) { |
| + base::win::ShortcutProperties new_prop; |
| + new_prop.set_target(new_target); |
| + |
| + // If the old icon matches old target, then update icon while keeping the old |
| + // icon index. Non-fatal if we fail to get the old icon. |
| + base::win::ShortcutProperties old_prop; |
| + if (base::win::ResolveShortcutProperties( |
| + shortcut_path, |
| + base::win::ShortcutProperties::PROPERTIES_ICON, |
| + &old_prop)) { |
| + if (InstallUtil::ProgramCompare(old_target).EvaluatePath(old_prop.icon)) |
| + new_prop.set_icon(new_target, old_prop.icon_index); |
| + } else { |
| + LOG(ERROR) << "Warning: failed to resolve " << shortcut_path.value(); |
|
gab
2014/01/02 15:51:46
Is this a warning or an error? The severity is ERR
huangs
2014/01/02 19:58:22
Ah, I didn't know LOG(WARNING) exists. Just remove
|
| + } |
| + |
| + if (base::win::CreateOrUpdateShortcutLink( |
| + shortcut_path, new_prop, base::win::SHORTCUT_UPDATE_EXISTING)) { |
| + return true; |
| + } |
| + LOG(ERROR) << "Failed to retarget " << shortcut_path.value(); |
| + return false; |
|
gab
2014/01/02 15:51:46
Avoid multiple return statements here by doing:
b
huangs
2014/01/02 19:58:22
Done.
|
| } |
| +// TODO(huangs): Restructure this to separate reading/filtering from operating. |
|
gab
2014/01/02 15:51:46
Isn't this already what this is doing? This won't
huangs
2014/01/02 19:58:22
Here {reading/filtering, operating} are integrated
|
| // {|location|, |dist|, |level|} determine |shortcut_folder|. |
| // For each shortcut in |shortcut_folder| that match |shortcut_filter|, apply |
| // |shortcut_operation|. Returns true if all operations are successful. |
| @@ -2091,18 +2111,18 @@ bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location, |
| } |
| // static |
| -bool ShellUtil::UpdateShortcutsWithArgs( |
| +bool ShellUtil::RetargetShortcutsWithArgs( |
| ShellUtil::ShortcutLocation location, |
| BrowserDistribution* dist, |
| ShellChange level, |
| - const base::FilePath& target_exe, |
| - const ShellUtil::ShortcutProperties& properties) { |
| + const base::FilePath& old_target_exe, |
| + const base::FilePath& new_target_exe) { |
| if (!ShellUtil::ShortcutLocationIsSupported(location)) |
| return true; // Vacuous success. |
| - FilterTargetEq shortcut_filter(target_exe, true); |
| + FilterTargetEq shortcut_filter(old_target_exe, true); |
| ShortcutOperationCallback shortcut_operation( |
| - base::Bind(&ShortcutOpUpdate, TranslateShortcutProperties(properties))); |
| + base::Bind(&ShortcutOpRetarget, old_target_exe, new_target_exe)); |
| return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), |
| shortcut_operation, location, dist, level); |
| } |