Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: chrome/installer/util/shell_util.cc

Issue 108193019: Installer: adding ResolveShortcutProperties(); updating shortcut icons during shortcut migration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits; fixing test comments and coverage. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 } 1256 }
1257 return true; 1257 return true;
1258 } 1258 }
1259 1259
1260 bool ShortcutOpDelete(const base::FilePath& shortcut_path) { 1260 bool ShortcutOpDelete(const base::FilePath& shortcut_path) {
1261 bool ret = base::DeleteFile(shortcut_path, false); 1261 bool ret = base::DeleteFile(shortcut_path, false);
1262 LOG_IF(ERROR, !ret) << "Failed to remove " << shortcut_path.value(); 1262 LOG_IF(ERROR, !ret) << "Failed to remove " << shortcut_path.value();
1263 return ret; 1263 return ret;
1264 } 1264 }
1265 1265
1266 bool ShortcutOpUpdate(const base::win::ShortcutProperties& shortcut_properties, 1266 bool ShortcutOpRetarget(const base::FilePath& old_target,
1267 const base::FilePath& shortcut_path) { 1267 const base::FilePath& new_target,
1268 bool ret = base::win::CreateOrUpdateShortcutLink( 1268 const base::FilePath& shortcut_path) {
1269 shortcut_path, shortcut_properties, base::win::SHORTCUT_UPDATE_EXISTING); 1269 base::win::ShortcutProperties new_prop;
1270 LOG_IF(ERROR, !ret) << "Failed to update " << shortcut_path.value(); 1270 new_prop.set_target(new_target);
1271 return ret; 1271
1272 // If the old icon matches old target, then update icon while keeping the old
1273 // icon index. Non-fatal if we fail to get the old icon.
1274 base::win::ShortcutProperties old_prop;
1275 if (base::win::ResolveShortcutProperties(
1276 shortcut_path,
1277 base::win::ShortcutProperties::PROPERTIES_ICON,
1278 &old_prop)) {
1279 if (InstallUtil::ProgramCompare(old_target).EvaluatePath(old_prop.icon))
1280 new_prop.set_icon(new_target, old_prop.icon_index);
1281 } else {
1282 LOG(ERROR) << "Failed to resolve " << shortcut_path.value();
1283 }
1284
1285 bool result = base::win::CreateOrUpdateShortcutLink(
1286 shortcut_path, new_prop, base::win::SHORTCUT_UPDATE_EXISTING);
1287 LOG_IF(ERROR, !result) << "Failed to retarget " << shortcut_path.value();
1288 return result;
1272 } 1289 }
1273 1290
1274 // {|location|, |dist|, |level|} determine |shortcut_folder|. 1291 // {|location|, |dist|, |level|} determine |shortcut_folder|.
1275 // For each shortcut in |shortcut_folder| that match |shortcut_filter|, apply 1292 // For each shortcut in |shortcut_folder| that match |shortcut_filter|, apply
1276 // |shortcut_operation|. Returns true if all operations are successful. 1293 // |shortcut_operation|. Returns true if all operations are successful.
1277 // All intended operations are attempted, even if failures occur. 1294 // All intended operations are attempted, even if failures occur.
1278 bool BatchShortcutAction(const ShortcutFilterCallback& shortcut_filter, 1295 bool BatchShortcutAction(const ShortcutFilterCallback& shortcut_filter,
1279 const ShortcutOperationCallback& shortcut_operation, 1296 const ShortcutOperationCallback& shortcut_operation,
1280 ShellUtil::ShortcutLocation location, 1297 ShellUtil::ShortcutLocation location,
1281 BrowserDistribution* dist, 1298 BrowserDistribution* dist,
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
2084 if (success && 2101 if (success &&
2085 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR || 2102 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR ||
2086 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR || 2103 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR ||
2087 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) { 2104 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) {
2088 success = RemoveShortcutFolderIfEmpty(location, dist, level); 2105 success = RemoveShortcutFolderIfEmpty(location, dist, level);
2089 } 2106 }
2090 return success; 2107 return success;
2091 } 2108 }
2092 2109
2093 // static 2110 // static
2094 bool ShellUtil::UpdateShortcutsWithArgs( 2111 bool ShellUtil::RetargetShortcutsWithArgs(
2095 ShellUtil::ShortcutLocation location, 2112 ShellUtil::ShortcutLocation location,
2096 BrowserDistribution* dist, 2113 BrowserDistribution* dist,
2097 ShellChange level, 2114 ShellChange level,
2098 const base::FilePath& target_exe, 2115 const base::FilePath& old_target_exe,
2099 const ShellUtil::ShortcutProperties& properties) { 2116 const base::FilePath& new_target_exe) {
2100 if (!ShellUtil::ShortcutLocationIsSupported(location)) 2117 if (!ShellUtil::ShortcutLocationIsSupported(location))
2101 return true; // Vacuous success. 2118 return true; // Vacuous success.
2102 2119
2103 FilterTargetEq shortcut_filter(target_exe, true); 2120 FilterTargetEq shortcut_filter(old_target_exe, true);
2104 ShortcutOperationCallback shortcut_operation( 2121 ShortcutOperationCallback shortcut_operation(
2105 base::Bind(&ShortcutOpUpdate, TranslateShortcutProperties(properties))); 2122 base::Bind(&ShortcutOpRetarget, old_target_exe, new_target_exe));
2106 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), 2123 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(),
2107 shortcut_operation, location, dist, level); 2124 shortcut_operation, location, dist, level);
2108 } 2125 }
2109 2126
2110 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { 2127 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) {
2111 // Use a thread-safe cache for the user's suffix. 2128 // Use a thread-safe cache for the user's suffix.
2112 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = 2129 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance =
2113 LAZY_INSTANCE_INITIALIZER; 2130 LAZY_INSTANCE_INITIALIZER;
2114 return suffix_instance.Get().GetSuffix(suffix); 2131 return suffix_instance.Get().GetSuffix(suffix);
2115 } 2132 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 // are any left...). 2184 // are any left...).
2168 if (free_bits >= 8 && next_byte_index < size) { 2185 if (free_bits >= 8 && next_byte_index < size) {
2169 free_bits -= 8; 2186 free_bits -= 8;
2170 bit_stream += bytes[next_byte_index++] << free_bits; 2187 bit_stream += bytes[next_byte_index++] << free_bits;
2171 } 2188 }
2172 } 2189 }
2173 2190
2174 DCHECK_EQ(ret.length(), encoded_length); 2191 DCHECK_EQ(ret.length(), encoded_length);
2175 return ret; 2192 return ret;
2176 } 2193 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698