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

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

Issue 6402: Fix some problems with machine level install. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « chrome/installer/setup/setup.cc ('k') | chrome/installer/util/browser_distribution.h » ('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) 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 <atlbase.h> 9 #include <atlbase.h>
10 #include <windows.h> 10 #include <windows.h>
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 LOG(ERROR) << "Failed to get location for shortcut."; 50 LOG(ERROR) << "Failed to get location for shortcut.";
51 } else { 51 } else {
52 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 52 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
53 file_util::AppendToPath(&shortcut_path, dist->GetApplicationName()); 53 file_util::AppendToPath(&shortcut_path, dist->GetApplicationName());
54 LOG(INFO) << "Deleting shortcut " << shortcut_path; 54 LOG(INFO) << "Deleting shortcut " << shortcut_path;
55 if (!file_util::Delete(shortcut_path, true)) 55 if (!file_util::Delete(shortcut_path, true))
56 LOG(ERROR) << "Failed to delete folder: " << shortcut_path; 56 LOG(ERROR) << "Failed to delete folder: " << shortcut_path;
57 } 57 }
58 } 58 }
59 59
60 // Deletes all installed files of Chromium and Folders. Before deleting it
61 // needs to move setup.exe in a temp folder because the current process
62 // is using that file. It returns false when it can not get the path to
63 // installation folder, in all other cases it returns true even in case
64 // of error (only logs the error).
65 bool DeleteFilesAndFolders(const std::wstring& exe_path, bool system_uninstall,
66 const installer::Version& installed_version) {
67 std::wstring install_path(installer::GetChromeInstallPath(system_uninstall));
68 if (install_path.empty()) {
69 LOG(ERROR) << "Could not get installation destination path.";
70 return false; // Nothing else we can do for uninstall, so we return.
71 } else {
72 LOG(INFO) << "install destination path: " << install_path;
73 }
74
75 std::wstring setup_exe(installer::GetInstallerPathUnderChrome(
76 install_path, installed_version.GetString()));
77 file_util::AppendToPath(&setup_exe, file_util::GetFilenameFromPath(exe_path));
78
79 std::wstring temp_file;
80 file_util::CreateTemporaryFileName(&temp_file);
81 file_util::Move(setup_exe, temp_file);
82
83 LOG(INFO) << "Deleting install path " << install_path;
84 if (!file_util::Delete(install_path, true))
85 LOG(ERROR) << "Failed to delete folder: " << install_path;
86
87 // Now check and delete if the parent directories are empty
88 // For example Google\Chrome or Chromium
89 std::wstring parent_dir = file_util::GetDirectoryFromPath(install_path);
90 if (!parent_dir.empty() && file_util::IsDirectoryEmpty(parent_dir)) {
91 if (!file_util::Delete(parent_dir, true))
92 LOG(ERROR) << "Failed to delete folder: " << parent_dir;
93 parent_dir = file_util::GetDirectoryFromPath(parent_dir);
94 if (!parent_dir.empty() &&
95 file_util::IsDirectoryEmpty(parent_dir)) {
96 if (!file_util::Delete(parent_dir, true))
97 LOG(ERROR) << "Failed to delete folder: " << parent_dir;
98 }
99 }
100 return true;
101 }
102
60 // This method tries to delete a registry key and logs an error message 103 // This method tries to delete a registry key and logs an error message
61 // in case of failure. It returns true if deletion is successful, 104 // in case of failure. It returns true if deletion is successful,
62 // otherwise false. 105 // otherwise false.
63 bool DeleteRegistryKey(RegKey& key, const std::wstring& key_path) { 106 bool DeleteRegistryKey(RegKey& key, const std::wstring& key_path) {
64 LOG(INFO) << "Deleting registry key " << key_path; 107 LOG(INFO) << "Deleting registry key " << key_path;
65 if (!key.DeleteKey(key_path.c_str())) { 108 if (!key.DeleteKey(key_path.c_str())) {
66 LOG(ERROR) << "Failed to delete registry key: " << key_path; 109 LOG(ERROR) << "Failed to delete registry key: " << key_path;
67 return false; 110 return false;
68 } 111 }
69 return true; 112 return true;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 162
120 163
121 installer_util::InstallStatus installer_setup::UninstallChrome( 164 installer_util::InstallStatus installer_setup::UninstallChrome(
122 const std::wstring& exe_path, bool system_uninstall, 165 const std::wstring& exe_path, bool system_uninstall,
123 const installer::Version& installed_version, bool remove_all) { 166 const installer::Version& installed_version, bool remove_all) {
124 installer_util::InstallStatus status = 167 installer_util::InstallStatus status =
125 IsChromeActiveOrUserCancelled(system_uninstall); 168 IsChromeActiveOrUserCancelled(system_uninstall);
126 if (status != installer_util::UNINSTALL_CONFIRMED) 169 if (status != installer_util::UNINSTALL_CONFIRMED)
127 return status; 170 return status;
128 171
129 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
130 dist->DoPreUninstallOperations();
131 #if defined(GOOGLE_CHROME_BUILD) 172 #if defined(GOOGLE_CHROME_BUILD)
132 // TODO(rahulk): This should be done by DoPreUninstallOperations call above 173 // TODO(rahulk): This should be done by DoPreUninstallOperations call above
133 wchar_t product[39]; // GUID + '\0' 174 wchar_t product[39]; // GUID + '\0'
134 MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL); // Don't show any UI to user. 175 MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL); // Don't show any UI to user.
135 for (int i = 0; MsiEnumRelatedProducts(google_update::kGearsUpgradeCode, 0, i, 176 for (int i = 0; MsiEnumRelatedProducts(google_update::kGearsUpgradeCode, 0, i,
136 product) != ERROR_NO_MORE_ITEMS; ++i) { 177 product) != ERROR_NO_MORE_ITEMS; ++i) {
137 LOG(INFO) << "Uninstalling Gears - " << product; 178 LOG(INFO) << "Uninstalling Gears - " << product;
138 unsigned int ret = MsiConfigureProduct(product, INSTALLLEVEL_MAXIMUM, 179 unsigned int ret = MsiConfigureProduct(product, INSTALLLEVEL_MAXIMUM,
139 INSTALLSTATE_ABSENT); 180 INSTALLSTATE_ABSENT);
140 if (ret != ERROR_SUCCESS) 181 if (ret != ERROR_SUCCESS)
141 LOG(ERROR) << "Failed to uninstall Gears " << product << ": " << ret; 182 LOG(ERROR) << "Failed to uninstall Gears " << product << ": " << ret;
142 } 183 }
143 #endif 184 #endif
144 185
145 // Chrome is not in use so lets uninstall Chrome by deleting various files 186 // Chrome is not in use so lets uninstall Chrome by deleting various files
146 // and registry entries. Here we will just make best effort and keep going 187 // and registry entries. Here we will just make best effort and keep going
147 // in case of errors. 188 // in case of errors.
148 // First delete shortcut from Start->Programs. 189 // First delete shortcut from Start->Programs.
149 DeleteChromeShortcut(system_uninstall); 190 DeleteChromeShortcut(system_uninstall);
150 191
151 // Delete the registry keys (Uninstall key and Version key). 192 // Delete the registry keys (Uninstall key and Version key).
152 HKEY reg_root = system_uninstall ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 193 HKEY reg_root = system_uninstall ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
153 RegKey key(reg_root, L"", KEY_ALL_ACCESS); 194 RegKey key(reg_root, L"", KEY_ALL_ACCESS);
195 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
154 DeleteRegistryKey(key, dist->GetUninstallRegPath()); 196 DeleteRegistryKey(key, dist->GetUninstallRegPath());
155 DeleteRegistryKey(key, dist->GetVersionKey()); 197 DeleteRegistryKey(key, dist->GetVersionKey());
156 198
157 // Delete Software\Classes\ChromeHTML, 199 // Delete Software\Classes\ChromeHTML,
158 // Software\Clients\StartMenuInternet\chrome.exe and 200 // Software\Clients\StartMenuInternet\chrome.exe and
159 // Software\RegisteredApplications\Chrome 201 // Software\RegisteredApplications\Chrome
160 std::wstring html_prog_id(ShellUtil::kRegClasses); 202 std::wstring html_prog_id(ShellUtil::kRegClasses);
161 file_util::AppendToPath(&html_prog_id, ShellUtil::kChromeHTMLProgId); 203 file_util::AppendToPath(&html_prog_id, ShellUtil::kChromeHTMLProgId);
162 DeleteRegistryKey(key, html_prog_id); 204 DeleteRegistryKey(key, html_prog_id);
163 205
(...skipping 17 matching lines...) Expand all
181 223
182 // Delete media player registry key that exists only in HKLM. 224 // Delete media player registry key that exists only in HKLM.
183 std::wstring reg_path(installer::kMediaPlayerRegPath); 225 std::wstring reg_path(installer::kMediaPlayerRegPath);
184 file_util::AppendToPath(&reg_path, installer_util::kChromeExe); 226 file_util::AppendToPath(&reg_path, installer_util::kChromeExe);
185 DeleteRegistryKey(hklm_key, reg_path); 227 DeleteRegistryKey(hklm_key, reg_path);
186 hklm_key.Close(); 228 hklm_key.Close();
187 } 229 }
188 230
189 // Finally delete all the files from Chrome folder after moving setup.exe 231 // Finally delete all the files from Chrome folder after moving setup.exe
190 // to a temp location. 232 // to a temp location.
191 std::wstring install_path(installer::GetChromeInstallPath(system_uninstall)); 233 if (!DeleteFilesAndFolders(exe_path, system_uninstall, installed_version))
192 if (install_path.empty()) {
193 LOG(ERROR) << "Could not get installation destination path.";
194 // Nothing else we could do for uninstall, so we return.
195 return installer_util::UNINSTALL_FAILED; 234 return installer_util::UNINSTALL_FAILED;
196 } else {
197 LOG(INFO) << "install destination path: " << install_path;
198 }
199
200 std::wstring setup_exe(installer::GetInstallerPathUnderChrome(
201 install_path, installed_version.GetString()));
202 file_util::AppendToPath(&setup_exe, file_util::GetFilenameFromPath(exe_path));
203
204 std::wstring temp_file;
205 file_util::CreateTemporaryFileName(&temp_file);
206 file_util::Move(setup_exe, temp_file);
207
208 LOG(INFO) << "Deleting install path " << install_path;
209 if (!file_util::Delete(install_path, true))
210 LOG(ERROR) << "Failed to delete folder: " << install_path;
211 235
212 LOG(INFO) << "Uninstallation complete. Launching Uninstall survey."; 236 LOG(INFO) << "Uninstallation complete. Launching Uninstall survey.";
213 dist->DoPostUninstallOperations(installed_version); 237 dist->DoPostUninstallOperations(installed_version);
214 return installer_util::UNINSTALL_SUCCESSFUL; 238 return installer_util::UNINSTALL_SUCCESSFUL;
215 } 239 }
216 240
OLDNEW
« no previous file with comments | « chrome/installer/setup/setup.cc ('k') | chrome/installer/util/browser_distribution.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698