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

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

Issue 2292293002: Add installer::SetupSingleton. (Closed)
Patch Set: cleanup diff Created 4 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
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "base/win/windows_version.h" 44 #include "base/win/windows_version.h"
45 #include "chrome/common/chrome_constants.h" 45 #include "chrome/common/chrome_constants.h"
46 #include "chrome/common/chrome_paths.h" 46 #include "chrome/common/chrome_paths.h"
47 #include "chrome/common/chrome_switches.h" 47 #include "chrome/common/chrome_switches.h"
48 #include "chrome/installer/setup/archive_patch_helper.h" 48 #include "chrome/installer/setup/archive_patch_helper.h"
49 #include "chrome/installer/setup/install.h" 49 #include "chrome/installer/setup/install.h"
50 #include "chrome/installer/setup/install_worker.h" 50 #include "chrome/installer/setup/install_worker.h"
51 #include "chrome/installer/setup/installer_crash_reporting.h" 51 #include "chrome/installer/setup/installer_crash_reporting.h"
52 #include "chrome/installer/setup/installer_metrics.h" 52 #include "chrome/installer/setup/installer_metrics.h"
53 #include "chrome/installer/setup/setup_constants.h" 53 #include "chrome/installer/setup/setup_constants.h"
54 #include "chrome/installer/setup/setup_singleton.h"
54 #include "chrome/installer/setup/setup_util.h" 55 #include "chrome/installer/setup/setup_util.h"
55 #include "chrome/installer/setup/uninstall.h" 56 #include "chrome/installer/setup/uninstall.h"
56 #include "chrome/installer/util/browser_distribution.h" 57 #include "chrome/installer/util/browser_distribution.h"
57 #include "chrome/installer/util/delete_after_reboot_helper.h" 58 #include "chrome/installer/util/delete_after_reboot_helper.h"
58 #include "chrome/installer/util/delete_tree_work_item.h" 59 #include "chrome/installer/util/delete_tree_work_item.h"
59 #include "chrome/installer/util/google_update_constants.h" 60 #include "chrome/installer/util/google_update_constants.h"
60 #include "chrome/installer/util/google_update_settings.h" 61 #include "chrome/installer/util/google_update_settings.h"
61 #include "chrome/installer/util/google_update_util.h" 62 #include "chrome/installer/util/google_update_util.h"
62 #include "chrome/installer/util/helper.h" 63 #include "chrome/installer/util/helper.h"
63 #include "chrome/installer/util/html_dialog.h" 64 #include "chrome/installer/util/html_dialog.h"
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 LOG(ERROR) << "Path not found: " << chrome_exe.value(); 1083 LOG(ERROR) << "Path not found: " << chrome_exe.value();
1083 status = installer::INSTALL_FAILED; 1084 status = installer::INSTALL_FAILED;
1084 } 1085 }
1085 return status; 1086 return status;
1086 } 1087 }
1087 1088
1088 // This method processes any command line options that make setup.exe do 1089 // This method processes any command line options that make setup.exe do
1089 // various tasks other than installation (renaming chrome.exe, showing eula 1090 // various tasks other than installation (renaming chrome.exe, showing eula
1090 // among others). This function returns true if any such command line option 1091 // among others). This function returns true if any such command line option
1091 // has been found and processed (so setup.exe should exit at that point). 1092 // has been found and processed (so setup.exe should exit at that point).
1092 bool HandleNonInstallCmdLineOptions(const InstallationState& original_state, 1093 bool HandleNonInstallCmdLineOptions(const base::FilePath& setup_exe,
1093 const base::FilePath& setup_exe,
1094 const base::CommandLine& cmd_line, 1094 const base::CommandLine& cmd_line,
1095 InstallationState* original_state,
1095 InstallerState* installer_state, 1096 InstallerState* installer_state,
1096 int* exit_code) { 1097 int* exit_code) {
1097 // This option is independent of all others so doesn't belong in the if/else 1098 // This option is independent of all others so doesn't belong in the if/else
1098 // block below. 1099 // block below.
1099 if (cmd_line.HasSwitch(installer::switches::kDelay)) { 1100 if (cmd_line.HasSwitch(installer::switches::kDelay)) {
1100 const std::string delay_seconds_string( 1101 const std::string delay_seconds_string(
1101 cmd_line.GetSwitchValueASCII(installer::switches::kDelay)); 1102 cmd_line.GetSwitchValueASCII(installer::switches::kDelay));
1102 int delay_seconds; 1103 int delay_seconds;
1103 if (base::StringToInt(delay_seconds_string, &delay_seconds) && 1104 if (base::StringToInt(delay_seconds_string, &delay_seconds) &&
1104 delay_seconds > 0) { 1105 delay_seconds > 0) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 } 1152 }
1152 } else if (cmd_line.HasSwitch(installer::switches::kShowEula)) { 1153 } else if (cmd_line.HasSwitch(installer::switches::kShowEula)) {
1153 // Check if we need to show the EULA. If it is passed as a command line 1154 // Check if we need to show the EULA. If it is passed as a command line
1154 // then the dialog is shown and regardless of the outcome setup exits here. 1155 // then the dialog is shown and regardless of the outcome setup exits here.
1155 base::string16 inner_frame = 1156 base::string16 inner_frame =
1156 cmd_line.GetSwitchValueNative(installer::switches::kShowEula); 1157 cmd_line.GetSwitchValueNative(installer::switches::kShowEula);
1157 *exit_code = ShowEULADialog(inner_frame); 1158 *exit_code = ShowEULADialog(inner_frame);
1158 1159
1159 if (installer::EULA_REJECTED != *exit_code) { 1160 if (installer::EULA_REJECTED != *exit_code) {
1160 if (GoogleUpdateSettings::SetEULAConsent( 1161 if (GoogleUpdateSettings::SetEULAConsent(
1161 original_state, BrowserDistribution::GetDistribution(), true)) { 1162 *original_state, BrowserDistribution::GetDistribution(), true)) {
1162 CreateEULASentinel(BrowserDistribution::GetDistribution()); 1163 CreateEULASentinel(BrowserDistribution::GetDistribution());
1163 } 1164 }
1164 // For a metro-originated launch, we now need to launch back into metro. 1165 // For a metro-originated launch, we now need to launch back into metro.
1165 if (cmd_line.HasSwitch(installer::switches::kShowEulaForMetro)) 1166 if (cmd_line.HasSwitch(installer::switches::kShowEulaForMetro))
1166 ActivateMetroChrome(); 1167 ActivateMetroChrome();
1167 } 1168 }
1168 } else if (cmd_line.HasSwitch(installer::switches::kConfigureUserSettings)) { 1169 } else if (cmd_line.HasSwitch(installer::switches::kConfigureUserSettings)) {
1169 // NOTE: Should the work done here, on kConfigureUserSettings, change: 1170 // NOTE: Should the work done here, on kConfigureUserSettings, change:
1170 // kActiveSetupVersion in install_worker.cc needs to be increased for Active 1171 // kActiveSetupVersion in install_worker.cc needs to be increased for Active
1171 // Setup to invoke this again for all users of this install. 1172 // Setup to invoke this again for all users of this install.
1172 const Product* chrome_install = 1173 const Product* chrome_install =
1173 installer_state->FindProduct(BrowserDistribution::CHROME_BROWSER); 1174 installer_state->FindProduct(BrowserDistribution::CHROME_BROWSER);
1174 installer::InstallStatus status = installer::INVALID_STATE_FOR_OPTION; 1175 installer::InstallStatus status = installer::INVALID_STATE_FOR_OPTION;
1175 if (chrome_install && installer_state->system_install()) { 1176 if (chrome_install && installer_state->system_install()) {
1176 bool force = 1177 bool force =
1177 cmd_line.HasSwitch(installer::switches::kForceConfigureUserSettings); 1178 cmd_line.HasSwitch(installer::switches::kForceConfigureUserSettings);
1178 installer::HandleActiveSetupForBrowser(installer_state->target_path(), 1179 installer::HandleActiveSetupForBrowser(installer_state->target_path(),
1179 *chrome_install, force); 1180 *chrome_install, force);
1180 status = installer::INSTALL_REPAIRED; 1181 status = installer::INSTALL_REPAIRED;
1181 } else { 1182 } else {
1182 LOG(DFATAL) << "chrome_install:" << chrome_install 1183 LOG(DFATAL) << "chrome_install:" << chrome_install
1183 << ", system_install:" << installer_state->system_install(); 1184 << ", system_install:" << installer_state->system_install();
1184 } 1185 }
1185 *exit_code = InstallUtil::GetInstallReturnCode(status); 1186 *exit_code = InstallUtil::GetInstallReturnCode(status);
1186 } else if (cmd_line.HasSwitch(installer::switches::kRegisterDevChrome)) { 1187 } else if (cmd_line.HasSwitch(installer::switches::kRegisterDevChrome)) {
1187 installer::InstallStatus status = RegisterDevChrome( 1188 installer::InstallStatus status = RegisterDevChrome(
1188 original_state, *installer_state, setup_exe, cmd_line); 1189 *original_state, *installer_state, setup_exe, cmd_line);
1189 *exit_code = InstallUtil::GetInstallReturnCode(status); 1190 *exit_code = InstallUtil::GetInstallReturnCode(status);
1190 } else if (cmd_line.HasSwitch(installer::switches::kRegisterChromeBrowser)) { 1191 } else if (cmd_line.HasSwitch(installer::switches::kRegisterChromeBrowser)) {
1191 installer::InstallStatus status = installer::UNKNOWN_STATUS; 1192 installer::InstallStatus status = installer::UNKNOWN_STATUS;
1192 const Product* chrome_install = 1193 const Product* chrome_install =
1193 installer_state->FindProduct(BrowserDistribution::CHROME_BROWSER); 1194 installer_state->FindProduct(BrowserDistribution::CHROME_BROWSER);
1194 if (chrome_install) { 1195 if (chrome_install) {
1195 // If --register-chrome-browser option is specified, register all 1196 // If --register-chrome-browser option is specified, register all
1196 // Chrome protocol/file associations, as well as register it as a valid 1197 // Chrome protocol/file associations, as well as register it as a valid
1197 // browser for Start Menu->Internet shortcut. This switch will also 1198 // browser for Start Menu->Internet shortcut. This switch will also
1198 // register Chrome as a valid handler for a set of URL protocols that 1199 // register Chrome as a valid handler for a set of URL protocols that
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 chrome_exe, suffix, false)) 1232 chrome_exe, suffix, false))
1232 status = installer::IN_USE_UPDATED; 1233 status = installer::IN_USE_UPDATED;
1233 } 1234 }
1234 } else { 1235 } else {
1235 LOG(DFATAL) << "Can't register browser - Chrome distribution not found"; 1236 LOG(DFATAL) << "Can't register browser - Chrome distribution not found";
1236 } 1237 }
1237 *exit_code = InstallUtil::GetInstallReturnCode(status); 1238 *exit_code = InstallUtil::GetInstallReturnCode(status);
1238 } else if (cmd_line.HasSwitch(installer::switches::kRenameChromeExe)) { 1239 } else if (cmd_line.HasSwitch(installer::switches::kRenameChromeExe)) {
1239 // If --rename-chrome-exe is specified, we want to rename the executables 1240 // If --rename-chrome-exe is specified, we want to rename the executables
1240 // and exit. 1241 // and exit.
1241 *exit_code = RenameChromeExecutables(original_state, installer_state); 1242 std::unique_ptr<installer::SetupSingleton> setup_singleton(
1243 installer::SetupSingleton::Acquire(
1244 cmd_line, MasterPreferences::ForCurrentProcess(), installer_state,
1245 original_state));
1246 if (setup_singleton)
1247 *exit_code = RenameChromeExecutables(*original_state, installer_state);
1248 else
1249 *exit_code = installer::SETUP_SINGLETON_ACQUISITION_FAILED;
1242 } else if (cmd_line.HasSwitch( 1250 } else if (cmd_line.HasSwitch(
1243 installer::switches::kRemoveChromeRegistration)) { 1251 installer::switches::kRemoveChromeRegistration)) {
1244 // This is almost reverse of --register-chrome-browser option above. 1252 // This is almost reverse of --register-chrome-browser option above.
1245 // Here we delete Chrome browser registration. This option should only 1253 // Here we delete Chrome browser registration. This option should only
1246 // be used when setup.exe is launched with admin rights. We do not 1254 // be used when setup.exe is launched with admin rights. We do not
1247 // make any user specific changes in this option. 1255 // make any user specific changes in this option.
1248 base::string16 suffix; 1256 base::string16 suffix;
1249 if (cmd_line.HasSwitch( 1257 if (cmd_line.HasSwitch(
1250 installer::switches::kRegisterChromeBrowserSuffix)) { 1258 installer::switches::kRegisterChromeBrowserSuffix)) {
1251 suffix = cmd_line.GetSwitchValueNative( 1259 suffix = cmd_line.GetSwitchValueNative(
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 // the path service is the authoritative source for this path. One might think 1814 // the path service is the authoritative source for this path. One might think
1807 // that CommandLine::GetProgram would suffice, but it won't since 1815 // that CommandLine::GetProgram would suffice, but it won't since
1808 // CreateProcess may have been called with a command line that is somewhat 1816 // CreateProcess may have been called with a command line that is somewhat
1809 // ambiguous (e.g., an unquoted path with spaces, or a path lacking the file 1817 // ambiguous (e.g., an unquoted path with spaces, or a path lacking the file
1810 // extension), in which case CommandLineToArgv will not yield an argv with the 1818 // extension), in which case CommandLineToArgv will not yield an argv with the
1811 // true path to the program at position 0. 1819 // true path to the program at position 0.
1812 base::FilePath setup_exe; 1820 base::FilePath setup_exe;
1813 PathService::Get(base::FILE_EXE, &setup_exe); 1821 PathService::Get(base::FILE_EXE, &setup_exe);
1814 1822
1815 int exit_code = 0; 1823 int exit_code = 0;
1816 if (HandleNonInstallCmdLineOptions( 1824 if (HandleNonInstallCmdLineOptions(setup_exe, cmd_line, &original_state,
1817 original_state, setup_exe, cmd_line, &installer_state, &exit_code)) { 1825 &installer_state, &exit_code)) {
1818 return exit_code; 1826 return exit_code;
1819 } 1827 }
1820 1828
1821 if (system_install && !IsUserAnAdmin()) { 1829 if (system_install && !IsUserAnAdmin()) {
1822 if (base::win::GetVersion() >= base::win::VERSION_VISTA && 1830 if (base::win::GetVersion() >= base::win::VERSION_VISTA &&
1823 !cmd_line.HasSwitch(installer::switches::kRunAsAdmin)) { 1831 !cmd_line.HasSwitch(installer::switches::kRunAsAdmin)) {
1824 base::CommandLine new_cmd(base::CommandLine::NO_PROGRAM); 1832 base::CommandLine new_cmd(base::CommandLine::NO_PROGRAM);
1825 new_cmd.AppendArguments(cmd_line, true); 1833 new_cmd.AppendArguments(cmd_line, true);
1826 // Append --run-as-admin flag to let the new instance of setup.exe know 1834 // Append --run-as-admin flag to let the new instance of setup.exe know
1827 // that we already tried to launch ourselves as admin. 1835 // that we already tried to launch ourselves as admin.
1828 new_cmd.AppendSwitch(installer::switches::kRunAsAdmin); 1836 new_cmd.AppendSwitch(installer::switches::kRunAsAdmin);
1829 // If system_install became true due to an environment variable, append 1837 // If system_install became true due to an environment variable, append
1830 // it to the command line here since env vars may not propagate past the 1838 // it to the command line here since env vars may not propagate past the
1831 // elevation. 1839 // elevation.
1832 if (!new_cmd.HasSwitch(installer::switches::kSystemLevel)) 1840 if (!new_cmd.HasSwitch(installer::switches::kSystemLevel))
1833 new_cmd.AppendSwitch(installer::switches::kSystemLevel); 1841 new_cmd.AppendSwitch(installer::switches::kSystemLevel);
1834 1842
1835 DWORD exit_code = installer::UNKNOWN_STATUS; 1843 DWORD exit_code = installer::UNKNOWN_STATUS;
1836 InstallUtil::ExecuteExeAsAdmin(new_cmd, &exit_code); 1844 InstallUtil::ExecuteExeAsAdmin(new_cmd, &exit_code);
1837 return exit_code; 1845 return exit_code;
1838 } else { 1846 } else {
1839 LOG(ERROR) << "Non admin user can not install system level Chrome."; 1847 LOG(ERROR) << "Non admin user can not install system level Chrome.";
1840 installer_state.WriteInstallerResult(installer::INSUFFICIENT_RIGHTS, 1848 installer_state.WriteInstallerResult(installer::INSUFFICIENT_RIGHTS,
1841 IDS_INSTALL_INSUFFICIENT_RIGHTS_BASE, NULL); 1849 IDS_INSTALL_INSUFFICIENT_RIGHTS_BASE, NULL);
1842 return installer::INSUFFICIENT_RIGHTS; 1850 return installer::INSUFFICIENT_RIGHTS;
1843 } 1851 }
1844 } 1852 }
1845 1853
1854 std::unique_ptr<installer::SetupSingleton> setup_singleton(
1855 installer::SetupSingleton::Acquire(cmd_line, prefs, &installer_state,
1856 &original_state));
1857 if (!setup_singleton)
1858 return installer::SETUP_SINGLETON_ACQUISITION_FAILED;
grt (UTC plus 2) 2016/09/01 12:05:39 please use WriteInstallerResult as well so that th
fdoray 2016/09/01 15:45:22 Done. When is the UI string shown? Users should s
grt (UTC plus 2) 2016/09/01 21:22:41 Google Update will show the string if the user is
fdoray 2016/09/06 17:29:39 Removed WriteInstallerResult for the --rename-chro
1859
1846 UninstallMultiChromeFrameIfPresent(cmd_line, prefs, 1860 UninstallMultiChromeFrameIfPresent(cmd_line, prefs,
1847 &original_state, &installer_state); 1861 &original_state, &installer_state);
1848 1862
1849 base::FilePath installer_directory; 1863 base::FilePath installer_directory;
1850 installer::InstallStatus install_status = installer::UNKNOWN_STATUS; 1864 installer::InstallStatus install_status = installer::UNKNOWN_STATUS;
1851 // If --uninstall option is given, uninstall the identified product(s) 1865 // If --uninstall option is given, uninstall the identified product(s)
1852 if (is_uninstall) { 1866 if (is_uninstall) {
1853 install_status = 1867 install_status =
1854 UninstallProducts(original_state, installer_state, setup_exe, cmd_line); 1868 UninstallProducts(original_state, installer_state, setup_exe, cmd_line);
1855 } else { 1869 } else {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 // never invoked directly by Google Update. 1906 // never invoked directly by Google Update.
1893 return_code = InstallUtil::GetInstallReturnCode(install_status); 1907 return_code = InstallUtil::GetInstallReturnCode(install_status);
1894 } 1908 }
1895 1909
1896 installer::EndPersistentHistogramStorage(installer_state.target_path(), 1910 installer::EndPersistentHistogramStorage(installer_state.target_path(),
1897 system_install); 1911 system_install);
1898 VLOG(1) << "Installation complete, returning: " << return_code; 1912 VLOG(1) << "Installation complete, returning: " << return_code;
1899 1913
1900 return return_code; 1914 return return_code;
1901 } 1915 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698