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

Side by Side Diff: chrome/installer/setup/install.cc

Issue 1800303006: Fix the path of shortcuts with an icon in the current install dir. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix buildbot error Created 4 years, 9 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
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 #include "chrome/installer/setup/install.h" 5 #include "chrome/installer/setup/install.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shlobj.h> 8 #include <shlobj.h>
9 #include <time.h> 9 #include <time.h>
10 10
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 return installer::NEW_VERSION_UPDATED; 246 return installer::NEW_VERSION_UPDATED;
247 } 247 }
248 248
249 LOG(ERROR) << "Not sure how we got here while updating" 249 LOG(ERROR) << "Not sure how we got here while updating"
250 << ", new version: " << new_version 250 << ", new version: " << new_version
251 << ", old version: " << **current_version; 251 << ", old version: " << **current_version;
252 252
253 return installer::INSTALL_FAILED; 253 return installer::INSTALL_FAILED;
254 } 254 }
255 255
256 // Returns the number of components in |file_path|.
257 size_t GetNumPathComponents(const base::FilePath& file_path) {
258 std::vector<base::FilePath::StringType> components;
259 file_path.GetComponents(&components);
260 return components.size();
261 }
262
263 // Returns a path made with the |num_components| first components of
264 // |file_path|. |file_path| is returned as-is if it contains less than
265 // |num_components| components.
266 base::FilePath TruncatePath(const base::FilePath& file_path,
267 size_t num_components) {
268 std::vector<base::FilePath::StringType> components;
269 file_path.GetComponents(&components);
270 if (components.size() <= num_components)
271 return file_path;
272 base::FilePath truncated_file_path;
273 for (size_t i = 0; i < num_components; ++i)
274 truncated_file_path = truncated_file_path.Append(components[i]);
275 return truncated_file_path;
276 }
277
256 } // namespace 278 } // namespace
257 279
258 namespace installer { 280 namespace installer {
259 281
260 void UpdatePerUserShortcutsInLocation( 282 void UpdatePerUserShortcutsInLocation(
261 const ShellUtil::ShortcutLocation shortcut_location, 283 const ShellUtil::ShortcutLocation shortcut_location,
262 BrowserDistribution* dist, 284 BrowserDistribution* dist,
263 const base::FilePath& old_target_dir, 285 const base::FilePath& old_target_dir,
264 const base::FilePath& old_target_path_suffix, 286 const base::FilePath& old_target_name_suffix,
265 const base::FilePath& new_target_path) { 287 const base::FilePath& new_target_path) {
266 base::FilePath shortcut_path; 288 base::FilePath shortcut_path;
267 const bool get_shortcut_path_return = ShellUtil::GetShortcutPath( 289 const bool get_shortcut_path_return = ShellUtil::GetShortcutPath(
268 shortcut_location, dist, ShellUtil::CURRENT_USER, &shortcut_path); 290 shortcut_location, dist, ShellUtil::CURRENT_USER, &shortcut_path);
269 DCHECK(get_shortcut_path_return); 291 DCHECK(get_shortcut_path_return);
270 292
271 bool recursive = false; 293 bool recursive = false;
272 294
273 // TODO(fdoray): Modify GetShortcutPath such that it returns 295 // TODO(fdoray): Modify GetShortcutPath such that it returns
274 // ...\Quick Launch\User Pinned instead of 296 // ...\Quick Launch\User Pinned instead of
275 // ...\Quick Launch\User Pinned\TaskBar for SHORTCUT_LOCATION_TASKBAR_PINS. 297 // ...\Quick Launch\User Pinned\TaskBar for SHORTCUT_LOCATION_TASKBAR_PINS.
276 if (shortcut_location == ShellUtil::SHORTCUT_LOCATION_TASKBAR_PINS) { 298 if (shortcut_location == ShellUtil::SHORTCUT_LOCATION_TASKBAR_PINS) {
277 shortcut_path = shortcut_path.DirName(); 299 shortcut_path = shortcut_path.DirName();
278 recursive = true; 300 recursive = true;
279 } 301 }
280 302
303 const size_t num_old_target_dir_components =
304 GetNumPathComponents(old_target_dir);
305 InstallUtil::ProgramCompare old_target_dir_comparator(
306 old_target_dir,
307 InstallUtil::ProgramCompare::ComparisonType::FILE_OR_DIRECTORY);
308
281 base::FileEnumerator shortcuts_enum(shortcut_path, recursive, 309 base::FileEnumerator shortcuts_enum(shortcut_path, recursive,
282 base::FileEnumerator::FILES); 310 base::FileEnumerator::FILES);
283 for (base::FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty(); 311 for (base::FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty();
284 shortcut = shortcuts_enum.Next()) { 312 shortcut = shortcuts_enum.Next()) {
285 base::FilePath existing_target_path; 313 base::win::ShortcutProperties shortcut_properties;
286 if (!base::win::ResolveShortcut(shortcut, &existing_target_path, nullptr) || 314 if (!base::win::ResolveShortcutProperties(
287 !base::StartsWith(existing_target_path.value(), 315 shortcut, (base::win::ShortcutProperties::PROPERTIES_TARGET |
288 old_target_dir.AsEndingWithSeparator().value(), 316 base::win::ShortcutProperties::PROPERTIES_ICON),
289 base::CompareCase::INSENSITIVE_ASCII) || 317 &shortcut_properties)) {
290 !base::EndsWith(existing_target_path.value(),
291 old_target_path_suffix.value(),
292 base::CompareCase::INSENSITIVE_ASCII)) {
293 continue; 318 continue;
294 } 319 }
295 320
321 if (shortcut_properties.target.ReferencesParent() ||
322 shortcut_properties.icon.ReferencesParent()) {
323 continue;
gab 2016/03/21 19:28:13 Nice :-), I'd even add a NOTREACHED(); with a comm
324 }
325
326 // Skip shortcuts whose target isn't a file rooted at |old_target_dir| with
327 // a name ending in |old_target_name_suffix|. Except for shortcuts whose
328 // icon is rooted at |old_target_dir|. Note that there can be a false
329 // negative if the target path or the icon path is a symlink.
330 // TODO(fdoray): The second condition is only intended to fix Canary
331 // shortcuts broken by crbug.com/595374, remove it in May 2016.
332 if (!(old_target_dir_comparator.EvaluatePath(TruncatePath(
333 shortcut_properties.target, num_old_target_dir_components)) &&
334 base::EndsWith(shortcut_properties.target.BaseName().value(),
335 old_target_name_suffix.value(),
336 base::CompareCase::INSENSITIVE_ASCII)) &&
337 !old_target_dir_comparator.EvaluatePath(TruncatePath(
338 shortcut_properties.icon, num_old_target_dir_components))) {
339 continue;
340 }
341
296 base::win::ShortcutProperties updated_properties; 342 base::win::ShortcutProperties updated_properties;
297 updated_properties.set_target(new_target_path); 343 updated_properties.set_target(new_target_path);
298 base::win::CreateOrUpdateShortcutLink(shortcut, updated_properties, 344 base::win::CreateOrUpdateShortcutLink(shortcut, updated_properties,
299 base::win::SHORTCUT_UPDATE_EXISTING); 345 base::win::SHORTCUT_UPDATE_EXISTING);
300 } 346 }
301 } 347 }
302 348
303 void EscapeXmlAttributeValueInSingleQuotes(base::string16* att_value) { 349 void EscapeXmlAttributeValueInSingleQuotes(base::string16* att_value) {
304 base::ReplaceChars(*att_value, base::ASCIIToUTF16("&"), 350 base::ReplaceChars(*att_value, base::ASCIIToUTF16("&"),
305 base::ASCIIToUTF16("&amp;"), att_value); 351 base::ASCIIToUTF16("&amp;"), att_value);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 ShellUtil::MoveExistingShortcut( 503 ShellUtil::MoveExistingShortcut(
458 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED, 504 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
459 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT, 505 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT,
460 dist, start_menu_properties); 506 dist, start_menu_properties);
461 } 507 }
462 508
463 ExecuteAndLogShortcutOperation( 509 ExecuteAndLogShortcutOperation(
464 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT, dist, 510 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT, dist,
465 start_menu_properties, shortcut_operation); 511 start_menu_properties, shortcut_operation);
466 512
467 // Update the target path of existing per-user shortcuts. 513 // Update the target path of existing per-user shortcuts. TODO(fdoray): This
468 if (install_operation == INSTALL_SHORTCUT_REPLACE_EXISTING) { 514 // is only intended to fix Canary shortcuts broken by crbug.com/595374 and
515 // crbug.com/592040, remove it in May 2016.
516 if (InstallUtil::IsChromeSxSProcess() &&
517 install_operation == INSTALL_SHORTCUT_REPLACE_EXISTING) {
469 const base::FilePath updated_prefix = target.DirName().DirName(); 518 const base::FilePath updated_prefix = target.DirName().DirName();
470 const base::FilePath updated_suffix = target.BaseName(); 519 const base::FilePath updated_suffix = target.BaseName();
471 520
472 UpdatePerUserShortcutsInLocation(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist, 521 UpdatePerUserShortcutsInLocation(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist,
473 updated_prefix, updated_suffix, target); 522 updated_prefix, updated_suffix, target);
474 UpdatePerUserShortcutsInLocation(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, 523 UpdatePerUserShortcutsInLocation(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH,
475 dist, updated_prefix, updated_suffix, 524 dist, updated_prefix, updated_suffix,
476 target); 525 target);
477 UpdatePerUserShortcutsInLocation(ShellUtil::SHORTCUT_LOCATION_TASKBAR_PINS, 526 UpdatePerUserShortcutsInLocation(ShellUtil::SHORTCUT_LOCATION_TASKBAR_PINS,
478 dist, updated_prefix, updated_suffix, 527 dist, updated_prefix, updated_suffix,
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 // Read master_preferences copied beside chrome.exe at install. 762 // Read master_preferences copied beside chrome.exe at install.
714 MasterPreferences prefs(installation_root.AppendASCII(kDefaultMasterPrefs)); 763 MasterPreferences prefs(installation_root.AppendASCII(kDefaultMasterPrefs));
715 base::FilePath chrome_exe(installation_root.Append(kChromeExe)); 764 base::FilePath chrome_exe(installation_root.Append(kChromeExe));
716 CreateOrUpdateShortcuts( 765 CreateOrUpdateShortcuts(
717 chrome_exe, chrome, prefs, CURRENT_USER, install_operation); 766 chrome_exe, chrome, prefs, CURRENT_USER, install_operation);
718 767
719 UpdateDefaultBrowserBeaconForPath(chrome_exe); 768 UpdateDefaultBrowserBeaconForPath(chrome_exe);
720 } 769 }
721 770
722 } // namespace installer 771 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698