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