| 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 "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 // Deletes all installed files of Chromium and Folders. Before deleting it | 95 // Deletes all installed files of Chromium and Folders. Before deleting it |
| 96 // needs to move setup.exe in a temp folder because the current process | 96 // needs to move setup.exe in a temp folder because the current process |
| 97 // is using that file. It returns false when it can not get the path to | 97 // is using that file. It returns false when it can not get the path to |
| 98 // installation folder, in all other cases it returns true even in case | 98 // installation folder, in all other cases it returns true even in case |
| 99 // of error (only logs the error). | 99 // of error (only logs the error). |
| 100 bool DeleteFilesAndFolders(const std::wstring& exe_path, bool system_uninstall, | 100 bool DeleteFilesAndFolders(const std::wstring& exe_path, bool system_uninstall, |
| 101 const installer::Version& installed_version, | 101 const installer::Version& installed_version, |
| 102 std::wstring* local_state_path) { | 102 std::wstring* local_state_path, bool delete_profile) { |
| 103 std::wstring install_path(installer::GetChromeInstallPath(system_uninstall)); | 103 std::wstring install_path(installer::GetChromeInstallPath(system_uninstall)); |
| 104 if (install_path.empty()) { | 104 if (install_path.empty()) { |
| 105 LOG(ERROR) << "Could not get installation destination path."; | 105 LOG(ERROR) << "Could not get installation destination path."; |
| 106 return false; // Nothing else we can do for uninstall, so we return. | 106 return false; // Nothing else we can do for uninstall, so we return. |
| 107 } else { | 107 } else { |
| 108 LOG(INFO) << "install destination path: " << install_path; | 108 LOG(INFO) << "install destination path: " << install_path; |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Move setup.exe to the temp path. | 111 // Move setup.exe to the temp path. |
| 112 std::wstring setup_exe(installer::GetInstallerPathUnderChrome( | 112 std::wstring setup_exe(installer::GetInstallerPathUnderChrome( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 129 | 129 |
| 130 LOG(INFO) << "Deleting install path " << install_path; | 130 LOG(INFO) << "Deleting install path " << install_path; |
| 131 if (!file_util::Delete(install_path, true)) { | 131 if (!file_util::Delete(install_path, true)) { |
| 132 LOG(ERROR) << "Failed to delete folder (1st try): " << install_path; | 132 LOG(ERROR) << "Failed to delete folder (1st try): " << install_path; |
| 133 // Try closing any running chrome processes and deleting files once again. | 133 // Try closing any running chrome processes and deleting files once again. |
| 134 CloseAllChromeProcesses(); | 134 CloseAllChromeProcesses(); |
| 135 if (!file_util::Delete(install_path, true)) | 135 if (!file_util::Delete(install_path, true)) |
| 136 LOG(ERROR) << "Failed to delete folder (2nd try): " << install_path; | 136 LOG(ERROR) << "Failed to delete folder (2nd try): " << install_path; |
| 137 } | 137 } |
| 138 | 138 |
| 139 if (delete_profile) { |
| 140 LOG(INFO) << "Deleting user profile" << user_local_state.value(); |
| 141 if (!file_util::Delete(user_local_state, true)) |
| 142 LOG(ERROR) << "Failed to delete user profle dir: " |
| 143 << user_local_state.value(); |
| 144 } |
| 145 |
| 139 // Now check and delete if the parent directories are empty | 146 // Now check and delete if the parent directories are empty |
| 140 // For example Google\Chrome or Chromium | 147 // For example Google\Chrome or Chromium |
| 141 std::wstring parent_dir = file_util::GetDirectoryFromPath(install_path); | 148 std::wstring parent_dir = file_util::GetDirectoryFromPath(install_path); |
| 142 if (!parent_dir.empty() && file_util::IsDirectoryEmpty(parent_dir)) { | 149 if (!parent_dir.empty() && file_util::IsDirectoryEmpty(parent_dir)) { |
| 143 if (!file_util::Delete(parent_dir, true)) | 150 if (!file_util::Delete(parent_dir, true)) |
| 144 LOG(ERROR) << "Failed to delete folder: " << parent_dir; | 151 LOG(ERROR) << "Failed to delete folder: " << parent_dir; |
| 145 parent_dir = file_util::GetDirectoryFromPath(parent_dir); | 152 parent_dir = file_util::GetDirectoryFromPath(parent_dir); |
| 146 if (!parent_dir.empty() && | 153 if (!parent_dir.empty() && |
| 147 file_util::IsDirectoryEmpty(parent_dir)) { | 154 file_util::IsDirectoryEmpty(parent_dir)) { |
| 148 if (!file_util::Delete(parent_dir, true)) | 155 if (!file_util::Delete(parent_dir, true)) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 // give this method some brains and not kill chrome.exe launched | 202 // give this method some brains and not kill chrome.exe launched |
| 196 // by us, we will not uninstall if we get this return code). | 203 // by us, we will not uninstall if we get this return code). |
| 197 LOG(INFO) << "Launching Chrome to do uninstall tasks."; | 204 LOG(INFO) << "Launching Chrome to do uninstall tasks."; |
| 198 if (installer::LaunchChromeAndWaitForResult(system_uninstall, | 205 if (installer::LaunchChromeAndWaitForResult(system_uninstall, |
| 199 kCmdLineOptions, | 206 kCmdLineOptions, |
| 200 &exit_code)) { | 207 &exit_code)) { |
| 201 LOG(INFO) << "chrome.exe launched for uninstall confirmation returned: " | 208 LOG(INFO) << "chrome.exe launched for uninstall confirmation returned: " |
| 202 << exit_code; | 209 << exit_code; |
| 203 if ((exit_code == ResultCodes::UNINSTALL_CHROME_ALIVE) || | 210 if ((exit_code == ResultCodes::UNINSTALL_CHROME_ALIVE) || |
| 204 (exit_code == ResultCodes::UNINSTALL_USER_CANCEL) || | 211 (exit_code == ResultCodes::UNINSTALL_USER_CANCEL) || |
| 205 (exit_code == ResultCodes::HUNG)) | 212 (exit_code == ResultCodes::HUNG)) { |
| 206 return installer_util::UNINSTALL_CANCELLED; | 213 return installer_util::UNINSTALL_CANCELLED; |
| 214 } else if (exit_code == ResultCodes::UNINSTALL_DELETE_PROFILE) { |
| 215 return installer_util::UNINSTALL_DELETE_PROFILE; |
| 216 } |
| 207 } else { | 217 } else { |
| 208 LOG(ERROR) << "Failed to launch chrome.exe for uninstall confirmation."; | 218 LOG(ERROR) << "Failed to launch chrome.exe for uninstall confirmation."; |
| 209 } | 219 } |
| 210 | 220 |
| 211 return installer_util::UNINSTALL_CONFIRMED; | 221 return installer_util::UNINSTALL_CONFIRMED; |
| 212 } | 222 } |
| 213 } // namespace | 223 } // namespace |
| 214 | 224 |
| 215 | 225 |
| 216 installer_util::InstallStatus installer_setup::UninstallChrome( | 226 installer_util::InstallStatus installer_setup::UninstallChrome( |
| 217 const std::wstring& exe_path, bool system_uninstall, | 227 const std::wstring& exe_path, bool system_uninstall, |
| 218 const installer::Version& installed_version, | 228 const installer::Version& installed_version, |
| 219 bool remove_all, bool force_uninstall) { | 229 bool remove_all, bool force_uninstall) { |
| 230 installer_util::InstallStatus status = installer_util::UNINSTALL_CONFIRMED; |
| 220 if (!force_uninstall) { | 231 if (!force_uninstall) { |
| 221 installer_util::InstallStatus status = | 232 status = IsChromeActiveOrUserCancelled(system_uninstall); |
| 222 IsChromeActiveOrUserCancelled(system_uninstall); | 233 if (status != installer_util::UNINSTALL_CONFIRMED && |
| 223 if (status != installer_util::UNINSTALL_CONFIRMED) | 234 status != installer_util::UNINSTALL_DELETE_PROFILE) |
| 224 return status; | 235 return status; |
| 225 } else { | 236 } else { |
| 226 // Since --force-uninstall command line option is used, we are going to | 237 // Since --force-uninstall command line option is used, we are going to |
| 227 // do silent uninstall. Try to close all running Chrome instances. | 238 // do silent uninstall. Try to close all running Chrome instances. |
| 228 CloseAllChromeProcesses(); | 239 CloseAllChromeProcesses(); |
| 229 } | 240 } |
| 230 | 241 |
| 231 // Chrome is not in use so lets uninstall Chrome by deleting various files | 242 // Chrome is not in use so lets uninstall Chrome by deleting various files |
| 232 // and registry entries. Here we will just make best effort and keep going | 243 // and registry entries. Here we will just make best effort and keep going |
| 233 // in case of errors. | 244 // in case of errors. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 scoped_ptr<WorkItemList> dll_list(WorkItem::CreateWorkItemList()); | 329 scoped_ptr<WorkItemList> dll_list(WorkItem::CreateWorkItemList()); |
| 319 if (InstallUtil::BuildDLLRegistrationList(dll_path, kDllsToRegister, | 330 if (InstallUtil::BuildDLLRegistrationList(dll_path, kDllsToRegister, |
| 320 kNumDllsToRegister, false, | 331 kNumDllsToRegister, false, |
| 321 dll_list.get())) { | 332 dll_list.get())) { |
| 322 dll_list->Do(); | 333 dll_list->Do(); |
| 323 } | 334 } |
| 324 } | 335 } |
| 325 | 336 |
| 326 // Finally delete all the files from Chrome folder after moving setup.exe | 337 // Finally delete all the files from Chrome folder after moving setup.exe |
| 327 // and the user's Local State to a temp location. | 338 // and the user's Local State to a temp location. |
| 339 bool delete_profile = (status == installer_util::UNINSTALL_DELETE_PROFILE); |
| 328 std::wstring local_state_path; | 340 std::wstring local_state_path; |
| 341 installer_util::InstallStatus ret = installer_util::UNINSTALL_SUCCESSFUL; |
| 329 if (!DeleteFilesAndFolders(exe_path, system_uninstall, installed_version, | 342 if (!DeleteFilesAndFolders(exe_path, system_uninstall, installed_version, |
| 330 &local_state_path)) | 343 &local_state_path, delete_profile)) |
| 331 return installer_util::UNINSTALL_FAILED; | 344 ret = installer_util::UNINSTALL_FAILED; |
| 332 | 345 |
| 333 if (!force_uninstall) { | 346 if (!force_uninstall) { |
| 334 LOG(INFO) << "Uninstallation complete. Launching Uninstall survey."; | 347 LOG(INFO) << "Uninstallation complete. Launching Uninstall survey."; |
| 335 dist->DoPostUninstallOperations(installed_version, local_state_path); | 348 dist->DoPostUninstallOperations(installed_version, local_state_path); |
| 336 } | 349 } |
| 337 | 350 |
| 338 // Try and delete the preserved local state once the post-install | 351 // Try and delete the preserved local state once the post-install |
| 339 // operations are complete. | 352 // operations are complete. |
| 340 if (!local_state_path.empty()) | 353 if (!local_state_path.empty()) |
| 341 file_util::Delete(local_state_path, false); | 354 file_util::Delete(local_state_path, false); |
| 342 | 355 |
| 343 return installer_util::UNINSTALL_SUCCESSFUL; | 356 return ret; |
| 344 } | 357 } |
| OLD | NEW |