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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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/persistent_histogram_storage.h" | 52 #include "chrome/installer/setup/persistent_histogram_storage.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_singleton.h" |
55 #include "chrome/installer/setup/setup_util.h" | 55 #include "chrome/installer/setup/setup_util.h" |
56 #include "chrome/installer/setup/uninstall.h" | 56 #include "chrome/installer/setup/uninstall.h" |
57 #include "chrome/installer/util/browser_distribution.h" | 57 #include "chrome/installer/util/browser_distribution.h" |
58 #include "chrome/installer/util/delete_after_reboot_helper.h" | 58 #include "chrome/installer/util/delete_after_reboot_helper.h" |
59 #include "chrome/installer/util/delete_old_versions.h" | |
59 #include "chrome/installer/util/delete_tree_work_item.h" | 60 #include "chrome/installer/util/delete_tree_work_item.h" |
60 #include "chrome/installer/util/google_update_constants.h" | 61 #include "chrome/installer/util/google_update_constants.h" |
61 #include "chrome/installer/util/google_update_settings.h" | 62 #include "chrome/installer/util/google_update_settings.h" |
62 #include "chrome/installer/util/google_update_util.h" | 63 #include "chrome/installer/util/google_update_util.h" |
63 #include "chrome/installer/util/helper.h" | 64 #include "chrome/installer/util/helper.h" |
64 #include "chrome/installer/util/html_dialog.h" | 65 #include "chrome/installer/util/html_dialog.h" |
65 #include "chrome/installer/util/install_util.h" | 66 #include "chrome/installer/util/install_util.h" |
66 #include "chrome/installer/util/installation_state.h" | 67 #include "chrome/installer/util/installation_state.h" |
67 #include "chrome/installer/util/installation_validator.h" | 68 #include "chrome/installer/util/installation_validator.h" |
68 #include "chrome/installer/util/installer_state.h" | 69 #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); | 380 Product* chrome = installer_state->AddProduct(&multi_chrome); |
380 VLOG(1) << "Broken install of product to be included for repair: " | 381 VLOG(1) << "Broken install of product to be included for repair: " |
381 << chrome->distribution()->GetDisplayName(); | 382 << chrome->distribution()->GetDisplayName(); |
382 } // else uninstall the binaries in UninstallBinariesIfUnused. | 383 } // else uninstall the binaries in UninstallBinariesIfUnused. |
383 } | 384 } |
384 } | 385 } |
385 } | 386 } |
386 } | 387 } |
387 } | 388 } |
388 | 389 |
390 // Repetitively attempts to delete all files that belong to old versions of | |
391 // Chrome from |install_dir|. Waits 15 seconds before the first attempt and 5 | |
392 // minutes after each unsuccessful attempt. Returns when no files that belong to | |
393 // an old version of Chrome remain or when another process tries to acquire the | |
394 // SetupSingleton. | |
395 installer::InstallStatus RepeatDeleteOldVersionsUntilSuccess( | |
396 const base::FilePath& install_dir, | |
397 const installer::SetupSingleton& setup_singleton) { | |
398 int num_attempts = 0; | |
grt (UTC plus 2)
2016/09/14 10:42:10
hmm. should it give up after some number of tries?
fdoray
2016/09/27 19:42:15
Done.
| |
399 while (true) { | |
400 // Wait 15 seconds before the first attempt because trying to delete old | |
401 // files right away is likely to fail. Indeed, this is called in 2 | |
402 // occasions: | |
403 // - When the installer fails to delete old files after a not-in-use update: | |
404 // retrying immediately is likely to fail again. | |
405 // - When executables are successfully renamed on Chrome startup or | |
406 // shutdown: old files can't be deleted because Chrome is still in use. | |
407 // Wait 5 minutes after an unsuccessful attempt because retrying immediately | |
408 // is likely to fail again. | |
409 const base::TimeDelta max_wait_time = num_attempts == 0 | |
410 ? base::TimeDelta::FromSeconds(15) | |
411 : base::TimeDelta::FromMinutes(5); | |
412 if (setup_singleton.WaitForInterrupt(max_wait_time)) { | |
413 UMA_HISTOGRAM_COUNTS_1000( | |
414 "Setup.Install.NumDeleteOldVersionsAttemptsBeforeSingletonReleased", | |
415 num_attempts); | |
416 return installer::SETUP_SINGLETON_RELEASED; | |
417 } | |
418 | |
419 ++num_attempts; | |
420 if (installer::DeleteOldVersions(install_dir)) { | |
grt (UTC plus 2)
2016/09/14 10:42:10
WDYT of Process::current().SetProcessBackgrounded(
fdoray
2016/09/27 19:42:15
Done.
| |
421 VLOG(1) << "Successfully deleted all old files from " | |
422 "--delete-old-versions process."; | |
423 UMA_HISTOGRAM_COUNTS_1000( | |
424 "Setup.Install.NumDeleteOldVersionsAttemptsBeforeSuccess", | |
425 num_attempts); | |
426 return installer::DELETE_OLD_VERSIONS_SUCCESS; | |
427 } | |
428 VLOG(1) << "Failed to delete all old files from --delete-old-versions " | |
grt (UTC plus 2)
2016/09/14 10:42:10
since this could potentially repeat for a very lon
fdoray
2016/09/27 19:42:15
Done.
| |
429 "process. Will try again in 5 minutes."; | |
430 } | |
431 } | |
432 | |
389 // This function is called when --rename-chrome-exe option is specified on | 433 // 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 | 434 // 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 | 435 // 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 | 436 // 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. | 437 // 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 | 438 // This function also deletes elevation policies associated with the old version |
395 // if they exist. | 439 // if they exist. |setup_exe| is the path to the current executable. |
396 installer::InstallStatus RenameChromeExecutables( | 440 installer::InstallStatus RenameChromeExecutables( |
441 const base::FilePath& setup_exe, | |
397 const InstallationState& original_state, | 442 const InstallationState& original_state, |
398 InstallerState* installer_state) { | 443 InstallerState* installer_state) { |
399 // See what products are already installed in multi mode. When we do the | 444 // 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 | 445 // rename for multi installs, we must update all installations since they |
401 // share the binaries. | 446 // share the binaries. |
402 AddExistingMultiInstalls(original_state, installer_state); | 447 AddExistingMultiInstalls(original_state, installer_state); |
403 const base::FilePath &target_path = installer_state->target_path(); | 448 const base::FilePath &target_path = installer_state->target_path(); |
404 base::FilePath chrome_exe(target_path.Append(installer::kChromeExe)); | 449 base::FilePath chrome_exe(target_path.Append(installer::kChromeExe)); |
405 base::FilePath chrome_new_exe(target_path.Append(installer::kChromeNewExe)); | 450 base::FilePath chrome_new_exe(target_path.Append(installer::kChromeNewExe)); |
406 base::FilePath chrome_old_exe(target_path.Append(installer::kChromeOldExe)); | 451 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, | 492 install_list->AddDeleteRegValueWorkItem(reg_root, |
448 version_key, | 493 version_key, |
449 KEY_WOW64_32KEY, | 494 KEY_WOW64_32KEY, |
450 google_update::kRegRenameCmdField); | 495 google_update::kRegRenameCmdField); |
451 } | 496 } |
452 // old_chrome.exe is still in use in most cases, so ignore failures here. | 497 // old_chrome.exe is still in use in most cases, so ignore failures here. |
453 install_list->AddDeleteTreeWorkItem(chrome_old_exe, temp_path.path()) | 498 install_list->AddDeleteTreeWorkItem(chrome_old_exe, temp_path.path()) |
454 ->set_best_effort(true); | 499 ->set_best_effort(true); |
455 | 500 |
456 installer::InstallStatus ret = installer::RENAME_SUCCESSFUL; | 501 installer::InstallStatus ret = installer::RENAME_SUCCESSFUL; |
457 if (!install_list->Do()) { | 502 if (install_list->Do()) { |
503 installer::LaunchDeleteOldVersionsProcess(setup_exe, *installer_state); | |
504 } else { | |
458 LOG(ERROR) << "Renaming of executables failed. Rolling back any changes."; | 505 LOG(ERROR) << "Renaming of executables failed. Rolling back any changes."; |
459 install_list->Rollback(); | 506 install_list->Rollback(); |
460 ret = installer::RENAME_FAILED; | 507 ret = installer::RENAME_FAILED; |
461 } | 508 } |
462 // temp_path's dtor will take care of deleting or scheduling itself for | 509 // temp_path's dtor will take care of deleting or scheduling itself for |
463 // deletion at reboot when this scope closes. | 510 // deletion at reboot when this scope closes. |
464 VLOG(1) << "Deleting temporary directory " << temp_path.path().value(); | 511 VLOG(1) << "Deleting temporary directory " << temp_path.path().value(); |
465 | 512 |
466 return ret; | 513 return ret; |
467 } | 514 } |
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1229 status = installer::IN_USE_UPDATED; | 1276 status = installer::IN_USE_UPDATED; |
1230 } else { | 1277 } else { |
1231 if (ShellUtil::RegisterChromeBrowser(chrome_install->distribution(), | 1278 if (ShellUtil::RegisterChromeBrowser(chrome_install->distribution(), |
1232 chrome_exe, suffix, false)) | 1279 chrome_exe, suffix, false)) |
1233 status = installer::IN_USE_UPDATED; | 1280 status = installer::IN_USE_UPDATED; |
1234 } | 1281 } |
1235 } else { | 1282 } else { |
1236 LOG(DFATAL) << "Can't register browser - Chrome distribution not found"; | 1283 LOG(DFATAL) << "Can't register browser - Chrome distribution not found"; |
1237 } | 1284 } |
1238 *exit_code = InstallUtil::GetInstallReturnCode(status); | 1285 *exit_code = InstallUtil::GetInstallReturnCode(status); |
1239 } else if (cmd_line.HasSwitch(installer::switches::kRenameChromeExe)) { | 1286 } else if (cmd_line.HasSwitch(installer::switches::kDeleteOldVersions) || |
1240 // If --rename-chrome-exe is specified, we want to rename the executables | 1287 cmd_line.HasSwitch(installer::switches::kRenameChromeExe)) { |
1241 // and exit. | |
1242 std::unique_ptr<installer::SetupSingleton> setup_singleton( | 1288 std::unique_ptr<installer::SetupSingleton> setup_singleton( |
1243 installer::SetupSingleton::Acquire( | 1289 installer::SetupSingleton::Acquire( |
1244 cmd_line, MasterPreferences::ForCurrentProcess(), original_state, | 1290 cmd_line, MasterPreferences::ForCurrentProcess(), original_state, |
1245 installer_state)); | 1291 installer_state)); |
1246 if (!setup_singleton) | 1292 if (!setup_singleton) { |
1247 *exit_code = installer::SETUP_SINGLETON_ACQUISITION_FAILED; | 1293 *exit_code = installer::SETUP_SINGLETON_ACQUISITION_FAILED; |
1248 else | 1294 } else if (cmd_line.HasSwitch(installer::switches::kDeleteOldVersions)) { |
1249 *exit_code = RenameChromeExecutables(*original_state, installer_state); | 1295 *exit_code = RepeatDeleteOldVersionsUntilSuccess( |
1296 installer_state->target_path(), *setup_singleton); | |
1297 } else { | |
1298 DCHECK(cmd_line.HasSwitch(installer::switches::kRenameChromeExe)); | |
1299 *exit_code = | |
1300 RenameChromeExecutables(setup_exe, *original_state, installer_state); | |
1301 } | |
1250 } else if (cmd_line.HasSwitch( | 1302 } else if (cmd_line.HasSwitch( |
1251 installer::switches::kRemoveChromeRegistration)) { | 1303 installer::switches::kRemoveChromeRegistration)) { |
1252 // This is almost reverse of --register-chrome-browser option above. | 1304 // This is almost reverse of --register-chrome-browser option above. |
1253 // Here we delete Chrome browser registration. This option should only | 1305 // Here we delete Chrome browser registration. This option should only |
1254 // be used when setup.exe is launched with admin rights. We do not | 1306 // be used when setup.exe is launched with admin rights. We do not |
1255 // make any user specific changes in this option. | 1307 // make any user specific changes in this option. |
1256 base::string16 suffix; | 1308 base::string16 suffix; |
1257 if (cmd_line.HasSwitch( | 1309 if (cmd_line.HasSwitch( |
1258 installer::switches::kRegisterChromeBrowserSuffix)) { | 1310 installer::switches::kRegisterChromeBrowserSuffix)) { |
1259 suffix = cmd_line.GetSwitchValueNative( | 1311 suffix = cmd_line.GetSwitchValueNative( |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1912 // Note that we allow the status installer::UNINSTALL_REQUIRES_REBOOT | 1964 // Note that we allow the status installer::UNINSTALL_REQUIRES_REBOOT |
1913 // to pass through, since this is only returned on uninstall which is | 1965 // to pass through, since this is only returned on uninstall which is |
1914 // never invoked directly by Google Update. | 1966 // never invoked directly by Google Update. |
1915 return_code = InstallUtil::GetInstallReturnCode(install_status); | 1967 return_code = InstallUtil::GetInstallReturnCode(install_status); |
1916 } | 1968 } |
1917 | 1969 |
1918 VLOG(1) << "Installation complete, returning: " << return_code; | 1970 VLOG(1) << "Installation complete, returning: " << return_code; |
1919 | 1971 |
1920 return return_code; | 1972 return return_code; |
1921 } | 1973 } |
OLD | NEW |