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

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

Issue 316753003: Always read and write Google Update registry values from the 32-bit hive, even on 64-bit systems. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: code review changes Created 6 years, 6 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 | « no previous file | no next file » | 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 #include "chrome/installer/util/google_update_settings.h" 5 #include "chrome/installer/util/google_update_settings.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // Updates a registry key |name| to be |value| for the given |app_reg_data|. 68 // Updates a registry key |name| to be |value| for the given |app_reg_data|.
69 // If this is a |system_install|, then update the value under HKLM (istead of 69 // If this is a |system_install|, then update the value under HKLM (istead of
70 // HKCU for user-installs) using a group of keys (one for each OS user) and also 70 // HKCU for user-installs) using a group of keys (one for each OS user) and also
71 // include the method to |aggregate| these values when reporting. 71 // include the method to |aggregate| these values when reporting.
72 bool WriteGoogleUpdateStrKeyInternal(const AppRegistrationData& app_reg_data, 72 bool WriteGoogleUpdateStrKeyInternal(const AppRegistrationData& app_reg_data,
73 bool system_install, 73 bool system_install,
74 const wchar_t* const name, 74 const wchar_t* const name,
75 // presubmit: allow wstring 75 // presubmit: allow wstring
76 const std::wstring& value, 76 const std::wstring& value,
77 const wchar_t* const aggregate) { 77 const wchar_t* const aggregate) {
78 const REGSAM kAccess = KEY_SET_VALUE | KEY_WOW64_32KEY;
78 if (system_install) { 79 if (system_install) {
79 DCHECK(aggregate); 80 DCHECK(aggregate);
80 // Machine installs require each OS user to write a unique key under a 81 // Machine installs require each OS user to write a unique key under a
81 // named key in HKLM as well as an "aggregation" function that describes 82 // named key in HKLM as well as an "aggregation" function that describes
82 // how the values of multiple users are to be combined. 83 // how the values of multiple users are to be combined.
83 std::wstring uniquename; // presubmit: allow wstring 84 std::wstring uniquename; // presubmit: allow wstring
84 if (!base::win::GetUserSidString(&uniquename)) { 85 if (!base::win::GetUserSidString(&uniquename)) {
85 NOTREACHED(); 86 NOTREACHED();
86 return false; 87 return false;
87 } 88 }
88 89
89 base::string16 reg_path(app_reg_data.GetStateMediumKey()); 90 base::string16 reg_path(app_reg_data.GetStateMediumKey());
90 reg_path.append(L"\\"); 91 reg_path.append(L"\\");
91 reg_path.append(name); 92 reg_path.append(name);
92 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_SET_VALUE); 93 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), kAccess);
93 key.WriteValue(google_update::kRegAggregateMethod, aggregate); 94 key.WriteValue(google_update::kRegAggregateMethod, aggregate);
94 return (key.WriteValue(uniquename.c_str(), value.c_str()) == ERROR_SUCCESS); 95 return (key.WriteValue(uniquename.c_str(), value.c_str()) == ERROR_SUCCESS);
95 } else { 96 } else {
96 // User installs are easy: just write the values to HKCU tree. 97 // User installs are easy: just write the values to HKCU tree.
97 RegKey key(HKEY_CURRENT_USER, app_reg_data.GetStateKey().c_str(), 98 RegKey key(HKEY_CURRENT_USER, app_reg_data.GetStateKey().c_str(), kAccess);
98 KEY_SET_VALUE);
99 return (key.WriteValue(name, value.c_str()) == ERROR_SUCCESS); 99 return (key.WriteValue(name, value.c_str()) == ERROR_SUCCESS);
100 } 100 }
101 } 101 }
102 102
103 bool WriteGoogleUpdateStrKey(const wchar_t* const name, 103 bool WriteGoogleUpdateStrKey(const wchar_t* const name,
104 const std::wstring& value) { 104 const std::wstring& value) {
105 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 105 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
106 return WriteGoogleUpdateStrKeyInternal( 106 return WriteGoogleUpdateStrKeyInternal(
107 dist->GetAppRegistrationData(), false, name, value, NULL); 107 dist->GetAppRegistrationData(), false, name, value, NULL);
108 } 108 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 219
220 // Consent applies to all products in a multi-install package. 220 // Consent applies to all products in a multi-install package.
221 if (InstallUtil::IsMultiInstall(dist, system_install)) { 221 if (InstallUtil::IsMultiInstall(dist, system_install)) {
222 dist = BrowserDistribution::GetSpecificDistribution( 222 dist = BrowserDistribution::GetSpecificDistribution(
223 BrowserDistribution::CHROME_BINARIES); 223 BrowserDistribution::CHROME_BINARIES);
224 } 224 }
225 225
226 RegKey key; 226 RegKey key;
227 DWORD value = 0; 227 DWORD value = 0;
228 bool have_value = false; 228 bool have_value = false;
229 const REGSAM kAccess = KEY_QUERY_VALUE | KEY_WOW64_32KEY;
229 230
230 // For system-level installs, try ClientStateMedium first. 231 // For system-level installs, try ClientStateMedium first.
231 have_value = 232 have_value =
232 system_install && 233 system_install &&
233 key.Open(HKEY_LOCAL_MACHINE, dist->GetStateMediumKey().c_str(), 234 key.Open(HKEY_LOCAL_MACHINE, dist->GetStateMediumKey().c_str(),
234 KEY_QUERY_VALUE) == ERROR_SUCCESS && 235 kAccess) == ERROR_SUCCESS &&
235 key.ReadValueDW(google_update::kRegUsageStatsField, 236 key.ReadValueDW(google_update::kRegUsageStatsField,
236 &value) == ERROR_SUCCESS; 237 &value) == ERROR_SUCCESS;
237 238
238 // Otherwise, try ClientState. 239 // Otherwise, try ClientState.
239 if (!have_value) { 240 if (!have_value) {
240 have_value = 241 have_value =
241 key.Open(system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, 242 key.Open(system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
242 dist->GetStateKey().c_str(), 243 dist->GetStateKey().c_str(),
243 KEY_QUERY_VALUE) == ERROR_SUCCESS && 244 kAccess) == ERROR_SUCCESS &&
244 key.ReadValueDW(google_update::kRegUsageStatsField, 245 key.ReadValueDW(google_update::kRegUsageStatsField,
245 &value) == ERROR_SUCCESS; 246 &value) == ERROR_SUCCESS;
246 } 247 }
247 248
248 // Google Update specifically checks that the value is 1, so we do the same. 249 // Google Update specifically checks that the value is 1, so we do the same.
249 return have_value && value == 1; 250 return have_value && value == 1;
250 } 251 }
251 252
252 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) { 253 bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) {
253 return SetCollectStatsConsentAtLevel(IsSystemInstall(), consented); 254 return SetCollectStatsConsentAtLevel(IsSystemInstall(), consented);
(...skipping 10 matching lines...) Expand all
264 if (InstallUtil::IsMultiInstall(dist, system_install)) { 265 if (InstallUtil::IsMultiInstall(dist, system_install)) {
265 dist = BrowserDistribution::GetSpecificDistribution( 266 dist = BrowserDistribution::GetSpecificDistribution(
266 BrowserDistribution::CHROME_BINARIES); 267 BrowserDistribution::CHROME_BINARIES);
267 } 268 }
268 269
269 // Write to ClientStateMedium for system-level; ClientState otherwise. 270 // Write to ClientStateMedium for system-level; ClientState otherwise.
270 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 271 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
271 std::wstring reg_path = 272 std::wstring reg_path =
272 system_install ? dist->GetStateMediumKey() : dist->GetStateKey(); 273 system_install ? dist->GetStateMediumKey() : dist->GetStateKey();
273 RegKey key; 274 RegKey key;
274 LONG result = key.Create(root_key, reg_path.c_str(), KEY_SET_VALUE); 275 LONG result = key.Create(
276 root_key, reg_path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY);
275 if (result != ERROR_SUCCESS) { 277 if (result != ERROR_SUCCESS) {
276 LOG(ERROR) << "Failed opening key " << reg_path << " to set " 278 LOG(ERROR) << "Failed opening key " << reg_path << " to set "
277 << google_update::kRegUsageStatsField << "; result: " << result; 279 << google_update::kRegUsageStatsField << "; result: " << result;
278 } else { 280 } else {
279 result = key.WriteValue(google_update::kRegUsageStatsField, value); 281 result = key.WriteValue(google_update::kRegUsageStatsField, value);
280 LOG_IF(ERROR, result != ERROR_SUCCESS) << "Failed setting " 282 LOG_IF(ERROR, result != ERROR_SUCCESS) << "Failed setting "
281 << google_update::kRegUsageStatsField << " in key " << reg_path 283 << google_update::kRegUsageStatsField << " in key " << reg_path
282 << "; result: " << result; 284 << "; result: " << result;
283 } 285 }
284 return (result == ERROR_SUCCESS); 286 return (result == ERROR_SUCCESS);
(...skipping 11 matching lines...) Expand all
296 return WriteGoogleUpdateStrKey(google_update::kRegMetricsId, metrics_id_w); 298 return WriteGoogleUpdateStrKey(google_update::kRegMetricsId, metrics_id_w);
297 } 299 }
298 300
299 // EULA consent is only relevant for system-level installs. 301 // EULA consent is only relevant for system-level installs.
300 bool GoogleUpdateSettings::SetEULAConsent( 302 bool GoogleUpdateSettings::SetEULAConsent(
301 const InstallationState& machine_state, 303 const InstallationState& machine_state,
302 BrowserDistribution* dist, 304 BrowserDistribution* dist,
303 bool consented) { 305 bool consented) {
304 DCHECK(dist); 306 DCHECK(dist);
305 const DWORD eula_accepted = consented ? 1 : 0; 307 const DWORD eula_accepted = consented ? 1 : 0;
308 const REGSAM kAccess = KEY_SET_VALUE | KEY_WOW64_32KEY;
306 std::wstring reg_path = dist->GetStateMediumKey(); 309 std::wstring reg_path = dist->GetStateMediumKey();
307 bool succeeded = true; 310 bool succeeded = true;
308 RegKey key; 311 RegKey key;
309 312
310 // Write the consent value into the product's ClientStateMedium key. 313 // Write the consent value into the product's ClientStateMedium key.
311 if (key.Create(HKEY_LOCAL_MACHINE, reg_path.c_str(), 314 if (key.Create(HKEY_LOCAL_MACHINE, reg_path.c_str(),
312 KEY_SET_VALUE) != ERROR_SUCCESS || 315 kAccess) != ERROR_SUCCESS ||
313 key.WriteValue(google_update::kRegEULAAceptedField, 316 key.WriteValue(google_update::kRegEULAAceptedField,
314 eula_accepted) != ERROR_SUCCESS) { 317 eula_accepted) != ERROR_SUCCESS) {
315 succeeded = false; 318 succeeded = false;
316 } 319 }
317 320
318 // If this is a multi-install, also write it into the binaries' key. 321 // If this is a multi-install, also write it into the binaries' key.
319 // --mutli-install is not provided on the command-line, so deduce it from 322 // --mutli-install is not provided on the command-line, so deduce it from
320 // the product's state. 323 // the product's state.
321 const installer::ProductState* product_state = 324 const installer::ProductState* product_state =
322 machine_state.GetProductState(true, dist->GetType()); 325 machine_state.GetProductState(true, dist->GetType());
323 if (product_state != NULL && product_state->is_multi_install()) { 326 if (product_state != NULL && product_state->is_multi_install()) {
324 dist = BrowserDistribution::GetSpecificDistribution( 327 dist = BrowserDistribution::GetSpecificDistribution(
325 BrowserDistribution::CHROME_BINARIES); 328 BrowserDistribution::CHROME_BINARIES);
326 reg_path = dist->GetStateMediumKey(); 329 reg_path = dist->GetStateMediumKey();
327 if (key.Create(HKEY_LOCAL_MACHINE, reg_path.c_str(), 330 if (key.Create(HKEY_LOCAL_MACHINE, reg_path.c_str(),
328 KEY_SET_VALUE) != ERROR_SUCCESS || 331 kAccess) != ERROR_SUCCESS ||
329 key.WriteValue(google_update::kRegEULAAceptedField, 332 key.WriteValue(google_update::kRegEULAAceptedField,
330 eula_accepted) != ERROR_SUCCESS) { 333 eula_accepted) != ERROR_SUCCESS) {
331 succeeded = false; 334 succeeded = false;
332 } 335 }
333 } 336 }
334 337
335 return succeeded; 338 return succeeded;
336 } 339 }
337 340
338 int GoogleUpdateSettings::GetLastRunTime() { 341 int GoogleUpdateSettings::GetLastRunTime() {
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 UPDATE_POLICIES_COUNT); 693 UPDATE_POLICIES_COUNT);
691 } 694 }
692 695
693 base::string16 GoogleUpdateSettings::GetUninstallCommandLine( 696 base::string16 GoogleUpdateSettings::GetUninstallCommandLine(
694 bool system_install) { 697 bool system_install) {
695 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 698 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
696 base::string16 cmd_line; 699 base::string16 cmd_line;
697 RegKey update_key; 700 RegKey update_key;
698 701
699 if (update_key.Open(root_key, google_update::kRegPathGoogleUpdate, 702 if (update_key.Open(root_key, google_update::kRegPathGoogleUpdate,
700 KEY_QUERY_VALUE) == ERROR_SUCCESS) { 703 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) {
701 update_key.ReadValue(google_update::kRegUninstallCmdLine, &cmd_line); 704 update_key.ReadValue(google_update::kRegUninstallCmdLine, &cmd_line);
702 } 705 }
703 706
704 return cmd_line; 707 return cmd_line;
705 } 708 }
706 709
707 Version GoogleUpdateSettings::GetGoogleUpdateVersion(bool system_install) { 710 Version GoogleUpdateSettings::GetGoogleUpdateVersion(bool system_install) {
708 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 711 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
709 base::string16 version; 712 base::string16 version;
710 RegKey key; 713 RegKey key;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 } 874 }
872 875
873 // If the key or value was not present, return the empty string. 876 // If the key or value was not present, return the empty string.
874 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { 877 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) {
875 experiment_labels->clear(); 878 experiment_labels->clear();
876 return true; 879 return true;
877 } 880 }
878 881
879 return result == ERROR_SUCCESS; 882 return result == ERROR_SUCCESS;
880 } 883 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698