OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // This file defines functions that integrate Chrome in Windows shell. These | 5 // This file defines functions that integrate Chrome in Windows shell. These |
6 // functions can be used by Chrome as well as Chrome installer. All of the | 6 // functions can be used by Chrome as well as Chrome installer. All of the |
7 // work is done by the local functions defined in anonymous namespace in | 7 // work is done by the local functions defined in anonymous namespace in |
8 // this class. | 8 // this class. |
9 | 9 |
10 #include "chrome/installer/util/shell_util.h" | 10 #include "chrome/installer/util/shell_util.h" |
(...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 } | 1260 } |
1261 return true; | 1261 return true; |
1262 } | 1262 } |
1263 | 1263 |
1264 bool ShortcutOpDelete(const base::FilePath& shortcut_path) { | 1264 bool ShortcutOpDelete(const base::FilePath& shortcut_path) { |
1265 bool ret = base::DeleteFile(shortcut_path, false); | 1265 bool ret = base::DeleteFile(shortcut_path, false); |
1266 LOG_IF(ERROR, !ret) << "Failed to remove " << shortcut_path.value(); | 1266 LOG_IF(ERROR, !ret) << "Failed to remove " << shortcut_path.value(); |
1267 return ret; | 1267 return ret; |
1268 } | 1268 } |
1269 | 1269 |
1270 bool ShortcutOpUpdate(const base::win::ShortcutProperties& shortcut_properties, | 1270 bool ShortcutOpRetarget(const base::FilePath& old_target, |
1271 const base::FilePath& shortcut_path) { | 1271 const base::FilePath& new_target, |
1272 bool ret = base::win::CreateOrUpdateShortcutLink( | 1272 const base::FilePath& shortcut_path) { |
1273 shortcut_path, shortcut_properties, base::win::SHORTCUT_UPDATE_EXISTING); | 1273 base::win::ShortcutProperties new_prop; |
1274 LOG_IF(ERROR, !ret) << "Failed to update " << shortcut_path.value(); | 1274 new_prop.set_target(new_target); |
1275 return ret; | 1275 |
| 1276 // If the old icon matches old target, then update icon while keeping the old |
| 1277 // icon index. Non-fatal if we fail to get the old icon. |
| 1278 base::win::ShortcutProperties old_prop; |
| 1279 if (base::win::ResolveShortcutProperties( |
| 1280 shortcut_path, |
| 1281 base::win::ShortcutProperties::PROPERTIES_ICON, |
| 1282 &old_prop)) { |
| 1283 if (InstallUtil::ProgramCompare(old_target).EvaluatePath(old_prop.icon)) |
| 1284 new_prop.set_icon(new_target, old_prop.icon_index); |
| 1285 } else { |
| 1286 LOG(ERROR) << "Failed to resolve " << shortcut_path.value(); |
| 1287 } |
| 1288 |
| 1289 bool result = base::win::CreateOrUpdateShortcutLink( |
| 1290 shortcut_path, new_prop, base::win::SHORTCUT_UPDATE_EXISTING); |
| 1291 LOG_IF(ERROR, !result) << "Failed to retarget " << shortcut_path.value(); |
| 1292 return result; |
1276 } | 1293 } |
1277 | 1294 |
1278 // {|location|, |dist|, |level|} determine |shortcut_folder|. | 1295 // {|location|, |dist|, |level|} determine |shortcut_folder|. |
1279 // For each shortcut in |shortcut_folder| that match |shortcut_filter|, apply | 1296 // For each shortcut in |shortcut_folder| that match |shortcut_filter|, apply |
1280 // |shortcut_operation|. Returns true if all operations are successful. | 1297 // |shortcut_operation|. Returns true if all operations are successful. |
1281 // All intended operations are attempted, even if failures occur. | 1298 // All intended operations are attempted, even if failures occur. |
1282 bool BatchShortcutAction(const ShortcutFilterCallback& shortcut_filter, | 1299 bool BatchShortcutAction(const ShortcutFilterCallback& shortcut_filter, |
1283 const ShortcutOperationCallback& shortcut_operation, | 1300 const ShortcutOperationCallback& shortcut_operation, |
1284 ShellUtil::ShortcutLocation location, | 1301 ShellUtil::ShortcutLocation location, |
1285 BrowserDistribution* dist, | 1302 BrowserDistribution* dist, |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2097 if (success && | 2114 if (success && |
2098 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR || | 2115 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR || |
2099 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR || | 2116 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR || |
2100 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) { | 2117 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) { |
2101 success = RemoveShortcutFolderIfEmpty(location, dist, level); | 2118 success = RemoveShortcutFolderIfEmpty(location, dist, level); |
2102 } | 2119 } |
2103 return success; | 2120 return success; |
2104 } | 2121 } |
2105 | 2122 |
2106 // static | 2123 // static |
2107 bool ShellUtil::UpdateShortcutsWithArgs( | 2124 bool ShellUtil::RetargetShortcutsWithArgs( |
2108 ShellUtil::ShortcutLocation location, | 2125 ShellUtil::ShortcutLocation location, |
2109 BrowserDistribution* dist, | 2126 BrowserDistribution* dist, |
2110 ShellChange level, | 2127 ShellChange level, |
2111 const base::FilePath& target_exe, | 2128 const base::FilePath& old_target_exe, |
2112 const ShellUtil::ShortcutProperties& properties) { | 2129 const base::FilePath& new_target_exe) { |
2113 if (!ShellUtil::ShortcutLocationIsSupported(location)) | 2130 if (!ShellUtil::ShortcutLocationIsSupported(location)) |
2114 return true; // Vacuous success. | 2131 return true; // Vacuous success. |
2115 | 2132 |
2116 FilterTargetEq shortcut_filter(target_exe, true); | 2133 FilterTargetEq shortcut_filter(old_target_exe, true); |
2117 ShortcutOperationCallback shortcut_operation( | 2134 ShortcutOperationCallback shortcut_operation( |
2118 base::Bind(&ShortcutOpUpdate, TranslateShortcutProperties(properties))); | 2135 base::Bind(&ShortcutOpRetarget, old_target_exe, new_target_exe)); |
2119 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), | 2136 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), |
2120 shortcut_operation, location, dist, level); | 2137 shortcut_operation, location, dist, level); |
2121 } | 2138 } |
2122 | 2139 |
2123 bool ShellUtil::GetUserSpecificRegistrySuffix(base::string16* suffix) { | 2140 bool ShellUtil::GetUserSpecificRegistrySuffix(base::string16* suffix) { |
2124 // Use a thread-safe cache for the user's suffix. | 2141 // Use a thread-safe cache for the user's suffix. |
2125 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = | 2142 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = |
2126 LAZY_INSTANCE_INITIALIZER; | 2143 LAZY_INSTANCE_INITIALIZER; |
2127 return suffix_instance.Get().GetSuffix(suffix); | 2144 return suffix_instance.Get().GetSuffix(suffix); |
2128 } | 2145 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2180 // are any left...). | 2197 // are any left...). |
2181 if (free_bits >= 8 && next_byte_index < size) { | 2198 if (free_bits >= 8 && next_byte_index < size) { |
2182 free_bits -= 8; | 2199 free_bits -= 8; |
2183 bit_stream += bytes[next_byte_index++] << free_bits; | 2200 bit_stream += bytes[next_byte_index++] << free_bits; |
2184 } | 2201 } |
2185 } | 2202 } |
2186 | 2203 |
2187 DCHECK_EQ(ret.length(), encoded_length); | 2204 DCHECK_EQ(ret.length(), encoded_length); |
2188 return ret; | 2205 return ret; |
2189 } | 2206 } |
OLD | NEW |