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

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

Issue 1271893003: Add options to write version number to registry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix parethesis Created 5 years, 3 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
« no previous file with comments | « chrome/installer/setup/setup_constants.cc ('k') | chrome/installer/setup/setup_util.h » ('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/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
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
86 const MINIDUMP_TYPE kLargerDumpType = static_cast<MINIDUMP_TYPE>( 83 const MINIDUMP_TYPE kLargerDumpType = static_cast<MINIDUMP_TYPE>(
87 MiniDumpWithProcessThreadData | // Get PEB and TEB. 84 MiniDumpWithProcessThreadData | // Get PEB and TEB.
88 MiniDumpWithUnloadedModules | // Get unloaded modules when available. 85 MiniDumpWithUnloadedModules | // Get unloaded modules when available.
89 MiniDumpWithIndirectlyReferencedMemory); // Get memory referenced by stack. 86 MiniDumpWithIndirectlyReferencedMemory); // Get memory referenced by stack.
90 87
91 namespace { 88 namespace {
92 89
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).c_str());
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.c_str());
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
93 // Returns NULL if no compressed archive is available for processing, otherwise 170 // Returns NULL if no compressed archive is available for processing, otherwise
94 // returns a patch helper configured to uncompress and patch. 171 // returns a patch helper configured to uncompress and patch.
95 scoped_ptr<installer::ArchivePatchHelper> CreateChromeArchiveHelper( 172 scoped_ptr<installer::ArchivePatchHelper> CreateChromeArchiveHelper(
96 const base::FilePath& setup_exe, 173 const base::FilePath& setup_exe,
97 const base::CommandLine& command_line, 174 const base::CommandLine& command_line,
98 const installer::InstallerState& installer_state, 175 const installer::InstallerState& installer_state,
99 const base::FilePath& working_directory) { 176 const base::FilePath& working_directory) {
100 // A compressed archive is ordinarily given on the command line by the mini 177 // A compressed archive is ordinarily given on the command line by the mini
101 // installer. If one was not given, look for chrome.packed.7z next to the 178 // installer. If one was not given, look for chrome.packed.7z next to the
102 // running program. 179 // running program.
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 990
914 // This method processes any command line options that make setup.exe do 991 // This method processes any command line options that make setup.exe do
915 // various tasks other than installation (renaming chrome.exe, showing eula 992 // various tasks other than installation (renaming chrome.exe, showing eula
916 // among others). This function returns true if any such command line option 993 // among others). This function returns true if any such command line option
917 // has been found and processed (so setup.exe should exit at that point). 994 // has been found and processed (so setup.exe should exit at that point).
918 bool HandleNonInstallCmdLineOptions(const InstallationState& original_state, 995 bool HandleNonInstallCmdLineOptions(const InstallationState& original_state,
919 const base::FilePath& setup_exe, 996 const base::FilePath& setup_exe,
920 const base::CommandLine& cmd_line, 997 const base::CommandLine& cmd_line,
921 InstallerState* installer_state, 998 InstallerState* installer_state,
922 int* exit_code) { 999 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
923 // TODO(gab): Add a local |status| variable which each block below sets; 1012 // TODO(gab): Add a local |status| variable which each block below sets;
924 // only determine the |exit_code| from |status| at the end (this will allow 1013 // only determine the |exit_code| from |status| at the end (this will allow
925 // this method to validate that 1014 // this method to validate that
926 // (!handled || status != installer::UNKNOWN_STATUS)). 1015 // (!handled || status != installer::UNKNOWN_STATUS)).
927 bool handled = true; 1016 bool handled = true;
928 // TODO(tommi): Split these checks up into functions and use a data driven 1017 // TODO(tommi): Split these checks up into functions and use a data driven
929 // map of switch->function. 1018 // map of switch->function.
930 if (cmd_line.HasSwitch(installer::switches::kUpdateSetupExe)) { 1019 if (cmd_line.HasSwitch(installer::switches::kUpdateSetupExe)) {
931 installer::InstallStatus status = installer::SETUP_PATCH_FAILED; 1020 installer::InstallStatus status = installer::SETUP_PATCH_FAILED;
932 // If --update-setup-exe command line option is given, we apply the given 1021 // 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
1156 patch_file, 1245 patch_file,
1157 output_file); 1246 output_file);
1158 } else { 1247 } else {
1159 *exit_code = installer::PATCH_INVALID_ARGUMENTS; 1248 *exit_code = installer::PATCH_INVALID_ARGUMENTS;
1160 } 1249 }
1161 } else if (cmd_line.HasSwitch(installer::switches::kReenableAutoupdates)) { 1250 } else if (cmd_line.HasSwitch(installer::switches::kReenableAutoupdates)) {
1162 // setup.exe has been asked to attempt to reenable updates for Chrome. 1251 // setup.exe has been asked to attempt to reenable updates for Chrome.
1163 bool updates_enabled = GoogleUpdateSettings::ReenableAutoupdates(); 1252 bool updates_enabled = GoogleUpdateSettings::ReenableAutoupdates();
1164 *exit_code = updates_enabled ? installer::REENABLE_UPDATES_SUCCEEDED : 1253 *exit_code = updates_enabled ? installer::REENABLE_UPDATES_SUCCEEDED :
1165 installer::REENABLE_UPDATES_FAILED; 1254 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);
1166 } else { 1264 } else {
1167 handled = false; 1265 handled = false;
1168 } 1266 }
1169 1267
1170 return handled; 1268 return handled;
1171 } 1269 }
1172 1270
1173 // Returns the Custom information for the client identified by the exe path 1271 // Returns the Custom information for the client identified by the exe path
1174 // passed in. This information is used for crash reporting. 1272 // passed in. This information is used for crash reporting.
1175 google_breakpad::CustomClientInfo* GetCustomInfo(const wchar_t* exe_path) { 1273 google_breakpad::CustomClientInfo* GetCustomInfo(const wchar_t* exe_path) {
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 .Append(setup_path.BaseName()); 1644 .Append(setup_path.BaseName());
1547 } 1645 }
1548 const Products& products = installer_state.products(); 1646 const Products& products = installer_state.products();
1549 for (Products::const_iterator it = products.begin(); it < products.end(); 1647 for (Products::const_iterator it = products.begin(); it < products.end();
1550 ++it) { 1648 ++it) {
1551 const Product& product = **it; 1649 const Product& product = **it;
1552 product.LaunchUserExperiment(setup_path, install_status, system_install); 1650 product.LaunchUserExperiment(setup_path, install_status, system_install);
1553 } 1651 }
1554 } 1652 }
1555 1653
1556 // If installation completed successfully, return the path to the directory 1654 // If the installation completed successfully...
1557 // containing the newly installed setup.exe and uncompressed archive if the 1655 if (InstallUtil::GetInstallReturnCode(install_status) == 0) {
1558 // caller requested it. 1656 // Update the DisplayVersion created by an MSI-based install.
1559 if (installer_directory && 1657 std::string install_id;
1560 InstallUtil::GetInstallReturnCode(install_status) == 0) { 1658 if (prefs.GetString(installer::master_preferences::kMsiProductId,
1561 *installer_directory = 1659 &install_id)) {
1562 installer_state.GetInstallerDirectory(*installer_version); 1660 base::FilePath new_setup =
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 }
1563 } 1672 }
1564 1673
1565 // temp_path's dtor will take care of deleting or scheduling itself for 1674 // temp_path's dtor will take care of deleting or scheduling itself for
1566 // deletion at reboot when this scope closes. 1675 // deletion at reboot when this scope closes.
1567 VLOG(1) << "Deleting temporary directory " << temp_path.path().value(); 1676 VLOG(1) << "Deleting temporary directory " << temp_path.path().value();
1568 1677
1569 return install_status; 1678 return install_status;
1570 } 1679 }
1571 1680
1572 } // namespace installer 1681 } // namespace installer
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 // Note that we allow the status installer::UNINSTALL_REQUIRES_REBOOT 1826 // Note that we allow the status installer::UNINSTALL_REQUIRES_REBOOT
1718 // to pass through, since this is only returned on uninstall which is 1827 // to pass through, since this is only returned on uninstall which is
1719 // never invoked directly by Google Update. 1828 // never invoked directly by Google Update.
1720 return_code = InstallUtil::GetInstallReturnCode(install_status); 1829 return_code = InstallUtil::GetInstallReturnCode(install_status);
1721 } 1830 }
1722 1831
1723 VLOG(1) << "Installation complete, returning: " << return_code; 1832 VLOG(1) << "Installation complete, returning: " << return_code;
1724 1833
1725 return return_code; 1834 return return_code;
1726 } 1835 }
OLDNEW
« no previous file with comments | « chrome/installer/setup/setup_constants.cc ('k') | chrome/installer/setup/setup_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698