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 #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/files/file_enumerator.h" | 15 #include "base/files/file_enumerator.h" |
15 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
16 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
17 #include "base/logging.h" | 18 #include "base/logging.h" |
18 #include "base/numerics/safe_conversions.h" | 19 #include "base/numerics/safe_conversions.h" |
| 20 #include "base/process/launch.h" |
19 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
20 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
21 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
22 #include "base/win/shortcut.h" | 24 #include "base/win/shortcut.h" |
23 #include "base/win/windows_version.h" | 25 #include "base/win/windows_version.h" |
24 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
25 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/installer/setup/install_worker.h" | 28 #include "chrome/installer/setup/install_worker.h" |
27 #include "chrome/installer/setup/installer_crash_reporting.h" | 29 #include "chrome/installer/setup/installer_crash_reporting.h" |
28 #include "chrome/installer/setup/setup_constants.h" | 30 #include "chrome/installer/setup/setup_constants.h" |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 make_chrome_default || force_chrome_default_for_user); | 675 make_chrome_default || force_chrome_default_for_user); |
674 | 676 |
675 if (!installer_state.system_install()) { | 677 if (!installer_state.system_install()) { |
676 DCHECK_EQ(chrome_product->distribution(), | 678 DCHECK_EQ(chrome_product->distribution(), |
677 BrowserDistribution::GetDistribution()); | 679 BrowserDistribution::GetDistribution()); |
678 UpdateDefaultBrowserBeaconForPath( | 680 UpdateDefaultBrowserBeaconForPath( |
679 installer_state.target_path().Append(installer::kChromeExe)); | 681 installer_state.target_path().Append(installer::kChromeExe)); |
680 } | 682 } |
681 } | 683 } |
682 | 684 |
| 685 // Delete files that belong to old versions of Chrome. If that fails during |
| 686 // a not-in-use update, launch a --delete-old-version process. If this is an |
| 687 // in-use update, a --delete-old-versions process will be launched when |
| 688 // executables are renamed. |
683 installer_state.SetStage(REMOVING_OLD_VERSIONS); | 689 installer_state.SetStage(REMOVING_OLD_VERSIONS); |
684 // TODO(fdoray): Launch a cleanup process when this fails during a not-in- | 690 const bool is_in_use = |
685 // use update. crbug.com/451546 | 691 (result == IN_USE_UPDATED || result == IN_USE_DOWNGRADE); |
686 DeleteOldVersions(installer_state.target_path()); | 692 if (!DeleteOldVersions(installer_state.target_path()) && !is_in_use) { |
| 693 const base::FilePath new_version_setup_path = |
| 694 installer_state.GetInstallerDirectory(new_version) |
| 695 .Append(setup_path.BaseName()); |
| 696 LaunchDeleteOldVersionsProcess(new_version_setup_path, installer_state); |
| 697 } |
687 } | 698 } |
688 | 699 |
689 return result; | 700 return result; |
690 } | 701 } |
691 | 702 |
| 703 void LaunchDeleteOldVersionsProcess(const base::FilePath& setup_path, |
| 704 const InstallerState& installer_state) { |
| 705 // Deleting old versions is relevant if multi-install binaries are being |
| 706 // updated or if single-install Chrome is. |
| 707 const Product* product = |
| 708 installer_state.FindProduct(BrowserDistribution::CHROME_BINARIES); |
| 709 if (!product) |
| 710 product = installer_state.FindProduct(BrowserDistribution::CHROME_BROWSER); |
| 711 if (!product) |
| 712 return; |
| 713 |
| 714 base::CommandLine command_line(setup_path); |
| 715 product->AppendProductFlags(&command_line); |
| 716 command_line.AppendSwitch(switches::kDeleteOldVersions); |
| 717 |
| 718 if (installer_state.system_install()) |
| 719 command_line.AppendSwitch(switches::kSystemLevel); |
| 720 // Unconditionally enable verbose logging for now to make diagnosing potential |
| 721 // failures possible. |
| 722 command_line.AppendSwitch(switches::kVerboseLogging); |
| 723 |
| 724 base::LaunchOptions launch_options; |
| 725 launch_options.start_hidden = true; |
| 726 // Make sure not to launch from a version directory. Otherwise, it wouldn't be |
| 727 // possible to delete it. |
| 728 launch_options.current_directory = setup_path.DirName(); |
| 729 launch_options.force_breakaway_from_job_ = true; |
| 730 |
| 731 VLOG(1) << "Launching \"" << command_line.GetCommandLineString() |
| 732 << "\" to delete old versions."; |
| 733 base::Process process = base::LaunchProcess(command_line, launch_options); |
| 734 PLOG_IF(ERROR, !process.IsValid()) |
| 735 << "Failed to launch \"" << command_line.GetCommandLineString() << "\""; |
| 736 } |
| 737 |
692 void HandleOsUpgradeForBrowser(const installer::InstallerState& installer_state, | 738 void HandleOsUpgradeForBrowser(const installer::InstallerState& installer_state, |
693 const installer::Product& chrome, | 739 const installer::Product& chrome, |
694 const base::Version& installed_version) { | 740 const base::Version& installed_version) { |
695 DCHECK(chrome.is_chrome()); | 741 DCHECK(chrome.is_chrome()); |
696 | 742 |
697 VLOG(1) << "Updating and registering shortcuts for --on-os-upgrade."; | 743 VLOG(1) << "Updating and registering shortcuts for --on-os-upgrade."; |
698 | 744 |
699 // Read master_preferences copied beside chrome.exe at install. | 745 // Read master_preferences copied beside chrome.exe at install. |
700 const MasterPreferences prefs( | 746 const MasterPreferences prefs( |
701 installer_state.target_path().AppendASCII(kDefaultMasterPrefs)); | 747 installer_state.target_path().AppendASCII(kDefaultMasterPrefs)); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 // Read master_preferences copied beside chrome.exe at install. | 826 // Read master_preferences copied beside chrome.exe at install. |
781 MasterPreferences prefs(installation_root.AppendASCII(kDefaultMasterPrefs)); | 827 MasterPreferences prefs(installation_root.AppendASCII(kDefaultMasterPrefs)); |
782 base::FilePath chrome_exe(installation_root.Append(kChromeExe)); | 828 base::FilePath chrome_exe(installation_root.Append(kChromeExe)); |
783 CreateOrUpdateShortcuts( | 829 CreateOrUpdateShortcuts( |
784 chrome_exe, chrome, prefs, CURRENT_USER, install_operation); | 830 chrome_exe, chrome, prefs, CURRENT_USER, install_operation); |
785 | 831 |
786 UpdateDefaultBrowserBeaconForPath(chrome_exe); | 832 UpdateDefaultBrowserBeaconForPath(chrome_exe); |
787 } | 833 } |
788 | 834 |
789 } // namespace installer | 835 } // namespace installer |
OLD | NEW |