Index: chrome/installer/setup/setup_main.cc |
diff --git a/chrome/installer/setup/setup_main.cc b/chrome/installer/setup/setup_main.cc |
index 8bdd55c692be09e778be8c91a01c76bf38409fd8..85c46154ed201caad86a29c6b30a6ebd9fe36e58 100644 |
--- a/chrome/installer/setup/setup_main.cc |
+++ b/chrome/installer/setup/setup_main.cc |
@@ -81,6 +81,12 @@ using installer::Products; |
const wchar_t kGoogleUpdatePipeName[] = L"\\\\.\\pipe\\GoogleCrashServices\\"; |
const wchar_t kSystemPrincipalSid[] = L"S-1-5-18"; |
+const wchar_t kDisplayVersion[] = L"DisplayVersion"; |
+const wchar_t kMsiInstallRegistryPrefix[] = |
+ L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\" |
+ L"S-1-5-18\\Products\\"; |
+const wchar_t kMsiInstallRegistryPostfix[] = L"\\InstallProperties"; |
+const wchar_t kMsiDisplayVersionOverwriteDelay[] = L"30"; // seconds as string |
const MINIDUMP_TYPE kLargerDumpType = static_cast<MINIDUMP_TYPE>( |
MiniDumpWithProcessThreadData | // Get PEB and TEB. |
@@ -89,6 +95,67 @@ const MINIDUMP_TYPE kLargerDumpType = static_cast<MINIDUMP_TYPE>( |
namespace { |
+// Overwrite an existing DisplayVersion as written by the MSI installer |
+// with the real version number of Chrome. |
+LONG OverwriteDisplayVersion(const base::string16& path, |
+ const base::string16& value) { |
+ base::win::RegKey key; |
+ LONG result = 0; |
+ base::string16 existing; |
+ if ((result = key.Open(HKEY_LOCAL_MACHINE, path.c_str(), |
+ KEY_QUERY_VALUE | KEY_SET_VALUE | KEY_WOW64_64KEY)) |
+ != ERROR_SUCCESS) { |
+ LOG(ERROR) << "Failed to set DisplayVersion: " << path << " not found"; |
+ return result; |
+ } |
+ if ((result = key.ReadValue(kDisplayVersion, &existing)) != ERROR_SUCCESS) { |
+ LOG(ERROR) << "Failed to set DisplayVersion: " << kDisplayVersion |
+ << " not found under " << path; |
+ return result; |
+ } |
+ if ((result = key.WriteValue(kDisplayVersion, value.c_str())) |
+ != ERROR_SUCCESS) { |
+ LOG(ERROR) << "Failed to set DisplayVersion: " << kDisplayVersion |
+ << " could not be written under " << path; |
+ return result; |
+ } |
+ VLOG(1) << "Set DisplayVersion at " << path << " to " << value |
+ << " from " << existing; |
+ return ERROR_SUCCESS; |
+} |
+ |
+void DelayedOverwriteDisplayVersion(const base::FilePath& setup_exe, |
+ const std::string& id, |
+ const Version& version) { |
+ base::string16 reg_path(kMsiInstallRegistryPrefix); |
+ reg_path += base::UTF8ToUTF16(id); |
+ reg_path += kMsiInstallRegistryPostfix; |
+ |
+ // This process has to be able to exit so we launch ourselves with |
+ // instructions on what to do and then return. |
+ base::CommandLine command_line(setup_exe); |
+ command_line.AppendSwitchNative(installer::switches::kSetDisplayVersionPath, |
+ reg_path); |
+ command_line.AppendSwitchNative(installer::switches::kSetDisplayVersionValue, |
+ base::UTF8ToUTF16(version.GetString())); |
grt (UTC plus 2)
2015/09/02 20:43:55
nit: base::ASCIIToUTF16 here since we're certain t
bcwhite
2015/09/09 18:20:22
Done.
|
+ command_line.AppendSwitchNative(installer::switches::kDelay, |
+ kMsiDisplayVersionOverwriteDelay); |
+ |
+ STARTUPINFOW si = {sizeof(si)}; |
+ PROCESS_INFORMATION pi = {0}; |
+ if (!::CreateProcess(setup_exe.value().c_str(), |
+ &command_line.GetCommandLineString()[0], |
+ NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, |
+ &si, &pi)) { |
+ LOG(ERROR) << "Failed to set DisplayVersion: " |
+ << "could not launch subprocess to make desired changes." |
+ << " (error=" << ::GetLastError() << ")\n" |
+ << command_line.GetCommandLineString(); |
+ return; |
+ } |
+ ::CloseHandle(pi.hThread); |
+} |
+ |
// Returns NULL if no compressed archive is available for processing, otherwise |
// returns a patch helper configured to uncompress and patch. |
scoped_ptr<installer::ArchivePatchHelper> CreateChromeArchiveHelper( |
@@ -919,6 +986,18 @@ bool HandleNonInstallCmdLineOptions(const InstallationState& original_state, |
const base::CommandLine& cmd_line, |
InstallerState* installer_state, |
int* exit_code) { |
+ // This option is independent of all others so doesn't belong in the if/else |
+ // block below. |
+ if (cmd_line.HasSwitch(installer::switches::kDelay)) { |
+ const std::string delay_seconds_string( |
+ cmd_line.GetSwitchValueASCII(installer::switches::kDelay)); |
+ int delay_seconds; |
+ if (base::StringToInt(delay_seconds_string, &delay_seconds) && |
+ delay_seconds > 0) { |
+ ::Sleep(delay_seconds * 1000); |
grt (UTC plus 2)
2015/09/02 20:43:55
if sleeping is really the only way to do this (as
bcwhite
2015/09/09 18:20:23
Done.
I think the best way is to have the process
|
+ } |
+ } |
+ |
// TODO(gab): Add a local |status| variable which each block below sets; |
// only determine the |exit_code| from |status| at the end (this will allow |
// this method to validate that |
@@ -1162,6 +1241,14 @@ bool HandleNonInstallCmdLineOptions(const InstallationState& original_state, |
bool updates_enabled = GoogleUpdateSettings::ReenableAutoupdates(); |
*exit_code = updates_enabled ? installer::REENABLE_UPDATES_SUCCEEDED : |
installer::REENABLE_UPDATES_FAILED; |
+ } else if (cmd_line.HasSwitch(installer::switches::kSetDisplayVersionPath)) { |
+ const base::string16 registry_path( |
+ cmd_line.GetSwitchValueNative( |
+ installer::switches::kSetDisplayVersionPath)); |
+ const base::string16 registry_value( |
+ cmd_line.GetSwitchValueNative( |
+ installer::switches::kSetDisplayVersionValue)); |
+ *exit_code = OverwriteDisplayVersion(registry_path, registry_value); |
} else { |
handled = false; |
} |
@@ -1546,13 +1633,22 @@ InstallStatus InstallProductsHelper(const InstallationState& original_state, |
} |
} |
- // If installation completed successfully, return the path to the directory |
- // containing the newly installed setup.exe and uncompressed archive if the |
- // caller requested it. |
- if (installer_directory && |
- InstallUtil::GetInstallReturnCode(install_status) == 0) { |
- *installer_directory = |
- installer_state.GetInstallerDirectory(*installer_version); |
+ // If the installation completed successfully... |
+ if (InstallUtil::GetInstallReturnCode(install_status) == 0) { |
+ // Update the DisplayVersion created by an MSI-based install. |
+ std::string install_id; |
grt (UTC plus 2)
2015/09/02 20:43:55
nit: move install_id and new_setup into the body o
bcwhite
2015/09/09 18:20:22
install_id is used by the "if" statement but I've
|
+ base::FilePath new_setup = |
+ installer_state.GetInstallerDirectory(*installer_version); |
grt (UTC plus 2)
2015/09/02 20:43:55
four-space indent
bcwhite
2015/09/09 18:20:22
Done.
|
+ new_setup.Append(kSetupExe); |
grt (UTC plus 2)
2015/09/02 20:43:55
either "new_setup = new_setup.Append(kSetupExe);",
bcwhite
2015/09/09 18:20:22
Done.
|
+ if (prefs.GetString(installer::master_preferences::kMsiProductId, |
+ &install_id)) { |
+ DelayedOverwriteDisplayVersion(new_setup, install_id, *installer_version); |
+ } |
+ // Return the path to the directory containing the newly installed |
+ // setup.exe and uncompressed archive if the caller requested it. |
+ if (installer_directory) |
grt (UTC plus 2)
2015/09/02 20:43:55
nit: braces for multi-line body
bcwhite
2015/09/09 18:20:23
Done.
|
+ *installer_directory = |
+ installer_state.GetInstallerDirectory(*installer_version); |
} |
// temp_path's dtor will take care of deleting or scheduling itself for |