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 <windows.h> | 9 #include <windows.h> |
10 | 10 |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/files/file_enumerator.h" |
14 #include "base/path_service.h" | 15 #include "base/path_service.h" |
15 #include "base/process_util.h" | 16 #include "base/process_util.h" |
16 #include "base/string16.h" | 17 #include "base/string16.h" |
17 #include "base/string_util.h" | 18 #include "base/string_util.h" |
18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
20 #include "base/win/registry.h" | 21 #include "base/win/registry.h" |
21 #include "base/win/scoped_handle.h" | 22 #include "base/win/scoped_handle.h" |
22 #include "base/win/shortcut.h" | 23 #include "base/win/shortcut.h" |
23 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 if (remove_setup) | 247 if (remove_setup) |
247 VLOG(1) << "Removing setup.exe."; | 248 VLOG(1) << "Removing setup.exe."; |
248 } | 249 } |
249 } | 250 } |
250 | 251 |
251 // Removes all files from the installer directory, leaving setup.exe iff | 252 // Removes all files from the installer directory, leaving setup.exe iff |
252 // |remove_setup| is false. | 253 // |remove_setup| is false. |
253 // Returns false in case of an error. | 254 // Returns false in case of an error. |
254 bool RemoveInstallerFiles(const base::FilePath& installer_directory, | 255 bool RemoveInstallerFiles(const base::FilePath& installer_directory, |
255 bool remove_setup) { | 256 bool remove_setup) { |
256 using file_util::FileEnumerator; | 257 base::FileEnumerator file_enumerator( |
257 FileEnumerator file_enumerator( | |
258 installer_directory, | 258 installer_directory, |
259 false, | 259 false, |
260 FileEnumerator::FILES | FileEnumerator::DIRECTORIES); | 260 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES); |
261 bool success = true; | 261 bool success = true; |
262 | 262 |
263 base::FilePath setup_exe_base_name(installer::kSetupExe); | 263 base::FilePath setup_exe_base_name(installer::kSetupExe); |
264 | 264 |
265 while (true) { | 265 while (true) { |
266 base::FilePath to_delete(file_enumerator.Next()); | 266 base::FilePath to_delete(file_enumerator.Next()); |
267 if (to_delete.empty()) | 267 if (to_delete.empty()) |
268 break; | 268 break; |
269 if (!remove_setup && to_delete.BaseName() == setup_exe_base_name) | 269 if (!remove_setup && to_delete.BaseName() == setup_exe_base_name) |
270 continue; | 270 continue; |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 | 566 |
567 base::FilePath installer_directory; | 567 base::FilePath installer_directory; |
568 if (target_path.IsParent(setup_exe)) | 568 if (target_path.IsParent(setup_exe)) |
569 installer_directory = setup_exe.DirName(); | 569 installer_directory = setup_exe.DirName(); |
570 | 570 |
571 // Enumerate all the files in target_path recursively (breadth-first). | 571 // Enumerate all the files in target_path recursively (breadth-first). |
572 // We delete a file or folder unless it is a parent/child of the installer | 572 // We delete a file or folder unless it is a parent/child of the installer |
573 // directory. For parents of the installer directory, we will later recurse | 573 // directory. For parents of the installer directory, we will later recurse |
574 // and delete all the children (that are not also parents/children of the | 574 // and delete all the children (that are not also parents/children of the |
575 // installer directory). | 575 // installer directory). |
576 using file_util::FileEnumerator; | 576 base::FileEnumerator file_enumerator(target_path, true, |
577 FileEnumerator file_enumerator( | 577 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES); |
578 target_path, true, FileEnumerator::FILES | FileEnumerator::DIRECTORIES); | |
579 while (true) { | 578 while (true) { |
580 base::FilePath to_delete(file_enumerator.Next()); | 579 base::FilePath to_delete(file_enumerator.Next()); |
581 if (to_delete.empty()) | 580 if (to_delete.empty()) |
582 break; | 581 break; |
583 if (to_delete.BaseName().value() == installer::kChromeAppHostExe) | 582 if (to_delete.BaseName().value() == installer::kChromeAppHostExe) |
584 continue; | 583 continue; |
585 if (!installer_directory.empty() && | 584 if (!installer_directory.empty() && |
586 (to_delete == installer_directory || | 585 (to_delete == installer_directory || |
587 installer_directory.IsParent(to_delete) || | 586 installer_directory.IsParent(to_delete) || |
588 to_delete.IsParent(installer_directory))) { | 587 to_delete.IsParent(installer_directory))) { |
589 continue; | 588 continue; |
590 } | 589 } |
591 | 590 |
592 VLOG(1) << "Deleting install path " << to_delete.value(); | 591 VLOG(1) << "Deleting install path " << to_delete.value(); |
593 if (!file_util::Delete(to_delete, true)) { | 592 if (!file_util::Delete(to_delete, true)) { |
594 LOG(ERROR) << "Failed to delete path (1st try): " << to_delete.value(); | 593 LOG(ERROR) << "Failed to delete path (1st try): " << to_delete.value(); |
595 if (installer_state.FindProduct(BrowserDistribution::CHROME_FRAME)) { | 594 if (installer_state.FindProduct(BrowserDistribution::CHROME_FRAME)) { |
596 // We don't try killing Chrome processes for Chrome Frame builds since | 595 // We don't try killing Chrome processes for Chrome Frame builds since |
597 // that is unlikely to help. Instead, schedule files for deletion and | 596 // that is unlikely to help. Instead, schedule files for deletion and |
598 // return a value that will trigger a reboot prompt. | 597 // return a value that will trigger a reboot prompt. |
599 FileEnumerator::FindInfo find_info; | 598 base::FileEnumerator::FileInfo find_info = file_enumerator.GetInfo(); |
600 file_enumerator.GetFindInfo(&find_info); | 599 if (find_info.IsDirectory()) |
601 if (FileEnumerator::IsDirectory(find_info)) | |
602 ScheduleDirectoryForDeletion(to_delete.value().c_str()); | 600 ScheduleDirectoryForDeletion(to_delete.value().c_str()); |
603 else | 601 else |
604 ScheduleFileSystemEntityForDeletion(to_delete.value().c_str()); | 602 ScheduleFileSystemEntityForDeletion(to_delete.value().c_str()); |
605 result = DELETE_REQUIRES_REBOOT; | 603 result = DELETE_REQUIRES_REBOOT; |
606 } else { | 604 } else { |
607 // Try closing any running Chrome processes and deleting files once | 605 // Try closing any running Chrome processes and deleting files once |
608 // again. | 606 // again. |
609 CloseAllChromeProcesses(); | 607 CloseAllChromeProcesses(); |
610 if (!file_util::Delete(to_delete, true)) { | 608 if (!file_util::Delete(to_delete, true)) { |
611 LOG(ERROR) << "Failed to delete path (2nd try): " | 609 LOG(ERROR) << "Failed to delete path (2nd try): " |
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1428 // deletion unconditionally. If they are not empty, the session manager | 1426 // deletion unconditionally. If they are not empty, the session manager |
1429 // will not delete them on reboot. | 1427 // will not delete them on reboot. |
1430 ScheduleParentAndGrandparentForDeletion(target_path); | 1428 ScheduleParentAndGrandparentForDeletion(target_path); |
1431 } else if (DeleteApplicationProductAndVendorDirectories(target_path) == | 1429 } else if (DeleteApplicationProductAndVendorDirectories(target_path) == |
1432 installer::DELETE_FAILED) { | 1430 installer::DELETE_FAILED) { |
1433 *uninstall_status = installer::UNINSTALL_FAILED; | 1431 *uninstall_status = installer::UNINSTALL_FAILED; |
1434 } | 1432 } |
1435 } | 1433 } |
1436 | 1434 |
1437 } // namespace installer | 1435 } // namespace installer |
OLD | NEW |