OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 LOG(ERROR) << "Failed to get location for shortcut."; | 110 LOG(ERROR) << "Failed to get location for shortcut."; |
111 } else { | 111 } else { |
112 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 112 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
113 shortcut_path = shortcut_path.Append(dist->GetApplicationName()); | 113 shortcut_path = shortcut_path.Append(dist->GetApplicationName()); |
114 LOG(INFO) << "Deleting shortcut " << shortcut_path.value(); | 114 LOG(INFO) << "Deleting shortcut " << shortcut_path.value(); |
115 if (!file_util::Delete(shortcut_path, true)) | 115 if (!file_util::Delete(shortcut_path, true)) |
116 LOG(ERROR) << "Failed to delete folder: " << shortcut_path.value(); | 116 LOG(ERROR) << "Failed to delete folder: " << shortcut_path.value(); |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
| 120 bool ScheduleParentAndGrandparentForDeletion(const FilePath& path) { |
| 121 FilePath parent_dir = path.DirName(); |
| 122 bool ret = ScheduleFileSystemEntityForDeletion(parent_dir.value().c_str()); |
| 123 if (!ret) { |
| 124 LOG(ERROR) << "Failed to schedule parent dir for deletion: " |
| 125 << parent_dir.value(); |
| 126 } else { |
| 127 FilePath grandparent_dir(parent_dir.DirName()); |
| 128 ret = ScheduleFileSystemEntityForDeletion(grandparent_dir.value().c_str()); |
| 129 if (!ret) { |
| 130 LOG(ERROR) << "Failed to schedule grandparent dir for deletion: " |
| 131 << grandparent_dir.value(); |
| 132 } |
| 133 } |
| 134 return ret; |
| 135 } |
| 136 |
120 // Deletes empty parent & empty grandparent dir of given path. | 137 // Deletes empty parent & empty grandparent dir of given path. |
121 bool DeleteEmptyParentDir(const std::wstring& path) { | 138 bool DeleteEmptyParentDir(const std::wstring& path) { |
122 bool ret = true; | 139 bool ret = true; |
123 std::wstring parent_dir = file_util::GetDirectoryFromPath(path); | 140 std::wstring parent_dir = file_util::GetDirectoryFromPath(path); |
124 if (!parent_dir.empty() && file_util::IsDirectoryEmpty(parent_dir)) { | 141 if (!parent_dir.empty() && file_util::IsDirectoryEmpty(parent_dir)) { |
125 if (!file_util::Delete(parent_dir, true)) { | 142 if (!file_util::Delete(parent_dir, true)) { |
126 ret = false; | 143 ret = false; |
127 LOG(ERROR) << "Failed to delete folder: " << parent_dir; | 144 LOG(ERROR) << "Failed to delete folder: " << parent_dir; |
128 } | 145 } |
129 | 146 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 if (!file_util::Delete(user_local_state, true)) { | 243 if (!file_util::Delete(user_local_state, true)) { |
227 LOG(ERROR) << "Failed to delete user profile dir: " | 244 LOG(ERROR) << "Failed to delete user profile dir: " |
228 << user_local_state.value(); | 245 << user_local_state.value(); |
229 if (InstallUtil::IsChromeFrameProcess()) { | 246 if (InstallUtil::IsChromeFrameProcess()) { |
230 ScheduleDirectoryForDeletion(user_local_state.value().c_str()); | 247 ScheduleDirectoryForDeletion(user_local_state.value().c_str()); |
231 result = DELETE_REQUIRES_REBOOT; | 248 result = DELETE_REQUIRES_REBOOT; |
232 } else { | 249 } else { |
233 result = DELETE_FAILED; | 250 result = DELETE_FAILED; |
234 } | 251 } |
235 } | 252 } |
236 DeleteEmptyParentDir(user_local_state.value()); | 253 if (result == DELETE_REQUIRES_REBOOT) { |
| 254 ScheduleParentAndGrandparentForDeletion(user_local_state); |
| 255 } else { |
| 256 DeleteEmptyParentDir(user_local_state.value()); |
| 257 } |
237 } | 258 } |
238 | 259 |
239 // Now check and delete if the parent directories are empty | 260 if (result == DELETE_REQUIRES_REBOOT) { |
240 // For example Google\Chrome or Chromium | 261 // If we need a reboot to continue, schedule the parent directories for |
241 DeleteEmptyParentDir(install_path); | 262 // deletion unconditionally. If they are not empty, the session manager |
| 263 // will not delete them on reboot. |
| 264 ScheduleParentAndGrandparentForDeletion(FilePath(install_path)); |
| 265 } else { |
| 266 // Now check and delete if the parent directories are empty |
| 267 // For example Google\Chrome or Chromium |
| 268 DeleteEmptyParentDir(install_path); |
| 269 } |
242 return result; | 270 return result; |
243 } | 271 } |
244 | 272 |
245 // This method tries to delete a registry key and logs an error message | 273 // This method tries to delete a registry key and logs an error message |
246 // in case of failure. It returns true if deletion is successful, | 274 // in case of failure. It returns true if deletion is successful, |
247 // otherwise false. | 275 // otherwise false. |
248 bool DeleteRegistryKey(RegKey& key, const std::wstring& key_path) { | 276 bool DeleteRegistryKey(RegKey& key, const std::wstring& key_path) { |
249 LOG(INFO) << "Deleting registry key " << key_path; | 277 LOG(INFO) << "Deleting registry key " << key_path; |
250 if (!key.DeleteKey(key_path.c_str()) && | 278 if (!key.DeleteKey(key_path.c_str()) && |
251 ::GetLastError() != ERROR_MOD_NOT_FOUND) { | 279 ::GetLastError() != ERROR_MOD_NOT_FOUND) { |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 distribution_data); | 553 distribution_data); |
526 } | 554 } |
527 | 555 |
528 // Try and delete the preserved local state once the post-install | 556 // Try and delete the preserved local state once the post-install |
529 // operations are complete. | 557 // operations are complete. |
530 if (!local_state_path.empty()) | 558 if (!local_state_path.empty()) |
531 file_util::Delete(local_state_path, false); | 559 file_util::Delete(local_state_path, false); |
532 | 560 |
533 return ret; | 561 return ret; |
534 } | 562 } |
OLD | NEW |