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

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

Issue 2456853002: Remove shortcut path fixups introduced to repair breakages caused by r378802. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « chrome/installer/setup/install.h ('k') | chrome/installer/setup/install_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 13
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/files/file_enumerator.h"
16 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
17 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
18 #include "base/logging.h" 17 #include "base/logging.h"
19 #include "base/numerics/safe_conversions.h" 18 #include "base/numerics/safe_conversions.h"
20 #include "base/process/launch.h" 19 #include "base/process/launch.h"
21 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
22 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
23 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
24 #include "base/win/shortcut.h" 23 #include "base/win/shortcut.h"
25 #include "base/win/windows_version.h" 24 #include "base/win/windows_version.h"
26 #include "chrome/common/chrome_constants.h" 25 #include "chrome/common/chrome_constants.h"
27 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
28 #include "chrome/installer/setup/install_worker.h" 27 #include "chrome/installer/setup/install_worker.h"
29 #include "chrome/installer/setup/installer_crash_reporting.h" 28 #include "chrome/installer/setup/installer_crash_reporting.h"
30 #include "chrome/installer/setup/setup_constants.h" 29 #include "chrome/installer/setup/setup_constants.h"
31 #include "chrome/installer/setup/setup_util.h" 30 #include "chrome/installer/setup/setup_util.h"
32 #include "chrome/installer/setup/update_active_setup_version_work_item.h" 31 #include "chrome/installer/setup/update_active_setup_version_work_item.h"
33 #include "chrome/installer/util/beacons.h" 32 #include "chrome/installer/util/beacons.h"
34 #include "chrome/installer/util/browser_distribution.h" 33 #include "chrome/installer/util/browser_distribution.h"
35 #include "chrome/installer/util/create_reg_key_work_item.h" 34 #include "chrome/installer/util/create_reg_key_work_item.h"
36 #include "chrome/installer/util/delete_after_reboot_helper.h" 35 #include "chrome/installer/util/delete_after_reboot_helper.h"
37 #include "chrome/installer/util/delete_old_versions.h" 36 #include "chrome/installer/util/delete_old_versions.h"
38 #include "chrome/installer/util/google_update_constants.h" 37 #include "chrome/installer/util/google_update_constants.h"
39 #include "chrome/installer/util/helper.h" 38 #include "chrome/installer/util/helper.h"
40 #include "chrome/installer/util/install_util.h" 39 #include "chrome/installer/util/install_util.h"
41 #include "chrome/installer/util/master_preferences.h" 40 #include "chrome/installer/util/master_preferences.h"
42 #include "chrome/installer/util/master_preferences_constants.h" 41 #include "chrome/installer/util/master_preferences_constants.h"
43 #include "chrome/installer/util/set_reg_value_work_item.h" 42 #include "chrome/installer/util/set_reg_value_work_item.h"
44 #include "chrome/installer/util/shell_util.h"
45 #include "chrome/installer/util/util_constants.h" 43 #include "chrome/installer/util/util_constants.h"
46 #include "chrome/installer/util/work_item.h" 44 #include "chrome/installer/util/work_item.h"
47 #include "chrome/installer/util/work_item_list.h" 45 #include "chrome/installer/util/work_item_list.h"
48 46
49 namespace { 47 namespace {
50 48
51 void LogShortcutOperation(ShellUtil::ShortcutLocation location, 49 void LogShortcutOperation(ShellUtil::ShortcutLocation location,
52 BrowserDistribution* dist, 50 BrowserDistribution* dist,
53 const ShellUtil::ShortcutProperties& properties, 51 const ShellUtil::ShortcutProperties& properties,
54 ShellUtil::ShortcutOperation operation, 52 ShellUtil::ShortcutOperation operation,
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 return installer::OLD_VERSION_DOWNGRADE; 258 return installer::OLD_VERSION_DOWNGRADE;
261 } 259 }
262 260
263 LOG(ERROR) << "Not sure how we got here while updating" 261 LOG(ERROR) << "Not sure how we got here while updating"
264 << ", new version: " << new_version 262 << ", new version: " << new_version
265 << ", old version: " << **current_version; 263 << ", old version: " << **current_version;
266 264
267 return installer::INSTALL_FAILED; 265 return installer::INSTALL_FAILED;
268 } 266 }
269 267
270 // Returns the number of components in |file_path|. 268 } // end namespace
271 size_t GetNumPathComponents(const base::FilePath& file_path) {
272 std::vector<base::FilePath::StringType> components;
273 file_path.GetComponents(&components);
274 return components.size();
275 }
276
277 // Returns a path made with the |num_components| first components of
278 // |file_path|. |file_path| is returned as-is if it contains less than
279 // |num_components| components.
280 base::FilePath TruncatePath(const base::FilePath& file_path,
281 size_t num_components) {
282 std::vector<base::FilePath::StringType> components;
283 file_path.GetComponents(&components);
284 if (components.size() <= num_components)
285 return file_path;
286 base::FilePath truncated_file_path;
287 for (size_t i = 0; i < num_components; ++i)
288 truncated_file_path = truncated_file_path.Append(components[i]);
289 return truncated_file_path;
290 }
291
292 } // namespace
293 269
294 namespace installer { 270 namespace installer {
295 271
296 void UpdatePerUserShortcutsInLocation(
297 const ShellUtil::ShortcutLocation shortcut_location,
298 BrowserDistribution* dist,
299 const base::FilePath& old_target_dir,
300 const base::FilePath& old_target_name_suffix,
301 const base::FilePath& new_target_path) {
302 base::FilePath shortcut_path;
303 const bool get_shortcut_path_return = ShellUtil::GetShortcutPath(
304 shortcut_location, dist, ShellUtil::CURRENT_USER, &shortcut_path);
305 DCHECK(get_shortcut_path_return);
306
307 bool recursive = false;
308
309 // TODO(fdoray): Modify GetShortcutPath such that it returns
310 // ...\Quick Launch\User Pinned instead of
311 // ...\Quick Launch\User Pinned\TaskBar for SHORTCUT_LOCATION_TASKBAR_PINS.
312 if (shortcut_location == ShellUtil::SHORTCUT_LOCATION_TASKBAR_PINS) {
313 shortcut_path = shortcut_path.DirName();
314 recursive = true;
315 }
316
317 const size_t num_old_target_dir_components =
318 GetNumPathComponents(old_target_dir);
319 InstallUtil::ProgramCompare old_target_dir_comparator(
320 old_target_dir,
321 InstallUtil::ProgramCompare::ComparisonType::FILE_OR_DIRECTORY);
322
323 base::FileEnumerator shortcuts_enum(shortcut_path, recursive,
324 base::FileEnumerator::FILES);
325 for (base::FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty();
326 shortcut = shortcuts_enum.Next()) {
327 base::win::ShortcutProperties shortcut_properties;
328 if (!base::win::ResolveShortcutProperties(
329 shortcut, (base::win::ShortcutProperties::PROPERTIES_TARGET |
330 base::win::ShortcutProperties::PROPERTIES_ICON),
331 &shortcut_properties)) {
332 continue;
333 }
334
335 if (shortcut_properties.target.ReferencesParent() ||
336 shortcut_properties.icon.ReferencesParent()) {
337 continue;
338 }
339
340 // Skip shortcuts whose target isn't a file rooted at |old_target_dir| with
341 // a name ending in |old_target_name_suffix|. Except for shortcuts whose
342 // icon is rooted at |old_target_dir|. Note that there can be a false
343 // negative if the target path or the icon path is a symlink.
344 // TODO(fdoray): The second condition is only intended to fix Canary
345 // shortcuts broken by crbug.com/595374, remove it in May 2016.
346 if (!(old_target_dir_comparator.EvaluatePath(TruncatePath(
347 shortcut_properties.target, num_old_target_dir_components)) &&
348 base::EndsWith(shortcut_properties.target.BaseName().value(),
349 old_target_name_suffix.value(),
350 base::CompareCase::INSENSITIVE_ASCII)) &&
351 !old_target_dir_comparator.EvaluatePath(TruncatePath(
352 shortcut_properties.icon, num_old_target_dir_components))) {
353 continue;
354 }
355
356 base::win::ShortcutProperties updated_properties;
357 updated_properties.set_target(new_target_path);
358 base::win::CreateOrUpdateShortcutLink(shortcut, updated_properties,
359 base::win::SHORTCUT_UPDATE_EXISTING);
360 }
361 }
362
363 void EscapeXmlAttributeValueInSingleQuotes(base::string16* att_value) { 272 void EscapeXmlAttributeValueInSingleQuotes(base::string16* att_value) {
364 base::ReplaceChars(*att_value, base::ASCIIToUTF16("&"), 273 base::ReplaceChars(*att_value, base::ASCIIToUTF16("&"),
365 base::ASCIIToUTF16("&amp;"), att_value); 274 base::ASCIIToUTF16("&amp;"), att_value);
366 base::ReplaceChars(*att_value, base::ASCIIToUTF16("'"), 275 base::ReplaceChars(*att_value, base::ASCIIToUTF16("'"),
367 base::ASCIIToUTF16("&apos;"), att_value); 276 base::ASCIIToUTF16("&apos;"), att_value);
368 base::ReplaceChars(*att_value, base::ASCIIToUTF16("<"), 277 base::ReplaceChars(*att_value, base::ASCIIToUTF16("<"),
369 base::ASCIIToUTF16("&lt;"), att_value); 278 base::ASCIIToUTF16("&lt;"), att_value);
370 } 279 }
371 280
372 bool CreateVisualElementsManifest(const base::FilePath& src_path, 281 bool CreateVisualElementsManifest(const base::FilePath& src_path,
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 if (base::PathExists(old_shortcut_path)) { 429 if (base::PathExists(old_shortcut_path)) {
521 ShellUtil::MoveExistingShortcut( 430 ShellUtil::MoveExistingShortcut(
522 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED, 431 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
523 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT, 432 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT,
524 dist, start_menu_properties); 433 dist, start_menu_properties);
525 } 434 }
526 435
527 ExecuteAndLogShortcutOperation( 436 ExecuteAndLogShortcutOperation(
528 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT, dist, 437 ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT, dist,
529 start_menu_properties, shortcut_operation); 438 start_menu_properties, shortcut_operation);
530
531 // Update the target path of existing per-user shortcuts. TODO(fdoray): This
532 // is only intended to fix Canary shortcuts broken by crbug.com/595374 and
533 // crbug.com/592040, remove it in May 2016.
534 if (InstallUtil::IsChromeSxSProcess() &&
535 install_operation == INSTALL_SHORTCUT_REPLACE_EXISTING) {
536 const base::FilePath updated_prefix = target.DirName().DirName();
537 const base::FilePath updated_suffix = target.BaseName();
538
539 UpdatePerUserShortcutsInLocation(ShellUtil::SHORTCUT_LOCATION_DESKTOP, dist,
540 updated_prefix, updated_suffix, target);
541 UpdatePerUserShortcutsInLocation(ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH,
542 dist, updated_prefix, updated_suffix,
543 target);
544 UpdatePerUserShortcutsInLocation(ShellUtil::SHORTCUT_LOCATION_TASKBAR_PINS,
545 dist, updated_prefix, updated_suffix,
546 target);
547 }
548 } 439 }
549 440
550 void RegisterChromeOnMachine(const installer::InstallerState& installer_state, 441 void RegisterChromeOnMachine(const installer::InstallerState& installer_state,
551 const installer::Product& product, 442 const installer::Product& product,
552 bool make_chrome_default) { 443 bool make_chrome_default) {
553 DCHECK(product.is_chrome()); 444 DCHECK(product.is_chrome());
554 445
555 // Try to add Chrome to Media Player shim inclusion list. We don't do any 446 // Try to add Chrome to Media Player shim inclusion list. We don't do any
556 // error checking here because this operation will fail if user doesn't 447 // error checking here because this operation will fail if user doesn't
557 // have admin rights and we want to ignore the error. 448 // have admin rights and we want to ignore the error.
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 // Read master_preferences copied beside chrome.exe at install. 717 // Read master_preferences copied beside chrome.exe at install.
827 MasterPreferences prefs(installation_root.AppendASCII(kDefaultMasterPrefs)); 718 MasterPreferences prefs(installation_root.AppendASCII(kDefaultMasterPrefs));
828 base::FilePath chrome_exe(installation_root.Append(kChromeExe)); 719 base::FilePath chrome_exe(installation_root.Append(kChromeExe));
829 CreateOrUpdateShortcuts( 720 CreateOrUpdateShortcuts(
830 chrome_exe, chrome, prefs, CURRENT_USER, install_operation); 721 chrome_exe, chrome, prefs, CURRENT_USER, install_operation);
831 722
832 UpdateDefaultBrowserBeaconForPath(chrome_exe); 723 UpdateDefaultBrowserBeaconForPath(chrome_exe);
833 } 724 }
834 725
835 } // namespace installer 726 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/setup/install.h ('k') | chrome/installer/setup/install_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698