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 // This file defines the methods useful for uninstalling Chrome. | 5 // This file defines the methods useful for uninstalling Chrome. |
6 | 6 |
7 #include "chrome/installer/setup/uninstall.h" | 7 #include "chrome/installer/setup/uninstall.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 | 42 |
43 // Build-time generated include file. | 43 // Build-time generated include file. |
44 #include "registered_dlls.h" // NOLINT | 44 #include "registered_dlls.h" // NOLINT |
45 | 45 |
46 using base::win::RegKey; | 46 using base::win::RegKey; |
47 using installer::InstallStatus; | 47 using installer::InstallStatus; |
48 using installer::MasterPreferences; | 48 using installer::MasterPreferences; |
49 | 49 |
50 namespace { | 50 namespace { |
51 | 51 |
52 // Avoid leaving behind a Temp dir. If one exists, ask SelfCleaningTempDir to | |
53 // clean it up for us. This may involve scheduling it for deletion after | |
54 // reboot. Don't report that a reboot is required in this case, however. | |
55 // TODO(erikwright): Shouldn't this still lead to | |
56 // ScheduleParentAndGrandparentForDeletion? | |
tommi (sloooow) - chröme
2012/07/12 08:11:31
if so, file a bug for tracking?
erikwright (departed)
2012/07/16 20:13:11
I don't know the answer. I'll ask Greg OOB.
| |
57 void DeleteInstallTempDir(const FilePath& target_path) { | |
58 FilePath temp_path(target_path.DirName().Append(installer::kInstallTempDir)); | |
59 if (file_util::DirectoryExists(temp_path)) { | |
60 installer::SelfCleaningTempDir temp_dir; | |
61 if (!temp_dir.Initialize(target_path.DirName(), | |
62 installer::kInstallTempDir) || | |
63 !temp_dir.Delete()) { | |
64 LOG(ERROR) << "Failed to delete temp dir " << temp_path.value(); | |
65 } | |
66 } | |
67 } | |
68 | |
52 // Makes appropriate changes to the Google Update "ap" value in the registry. | 69 // Makes appropriate changes to the Google Update "ap" value in the registry. |
53 // Specifically, removes the flags associated with this product ("-chrome" or | 70 // Specifically, removes the flags associated with this product ("-chrome" or |
54 // "-chromeframe[-readymode]") from the "ap" values for all other | 71 // "-chromeframe[-readymode]") from the "ap" values for all other |
55 // installed products and for the multi-installer package. | 72 // installed products and for the multi-installer package. |
56 void ProcessGoogleUpdateItems( | 73 void ProcessGoogleUpdateItems( |
57 const installer::InstallationState& original_state, | 74 const installer::InstallationState& original_state, |
58 const installer::InstallerState& installer_state, | 75 const installer::InstallerState& installer_state, |
59 const installer::Product& product) { | 76 const installer::Product& product) { |
60 DCHECK(installer_state.is_multi_install()); | 77 DCHECK(installer_state.is_multi_install()); |
61 const bool system_level = installer_state.system_install(); | 78 const bool system_level = installer_state.system_install(); |
62 BrowserDistribution* distribution = product.distribution(); | 79 BrowserDistribution* distribution = product.distribution(); |
63 const HKEY reg_root = installer_state.root_key(); | 80 const HKEY reg_root = installer_state.root_key(); |
64 const installer::ProductState* product_state = | 81 const installer::ProductState* product_state = |
65 original_state.GetProductState(system_level, distribution->GetType()); | 82 original_state.GetProductState(system_level, distribution->GetType()); |
66 DCHECK(product_state != NULL); | 83 DCHECK(product_state != NULL); |
67 installer::ChannelInfo channel_info; | 84 installer::ChannelInfo channel_info; |
68 | 85 |
69 // Remove product's flags from the channel value. | 86 // Remove product's flags from the channel value. |
70 channel_info.set_value(product_state->channel().value()); | 87 channel_info.set_value(product_state->channel().value()); |
71 const bool modified = product.SetChannelFlags(false, &channel_info); | 88 const bool modified = product.SetChannelFlags(false, &channel_info); |
72 | 89 |
73 // Apply the new channel value to all other products and to the multi package. | 90 // Apply the new channel value to all other products and to the multi package. |
74 if (modified) { | 91 if (modified) { |
75 BrowserDistribution::Type other_dist_types[] = { | 92 std::vector<BrowserDistribution::Type> other_dist_types; |
76 (distribution->GetType() == BrowserDistribution::CHROME_BROWSER) ? | 93 for (size_t i = 0; i < BrowserDistribution::kNumProductTypes; ++i) { |
77 BrowserDistribution::CHROME_FRAME : | 94 if (distribution->GetType() != BrowserDistribution::kProductTypes[i]) |
78 BrowserDistribution::CHROME_BROWSER, | 95 other_dist_types.push_back(BrowserDistribution::kProductTypes[i]); |
79 BrowserDistribution::CHROME_BINARIES | 96 } |
80 }; | 97 |
81 scoped_ptr<WorkItemList> | 98 scoped_ptr<WorkItemList> |
82 update_list(WorkItem::CreateNoRollbackWorkItemList()); | 99 update_list(WorkItem::CreateNoRollbackWorkItemList()); |
83 | 100 |
84 for (int i = 0; i < arraysize(other_dist_types); ++i) { | 101 for (size_t i = 0; i < other_dist_types.size(); ++i) { |
102 // TODO(erikwright): Who updates the ap value for the binaries? | |
85 BrowserDistribution::Type other_dist_type = other_dist_types[i]; | 103 BrowserDistribution::Type other_dist_type = other_dist_types[i]; |
86 product_state = | 104 product_state = |
87 original_state.GetProductState(system_level, other_dist_type); | 105 original_state.GetProductState(system_level, other_dist_type); |
88 // Only modify other products if they're installed and multi. | 106 // Only modify other products if they're installed and multi. |
89 if (product_state != NULL && | 107 if (product_state != NULL && |
90 product_state->is_multi_install() && | 108 product_state->is_multi_install() && |
91 !product_state->channel().Equals(channel_info)) { | 109 !product_state->channel().Equals(channel_info)) { |
92 BrowserDistribution* other_dist = | 110 BrowserDistribution* other_dist = |
93 BrowserDistribution::GetSpecificDistribution(other_dist_type); | 111 BrowserDistribution::GetSpecificDistribution(other_dist_type); |
94 update_list->AddSetRegValueWorkItem(reg_root, other_dist->GetStateKey(), | 112 update_list->AddSetRegValueWorkItem(reg_root, other_dist->GetStateKey(), |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 // We cannot delete the file right away, but try to delete it some other | 407 // We cannot delete the file right away, but try to delete it some other |
390 // way. Either with the help of a different process or the system. | 408 // way. Either with the help of a different process or the system. |
391 if (ret && !file_util::DeleteAfterReboot(temp_file)) { | 409 if (ret && !file_util::DeleteAfterReboot(temp_file)) { |
392 static const uint32 kDeleteAfterMs = 10 * 1000; | 410 static const uint32 kDeleteAfterMs = 10 * 1000; |
393 installer::DeleteFileFromTempProcess(temp_file, kDeleteAfterMs); | 411 installer::DeleteFileFromTempProcess(temp_file, kDeleteAfterMs); |
394 } | 412 } |
395 } | 413 } |
396 return ret; | 414 return ret; |
397 } | 415 } |
398 | 416 |
399 DeleteResult DeleteFilesAndFolders(const InstallerState& installer_state, | 417 DeleteResult DeleteAppHostFilesAndFolders(const InstallerState& installer_state, |
400 const Version& installed_version) { | 418 const Version& installed_version) { |
401 const FilePath& target_path = installer_state.target_path(); | 419 const FilePath& target_path = installer_state.target_path(); |
402 if (target_path.empty()) { | 420 if (target_path.empty()) { |
403 LOG(ERROR) << "DeleteFilesAndFolders: no installation destination path."; | 421 LOG(ERROR) << "DeleteAppHostFilesAndFolders: no installation destination " |
422 << "path."; | |
404 return DELETE_FAILED; // Nothing else we can do to uninstall, so we return. | 423 return DELETE_FAILED; // Nothing else we can do to uninstall, so we return. |
405 } | 424 } |
406 | 425 |
426 DeleteInstallTempDir(target_path); | |
427 | |
407 DeleteResult result = DELETE_SUCCEEDED; | 428 DeleteResult result = DELETE_SUCCEEDED; |
408 | 429 |
409 // Avoid leaving behind a Temp dir. If one exists, ask SelfCleaningTempDir to | 430 FilePath app_host_exe(target_path.Append(installer::kChromeAppHostExe)); |
410 // clean it up for us. This may involve scheduling it for deletion after | 431 if (!file_util::Delete(app_host_exe, false)) { |
411 // reboot. Don't report that a reboot is required in this case, however. | 432 result = DELETE_FAILED; |
412 FilePath temp_path(target_path.DirName().Append(kInstallTempDir)); | 433 LOG(ERROR) << "Failed to delete path: " << app_host_exe.value(); |
413 if (file_util::DirectoryExists(temp_path)) { | 434 } else { |
414 installer::SelfCleaningTempDir temp_dir; | 435 DeleteEmptyParentDir(target_path); |
415 if (!temp_dir.Initialize(target_path.DirName(), kInstallTempDir) || | |
416 !temp_dir.Delete()) { | |
417 LOG(ERROR) << "Failed to delete temp dir " << temp_path.value(); | |
418 } | |
419 } | 436 } |
420 | 437 |
421 VLOG(1) << "Deleting install path " << target_path.value(); | 438 return result; |
422 if (!file_util::Delete(target_path, true)) { | 439 } |
423 LOG(ERROR) << "Failed to delete folder (1st try): " << target_path.value(); | 440 |
424 if (installer_state.FindProduct(BrowserDistribution::CHROME_FRAME)) { | 441 DeleteResult DeleteChromeFilesAndFolders(const InstallerState& installer_state, |
425 // We don't try killing Chrome processes for Chrome Frame builds since | 442 const Version& installed_version) { |
426 // that is unlikely to help. Instead, schedule files for deletion and | 443 const FilePath& target_path = installer_state.target_path(); |
427 // return a value that will trigger a reboot prompt. | 444 if (target_path.empty()) { |
428 ScheduleDirectoryForDeletion(target_path.value().c_str()); | 445 LOG(ERROR) << "DeleteChromeFilesAndFolders: no installation destination " |
429 result = DELETE_REQUIRES_REBOOT; | 446 << "path."; |
430 } else { | 447 return DELETE_FAILED; // Nothing else we can do to uninstall, so we return. |
431 // Try closing any running chrome processes and deleting files once again. | 448 } |
432 CloseAllChromeProcesses(); | 449 |
433 if (!file_util::Delete(target_path, true)) { | 450 DeleteInstallTempDir(target_path); |
434 LOG(ERROR) << "Failed to delete folder (2nd try): " | 451 |
435 << target_path.value(); | 452 DeleteResult result = DELETE_SUCCEEDED; |
436 result = DELETE_FAILED; | 453 |
454 using file_util::FileEnumerator; | |
455 FileEnumerator file_enumerator( | |
456 target_path, | |
457 false, | |
458 static_cast<FileEnumerator::FileType>(FileEnumerator::FILES | | |
459 FileEnumerator::DIRECTORIES)); | |
460 while (true) { | |
461 FilePath to_delete(file_enumerator.Next()); | |
462 if (to_delete.empty()) | |
463 break; | |
464 if (to_delete.BaseName().value() == installer::kChromeAppHostExe) | |
465 continue; | |
466 | |
467 VLOG(1) << "Deleting install path " << target_path.value(); | |
468 if (!file_util::Delete(to_delete, true)) { | |
469 LOG(ERROR) << "Failed to delete path (1st try): " << to_delete.value(); | |
470 if (installer_state.FindProduct(BrowserDistribution::CHROME_FRAME)) { | |
471 // We don't try killing Chrome processes for Chrome Frame builds since | |
472 // that is unlikely to help. Instead, schedule files for deletion and | |
473 // return a value that will trigger a reboot prompt. | |
474 FileEnumerator::FindInfo find_info; | |
475 file_enumerator.GetFindInfo(&find_info); | |
476 if (FileEnumerator::IsDirectory(find_info)) | |
477 ScheduleDirectoryForDeletion(to_delete.value().c_str()); | |
478 else | |
479 ScheduleFileSystemEntityForDeletion(to_delete.value().c_str()); | |
480 result = DELETE_REQUIRES_REBOOT; | |
481 } else { | |
482 // Try closing any running Chrome processes and deleting files once | |
483 // again. | |
484 CloseAllChromeProcesses(); | |
485 if (!file_util::Delete(to_delete, true)) { | |
486 LOG(ERROR) << "Failed to delete path (2nd try): " | |
487 << to_delete.value(); | |
488 result = DELETE_FAILED; | |
489 break; | |
490 } | |
437 } | 491 } |
438 } | 492 } |
439 } | 493 } |
440 | 494 |
441 if (result == DELETE_REQUIRES_REBOOT) { | 495 if (result == DELETE_REQUIRES_REBOOT) { |
442 // If we need a reboot to continue, schedule the parent directories for | 496 // If we need a reboot to continue, schedule the parent directories for |
443 // deletion unconditionally. If they are not empty, the session manager | 497 // deletion unconditionally. If they are not empty, the session manager |
444 // will not delete them on reboot. | 498 // will not delete them on reboot. |
445 ScheduleParentAndGrandparentForDeletion(target_path); | 499 ScheduleParentAndGrandparentForDeletion(target_path); |
446 } else { | 500 } else { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 | 544 |
491 bool ShouldDeleteProfile(const InstallerState& installer_state, | 545 bool ShouldDeleteProfile(const InstallerState& installer_state, |
492 const CommandLine& cmd_line, InstallStatus status, | 546 const CommandLine& cmd_line, InstallStatus status, |
493 const Product& product) { | 547 const Product& product) { |
494 bool should_delete = false; | 548 bool should_delete = false; |
495 | 549 |
496 // Chrome Frame uninstallations always want to delete the profile (we have no | 550 // Chrome Frame uninstallations always want to delete the profile (we have no |
497 // UI to prompt otherwise and the profile stores no useful data anyway) | 551 // UI to prompt otherwise and the profile stores no useful data anyway) |
498 // unless they are managed by MSI. MSI uninstalls will explicitly include | 552 // unless they are managed by MSI. MSI uninstalls will explicitly include |
499 // the --delete-profile flag to distinguish them from MSI upgrades. | 553 // the --delete-profile flag to distinguish them from MSI upgrades. |
500 if (!product.is_chrome() && !installer_state.is_msi()) { | 554 if (product.is_chrome_frame() && !installer_state.is_msi()) { |
501 should_delete = true; | 555 should_delete = true; |
502 } else { | 556 } else { |
503 should_delete = | 557 should_delete = |
504 status == installer::UNINSTALL_DELETE_PROFILE || | 558 status == installer::UNINSTALL_DELETE_PROFILE || |
505 cmd_line.HasSwitch(installer::switches::kDeleteProfile); | 559 cmd_line.HasSwitch(installer::switches::kDeleteProfile); |
506 } | 560 } |
507 | 561 |
508 return should_delete; | 562 return should_delete; |
509 } | 563 } |
510 | 564 |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
833 if (installer_state.system_install() || | 887 if (installer_state.system_install() || |
834 (remove_all && | 888 (remove_all && |
835 ShellUtil::QuickIsChromeRegisteredInHKLM( | 889 ShellUtil::QuickIsChromeRegisteredInHKLM( |
836 browser_dist, chrome_exe, suffix))) { | 890 browser_dist, chrome_exe, suffix))) { |
837 DeleteChromeRegistrationKeys(browser_dist, HKEY_LOCAL_MACHINE, suffix, | 891 DeleteChromeRegistrationKeys(browser_dist, HKEY_LOCAL_MACHINE, suffix, |
838 installer_state.target_path(), &ret); | 892 installer_state.target_path(), &ret); |
839 } | 893 } |
840 | 894 |
841 ProcessDelegateExecuteWorkItems(installer_state, product); | 895 ProcessDelegateExecuteWorkItems(installer_state, product); |
842 | 896 |
843 if (!is_chrome) { | 897 if (product.is_chrome_frame()) { |
844 ProcessChromeFrameWorkItems(original_state, installer_state, setup_path, | 898 ProcessChromeFrameWorkItems(original_state, installer_state, setup_path, |
845 product); | 899 product); |
846 } | 900 } |
847 | 901 |
848 if (installer_state.is_multi_install()) | 902 if (installer_state.is_multi_install()) |
849 ProcessGoogleUpdateItems(original_state, installer_state, product); | 903 ProcessGoogleUpdateItems(original_state, installer_state, product); |
850 | 904 |
851 ProcessQuickEnableWorkItems(installer_state, original_state); | 905 ProcessQuickEnableWorkItems(installer_state, original_state); |
852 | 906 |
853 // Get the state of the installed product (if any) | 907 // Get the state of the installed product (if any) |
(...skipping 27 matching lines...) Expand all Loading... | |
881 | 935 |
882 AddRegisterComDllWorkItems(dll_folder, | 936 AddRegisterComDllWorkItems(dll_folder, |
883 com_dll_list, | 937 com_dll_list, |
884 installer_state.system_install(), | 938 installer_state.system_install(), |
885 false, // Unregister | 939 false, // Unregister |
886 true, // May fail | 940 true, // May fail |
887 unreg_work_item_list.get()); | 941 unreg_work_item_list.get()); |
888 unreg_work_item_list->Do(); | 942 unreg_work_item_list->Do(); |
889 } | 943 } |
890 | 944 |
891 if (!is_chrome) | 945 if (product.is_chrome_frame()) |
892 ProcessIELowRightsPolicyWorkItems(installer_state); | 946 ProcessIELowRightsPolicyWorkItems(installer_state); |
893 } | 947 } |
894 | 948 |
895 // Close any Chrome Frame helper processes that may be running. | 949 // Close any Chrome Frame helper processes that may be running. |
896 if (product.is_chrome_frame()) { | 950 if (product.is_chrome_frame()) { |
897 VLOG(1) << "Closing the Chrome Frame helper process"; | 951 VLOG(1) << "Closing the Chrome Frame helper process"; |
898 CloseChromeFrameHelperProcess(); | 952 CloseChromeFrameHelperProcess(); |
899 } | 953 } |
900 | 954 |
901 if (product_state == NULL) | 955 if (product_state == NULL) |
902 return installer::UNINSTALL_SUCCESSFUL; | 956 return installer::UNINSTALL_SUCCESSFUL; |
903 | 957 |
904 // Finally delete all the files from Chrome folder after moving setup.exe | 958 // Finally delete all the files from Chrome folder after moving setup.exe |
905 // and the user's Local State to a temp location. | 959 // and the user's Local State to a temp location. |
906 bool delete_profile = ShouldDeleteProfile(installer_state, cmd_line, status, | 960 bool delete_profile = ShouldDeleteProfile(installer_state, cmd_line, status, |
907 product); | 961 product); |
908 ret = installer::UNINSTALL_SUCCESSFUL; | 962 ret = installer::UNINSTALL_SUCCESSFUL; |
909 | 963 |
910 // When deleting files, we must make sure that we're either a "single" | 964 // When deleting files, we must make sure that we're either a "single" |
911 // (aka non-multi) installation or, in the case of multi, that no other | 965 // (aka non-multi) installation or we are the Chrome Binaries. |
912 // "multi" products share the binaries we are about to delete. | |
913 | 966 |
914 bool can_delete_files = true; | 967 FilePath backup_state_file( |
915 if (installer_state.is_multi_install()) { | 968 BackupLocalStateFile(GetLocalStateFolder(product))); |
916 ProductState prod_state; | |
917 for (size_t i = 0; i < BrowserDistribution::kNumProductTypes; ++i) { | |
918 if (prod_state.Initialize(installer_state.system_install(), | |
919 BrowserDistribution::kProductTypes[i]) && | |
920 prod_state.is_multi_install()) { | |
921 can_delete_files = false; | |
922 break; | |
923 } | |
924 } | |
925 LOG(INFO) << (can_delete_files ? "Shared binaries will be deleted." : | |
926 "Shared binaries still in use."); | |
927 if (can_delete_files) { | |
928 BrowserDistribution* multi_dist = | |
929 installer_state.multi_package_binaries_distribution(); | |
930 InstallUtil::DeleteRegistryKey(reg_root, multi_dist->GetVersionKey()); | |
931 } | |
932 } | |
933 | |
934 FilePath backup_state_file(BackupLocalStateFile( | |
935 GetLocalStateFolder(product))); | |
936 | 969 |
937 DeleteResult delete_result = DELETE_SUCCEEDED; | 970 DeleteResult delete_result = DELETE_SUCCEEDED; |
938 if (can_delete_files) { | 971 |
972 if (product.is_chrome_app_host()) { | |
973 DeleteAppHostFilesAndFolders(installer_state, product_state->version()); | |
974 } else if (!installer_state.is_multi_install() || | |
975 product.is_chrome_binaries()) { | |
976 | |
939 // In order to be able to remove the folder in which we're running, we | 977 // In order to be able to remove the folder in which we're running, we |
940 // need to move setup.exe out of the install folder. | 978 // need to move setup.exe out of the install folder. |
941 // TODO(tommi): What if the temp folder is on a different volume? | 979 // TODO(tommi): What if the temp folder is on a different volume? |
942 MoveSetupOutOfInstallFolder(installer_state, setup_path, | 980 MoveSetupOutOfInstallFolder(installer_state, setup_path, |
943 product_state->version()); | 981 product_state->version()); |
944 delete_result = DeleteFilesAndFolders(installer_state, | 982 delete_result = DeleteChromeFilesAndFolders(installer_state, |
945 product_state->version()); | 983 product_state->version()); |
946 } | 984 } |
947 | 985 |
948 if (delete_profile) | 986 if (delete_profile) |
949 DeleteLocalState(product); | 987 DeleteLocalState(product); |
950 | 988 |
951 if (delete_result == DELETE_FAILED) { | 989 if (delete_result == DELETE_FAILED) { |
952 ret = installer::UNINSTALL_FAILED; | 990 ret = installer::UNINSTALL_FAILED; |
953 } else if (delete_result == DELETE_REQUIRES_REBOOT) { | 991 } else if (delete_result == DELETE_REQUIRES_REBOOT) { |
954 ret = installer::UNINSTALL_REQUIRES_REBOOT; | 992 ret = installer::UNINSTALL_REQUIRES_REBOOT; |
955 } | 993 } |
956 | 994 |
957 if (!force_uninstall) { | 995 if (!force_uninstall) { |
958 VLOG(1) << "Uninstallation complete. Launching Uninstall survey."; | 996 VLOG(1) << "Uninstallation complete. Launching post-uninstall operations."; |
959 browser_dist->DoPostUninstallOperations(product_state->version(), | 997 browser_dist->DoPostUninstallOperations(product_state->version(), |
960 backup_state_file, distribution_data); | 998 backup_state_file, distribution_data); |
961 } | 999 } |
962 | 1000 |
963 // Try and delete the preserved local state once the post-install | 1001 // Try and delete the preserved local state once the post-install |
964 // operations are complete. | 1002 // operations are complete. |
965 if (!backup_state_file.empty()) | 1003 if (!backup_state_file.empty()) |
966 file_util::Delete(backup_state_file, false); | 1004 file_util::Delete(backup_state_file, false); |
967 | 1005 |
968 return ret; | 1006 return ret; |
969 } | 1007 } |
970 | 1008 |
971 } // namespace installer | 1009 } // namespace installer |
OLD | NEW |