Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: chrome/installer/setup/uninstall.cc

Issue 811283002: [Installer] Cleaning up dead code for App Launcher / App Host installs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment fix. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/installer/setup/setup_util.cc ('k') | chrome/installer/util/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/base_paths.h" 13 #include "base/base_paths.h"
14 #include "base/files/file_enumerator.h" 14 #include "base/files/file_enumerator.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/process/kill.h" 17 #include "base/process/kill.h"
18 #include "base/strings/string16.h" 18 #include "base/strings/string16.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "base/win/registry.h" 22 #include "base/win/registry.h"
23 #include "base/win/scoped_handle.h" 23 #include "base/win/scoped_handle.h"
24 #include "base/win/shortcut.h" 24 #include "base/win/shortcut.h"
25 #include "base/win/windows_version.h" 25 #include "base/win/windows_version.h"
26 #include "chrome/common/chrome_constants.h" 26 #include "chrome/common/chrome_constants.h"
27 #include "chrome/common/chrome_paths.h" 27 #include "chrome/common/chrome_paths.h"
28 #include "chrome/common/chrome_result_codes.h" 28 #include "chrome/common/chrome_result_codes.h"
29 #include "chrome/installer/setup/app_launcher_installer.h"
29 #include "chrome/installer/setup/install.h" 30 #include "chrome/installer/setup/install.h"
30 #include "chrome/installer/setup/install_worker.h" 31 #include "chrome/installer/setup/install_worker.h"
31 #include "chrome/installer/setup/setup_constants.h" 32 #include "chrome/installer/setup/setup_constants.h"
32 #include "chrome/installer/setup/setup_util.h" 33 #include "chrome/installer/setup/setup_util.h"
33 #include "chrome/installer/util/auto_launch_util.h" 34 #include "chrome/installer/util/auto_launch_util.h"
34 #include "chrome/installer/util/browser_distribution.h" 35 #include "chrome/installer/util/browser_distribution.h"
35 #include "chrome/installer/util/channel_info.h" 36 #include "chrome/installer/util/channel_info.h"
36 #include "chrome/installer/util/delete_after_reboot_helper.h" 37 #include "chrome/installer/util/delete_after_reboot_helper.h"
37 #include "chrome/installer/util/firewall_manager_win.h" 38 #include "chrome/installer/util/firewall_manager_win.h"
38 #include "chrome/installer/util/google_update_constants.h" 39 #include "chrome/installer/util/google_update_constants.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 179
179 // If chrome has been reactivated, clear all events for this brand as well. 180 // If chrome has been reactivated, clear all events for this brand as well.
180 base::string16 reactivation_brand_wide; 181 base::string16 reactivation_brand_wide;
181 if (GoogleUpdateSettings::GetReactivationBrand(&reactivation_brand_wide)) { 182 if (GoogleUpdateSettings::GetReactivationBrand(&reactivation_brand_wide)) {
182 std::string reactivation_brand(base::UTF16ToASCII(reactivation_brand_wide)); 183 std::string reactivation_brand(base::UTF16ToASCII(reactivation_brand_wide));
183 rlz_lib::SupplementaryBranding branding(reactivation_brand.c_str()); 184 rlz_lib::SupplementaryBranding branding(reactivation_brand.c_str());
184 rlz_lib::ClearProductState(rlz_lib::CHROME, points); 185 rlz_lib::ClearProductState(rlz_lib::CHROME, points);
185 } 186 }
186 } 187 }
187 188
188 // Decides whether setup.exe and the installer archive should be removed based 189 // Returns whether setup.exe should be removed based on the original and
189 // on the original and installer states: 190 // installer states:
190 // * non-multi product being uninstalled: remove both 191 // * non-multi product being uninstalled: remove setup.exe
191 // * any multi product left besides App Host: keep both 192 // * any multi product left: keep setup.exe
192 // * only App Host left: keep setup.exe 193 bool CheckShouldRemoveSetup(const InstallationState& original_state,
193 void CheckShouldRemoveSetupAndArchive(const InstallationState& original_state, 194 const InstallerState& installer_state) {
194 const InstallerState& installer_state, 195 // If any multi-install product is left we must leave the installer and
195 bool* remove_setup, 196 // archive.
196 bool* remove_archive) {
197 *remove_setup = true;
198 *remove_archive = true;
199
200 // If any multi-install product is left (other than App Host) we must leave
201 // the installer and archive. For the App Host, we only leave the installer.
202 if (!installer_state.is_multi_install()) { 197 if (!installer_state.is_multi_install()) {
203 VLOG(1) << "Removing all installer files for a non-multi installation."; 198 VLOG(1) << "Removing all installer files for a non-multi installation.";
204 } else { 199 } else {
205 // Loop through all known products... 200 // Loop through all known products...
206 for (size_t i = 0; i < BrowserDistribution::NUM_TYPES; ++i) { 201 for (size_t i = 0; i < BrowserDistribution::NUM_TYPES; ++i) {
207 BrowserDistribution::Type dist_type = 202 BrowserDistribution::Type dist_type =
208 static_cast<BrowserDistribution::Type>(i); 203 static_cast<BrowserDistribution::Type>(i);
209 const ProductState* product_state = original_state.GetProductState( 204 const ProductState* product_state = original_state.GetProductState(
210 installer_state.system_install(), dist_type); 205 installer_state.system_install(), dist_type);
211 // If the product is installed, in multi mode, and is not part of the 206 // If the product is installed, in multi mode, and is not part of the
212 // active uninstallation... 207 // active uninstallation...
213 if (product_state && product_state->is_multi_install() && 208 if (product_state && product_state->is_multi_install() &&
214 !installer_state.FindProduct(dist_type)) { 209 !installer_state.FindProduct(dist_type)) {
215 // setup.exe will not be removed as there is a remaining multi-install 210 // setup.exe will not be removed as there is a remaining multi-install
216 // product. 211 // product.
217 *remove_setup = false; 212 VLOG(1) << "Keeping all installer files due to a remaining "
218 // As a special case, we can still remove the actual archive if the 213 << "multi-install product.";
219 // only remaining product is the App Host. 214 return false;
220 if (dist_type != BrowserDistribution::CHROME_APP_HOST) {
221 VLOG(1) << "Keeping all installer files due to a remaining "
222 << "multi-install product.";
223 *remove_archive = false;
224 return;
225 }
226 VLOG(1) << "Keeping setup.exe due to a remaining "
227 << "app-host installation.";
228 } 215 }
229 } 216 }
230 VLOG(1) << "Removing the installer archive."; 217 VLOG(1) << "Removing all installer files.";
231 if (remove_setup)
232 VLOG(1) << "Removing setup.exe.";
233 } 218 }
219 return true;
234 } 220 }
235 221
236 // Removes all files from the installer directory, leaving setup.exe iff 222 // Removes all files from the installer directory, leaving setup.exe iff
237 // |remove_setup| is false. 223 // |remove_setup| is false.
238 // Returns false in case of an error. 224 // Returns false in case of an error.
239 bool RemoveInstallerFiles(const base::FilePath& installer_directory, 225 bool RemoveInstallerFiles(const base::FilePath& installer_directory,
240 bool remove_setup) { 226 bool remove_setup) {
241 base::FileEnumerator file_enumerator( 227 base::FileEnumerator file_enumerator(
242 installer_directory, 228 installer_directory,
243 false, 229 false,
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 // We cannot delete the file right away, but try to delete it some other 492 // We cannot delete the file right away, but try to delete it some other
507 // way. Either with the help of a different process or the system. 493 // way. Either with the help of a different process or the system.
508 if (!base::DeleteFileAfterReboot(temp_file)) { 494 if (!base::DeleteFileAfterReboot(temp_file)) {
509 const uint32 kDeleteAfterMs = 10 * 1000; 495 const uint32 kDeleteAfterMs = 10 * 1000;
510 installer::DeleteFileFromTempProcess(temp_file, kDeleteAfterMs); 496 installer::DeleteFileFromTempProcess(temp_file, kDeleteAfterMs);
511 } 497 }
512 } 498 }
513 return true; 499 return true;
514 } 500 }
515 501
516 DeleteResult DeleteAppHostFilesAndFolders(const InstallerState& installer_state,
517 const Version& installed_version) {
518 const base::FilePath& target_path = installer_state.target_path();
519 if (target_path.empty()) {
520 LOG(ERROR) << "DeleteAppHostFilesAndFolders: no installation destination "
521 << "path.";
522 return DELETE_FAILED; // Nothing else we can do to uninstall, so we return.
523 }
524
525 DeleteInstallTempDir(target_path);
526
527 DeleteResult result = DELETE_SUCCEEDED;
528
529 base::FilePath app_host_exe(target_path.Append(installer::kChromeAppHostExe));
530 if (!base::DeleteFile(app_host_exe, false)) {
531 result = DELETE_FAILED;
532 LOG(ERROR) << "Failed to delete path: " << app_host_exe.value();
533 }
534
535 return result;
536 }
537
538 DeleteResult DeleteChromeFilesAndFolders(const InstallerState& installer_state, 502 DeleteResult DeleteChromeFilesAndFolders(const InstallerState& installer_state,
539 const base::FilePath& setup_exe) { 503 const base::FilePath& setup_exe) {
540 const base::FilePath& target_path = installer_state.target_path(); 504 const base::FilePath& target_path = installer_state.target_path();
541 if (target_path.empty()) { 505 if (target_path.empty()) {
542 LOG(ERROR) << "DeleteChromeFilesAndFolders: no installation destination " 506 LOG(ERROR) << "DeleteChromeFilesAndFolders: no installation destination "
543 << "path."; 507 << "path.";
544 return DELETE_FAILED; // Nothing else we can do to uninstall, so we return. 508 return DELETE_FAILED; // Nothing else we can do to uninstall, so we return.
545 } 509 }
546 510
547 DeleteInstallTempDir(target_path); 511 DeleteInstallTempDir(target_path);
548 512
549 DeleteResult result = DELETE_SUCCEEDED; 513 DeleteResult result = DELETE_SUCCEEDED;
550 514
551 base::FilePath installer_directory; 515 base::FilePath installer_directory;
552 if (target_path.IsParent(setup_exe)) 516 if (target_path.IsParent(setup_exe))
553 installer_directory = setup_exe.DirName(); 517 installer_directory = setup_exe.DirName();
554 518
555 // Enumerate all the files in target_path recursively (breadth-first). 519 // Enumerate all the files in target_path recursively (breadth-first).
556 // We delete a file or folder unless it is a parent/child of the installer 520 // We delete a file or folder unless it is a parent/child of the installer
557 // directory. For parents of the installer directory, we will later recurse 521 // directory. For parents of the installer directory, we will later recurse
558 // and delete all the children (that are not also parents/children of the 522 // and delete all the children (that are not also parents/children of the
559 // installer directory). 523 // installer directory).
560 base::FileEnumerator file_enumerator(target_path, true, 524 base::FileEnumerator file_enumerator(target_path, true,
561 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES); 525 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES);
562 for (base::FilePath to_delete = file_enumerator.Next(); !to_delete.empty(); 526 for (base::FilePath to_delete = file_enumerator.Next(); !to_delete.empty();
563 to_delete = file_enumerator.Next()) { 527 to_delete = file_enumerator.Next()) {
564 if (to_delete.BaseName().value() == installer::kChromeAppHostExe)
565 continue;
566 if (!installer_directory.empty() && 528 if (!installer_directory.empty() &&
567 (to_delete == installer_directory || 529 (to_delete == installer_directory ||
568 installer_directory.IsParent(to_delete) || 530 installer_directory.IsParent(to_delete) ||
569 to_delete.IsParent(installer_directory))) { 531 to_delete.IsParent(installer_directory))) {
570 continue; 532 continue;
571 } 533 }
572 534
573 VLOG(1) << "Deleting install path " << to_delete.value(); 535 VLOG(1) << "Deleting install path " << to_delete.value();
574 if (!base::DeleteFile(to_delete, true)) { 536 if (!base::DeleteFile(to_delete, true)) {
575 LOG(ERROR) << "Failed to delete path (1st try): " << to_delete.value(); 537 LOG(ERROR) << "Failed to delete path (1st try): " << to_delete.value();
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 if (is_chrome) { 1174 if (is_chrome) {
1213 const base::string16 suffix( 1175 const base::string16 suffix(
1214 ShellUtil::GetCurrentInstallationSuffix(browser_dist, chrome_exe)); 1176 ShellUtil::GetCurrentInstallationSuffix(browser_dist, chrome_exe));
1215 1177
1216 // Remove all Chrome registration keys. 1178 // Remove all Chrome registration keys.
1217 // Registration data is put in HKCU for both system level and user level 1179 // Registration data is put in HKCU for both system level and user level
1218 // installs. 1180 // installs.
1219 DeleteChromeRegistrationKeys(installer_state, browser_dist, 1181 DeleteChromeRegistrationKeys(installer_state, browser_dist,
1220 HKEY_CURRENT_USER, suffix, &ret); 1182 HKEY_CURRENT_USER, suffix, &ret);
1221 1183
1184 #if defined(GOOGLE_CHROME_BUILD)
1185 if (!InstallUtil::IsChromeSxSProcess())
1186 RemoveAppLauncherVersionKey(reg_root);
1187 #endif // GOOGLE_CHROME_BUILD
1188
1222 // If the user's Chrome is registered with a suffix: it is possible that old 1189 // If the user's Chrome is registered with a suffix: it is possible that old
1223 // unsuffixed registrations were left in HKCU (e.g. if this install was 1190 // unsuffixed registrations were left in HKCU (e.g. if this install was
1224 // previously installed with no suffix in HKCU (old suffix rules if the user 1191 // previously installed with no suffix in HKCU (old suffix rules if the user
1225 // is not an admin (or declined UAC at first run)) and later had to be 1192 // is not an admin (or declined UAC at first run)) and later had to be
1226 // suffixed when fully registered in HKLM (e.g. when later making Chrome 1193 // suffixed when fully registered in HKLM (e.g. when later making Chrome
1227 // default through the UI)). 1194 // default through the UI)).
1228 // Remove remaining HKCU entries with no suffix if any. 1195 // Remove remaining HKCU entries with no suffix if any.
1229 if (!suffix.empty()) { 1196 if (!suffix.empty()) {
1230 DeleteChromeRegistrationKeys(installer_state, browser_dist, 1197 DeleteChromeRegistrationKeys(installer_state, browser_dist,
1231 HKEY_CURRENT_USER, base::string16(), &ret); 1198 HKEY_CURRENT_USER, base::string16(), &ret);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 1237
1271 UninstallActiveSetupEntries(installer_state, product); 1238 UninstallActiveSetupEntries(installer_state, product);
1272 1239
1273 UninstallFirewallRules(browser_dist, chrome_exe); 1240 UninstallFirewallRules(browser_dist, chrome_exe);
1274 1241
1275 RemoveBlacklistState(); 1242 RemoveBlacklistState();
1276 1243
1277 // Notify the shell that associations have changed since Chrome was likely 1244 // Notify the shell that associations have changed since Chrome was likely
1278 // unregistered. 1245 // unregistered.
1279 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); 1246 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
1280
1281 // TODO(huangs): Implement actual migration code and remove the hack below.
1282 // Remove the "shadow" App Launcher registry keys.
1283 // TODO(hunags): Management of this key should not be conditional on
1284 // multi-install since the app list feature is available regardless of how
1285 // chrome is installed.
1286 if (installer_state.is_multi_install()) {
1287 // Delete the "shadow" keys.
1288 BrowserDistribution* shadow_app_launcher_dist =
1289 BrowserDistribution::GetSpecificDistribution(
1290 BrowserDistribution::CHROME_APP_HOST);
1291 InstallUtil::DeleteRegistryKey(
1292 reg_root,
1293 shadow_app_launcher_dist->GetVersionKey(),
1294 KEY_WOW64_32KEY);
1295 }
1296 } 1247 }
1297 1248
1298 if (installer_state.is_multi_install()) 1249 if (installer_state.is_multi_install())
1299 ProcessGoogleUpdateItems(original_state, installer_state, product); 1250 ProcessGoogleUpdateItems(original_state, installer_state, product);
1300 1251
1301 // Get the state of the installed product (if any) 1252 // Get the state of the installed product (if any)
1302 const ProductState* product_state = 1253 const ProductState* product_state =
1303 original_state.GetProductState(installer_state.system_install(), 1254 original_state.GetProductState(installer_state.system_install(),
1304 browser_dist->GetType()); 1255 browser_dist->GetType());
1305 1256
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 base::FilePath user_data_dir(GetUserDataDir(product)); 1313 base::FilePath user_data_dir(GetUserDataDir(product));
1363 base::FilePath backup_state_file; 1314 base::FilePath backup_state_file;
1364 if (!user_data_dir.empty()) { 1315 if (!user_data_dir.empty()) {
1365 backup_state_file = BackupLocalStateFile(user_data_dir); 1316 backup_state_file = BackupLocalStateFile(user_data_dir);
1366 } else { 1317 } else {
1367 LOG(ERROR) << "Could not retrieve the user's profile directory."; 1318 LOG(ERROR) << "Could not retrieve the user's profile directory.";
1368 ret = installer::UNINSTALL_FAILED; 1319 ret = installer::UNINSTALL_FAILED;
1369 delete_profile = false; 1320 delete_profile = false;
1370 } 1321 }
1371 1322
1372 if (product.is_chrome_app_host()) { 1323 if (!installer_state.is_multi_install() || product.is_chrome_binaries()) {
1373 DeleteAppHostFilesAndFolders(installer_state, product_state->version());
1374 } else if (!installer_state.is_multi_install() ||
1375 product.is_chrome_binaries()) {
1376 DeleteResult delete_result = DeleteChromeFilesAndFolders( 1324 DeleteResult delete_result = DeleteChromeFilesAndFolders(
1377 installer_state, base::MakeAbsoluteFilePath(setup_exe)); 1325 installer_state, base::MakeAbsoluteFilePath(setup_exe));
1378 if (delete_result == DELETE_FAILED) { 1326 if (delete_result == DELETE_FAILED) {
1379 ret = installer::UNINSTALL_FAILED; 1327 ret = installer::UNINSTALL_FAILED;
1380 } else if (delete_result == DELETE_REQUIRES_REBOOT) { 1328 } else if (delete_result == DELETE_REQUIRES_REBOOT) {
1381 ret = installer::UNINSTALL_REQUIRES_REBOOT; 1329 ret = installer::UNINSTALL_REQUIRES_REBOOT;
1382 } 1330 }
1383 } 1331 }
1384 1332
1385 if (delete_profile) 1333 if (delete_profile)
(...skipping 27 matching lines...) Expand all
1413 LOG(ERROR) << "No installation destination path."; 1361 LOG(ERROR) << "No installation destination path.";
1414 *uninstall_status = UNINSTALL_FAILED; 1362 *uninstall_status = UNINSTALL_FAILED;
1415 return; 1363 return;
1416 } 1364 }
1417 if (!target_path.IsParent(base::MakeAbsoluteFilePath(setup_exe))) { 1365 if (!target_path.IsParent(base::MakeAbsoluteFilePath(setup_exe))) {
1418 VLOG(1) << "setup.exe is not in target path. Skipping installer cleanup."; 1366 VLOG(1) << "setup.exe is not in target path. Skipping installer cleanup.";
1419 return; 1367 return;
1420 } 1368 }
1421 base::FilePath install_directory(setup_exe.DirName()); 1369 base::FilePath install_directory(setup_exe.DirName());
1422 1370
1423 bool remove_setup = true; 1371 bool remove_setup = CheckShouldRemoveSetup(original_state, installer_state);
1424 bool remove_archive = true;
1425 CheckShouldRemoveSetupAndArchive(original_state, installer_state,
1426 &remove_setup, &remove_archive);
1427 if (!remove_archive)
1428 return;
1429 1372
1430 if (remove_setup) { 1373 if (remove_setup) {
1431 // In order to be able to remove the folder in which we're running, we 1374 // In order to be able to remove the folder in which we're running, we
1432 // need to move setup.exe out of the install folder. 1375 // need to move setup.exe out of the install folder.
1433 // TODO(tommi): What if the temp folder is on a different volume? 1376 // TODO(tommi): What if the temp folder is on a different volume?
1434 MoveSetupOutOfInstallFolder(installer_state, setup_exe); 1377 MoveSetupOutOfInstallFolder(installer_state, setup_exe);
1435 } 1378 }
1436 1379
1437 // Remove files from "...\<product>\Application\<version>\Installer" 1380 // Remove files from "...\<product>\Application\<version>\Installer"
1438 if (!RemoveInstallerFiles(install_directory, remove_setup)) { 1381 if (!RemoveInstallerFiles(install_directory, remove_setup)) {
(...skipping 28 matching lines...) Expand all
1467 // If we need a reboot to continue, schedule the parent directories for 1410 // If we need a reboot to continue, schedule the parent directories for
1468 // deletion unconditionally. If they are not empty, the session manager 1411 // deletion unconditionally. If they are not empty, the session manager
1469 // will not delete them on reboot. 1412 // will not delete them on reboot.
1470 ScheduleParentAndGrandparentForDeletion(target_path); 1413 ScheduleParentAndGrandparentForDeletion(target_path);
1471 } else if (DeleteChromeDirectoriesIfEmpty(target_path) == DELETE_FAILED) { 1414 } else if (DeleteChromeDirectoriesIfEmpty(target_path) == DELETE_FAILED) {
1472 *uninstall_status = UNINSTALL_FAILED; 1415 *uninstall_status = UNINSTALL_FAILED;
1473 } 1416 }
1474 } 1417 }
1475 1418
1476 } // namespace installer 1419 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/setup/setup_util.cc ('k') | chrome/installer/util/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698