| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <atlbase.h> | |
| 10 #include <windows.h> | |
| 11 #include <msi.h> | |
| 12 | |
| 13 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 14 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 15 #include "base/process_util.h" | |
| 16 #include "base/registry.h" | 11 #include "base/registry.h" |
| 17 #include "base/scoped_ptr.h" | |
| 18 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 19 #include "base/win_util.h" | |
| 20 #include "base/wmi_util.h" | |
| 21 #include "chrome/app/result_codes.h" | 13 #include "chrome/app/result_codes.h" |
| 22 #include "chrome/common/chrome_constants.h" | |
| 23 #include "chrome/installer/setup/setup.h" | 14 #include "chrome/installer/setup/setup.h" |
| 24 #include "chrome/installer/setup/setup_constants.h" | 15 #include "chrome/installer/setup/setup_constants.h" |
| 25 #include "chrome/installer/util/browser_distribution.h" | 16 #include "chrome/installer/util/browser_distribution.h" |
| 26 #include "chrome/installer/util/helper.h" | 17 #include "chrome/installer/util/helper.h" |
| 27 #include "chrome/installer/util/install_util.h" | |
| 28 #include "chrome/installer/util/l10n_string_util.h" | |
| 29 #include "chrome/installer/util/logging_installer.h" | 18 #include "chrome/installer/util/logging_installer.h" |
| 30 #include "chrome/installer/util/google_update_constants.h" | |
| 31 #include "chrome/installer/util/google_update_settings.h" | |
| 32 #include "chrome/installer/util/shell_util.h" | 19 #include "chrome/installer/util/shell_util.h" |
| 33 #include "chrome/installer/util/util_constants.h" | |
| 34 #include "chrome/installer/util/version.h" | 20 #include "chrome/installer/util/version.h" |
| 35 | 21 |
| 36 #include "installer_util_strings.h" | |
| 37 | |
| 38 namespace { | 22 namespace { |
| 39 | 23 |
| 40 // This functions checks for any Chrome instances that are | 24 // This functions checks for any Chrome instances that are |
| 41 // running and first asks them to close politely by sending a Windows message. | 25 // running and first asks them to close politely by sending a Windows message. |
| 42 // If there is an error while sending message or if there are still Chrome | 26 // If there is an error while sending message or if there are still Chrome |
| 43 // procesess active after the message has been sent, this function will try | 27 // procesess active after the message has been sent, this function will try |
| 44 // to kill them. | 28 // to kill them. |
| 45 void CloseAllChromeProcesses() { | 29 void CloseAllChromeProcesses() { |
| 46 for (int j = 0; j < 4; ++j) { | 30 for (int j = 0; j < 4; ++j) { |
| 47 std::wstring wnd_class(L"Chrome_ContainerWin_"); | 31 std::wstring wnd_class(L"Chrome_ContainerWin_"); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 install_path, installed_version.GetString())); | 96 install_path, installed_version.GetString())); |
| 113 file_util::AppendToPath(&setup_exe, file_util::GetFilenameFromPath(exe_path)); | 97 file_util::AppendToPath(&setup_exe, file_util::GetFilenameFromPath(exe_path)); |
| 114 | 98 |
| 115 std::wstring temp_file; | 99 std::wstring temp_file; |
| 116 file_util::CreateTemporaryFileName(&temp_file); | 100 file_util::CreateTemporaryFileName(&temp_file); |
| 117 file_util::Move(setup_exe, temp_file); | 101 file_util::Move(setup_exe, temp_file); |
| 118 | 102 |
| 119 LOG(INFO) << "Deleting install path " << install_path; | 103 LOG(INFO) << "Deleting install path " << install_path; |
| 120 if (!file_util::Delete(install_path, true)) { | 104 if (!file_util::Delete(install_path, true)) { |
| 121 LOG(ERROR) << "Failed to delete folder (1st try): " << install_path; | 105 LOG(ERROR) << "Failed to delete folder (1st try): " << install_path; |
| 122 // This is to let any closing chrome.exe die before trying delete one | 106 // Try closing any running chrome processes and deleting files once again. |
| 123 // more time. | 107 CloseAllChromeProcesses(); |
| 124 Sleep(10000); | |
| 125 if (!file_util::Delete(install_path, true)) | 108 if (!file_util::Delete(install_path, true)) |
| 126 LOG(ERROR) << "Failed to delete folder (2nd try): " << install_path; | 109 LOG(ERROR) << "Failed to delete folder (2nd try): " << install_path; |
| 127 } | 110 } |
| 128 | 111 |
| 129 // Now check and delete if the parent directories are empty | 112 // Now check and delete if the parent directories are empty |
| 130 // For example Google\Chrome or Chromium | 113 // For example Google\Chrome or Chromium |
| 131 std::wstring parent_dir = file_util::GetDirectoryFromPath(install_path); | 114 std::wstring parent_dir = file_util::GetDirectoryFromPath(install_path); |
| 132 if (!parent_dir.empty() && file_util::IsDirectoryEmpty(parent_dir)) { | 115 if (!parent_dir.empty() && file_util::IsDirectoryEmpty(parent_dir)) { |
| 133 if (!file_util::Delete(parent_dir, true)) | 116 if (!file_util::Delete(parent_dir, true)) |
| 134 LOG(ERROR) << "Failed to delete folder: " << parent_dir; | 117 LOG(ERROR) << "Failed to delete folder: " << parent_dir; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 installer_util::InstallStatus status = | 194 installer_util::InstallStatus status = |
| 212 IsChromeActiveOrUserCancelled(system_uninstall); | 195 IsChromeActiveOrUserCancelled(system_uninstall); |
| 213 if (status != installer_util::UNINSTALL_CONFIRMED) | 196 if (status != installer_util::UNINSTALL_CONFIRMED) |
| 214 return status; | 197 return status; |
| 215 } else { | 198 } else { |
| 216 // Since --force-uninstall command line option is used, we are going to | 199 // Since --force-uninstall command line option is used, we are going to |
| 217 // do silent uninstall. Try to close all running Chrome instances. | 200 // do silent uninstall. Try to close all running Chrome instances. |
| 218 CloseAllChromeProcesses(); | 201 CloseAllChromeProcesses(); |
| 219 } | 202 } |
| 220 | 203 |
| 221 #if defined(GOOGLE_CHROME_BUILD) | |
| 222 // TODO(rahulk): This should be done by DoPreUninstallOperations call above | |
| 223 wchar_t product[39]; // GUID + '\0' | |
| 224 MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL); // Don't show any UI to user. | |
| 225 for (int i = 0; MsiEnumRelatedProducts(google_update::kGearsUpgradeCode, 0, i, | |
| 226 product) != ERROR_NO_MORE_ITEMS; ++i) { | |
| 227 LOG(INFO) << "Uninstalling Gears - " << product; | |
| 228 unsigned int ret = MsiConfigureProduct(product, INSTALLLEVEL_MAXIMUM, | |
| 229 INSTALLSTATE_ABSENT); | |
| 230 if (ret != ERROR_SUCCESS) | |
| 231 LOG(ERROR) << "Failed to uninstall Gears " << product << ": " << ret; | |
| 232 } | |
| 233 #endif | |
| 234 | |
| 235 // Chrome is not in use so lets uninstall Chrome by deleting various files | 204 // Chrome is not in use so lets uninstall Chrome by deleting various files |
| 236 // and registry entries. Here we will just make best effort and keep going | 205 // and registry entries. Here we will just make best effort and keep going |
| 237 // in case of errors. | 206 // in case of errors. |
| 238 // First delete shortcut from Start->Programs. | 207 // First delete shortcut from Start->Programs. |
| 239 DeleteChromeShortcut(system_uninstall); | 208 DeleteChromeShortcut(system_uninstall); |
| 240 | 209 |
| 241 // Delete the registry keys (Uninstall key and Version key). | 210 // Delete the registry keys (Uninstall key and Version key). |
| 242 HKEY reg_root = system_uninstall ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 211 HKEY reg_root = system_uninstall ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 243 RegKey key(reg_root, L"", KEY_ALL_ACCESS); | 212 RegKey key(reg_root, L"", KEY_ALL_ACCESS); |
| 244 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 213 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 // Finally delete all the files from Chrome folder after moving setup.exe | 249 // Finally delete all the files from Chrome folder after moving setup.exe |
| 281 // to a temp location. | 250 // to a temp location. |
| 282 if (!DeleteFilesAndFolders(exe_path, system_uninstall, installed_version)) | 251 if (!DeleteFilesAndFolders(exe_path, system_uninstall, installed_version)) |
| 283 return installer_util::UNINSTALL_FAILED; | 252 return installer_util::UNINSTALL_FAILED; |
| 284 | 253 |
| 285 LOG(INFO) << "Uninstallation complete. Launching Uninstall survey."; | 254 LOG(INFO) << "Uninstallation complete. Launching Uninstall survey."; |
| 286 dist->DoPostUninstallOperations(installed_version); | 255 dist->DoPostUninstallOperations(installed_version); |
| 287 return installer_util::UNINSTALL_SUCCESSFUL; | 256 return installer_util::UNINSTALL_SUCCESSFUL; |
| 288 } | 257 } |
| 289 | 258 |
| OLD | NEW |