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

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

Issue 2333853002: Support --delete-old-versions in setup.exe. (Closed)
Patch Set: 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_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
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(
grt (UTC plus 2) 2016/09/13 08:10:40 it looks like we'll be blind to how this performs.
fdoray 2016/09/13 21:34:54 Done.
396 const base::FilePath& install_dir,
397 const installer::SetupSingleton& setup_singleton) {
398 // Wait 15 seconds because trying to delete old files right away is likely to
399 // fail. Indeed, this is called in 2 occasions:
400 // - When the installer fails to delete old files after a not-in-use update:
401 // retrying immediately is likely to fail again.
402 // - When executables are successfully renamed on Chrome startup or shutdown:
403 // old files can't be deleted because Chrome is still in use.
404 if (setup_singleton.WaitForInterrupt(base::TimeDelta::FromSeconds(15)))
405 return installer::SETUP_SINGLETON_RELEASED;
406
407 for (;;) {
grt (UTC plus 2) 2016/09/13 08:10:40 why not? while (true) {
fdoray 2016/09/13 21:34:54 Done.
408 if (installer::DeleteOldVersions(install_dir)) {
409 LOG(INFO) << "Successfully deleted old files from --delete-old-versions "
grt (UTC plus 2) 2016/09/13 08:10:40 please use VLOG(1) here and below
fdoray 2016/09/13 21:34:54 Done.
410 "process.";
411 return installer::DELETE_OLD_VERSIONS_SUCCESS;
412 }
413
414 LOG(INFO) << "Failed to delete old files from --delete-old-versions "
grt (UTC plus 2) 2016/09/13 08:10:40 does this case mean that no old files were deleted
fdoray 2016/09/13 21:34:54 Done. It means that not *all* old files were delet
415 "process. Will try again in 5 minutes.";
416 if (setup_singleton.WaitForInterrupt(base::TimeDelta::FromMinutes(5)))
417 return installer::SETUP_SINGLETON_RELEASED;
418 }
419 }
420
389 // This function is called when --rename-chrome-exe option is specified on 421 // 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 422 // 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 423 // 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 424 // 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. 425 // 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 426 // This function also deletes elevation policies associated with the old version
395 // if they exist. 427 // if they exist.
396 installer::InstallStatus RenameChromeExecutables( 428 installer::InstallStatus RenameChromeExecutables(
397 const InstallationState& original_state, 429 const InstallationState& original_state,
398 InstallerState* installer_state) { 430 InstallerState* installer_state) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 install_list->AddDeleteRegValueWorkItem(reg_root, 479 install_list->AddDeleteRegValueWorkItem(reg_root,
448 version_key, 480 version_key,
449 KEY_WOW64_32KEY, 481 KEY_WOW64_32KEY,
450 google_update::kRegRenameCmdField); 482 google_update::kRegRenameCmdField);
451 } 483 }
452 // old_chrome.exe is still in use in most cases, so ignore failures here. 484 // old_chrome.exe is still in use in most cases, so ignore failures here.
453 install_list->AddDeleteTreeWorkItem(chrome_old_exe, temp_path.path()) 485 install_list->AddDeleteTreeWorkItem(chrome_old_exe, temp_path.path())
454 ->set_best_effort(true); 486 ->set_best_effort(true);
455 487
456 installer::InstallStatus ret = installer::RENAME_SUCCESSFUL; 488 installer::InstallStatus ret = installer::RENAME_SUCCESSFUL;
457 if (!install_list->Do()) { 489 if (install_list->Do()) {
490 installer::LaunchDeleteOldVersionsProcess(*installer_state);
grt (UTC plus 2) 2016/09/13 08:10:40 in this specific case, the current setup.exe (Path
fdoray 2016/09/13 21:34:54 Done.
491 } else {
458 LOG(ERROR) << "Renaming of executables failed. Rolling back any changes."; 492 LOG(ERROR) << "Renaming of executables failed. Rolling back any changes.";
459 install_list->Rollback(); 493 install_list->Rollback();
460 ret = installer::RENAME_FAILED; 494 ret = installer::RENAME_FAILED;
461 } 495 }
462 // temp_path's dtor will take care of deleting or scheduling itself for 496 // temp_path's dtor will take care of deleting or scheduling itself for
463 // deletion at reboot when this scope closes. 497 // deletion at reboot when this scope closes.
464 VLOG(1) << "Deleting temporary directory " << temp_path.path().value(); 498 VLOG(1) << "Deleting temporary directory " << temp_path.path().value();
465 499
466 return ret; 500 return ret;
467 } 501 }
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 status = installer::IN_USE_UPDATED; 1263 status = installer::IN_USE_UPDATED;
1230 } else { 1264 } else {
1231 if (ShellUtil::RegisterChromeBrowser(chrome_install->distribution(), 1265 if (ShellUtil::RegisterChromeBrowser(chrome_install->distribution(),
1232 chrome_exe, suffix, false)) 1266 chrome_exe, suffix, false))
1233 status = installer::IN_USE_UPDATED; 1267 status = installer::IN_USE_UPDATED;
1234 } 1268 }
1235 } else { 1269 } else {
1236 LOG(DFATAL) << "Can't register browser - Chrome distribution not found"; 1270 LOG(DFATAL) << "Can't register browser - Chrome distribution not found";
1237 } 1271 }
1238 *exit_code = InstallUtil::GetInstallReturnCode(status); 1272 *exit_code = InstallUtil::GetInstallReturnCode(status);
1239 } else if (cmd_line.HasSwitch(installer::switches::kRenameChromeExe)) { 1273 } else if (cmd_line.HasSwitch(installer::switches::kDeleteOldVersions) ||
1240 // If --rename-chrome-exe is specified, we want to rename the executables 1274 cmd_line.HasSwitch(installer::switches::kRenameChromeExe)) {
1241 // and exit.
1242 std::unique_ptr<installer::SetupSingleton> setup_singleton( 1275 std::unique_ptr<installer::SetupSingleton> setup_singleton(
1243 installer::SetupSingleton::Acquire( 1276 installer::SetupSingleton::Acquire(
1244 cmd_line, MasterPreferences::ForCurrentProcess(), original_state, 1277 cmd_line, MasterPreferences::ForCurrentProcess(), original_state,
1245 installer_state)); 1278 installer_state));
1246 if (!setup_singleton) 1279 if (!setup_singleton) {
1247 *exit_code = installer::SETUP_SINGLETON_ACQUISITION_FAILED; 1280 *exit_code = installer::SETUP_SINGLETON_ACQUISITION_FAILED;
1248 else 1281 } else if (cmd_line.HasSwitch(installer::switches::kDeleteOldVersions)) {
1282 *exit_code = RepeatDeleteOldVersionsUntilSuccess(
1283 installer_state->target_path(), *setup_singleton);
1284 } else {
1285 DCHECK(cmd_line.HasSwitch(installer::switches::kRenameChromeExe));
1249 *exit_code = RenameChromeExecutables(*original_state, installer_state); 1286 *exit_code = RenameChromeExecutables(*original_state, installer_state);
1287 }
1250 } else if (cmd_line.HasSwitch( 1288 } else if (cmd_line.HasSwitch(
1251 installer::switches::kRemoveChromeRegistration)) { 1289 installer::switches::kRemoveChromeRegistration)) {
1252 // This is almost reverse of --register-chrome-browser option above. 1290 // This is almost reverse of --register-chrome-browser option above.
1253 // Here we delete Chrome browser registration. This option should only 1291 // Here we delete Chrome browser registration. This option should only
1254 // be used when setup.exe is launched with admin rights. We do not 1292 // be used when setup.exe is launched with admin rights. We do not
1255 // make any user specific changes in this option. 1293 // make any user specific changes in this option.
1256 base::string16 suffix; 1294 base::string16 suffix;
1257 if (cmd_line.HasSwitch( 1295 if (cmd_line.HasSwitch(
1258 installer::switches::kRegisterChromeBrowserSuffix)) { 1296 installer::switches::kRegisterChromeBrowserSuffix)) {
1259 suffix = cmd_line.GetSwitchValueNative( 1297 suffix = cmd_line.GetSwitchValueNative(
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 return exit_code; 1883 return exit_code;
1846 } else { 1884 } else {
1847 LOG(ERROR) << "Non admin user can not install system level Chrome."; 1885 LOG(ERROR) << "Non admin user can not install system level Chrome.";
1848 installer_state.WriteInstallerResult(installer::INSUFFICIENT_RIGHTS, 1886 installer_state.WriteInstallerResult(installer::INSUFFICIENT_RIGHTS,
1849 IDS_INSTALL_INSUFFICIENT_RIGHTS_BASE, NULL); 1887 IDS_INSTALL_INSUFFICIENT_RIGHTS_BASE, NULL);
1850 return installer::INSUFFICIENT_RIGHTS; 1888 return installer::INSUFFICIENT_RIGHTS;
1851 } 1889 }
1852 } 1890 }
1853 1891
1854 std::unique_ptr<installer::SetupSingleton> setup_singleton( 1892 std::unique_ptr<installer::SetupSingleton> setup_singleton(
1855 installer::SetupSingleton::Acquire(cmd_line, prefs, &original_state, 1893 installer::SetupSingleton::Acquire(cmd_line, prefs, &original_state,
grt (UTC plus 2) 2016/09/13 08:10:41 how about UMA for how much time it takes to acquir
fdoray 2016/09/13 21:34:54 It can't take more than 5+5 seconds = 10 seconds h
grt (UTC plus 2) 2016/09/14 10:42:10 I forgot about the short timeout. No, I think that
1856 &installer_state)); 1894 &installer_state));
1857 if (!setup_singleton) { 1895 if (!setup_singleton) {
1858 installer_state.WriteInstallerResult( 1896 installer_state.WriteInstallerResult(
1859 installer::SETUP_SINGLETON_ACQUISITION_FAILED, 1897 installer::SETUP_SINGLETON_ACQUISITION_FAILED,
1860 IDS_INSTALL_SINGLETON_ACQUISITION_FAILED_BASE, nullptr); 1898 IDS_INSTALL_SINGLETON_ACQUISITION_FAILED_BASE, nullptr);
1861 return installer::SETUP_SINGLETON_ACQUISITION_FAILED; 1899 return installer::SETUP_SINGLETON_ACQUISITION_FAILED;
1862 } 1900 }
1863 1901
1864 UninstallMultiChromeFrameIfPresent(cmd_line, prefs, 1902 UninstallMultiChromeFrameIfPresent(cmd_line, prefs,
1865 &original_state, &installer_state); 1903 &original_state, &installer_state);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1910 // never invoked directly by Google Update. 1948 // never invoked directly by Google Update.
1911 return_code = InstallUtil::GetInstallReturnCode(install_status); 1949 return_code = InstallUtil::GetInstallReturnCode(install_status);
1912 } 1950 }
1913 1951
1914 installer::EndPersistentHistogramStorage(installer_state.target_path(), 1952 installer::EndPersistentHistogramStorage(installer_state.target_path(),
1915 system_install); 1953 system_install);
1916 VLOG(1) << "Installation complete, returning: " << return_code; 1954 VLOG(1) << "Installation complete, returning: " << return_code;
1917 1955
1918 return return_code; 1956 return return_code;
1919 } 1957 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698