| 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/setup_main.h" | 5 #include "chrome/installer/setup/setup_main.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <msi.h> | 8 #include <msi.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <shlobj.h> | 10 #include <shlobj.h> |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 #endif | 73 #endif |
| 74 | 74 |
| 75 using installer::InstallerState; | 75 using installer::InstallerState; |
| 76 using installer::InstallationState; | 76 using installer::InstallationState; |
| 77 using installer::InstallationValidator; | 77 using installer::InstallationValidator; |
| 78 using installer::MasterPreferences; | 78 using installer::MasterPreferences; |
| 79 using installer::Product; | 79 using installer::Product; |
| 80 using installer::ProductState; | 80 using installer::ProductState; |
| 81 using installer::Products; | 81 using installer::Products; |
| 82 | 82 |
| 83 const wchar_t kGoogleUpdatePipeName[] = L"\\\\.\\pipe\\GoogleCrashServices\\"; |
| 84 const wchar_t kSystemPrincipalSid[] = L"S-1-5-18"; |
| 85 |
| 83 const MINIDUMP_TYPE kLargerDumpType = static_cast<MINIDUMP_TYPE>( | 86 const MINIDUMP_TYPE kLargerDumpType = static_cast<MINIDUMP_TYPE>( |
| 84 MiniDumpWithProcessThreadData | // Get PEB and TEB. | 87 MiniDumpWithProcessThreadData | // Get PEB and TEB. |
| 85 MiniDumpWithUnloadedModules | // Get unloaded modules when available. | 88 MiniDumpWithUnloadedModules | // Get unloaded modules when available. |
| 86 MiniDumpWithIndirectlyReferencedMemory); // Get memory referenced by stack. | 89 MiniDumpWithIndirectlyReferencedMemory); // Get memory referenced by stack. |
| 87 | 90 |
| 88 namespace { | 91 namespace { |
| 89 | 92 |
| 90 const wchar_t kGoogleUpdatePipeName[] = L"\\\\.\\pipe\\GoogleCrashServices\\"; | |
| 91 const wchar_t kSystemPrincipalSid[] = L"S-1-5-18"; | |
| 92 const wchar_t kDisplayVersion[] = L"DisplayVersion"; | |
| 93 const wchar_t kMsiDisplayVersionOverwriteDelay[] = L"10"; // seconds as string | |
| 94 | |
| 95 // Overwrite an existing DisplayVersion as written by the MSI installer | |
| 96 // with the real version number of Chrome. | |
| 97 LONG OverwriteDisplayVersion(const base::string16& path, | |
| 98 const base::string16& value, | |
| 99 REGSAM wowkey) { | |
| 100 base::win::RegKey key; | |
| 101 LONG result = 0; | |
| 102 base::string16 existing; | |
| 103 if ((result = key.Open(HKEY_LOCAL_MACHINE, path.c_str(), | |
| 104 KEY_QUERY_VALUE | KEY_SET_VALUE | wowkey)) | |
| 105 != ERROR_SUCCESS) { | |
| 106 LOG(ERROR) << "Failed to set DisplayVersion: " << path << " not found"; | |
| 107 return result; | |
| 108 } | |
| 109 if ((result = key.ReadValue(kDisplayVersion, &existing)) != ERROR_SUCCESS) { | |
| 110 LOG(ERROR) << "Failed to set DisplayVersion: " << kDisplayVersion | |
| 111 << " not found under " << path; | |
| 112 return result; | |
| 113 } | |
| 114 if ((result = key.WriteValue(kDisplayVersion, value.c_str())) | |
| 115 != ERROR_SUCCESS) { | |
| 116 LOG(ERROR) << "Failed to set DisplayVersion: " << kDisplayVersion | |
| 117 << " could not be written under " << path; | |
| 118 return result; | |
| 119 } | |
| 120 VLOG(1) << "Set DisplayVersion at " << path << " to " << value | |
| 121 << " from " << existing; | |
| 122 return ERROR_SUCCESS; | |
| 123 } | |
| 124 | |
| 125 LONG OverwriteDisplayVersions(const base::string16& product, | |
| 126 const base::string16& value) { | |
| 127 // The version is held in two places. Frist change it in the MSI Installer | |
| 128 // registry entry. It is held under a "squashed guid" key. | |
| 129 base::string16 reg_path = base::StringPrintf( | |
| 130 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\" | |
| 131 L"%ls\\Products\\%ls\\InstallProperties", kSystemPrincipalSid, | |
| 132 installer::GuidToSquid(product)); | |
| 133 LONG result1 = OverwriteDisplayVersion(reg_path, value, KEY_WOW64_64KEY); | |
| 134 | |
| 135 // The display version also exists under the Unininstall registry key with | |
| 136 // the original guid. Check both WOW64_64 and WOW64_32. | |
| 137 reg_path = base::StringPrintf( | |
| 138 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{%ls}", | |
| 139 product); | |
| 140 LONG result2 = OverwriteDisplayVersion(reg_path, value, KEY_WOW64_64KEY); | |
| 141 if (result2 != ERROR_SUCCESS) | |
| 142 result2 = OverwriteDisplayVersion(reg_path, value, KEY_WOW64_32KEY); | |
| 143 | |
| 144 return result1 != ERROR_SUCCESS ? result1 : result2; | |
| 145 } | |
| 146 | |
| 147 void DelayedOverwriteDisplayVersions(const base::FilePath& setup_exe, | |
| 148 const std::string& id, | |
| 149 const Version& version) { | |
| 150 // This process has to be able to exit so we launch ourselves with | |
| 151 // instructions on what to do and then return. | |
| 152 base::CommandLine command_line(setup_exe); | |
| 153 command_line.AppendSwitchASCII(installer::switches::kSetDisplayVersionProduct, | |
| 154 id); | |
| 155 command_line.AppendSwitchASCII(installer::switches::kSetDisplayVersionValue, | |
| 156 version.GetString()); | |
| 157 command_line.AppendSwitchNative(installer::switches::kDelay, | |
| 158 kMsiDisplayVersionOverwriteDelay); | |
| 159 | |
| 160 base::LaunchOptions launch_options; | |
| 161 launch_options.force_breakaway_from_job_ = true; | |
| 162 base::Process writer = base::LaunchProcess(command_line, launch_options); | |
| 163 if (!writer.IsValid()) { | |
| 164 PLOG(ERROR) << "Failed to set DisplayVersion: " | |
| 165 << "could not launch subprocess to make desired changes." | |
| 166 << " <<" << command_line.GetCommandLineString() << ">>"; | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 // Returns NULL if no compressed archive is available for processing, otherwise | 93 // Returns NULL if no compressed archive is available for processing, otherwise |
| 171 // returns a patch helper configured to uncompress and patch. | 94 // returns a patch helper configured to uncompress and patch. |
| 172 scoped_ptr<installer::ArchivePatchHelper> CreateChromeArchiveHelper( | 95 scoped_ptr<installer::ArchivePatchHelper> CreateChromeArchiveHelper( |
| 173 const base::FilePath& setup_exe, | 96 const base::FilePath& setup_exe, |
| 174 const base::CommandLine& command_line, | 97 const base::CommandLine& command_line, |
| 175 const installer::InstallerState& installer_state, | 98 const installer::InstallerState& installer_state, |
| 176 const base::FilePath& working_directory) { | 99 const base::FilePath& working_directory) { |
| 177 // A compressed archive is ordinarily given on the command line by the mini | 100 // A compressed archive is ordinarily given on the command line by the mini |
| 178 // installer. If one was not given, look for chrome.packed.7z next to the | 101 // installer. If one was not given, look for chrome.packed.7z next to the |
| 179 // running program. | 102 // running program. |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 | 913 |
| 991 // This method processes any command line options that make setup.exe do | 914 // This method processes any command line options that make setup.exe do |
| 992 // various tasks other than installation (renaming chrome.exe, showing eula | 915 // various tasks other than installation (renaming chrome.exe, showing eula |
| 993 // among others). This function returns true if any such command line option | 916 // among others). This function returns true if any such command line option |
| 994 // has been found and processed (so setup.exe should exit at that point). | 917 // has been found and processed (so setup.exe should exit at that point). |
| 995 bool HandleNonInstallCmdLineOptions(const InstallationState& original_state, | 918 bool HandleNonInstallCmdLineOptions(const InstallationState& original_state, |
| 996 const base::FilePath& setup_exe, | 919 const base::FilePath& setup_exe, |
| 997 const base::CommandLine& cmd_line, | 920 const base::CommandLine& cmd_line, |
| 998 InstallerState* installer_state, | 921 InstallerState* installer_state, |
| 999 int* exit_code) { | 922 int* exit_code) { |
| 1000 // This option is independent of all others so doesn't belong in the if/else | |
| 1001 // block below. | |
| 1002 if (cmd_line.HasSwitch(installer::switches::kDelay)) { | |
| 1003 const std::string delay_seconds_string( | |
| 1004 cmd_line.GetSwitchValueASCII(installer::switches::kDelay)); | |
| 1005 int delay_seconds; | |
| 1006 if (base::StringToInt(delay_seconds_string, &delay_seconds) && | |
| 1007 delay_seconds > 0) { | |
| 1008 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(delay_seconds)); | |
| 1009 } | |
| 1010 } | |
| 1011 | |
| 1012 // TODO(gab): Add a local |status| variable which each block below sets; | 923 // TODO(gab): Add a local |status| variable which each block below sets; |
| 1013 // only determine the |exit_code| from |status| at the end (this will allow | 924 // only determine the |exit_code| from |status| at the end (this will allow |
| 1014 // this method to validate that | 925 // this method to validate that |
| 1015 // (!handled || status != installer::UNKNOWN_STATUS)). | 926 // (!handled || status != installer::UNKNOWN_STATUS)). |
| 1016 bool handled = true; | 927 bool handled = true; |
| 1017 // TODO(tommi): Split these checks up into functions and use a data driven | 928 // TODO(tommi): Split these checks up into functions and use a data driven |
| 1018 // map of switch->function. | 929 // map of switch->function. |
| 1019 if (cmd_line.HasSwitch(installer::switches::kUpdateSetupExe)) { | 930 if (cmd_line.HasSwitch(installer::switches::kUpdateSetupExe)) { |
| 1020 installer::InstallStatus status = installer::SETUP_PATCH_FAILED; | 931 installer::InstallStatus status = installer::SETUP_PATCH_FAILED; |
| 1021 // If --update-setup-exe command line option is given, we apply the given | 932 // If --update-setup-exe command line option is given, we apply the given |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 patch_file, | 1156 patch_file, |
| 1246 output_file); | 1157 output_file); |
| 1247 } else { | 1158 } else { |
| 1248 *exit_code = installer::PATCH_INVALID_ARGUMENTS; | 1159 *exit_code = installer::PATCH_INVALID_ARGUMENTS; |
| 1249 } | 1160 } |
| 1250 } else if (cmd_line.HasSwitch(installer::switches::kReenableAutoupdates)) { | 1161 } else if (cmd_line.HasSwitch(installer::switches::kReenableAutoupdates)) { |
| 1251 // setup.exe has been asked to attempt to reenable updates for Chrome. | 1162 // setup.exe has been asked to attempt to reenable updates for Chrome. |
| 1252 bool updates_enabled = GoogleUpdateSettings::ReenableAutoupdates(); | 1163 bool updates_enabled = GoogleUpdateSettings::ReenableAutoupdates(); |
| 1253 *exit_code = updates_enabled ? installer::REENABLE_UPDATES_SUCCEEDED : | 1164 *exit_code = updates_enabled ? installer::REENABLE_UPDATES_SUCCEEDED : |
| 1254 installer::REENABLE_UPDATES_FAILED; | 1165 installer::REENABLE_UPDATES_FAILED; |
| 1255 } else if (cmd_line.HasSwitch( | |
| 1256 installer::switches::kSetDisplayVersionProduct)) { | |
| 1257 const base::string16 registry_product( | |
| 1258 cmd_line.GetSwitchValueNative( | |
| 1259 installer::switches::kSetDisplayVersionProduct)); | |
| 1260 const base::string16 registry_value( | |
| 1261 cmd_line.GetSwitchValueNative( | |
| 1262 installer::switches::kSetDisplayVersionValue)); | |
| 1263 *exit_code = OverwriteDisplayVersions(registry_product, registry_value); | |
| 1264 } else { | 1166 } else { |
| 1265 handled = false; | 1167 handled = false; |
| 1266 } | 1168 } |
| 1267 | 1169 |
| 1268 return handled; | 1170 return handled; |
| 1269 } | 1171 } |
| 1270 | 1172 |
| 1271 // Returns the Custom information for the client identified by the exe path | 1173 // Returns the Custom information for the client identified by the exe path |
| 1272 // passed in. This information is used for crash reporting. | 1174 // passed in. This information is used for crash reporting. |
| 1273 google_breakpad::CustomClientInfo* GetCustomInfo(const wchar_t* exe_path) { | 1175 google_breakpad::CustomClientInfo* GetCustomInfo(const wchar_t* exe_path) { |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1644 .Append(setup_path.BaseName()); | 1546 .Append(setup_path.BaseName()); |
| 1645 } | 1547 } |
| 1646 const Products& products = installer_state.products(); | 1548 const Products& products = installer_state.products(); |
| 1647 for (Products::const_iterator it = products.begin(); it < products.end(); | 1549 for (Products::const_iterator it = products.begin(); it < products.end(); |
| 1648 ++it) { | 1550 ++it) { |
| 1649 const Product& product = **it; | 1551 const Product& product = **it; |
| 1650 product.LaunchUserExperiment(setup_path, install_status, system_install); | 1552 product.LaunchUserExperiment(setup_path, install_status, system_install); |
| 1651 } | 1553 } |
| 1652 } | 1554 } |
| 1653 | 1555 |
| 1654 // If the installation completed successfully... | 1556 // If installation completed successfully, return the path to the directory |
| 1655 if (InstallUtil::GetInstallReturnCode(install_status) == 0) { | 1557 // containing the newly installed setup.exe and uncompressed archive if the |
| 1656 // Update the DisplayVersion created by an MSI-based install. | 1558 // caller requested it. |
| 1657 std::string install_id; | 1559 if (installer_directory && |
| 1658 if (prefs.GetString(installer::master_preferences::kMsiProductId, | 1560 InstallUtil::GetInstallReturnCode(install_status) == 0) { |
| 1659 &install_id)) { | 1561 *installer_directory = |
| 1660 base::FilePath new_setup = | 1562 installer_state.GetInstallerDirectory(*installer_version); |
| 1661 installer_state.GetInstallerDirectory(*installer_version) | |
| 1662 .Append(kSetupExe); | |
| 1663 DelayedOverwriteDisplayVersions( | |
| 1664 new_setup, install_id, *installer_version); | |
| 1665 } | |
| 1666 // Return the path to the directory containing the newly installed | |
| 1667 // setup.exe and uncompressed archive if the caller requested it. | |
| 1668 if (installer_directory) { | |
| 1669 *installer_directory = | |
| 1670 installer_state.GetInstallerDirectory(*installer_version); | |
| 1671 } | |
| 1672 } | 1563 } |
| 1673 | 1564 |
| 1674 // temp_path's dtor will take care of deleting or scheduling itself for | 1565 // temp_path's dtor will take care of deleting or scheduling itself for |
| 1675 // deletion at reboot when this scope closes. | 1566 // deletion at reboot when this scope closes. |
| 1676 VLOG(1) << "Deleting temporary directory " << temp_path.path().value(); | 1567 VLOG(1) << "Deleting temporary directory " << temp_path.path().value(); |
| 1677 | 1568 |
| 1678 return install_status; | 1569 return install_status; |
| 1679 } | 1570 } |
| 1680 | 1571 |
| 1681 } // namespace installer | 1572 } // namespace installer |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1826 // Note that we allow the status installer::UNINSTALL_REQUIRES_REBOOT | 1717 // Note that we allow the status installer::UNINSTALL_REQUIRES_REBOOT |
| 1827 // to pass through, since this is only returned on uninstall which is | 1718 // to pass through, since this is only returned on uninstall which is |
| 1828 // never invoked directly by Google Update. | 1719 // never invoked directly by Google Update. |
| 1829 return_code = InstallUtil::GetInstallReturnCode(install_status); | 1720 return_code = InstallUtil::GetInstallReturnCode(install_status); |
| 1830 } | 1721 } |
| 1831 | 1722 |
| 1832 VLOG(1) << "Installation complete, returning: " << return_code; | 1723 VLOG(1) << "Installation complete, returning: " << return_code; |
| 1833 | 1724 |
| 1834 return return_code; | 1725 return return_code; |
| 1835 } | 1726 } |
| OLD | NEW |