| 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 <shlobj.h> |
| 10 |
| 9 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 10 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 11 #include "base/registry.h" | 13 #include "base/registry.h" |
| 12 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/win_util.h" |
| 13 #include "chrome/common/result_codes.h" | 16 #include "chrome/common/result_codes.h" |
| 14 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" |
| 15 #include "chrome/common/chrome_paths_internal.h" | 18 #include "chrome/common/chrome_paths_internal.h" |
| 16 #include "chrome/installer/setup/setup.h" | 19 #include "chrome/installer/setup/setup.h" |
| 17 #include "chrome/installer/setup/setup_constants.h" | 20 #include "chrome/installer/setup/setup_constants.h" |
| 18 #include "chrome/installer/util/browser_distribution.h" | 21 #include "chrome/installer/util/browser_distribution.h" |
| 19 #include "chrome/installer/util/helper.h" | 22 #include "chrome/installer/util/helper.h" |
| 20 #include "chrome/installer/util/install_util.h" | 23 #include "chrome/installer/util/install_util.h" |
| 21 #include "chrome/installer/util/logging_installer.h" | 24 #include "chrome/installer/util/logging_installer.h" |
| 22 #include "chrome/installer/util/shell_util.h" | 25 #include "chrome/installer/util/shell_util.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 LOG(ERROR) << "Failed to launch chrome.exe for uninstall confirmation."; | 221 LOG(ERROR) << "Failed to launch chrome.exe for uninstall confirmation."; |
| 219 } | 222 } |
| 220 | 223 |
| 221 return installer_util::UNINSTALL_CONFIRMED; | 224 return installer_util::UNINSTALL_CONFIRMED; |
| 222 } | 225 } |
| 223 } // namespace | 226 } // namespace |
| 224 | 227 |
| 225 | 228 |
| 226 installer_util::InstallStatus installer_setup::UninstallChrome( | 229 installer_util::InstallStatus installer_setup::UninstallChrome( |
| 227 const std::wstring& exe_path, bool system_uninstall, | 230 const std::wstring& exe_path, bool system_uninstall, |
| 228 const installer::Version& installed_version, | 231 bool remove_all, bool force_uninstall, |
| 229 bool remove_all, bool force_uninstall) { | 232 const CommandLine& cmd_line, const wchar_t* cmd_params) { |
| 230 installer_util::InstallStatus status = installer_util::UNINSTALL_CONFIRMED; | 233 installer_util::InstallStatus status = installer_util::UNINSTALL_CONFIRMED; |
| 231 if (!force_uninstall) { | 234 if (force_uninstall) { |
| 235 // Since --force-uninstall command line option is used, we are going to |
| 236 // do silent uninstall. Try to close all running Chrome instances. |
| 237 CloseAllChromeProcesses(); |
| 238 } else { // no --force-uninstall so lets show some UI dialog boxes. |
| 232 status = IsChromeActiveOrUserCancelled(system_uninstall); | 239 status = IsChromeActiveOrUserCancelled(system_uninstall); |
| 233 if (status != installer_util::UNINSTALL_CONFIRMED && | 240 if (status != installer_util::UNINSTALL_CONFIRMED && |
| 234 status != installer_util::UNINSTALL_DELETE_PROFILE) | 241 status != installer_util::UNINSTALL_DELETE_PROFILE) |
| 235 return status; | 242 return status; |
| 236 } else { | 243 |
| 237 // Since --force-uninstall command line option is used, we are going to | 244 // Check if we need admin rights to cleanup HKLM. If we do, try to launch |
| 238 // do silent uninstall. Try to close all running Chrome instances. | 245 // another uninstaller (silent) in elevated mode to do HKLM cleanup. |
| 239 CloseAllChromeProcesses(); | 246 // And continue uninstalling in the current process also to do HKCU cleanup. |
| 247 if (remove_all && |
| 248 ShellUtil::AdminNeededForRegistryCleanup() && |
| 249 !::IsUserAnAdmin() && |
| 250 (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA) && |
| 251 !cmd_line.HasSwitch(installer_util::switches::kRunAsAdmin)) { |
| 252 std::wstring exe = cmd_line.program(); |
| 253 std::wstring params(cmd_params); |
| 254 // Append --run-as-admin flag to let the new instance of setup.exe know |
| 255 // that we already tried to launch ourselves as admin. |
| 256 params.append(L" --"); |
| 257 params.append(installer_util::switches::kRunAsAdmin); |
| 258 // Append --force-uninstall to keep it silent. |
| 259 params.append(L" --"); |
| 260 params.append(installer_util::switches::kForceUninstall); |
| 261 if (status == installer_util::UNINSTALL_DELETE_PROFILE) { |
| 262 params.append(L" --"); |
| 263 params.append(installer_util::switches::kDeleteProfile); |
| 264 } |
| 265 DWORD exit_code = installer_util::UNKNOWN_STATUS; |
| 266 InstallUtil::ExecuteExeAsAdmin(exe, params, &exit_code); |
| 267 } |
| 240 } | 268 } |
| 241 | 269 |
| 270 // Get the version of installed Chrome (if any) |
| 271 scoped_ptr<installer::Version> |
| 272 installed_version(InstallUtil::GetChromeVersion(system_uninstall)); |
| 273 |
| 242 // Chrome is not in use so lets uninstall Chrome by deleting various files | 274 // Chrome is not in use so lets uninstall Chrome by deleting various files |
| 243 // and registry entries. Here we will just make best effort and keep going | 275 // and registry entries. Here we will just make best effort and keep going |
| 244 // in case of errors. | 276 // in case of errors. |
| 245 // First delete shortcuts from Start->Programs, Desktop & Quick Launch. | 277 // First delete shortcuts from Start->Programs, Desktop & Quick Launch. |
| 246 DeleteChromeShortcut(system_uninstall); | 278 DeleteChromeShortcut(system_uninstall); |
| 247 | 279 |
| 248 // Delete the registry keys (Uninstall key and Version key). | 280 // Delete the registry keys (Uninstall key and Version key). |
| 249 HKEY reg_root = system_uninstall ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 281 HKEY reg_root = system_uninstall ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 250 RegKey key(reg_root, L"", KEY_ALL_ACCESS); | 282 RegKey key(reg_root, L"", KEY_ALL_ACCESS); |
| 251 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 283 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 std::wstring app_path_key(ShellUtil::kAppPathsRegistryKey); | 352 std::wstring app_path_key(ShellUtil::kAppPathsRegistryKey); |
| 321 file_util::AppendToPath(&app_path_key, installer_util::kChromeExe); | 353 file_util::AppendToPath(&app_path_key, installer_util::kChromeExe); |
| 322 DeleteRegistryKey(hklm_key, app_path_key); | 354 DeleteRegistryKey(hklm_key, app_path_key); |
| 323 | 355 |
| 324 // Delete media player registry key that exists only in HKLM. | 356 // Delete media player registry key that exists only in HKLM. |
| 325 std::wstring reg_path(installer::kMediaPlayerRegPath); | 357 std::wstring reg_path(installer::kMediaPlayerRegPath); |
| 326 file_util::AppendToPath(®_path, installer_util::kChromeExe); | 358 file_util::AppendToPath(®_path, installer_util::kChromeExe); |
| 327 DeleteRegistryKey(hklm_key, reg_path); | 359 DeleteRegistryKey(hklm_key, reg_path); |
| 328 hklm_key.Close(); | 360 hklm_key.Close(); |
| 329 | 361 |
| 330 // Unregister any dll servers that we may have registered. | 362 if (installed_version.get()) { |
| 331 std::wstring dll_path(installer::GetChromeInstallPath(system_uninstall)); | 363 // Unregister any dll servers that we may have registered. |
| 332 file_util::AppendToPath(&dll_path, installed_version.GetString()); | 364 std::wstring dll_path(installer::GetChromeInstallPath(system_uninstall)); |
| 365 file_util::AppendToPath(&dll_path, installed_version->GetString()); |
| 333 | 366 |
| 334 scoped_ptr<WorkItemList> dll_list(WorkItem::CreateWorkItemList()); | 367 scoped_ptr<WorkItemList> dll_list(WorkItem::CreateWorkItemList()); |
| 335 if (InstallUtil::BuildDLLRegistrationList(dll_path, kDllsToRegister, | 368 if (InstallUtil::BuildDLLRegistrationList(dll_path, kDllsToRegister, |
| 336 kNumDllsToRegister, false, | 369 kNumDllsToRegister, false, |
| 337 dll_list.get())) { | 370 dll_list.get())) { |
| 338 dll_list->Do(); | 371 dll_list->Do(); |
| 372 } |
| 339 } | 373 } |
| 340 } | 374 } |
| 341 | 375 |
| 376 if (!installed_version.get()) |
| 377 return installer_util::UNINSTALL_SUCCESSFUL; |
| 378 |
| 342 // Finally delete all the files from Chrome folder after moving setup.exe | 379 // Finally delete all the files from Chrome folder after moving setup.exe |
| 343 // and the user's Local State to a temp location. | 380 // and the user's Local State to a temp location. |
| 344 bool delete_profile = (status == installer_util::UNINSTALL_DELETE_PROFILE); | 381 bool delete_profile = (status == installer_util::UNINSTALL_DELETE_PROFILE) || |
| 382 (cmd_line.HasSwitch(installer_util::switches::kDeleteProfile)); |
| 345 std::wstring local_state_path; | 383 std::wstring local_state_path; |
| 346 installer_util::InstallStatus ret = installer_util::UNINSTALL_SUCCESSFUL; | 384 installer_util::InstallStatus ret = installer_util::UNINSTALL_SUCCESSFUL; |
| 347 if (!DeleteFilesAndFolders(exe_path, system_uninstall, installed_version, | 385 if (!DeleteFilesAndFolders(exe_path, system_uninstall, *installed_version, |
| 348 &local_state_path, delete_profile)) | 386 &local_state_path, delete_profile)) |
| 349 ret = installer_util::UNINSTALL_FAILED; | 387 ret = installer_util::UNINSTALL_FAILED; |
| 350 | 388 |
| 351 if (!force_uninstall) { | 389 if (!force_uninstall) { |
| 352 LOG(INFO) << "Uninstallation complete. Launching Uninstall survey."; | 390 LOG(INFO) << "Uninstallation complete. Launching Uninstall survey."; |
| 353 dist->DoPostUninstallOperations(installed_version, local_state_path, | 391 dist->DoPostUninstallOperations(*installed_version, local_state_path, |
| 354 distribution_data); | 392 distribution_data); |
| 355 } | 393 } |
| 356 | 394 |
| 357 // Try and delete the preserved local state once the post-install | 395 // Try and delete the preserved local state once the post-install |
| 358 // operations are complete. | 396 // operations are complete. |
| 359 if (!local_state_path.empty()) | 397 if (!local_state_path.empty()) |
| 360 file_util::Delete(local_state_path, false); | 398 file_util::Delete(local_state_path, false); |
| 361 | 399 |
| 362 return ret; | 400 return ret; |
| 363 } | 401 } |
| OLD | NEW |