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

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: Removing 'shortcut update' flow; adding unit tests for shortcut retargeting; refactoring unittests. 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) << "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
1283 }
1284
1285 if (base::win::CreateOrUpdateShortcutLink(
1286 shortcut_path, new_prop, base::win::SHORTCUT_UPDATE_EXISTING)) {
1287 return true;
1288 }
1289 LOG(ERROR) << "Failed to retarget " << shortcut_path.value();
1290 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.
1272 } 1291 }
1273 1292
1293 // 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
1274 // {|location|, |dist|, |level|} determine |shortcut_folder|. 1294 // {|location|, |dist|, |level|} determine |shortcut_folder|.
1275 // For each shortcut in |shortcut_folder| that match |shortcut_filter|, apply 1295 // For each shortcut in |shortcut_folder| that match |shortcut_filter|, apply
1276 // |shortcut_operation|. Returns true if all operations are successful. 1296 // |shortcut_operation|. Returns true if all operations are successful.
1277 // All intended operations are attempted, even if failures occur. 1297 // All intended operations are attempted, even if failures occur.
1278 bool BatchShortcutAction(const ShortcutFilterCallback& shortcut_filter, 1298 bool BatchShortcutAction(const ShortcutFilterCallback& shortcut_filter,
1279 const ShortcutOperationCallback& shortcut_operation, 1299 const ShortcutOperationCallback& shortcut_operation,
1280 ShellUtil::ShortcutLocation location, 1300 ShellUtil::ShortcutLocation location,
1281 BrowserDistribution* dist, 1301 BrowserDistribution* dist,
1282 ShellUtil::ShellChange level) { 1302 ShellUtil::ShellChange level) {
1283 DCHECK(!shortcut_operation.is_null()); 1303 DCHECK(!shortcut_operation.is_null());
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
2084 if (success && 2104 if (success &&
2085 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR || 2105 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR ||
2086 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR || 2106 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR ||
2087 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) { 2107 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) {
2088 success = RemoveShortcutFolderIfEmpty(location, dist, level); 2108 success = RemoveShortcutFolderIfEmpty(location, dist, level);
2089 } 2109 }
2090 return success; 2110 return success;
2091 } 2111 }
2092 2112
2093 // static 2113 // static
2094 bool ShellUtil::UpdateShortcutsWithArgs( 2114 bool ShellUtil::RetargetShortcutsWithArgs(
2095 ShellUtil::ShortcutLocation location, 2115 ShellUtil::ShortcutLocation location,
2096 BrowserDistribution* dist, 2116 BrowserDistribution* dist,
2097 ShellChange level, 2117 ShellChange level,
2098 const base::FilePath& target_exe, 2118 const base::FilePath& old_target_exe,
2099 const ShellUtil::ShortcutProperties& properties) { 2119 const base::FilePath& new_target_exe) {
2100 if (!ShellUtil::ShortcutLocationIsSupported(location)) 2120 if (!ShellUtil::ShortcutLocationIsSupported(location))
2101 return true; // Vacuous success. 2121 return true; // Vacuous success.
2102 2122
2103 FilterTargetEq shortcut_filter(target_exe, true); 2123 FilterTargetEq shortcut_filter(old_target_exe, true);
2104 ShortcutOperationCallback shortcut_operation( 2124 ShortcutOperationCallback shortcut_operation(
2105 base::Bind(&ShortcutOpUpdate, TranslateShortcutProperties(properties))); 2125 base::Bind(&ShortcutOpRetarget, old_target_exe, new_target_exe));
2106 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), 2126 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(),
2107 shortcut_operation, location, dist, level); 2127 shortcut_operation, location, dist, level);
2108 } 2128 }
2109 2129
2110 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { 2130 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) {
2111 // Use a thread-safe cache for the user's suffix. 2131 // Use a thread-safe cache for the user's suffix.
2112 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = 2132 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance =
2113 LAZY_INSTANCE_INITIALIZER; 2133 LAZY_INSTANCE_INITIALIZER;
2114 return suffix_instance.Get().GetSuffix(suffix); 2134 return suffix_instance.Get().GetSuffix(suffix);
2115 } 2135 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 // are any left...). 2187 // are any left...).
2168 if (free_bits >= 8 && next_byte_index < size) { 2188 if (free_bits >= 8 && next_byte_index < size) {
2169 free_bits -= 8; 2189 free_bits -= 8;
2170 bit_stream += bytes[next_byte_index++] << free_bits; 2190 bit_stream += bytes[next_byte_index++] << free_bits;
2171 } 2191 }
2172 } 2192 }
2173 2193
2174 DCHECK_EQ(ret.length(), encoded_length); 2194 DCHECK_EQ(ret.length(), encoded_length);
2175 return ret; 2195 return ret;
2176 } 2196 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698