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> |
11 #include <stddef.h> | 11 #include <stddef.h> |
12 #include <stdint.h> | 12 #include <stdint.h> |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 #include "base/at_exit.h" | 17 #include "base/at_exit.h" |
18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
19 #include "base/file_version_info.h" | 19 #include "base/file_version_info.h" |
20 #include "base/files/file_path.h" | 20 #include "base/files/file_path.h" |
21 #include "base/files/file_util.h" | 21 #include "base/files/file_util.h" |
22 #include "base/files/scoped_temp_dir.h" | 22 #include "base/files/scoped_temp_dir.h" |
23 #include "base/macros.h" | 23 #include "base/macros.h" |
24 #include "base/metrics/histogram_macros.h" | 24 #include "base/metrics/histogram_macros.h" |
25 #include "base/numerics/safe_conversions.h" | 25 #include "base/numerics/safe_conversions.h" |
26 #include "base/path_service.h" | 26 #include "base/path_service.h" |
27 #include "base/process/launch.h" | 27 #include "base/process/launch.h" |
28 #include "base/process/memory.h" | 28 #include "base/process/memory.h" |
| 29 #include "base/process/process.h" |
29 #include "base/process/process_metrics.h" | 30 #include "base/process/process_metrics.h" |
30 #include "base/strings/string16.h" | 31 #include "base/strings/string16.h" |
31 #include "base/strings/string_number_conversions.h" | 32 #include "base/strings/string_number_conversions.h" |
32 #include "base/strings/string_util.h" | 33 #include "base/strings/string_util.h" |
33 #include "base/strings/stringprintf.h" | 34 #include "base/strings/stringprintf.h" |
34 #include "base/strings/utf_string_conversions.h" | 35 #include "base/strings/utf_string_conversions.h" |
35 #include "base/time/time.h" | 36 #include "base/time/time.h" |
36 #include "base/values.h" | 37 #include "base/values.h" |
37 #include "base/version.h" | 38 #include "base/version.h" |
38 #include "base/win/process_startup_helper.h" | 39 #include "base/win/process_startup_helper.h" |
(...skipping 10 matching lines...) Expand all Loading... |
49 #include "chrome/installer/setup/install.h" | 50 #include "chrome/installer/setup/install.h" |
50 #include "chrome/installer/setup/install_worker.h" | 51 #include "chrome/installer/setup/install_worker.h" |
51 #include "chrome/installer/setup/installer_crash_reporting.h" | 52 #include "chrome/installer/setup/installer_crash_reporting.h" |
52 #include "chrome/installer/setup/persistent_histogram_storage.h" | 53 #include "chrome/installer/setup/persistent_histogram_storage.h" |
53 #include "chrome/installer/setup/setup_constants.h" | 54 #include "chrome/installer/setup/setup_constants.h" |
54 #include "chrome/installer/setup/setup_singleton.h" | 55 #include "chrome/installer/setup/setup_singleton.h" |
55 #include "chrome/installer/setup/setup_util.h" | 56 #include "chrome/installer/setup/setup_util.h" |
56 #include "chrome/installer/setup/uninstall.h" | 57 #include "chrome/installer/setup/uninstall.h" |
57 #include "chrome/installer/util/browser_distribution.h" | 58 #include "chrome/installer/util/browser_distribution.h" |
58 #include "chrome/installer/util/delete_after_reboot_helper.h" | 59 #include "chrome/installer/util/delete_after_reboot_helper.h" |
| 60 #include "chrome/installer/util/delete_old_versions.h" |
59 #include "chrome/installer/util/delete_tree_work_item.h" | 61 #include "chrome/installer/util/delete_tree_work_item.h" |
60 #include "chrome/installer/util/google_update_constants.h" | 62 #include "chrome/installer/util/google_update_constants.h" |
61 #include "chrome/installer/util/google_update_settings.h" | 63 #include "chrome/installer/util/google_update_settings.h" |
62 #include "chrome/installer/util/google_update_util.h" | 64 #include "chrome/installer/util/google_update_util.h" |
63 #include "chrome/installer/util/helper.h" | 65 #include "chrome/installer/util/helper.h" |
64 #include "chrome/installer/util/html_dialog.h" | 66 #include "chrome/installer/util/html_dialog.h" |
65 #include "chrome/installer/util/install_util.h" | 67 #include "chrome/installer/util/install_util.h" |
66 #include "chrome/installer/util/installation_state.h" | 68 #include "chrome/installer/util/installation_state.h" |
67 #include "chrome/installer/util/installation_validator.h" | 69 #include "chrome/installer/util/installation_validator.h" |
68 #include "chrome/installer/util/installer_state.h" | 70 #include "chrome/installer/util/installer_state.h" |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 Product* chrome = installer_state->AddProduct(&multi_chrome); | 381 Product* chrome = installer_state->AddProduct(&multi_chrome); |
380 VLOG(1) << "Broken install of product to be included for repair: " | 382 VLOG(1) << "Broken install of product to be included for repair: " |
381 << chrome->distribution()->GetDisplayName(); | 383 << chrome->distribution()->GetDisplayName(); |
382 } // else uninstall the binaries in UninstallBinariesIfUnused. | 384 } // else uninstall the binaries in UninstallBinariesIfUnused. |
383 } | 385 } |
384 } | 386 } |
385 } | 387 } |
386 } | 388 } |
387 } | 389 } |
388 | 390 |
| 391 void RecordNumDeleteOldVersionsAttempsBeforeAbort(int num_attempts) { |
| 392 UMA_HISTOGRAM_COUNTS_100( |
| 393 "Setup.Install.NumDeleteOldVersionsAttemptsBeforeAbort", num_attempts); |
| 394 } |
| 395 |
| 396 // Repetitively attempts to delete all files that belong to old versions of |
| 397 // Chrome from |install_dir|. Waits 15 seconds before the first attempt and 5 |
| 398 // minutes after each unsuccessful attempt. Returns when no files that belong to |
| 399 // an old version of Chrome remain or when another process tries to acquire the |
| 400 // SetupSingleton. |
| 401 installer::InstallStatus RepeatDeleteOldVersions( |
| 402 const base::FilePath& install_dir, |
| 403 const installer::SetupSingleton& setup_singleton) { |
| 404 constexpr int kMaxNumAttempts = 12; |
| 405 int num_attempts = 0; |
| 406 |
| 407 while (num_attempts < kMaxNumAttempts) { |
| 408 // Wait 15 seconds before the first attempt because trying to delete old |
| 409 // files right away is likely to fail. Indeed, this is called in 2 |
| 410 // occasions: |
| 411 // - When the installer fails to delete old files after a not-in-use update: |
| 412 // retrying immediately is likely to fail again. |
| 413 // - When executables are successfully renamed on Chrome startup or |
| 414 // shutdown: old files can't be deleted because Chrome is still in use. |
| 415 // Wait 5 minutes after an unsuccessful attempt because retrying immediately |
| 416 // is likely to fail again. |
| 417 const base::TimeDelta max_wait_time = num_attempts == 0 |
| 418 ? base::TimeDelta::FromSeconds(15) |
| 419 : base::TimeDelta::FromMinutes(5); |
| 420 if (setup_singleton.WaitForInterrupt(max_wait_time)) { |
| 421 VLOG(1) << "Exiting --delete-old-versions process because another " |
| 422 "process tries to acquire the SetupSingleton."; |
| 423 RecordNumDeleteOldVersionsAttempsBeforeAbort(num_attempts); |
| 424 return installer::SETUP_SINGLETON_RELEASED; |
| 425 } |
| 426 |
| 427 const bool was_backgrounded = |
| 428 base::Process::Current().SetProcessBackgrounded(true); |
| 429 const bool delete_old_versions_success = |
| 430 installer::DeleteOldVersions(install_dir); |
| 431 if (!was_backgrounded) |
| 432 base::Process::Current().SetProcessBackgrounded(false); |
| 433 ++num_attempts; |
| 434 |
| 435 if (delete_old_versions_success) { |
| 436 VLOG(1) << "Successfully deleted all old files from " |
| 437 "--delete-old-versions process."; |
| 438 UMA_HISTOGRAM_COUNTS_100( |
| 439 "Setup.Install.NumDeleteOldVersionsAttemptsBeforeSuccess", |
| 440 num_attempts); |
| 441 return installer::DELETE_OLD_VERSIONS_SUCCESS; |
| 442 } else if (num_attempts == 1) { |
| 443 VLOG(1) << "Failed to delete all old files from --delete-old-versions " |
| 444 "process. Will retry every five minutes."; |
| 445 } |
| 446 } |
| 447 |
| 448 VLOG(1) << "Exiting --delete-old-versions process after retrying too many " |
| 449 "times to delete all old files."; |
| 450 DCHECK_EQ(num_attempts, kMaxNumAttempts); |
| 451 RecordNumDeleteOldVersionsAttempsBeforeAbort(num_attempts); |
| 452 return installer::DELETE_OLD_VERSIONS_TOO_MANY_ATTEMPTS; |
| 453 } |
| 454 |
389 // This function is called when --rename-chrome-exe option is specified on | 455 // This function is called when --rename-chrome-exe option is specified on |
390 // setup.exe command line. This function assumes an in-use update has happened | 456 // setup.exe command line. This function assumes an in-use update has happened |
391 // for Chrome so there should be a file called new_chrome.exe on the file | 457 // for Chrome so there should be a file called new_chrome.exe on the file |
392 // system and a key called 'opv' in the registry. This function will move | 458 // system and a key called 'opv' in the registry. This function will move |
393 // new_chrome.exe to chrome.exe and delete 'opv' key in one atomic operation. | 459 // new_chrome.exe to chrome.exe and delete 'opv' key in one atomic operation. |
394 // This function also deletes elevation policies associated with the old version | 460 // This function also deletes elevation policies associated with the old version |
395 // if they exist. | 461 // if they exist. |setup_exe| is the path to the current executable. |
396 installer::InstallStatus RenameChromeExecutables( | 462 installer::InstallStatus RenameChromeExecutables( |
| 463 const base::FilePath& setup_exe, |
397 const InstallationState& original_state, | 464 const InstallationState& original_state, |
398 InstallerState* installer_state) { | 465 InstallerState* installer_state) { |
399 // See what products are already installed in multi mode. When we do the | 466 // See what products are already installed in multi mode. When we do the |
400 // rename for multi installs, we must update all installations since they | 467 // rename for multi installs, we must update all installations since they |
401 // share the binaries. | 468 // share the binaries. |
402 AddExistingMultiInstalls(original_state, installer_state); | 469 AddExistingMultiInstalls(original_state, installer_state); |
403 const base::FilePath &target_path = installer_state->target_path(); | 470 const base::FilePath &target_path = installer_state->target_path(); |
404 base::FilePath chrome_exe(target_path.Append(installer::kChromeExe)); | 471 base::FilePath chrome_exe(target_path.Append(installer::kChromeExe)); |
405 base::FilePath chrome_new_exe(target_path.Append(installer::kChromeNewExe)); | 472 base::FilePath chrome_new_exe(target_path.Append(installer::kChromeNewExe)); |
406 base::FilePath chrome_old_exe(target_path.Append(installer::kChromeOldExe)); | 473 base::FilePath chrome_old_exe(target_path.Append(installer::kChromeOldExe)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 install_list->AddDeleteRegValueWorkItem(reg_root, | 514 install_list->AddDeleteRegValueWorkItem(reg_root, |
448 version_key, | 515 version_key, |
449 KEY_WOW64_32KEY, | 516 KEY_WOW64_32KEY, |
450 google_update::kRegRenameCmdField); | 517 google_update::kRegRenameCmdField); |
451 } | 518 } |
452 // old_chrome.exe is still in use in most cases, so ignore failures here. | 519 // old_chrome.exe is still in use in most cases, so ignore failures here. |
453 install_list->AddDeleteTreeWorkItem(chrome_old_exe, temp_path.path()) | 520 install_list->AddDeleteTreeWorkItem(chrome_old_exe, temp_path.path()) |
454 ->set_best_effort(true); | 521 ->set_best_effort(true); |
455 | 522 |
456 installer::InstallStatus ret = installer::RENAME_SUCCESSFUL; | 523 installer::InstallStatus ret = installer::RENAME_SUCCESSFUL; |
457 if (!install_list->Do()) { | 524 if (install_list->Do()) { |
| 525 installer::LaunchDeleteOldVersionsProcess(setup_exe, *installer_state); |
| 526 } else { |
458 LOG(ERROR) << "Renaming of executables failed. Rolling back any changes."; | 527 LOG(ERROR) << "Renaming of executables failed. Rolling back any changes."; |
459 install_list->Rollback(); | 528 install_list->Rollback(); |
460 ret = installer::RENAME_FAILED; | 529 ret = installer::RENAME_FAILED; |
461 } | 530 } |
462 // temp_path's dtor will take care of deleting or scheduling itself for | 531 // temp_path's dtor will take care of deleting or scheduling itself for |
463 // deletion at reboot when this scope closes. | 532 // deletion at reboot when this scope closes. |
464 VLOG(1) << "Deleting temporary directory " << temp_path.path().value(); | 533 VLOG(1) << "Deleting temporary directory " << temp_path.path().value(); |
465 | 534 |
466 return ret; | 535 return ret; |
467 } | 536 } |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 status = installer::IN_USE_UPDATED; | 1297 status = installer::IN_USE_UPDATED; |
1229 } else { | 1298 } else { |
1230 if (ShellUtil::RegisterChromeBrowser(chrome_install->distribution(), | 1299 if (ShellUtil::RegisterChromeBrowser(chrome_install->distribution(), |
1231 chrome_exe, suffix, false)) | 1300 chrome_exe, suffix, false)) |
1232 status = installer::IN_USE_UPDATED; | 1301 status = installer::IN_USE_UPDATED; |
1233 } | 1302 } |
1234 } else { | 1303 } else { |
1235 LOG(DFATAL) << "Can't register browser - Chrome distribution not found"; | 1304 LOG(DFATAL) << "Can't register browser - Chrome distribution not found"; |
1236 } | 1305 } |
1237 *exit_code = InstallUtil::GetInstallReturnCode(status); | 1306 *exit_code = InstallUtil::GetInstallReturnCode(status); |
1238 } else if (cmd_line.HasSwitch(installer::switches::kRenameChromeExe)) { | 1307 } else if (cmd_line.HasSwitch(installer::switches::kDeleteOldVersions) || |
1239 // If --rename-chrome-exe is specified, we want to rename the executables | 1308 cmd_line.HasSwitch(installer::switches::kRenameChromeExe)) { |
1240 // and exit. | |
1241 std::unique_ptr<installer::SetupSingleton> setup_singleton( | 1309 std::unique_ptr<installer::SetupSingleton> setup_singleton( |
1242 installer::SetupSingleton::Acquire( | 1310 installer::SetupSingleton::Acquire( |
1243 cmd_line, MasterPreferences::ForCurrentProcess(), original_state, | 1311 cmd_line, MasterPreferences::ForCurrentProcess(), original_state, |
1244 installer_state)); | 1312 installer_state)); |
1245 if (!setup_singleton) | 1313 if (!setup_singleton) { |
1246 *exit_code = installer::SETUP_SINGLETON_ACQUISITION_FAILED; | 1314 *exit_code = installer::SETUP_SINGLETON_ACQUISITION_FAILED; |
1247 else | 1315 } else if (cmd_line.HasSwitch(installer::switches::kDeleteOldVersions)) { |
1248 *exit_code = RenameChromeExecutables(*original_state, installer_state); | 1316 // In multi-install mode, determine what products are installed to |
| 1317 // populate the target_path() used below. |
| 1318 AddExistingMultiInstalls(*original_state, installer_state); |
| 1319 |
| 1320 *exit_code = RepeatDeleteOldVersions(installer_state->target_path(), |
| 1321 *setup_singleton); |
| 1322 } else { |
| 1323 DCHECK(cmd_line.HasSwitch(installer::switches::kRenameChromeExe)); |
| 1324 *exit_code = |
| 1325 RenameChromeExecutables(setup_exe, *original_state, installer_state); |
| 1326 } |
1249 } else if (cmd_line.HasSwitch( | 1327 } else if (cmd_line.HasSwitch( |
1250 installer::switches::kRemoveChromeRegistration)) { | 1328 installer::switches::kRemoveChromeRegistration)) { |
1251 // This is almost reverse of --register-chrome-browser option above. | 1329 // This is almost reverse of --register-chrome-browser option above. |
1252 // Here we delete Chrome browser registration. This option should only | 1330 // Here we delete Chrome browser registration. This option should only |
1253 // be used when setup.exe is launched with admin rights. We do not | 1331 // be used when setup.exe is launched with admin rights. We do not |
1254 // make any user specific changes in this option. | 1332 // make any user specific changes in this option. |
1255 base::string16 suffix; | 1333 base::string16 suffix; |
1256 if (cmd_line.HasSwitch( | 1334 if (cmd_line.HasSwitch( |
1257 installer::switches::kRegisterChromeBrowserSuffix)) { | 1335 installer::switches::kRegisterChromeBrowserSuffix)) { |
1258 suffix = cmd_line.GetSwitchValueNative( | 1336 suffix = cmd_line.GetSwitchValueNative( |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1911 // Note that we allow the status installer::UNINSTALL_REQUIRES_REBOOT | 1989 // Note that we allow the status installer::UNINSTALL_REQUIRES_REBOOT |
1912 // to pass through, since this is only returned on uninstall which is | 1990 // to pass through, since this is only returned on uninstall which is |
1913 // never invoked directly by Google Update. | 1991 // never invoked directly by Google Update. |
1914 return_code = InstallUtil::GetInstallReturnCode(install_status); | 1992 return_code = InstallUtil::GetInstallReturnCode(install_status); |
1915 } | 1993 } |
1916 | 1994 |
1917 VLOG(1) << "Installation complete, returning: " << return_code; | 1995 VLOG(1) << "Installation complete, returning: " << return_code; |
1918 | 1996 |
1919 return return_code; | 1997 return return_code; |
1920 } | 1998 } |
OLD | NEW |