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

Side by Side Diff: chrome/installer/util/install_util.cc

Issue 6090006: Regkey functions return error code instead of bool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // See the corresponding header file for description of the functions in this 5 // See the corresponding header file for description of the functions in this
6 // file. 6 // file.
7 7
8 #include "chrome/installer/util/install_util.h" 8 #include "chrome/installer/util/install_util.h"
9 9
10 #include <shellapi.h> 10 #include <shellapi.h>
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 RegKey key(root, dist->GetUninstallRegPath().c_str(), KEY_READ); 75 RegKey key(root, dist->GetUninstallRegPath().c_str(), KEY_READ);
76 std::wstring uninstall_cmd; 76 std::wstring uninstall_cmd;
77 key.ReadValue(installer::kUninstallStringField, &uninstall_cmd); 77 key.ReadValue(installer::kUninstallStringField, &uninstall_cmd);
78 return uninstall_cmd; 78 return uninstall_cmd;
79 } 79 }
80 80
81 Version* InstallUtil::GetChromeVersion(BrowserDistribution* dist, 81 Version* InstallUtil::GetChromeVersion(BrowserDistribution* dist,
82 bool system_install) { 82 bool system_install) {
83 DCHECK(dist); 83 DCHECK(dist);
84 RegKey key; 84 RegKey key;
85 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
86 LONG result = key.Open(reg_root, dist->GetVersionKey().c_str(), KEY_READ);
87
85 std::wstring version_str; 88 std::wstring version_str;
89 if (result == ERROR_SUCCESS)
90 result = key.ReadValue(google_update::kRegVersionField, &version_str);
86 91
87 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 92 Version* ret = NULL;
88 if (!key.Open(reg_root, dist->GetVersionKey().c_str(), KEY_READ) || 93 if (result == ERROR_SUCCESS && !version_str.empty()) {
89 !key.ReadValue(google_update::kRegVersionField, &version_str)) { 94 VLOG(1) << "Existing " << dist->GetApplicationName()
95 << " version found " << version_str;
96 ret = Version::GetVersionFromString(WideToASCII(version_str));
97 } else {
98 DCHECK_EQ(ERROR_FILE_NOT_FOUND, result);
90 VLOG(1) << "No existing " << dist->GetApplicationName() 99 VLOG(1) << "No existing " << dist->GetApplicationName()
91 << " install found."; 100 << " install found.";
92 key.Close();
93 return NULL;
94 } 101 }
95 key.Close(); 102
96 VLOG(1) << "Existing " << dist->GetApplicationName() 103 return ret;
97 << " version found " << version_str;
98 return Version::GetVersionFromString(WideToASCII(version_str));
99 } 104 }
100 105
101 bool InstallUtil::IsOSSupported() { 106 bool InstallUtil::IsOSSupported() {
102 int major, minor; 107 int major, minor;
103 base::win::Version version = base::win::GetVersion(); 108 base::win::Version version = base::win::GetVersion();
104 base::win::GetServicePackLevel(&major, &minor); 109 base::win::GetServicePackLevel(&major, &minor);
105 110
106 // We do not support Win2K or older, or XP without service pack 2. 111 // We do not support Win2K or older, or XP without service pack 2.
107 VLOG(1) << "Windows Version: " << version 112 VLOG(1) << "Windows Version: " << version
108 << ", Service Pack: " << major << "." << minor; 113 << ", Service Pack: " << major << "." << minor;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 } 193 }
189 return (dll_names_count > 0) && success; 194 return (dll_names_count > 0) && success;
190 } 195 }
191 196
192 // This method tries to delete a registry key and logs an error message 197 // This method tries to delete a registry key and logs an error message
193 // in case of failure. It returns true if deletion is successful, 198 // in case of failure. It returns true if deletion is successful,
194 // otherwise false. 199 // otherwise false.
195 bool InstallUtil::DeleteRegistryKey(RegKey& root_key, 200 bool InstallUtil::DeleteRegistryKey(RegKey& root_key,
196 const std::wstring& key_path) { 201 const std::wstring& key_path) {
197 VLOG(1) << "Deleting registry key " << key_path; 202 VLOG(1) << "Deleting registry key " << key_path;
198 if (!root_key.DeleteKey(key_path.c_str()) && 203 LONG result = root_key.DeleteKey(key_path.c_str());
199 ::GetLastError() != ERROR_FILE_NOT_FOUND) { 204 if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) {
200 PLOG(ERROR) << "Failed to delete registry key: " << key_path; 205 PLOG(ERROR) << "Failed to delete registry key: " << key_path
206 << " error: " << result;
201 return false; 207 return false;
202 } 208 }
203 return true; 209 return true;
204 } 210 }
205 211
206 // This method tries to delete a registry value and logs an error message 212 // This method tries to delete a registry value and logs an error message
207 // in case of failure. It returns true if deletion is successful, 213 // in case of failure. It returns true if deletion is successful,
208 // otherwise false. 214 // otherwise false.
209 bool InstallUtil::DeleteRegistryValue(HKEY reg_root, 215 bool InstallUtil::DeleteRegistryValue(HKEY reg_root,
210 const std::wstring& key_path, 216 const std::wstring& key_path,
211 const std::wstring& value_name) { 217 const std::wstring& value_name) {
212 RegKey key(reg_root, key_path.c_str(), KEY_ALL_ACCESS); 218 RegKey key(reg_root, key_path.c_str(), KEY_ALL_ACCESS);
213 VLOG(1) << "Deleting registry value " << value_name; 219 VLOG(1) << "Deleting registry value " << value_name;
214 if (key.ValueExists(value_name.c_str()) && 220 if (key.ValueExists(value_name.c_str())) {
215 !key.DeleteValue(value_name.c_str())) { 221 LONG result = key.DeleteValue(value_name.c_str());
216 LOG(ERROR) << "Failed to delete registry value: " << value_name; 222 if (result != ERROR_SUCCESS) {
217 return false; 223 LOG(ERROR) << "Failed to delete registry value: " << value_name
224 << " error: " << result;
225 return false;
226 }
218 } 227 }
219 return true; 228 return true;
220 } 229 }
221 230
222 // static 231 // static
223 int InstallUtil::GetInstallReturnCode(installer::InstallStatus status) { 232 int InstallUtil::GetInstallReturnCode(installer::InstallStatus status) {
224 switch (status) { 233 switch (status) {
225 case installer::FIRST_INSTALL_SUCCESS: 234 case installer::FIRST_INSTALL_SUCCESS:
226 case installer::INSTALL_REPAIRED: 235 case installer::INSTALL_REPAIRED:
227 case installer::NEW_VERSION_UPDATED: 236 case installer::NEW_VERSION_UPDATED:
228 case installer::IN_USE_UPDATED: 237 case installer::IN_USE_UPDATED:
229 return 0; 238 return 0;
230 default: 239 default:
231 return status; 240 return status;
232 } 241 }
233 } 242 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698