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

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

Issue 371753002: Installer refactoring: using string16 instead of wstring for GoogleUpdateSettings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updating callers to use string16 to interface with GoogleUpdateSettings. Created 6 years, 5 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) 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>
9 8
10 #include "base/command_line.h" 9 #include "base/command_line.h"
11 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
12 #include "base/logging.h" 11 #include "base/logging.h"
13 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
14 #include "base/path_service.h" 13 #include "base/path_service.h"
15 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
18 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
(...skipping 27 matching lines...) Expand all
46 const GoogleUpdateSettings::UpdatePolicy 45 const GoogleUpdateSettings::UpdatePolicy
47 GoogleUpdateSettings::kDefaultUpdatePolicy = 46 GoogleUpdateSettings::kDefaultUpdatePolicy =
48 #if defined(GOOGLE_CHROME_BUILD) 47 #if defined(GOOGLE_CHROME_BUILD)
49 GoogleUpdateSettings::AUTOMATIC_UPDATES; 48 GoogleUpdateSettings::AUTOMATIC_UPDATES;
50 #else 49 #else
51 GoogleUpdateSettings::UPDATES_DISABLED; 50 GoogleUpdateSettings::UPDATES_DISABLED;
52 #endif 51 #endif
53 52
54 namespace { 53 namespace {
55 54
56 bool ReadGoogleUpdateStrKey(const wchar_t* const name, std::wstring* value) { 55 bool ReadGoogleUpdateStrKey(const wchar_t* const name, base::string16* value) {
57 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 56 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
58 std::wstring reg_path = dist->GetStateKey(); 57 base::string16 reg_path = dist->GetStateKey();
59 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WOW64_32KEY); 58 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WOW64_32KEY);
60 if (key.ReadValue(name, value) != ERROR_SUCCESS) { 59 if (key.ReadValue(name, value) != ERROR_SUCCESS) {
61 RegKey hklm_key( 60 RegKey hklm_key(
62 HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ | KEY_WOW64_32KEY); 61 HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ | KEY_WOW64_32KEY);
63 return (hklm_key.ReadValue(name, value) == ERROR_SUCCESS); 62 return (hklm_key.ReadValue(name, value) == ERROR_SUCCESS);
64 } 63 }
65 return true; 64 return true;
66 } 65 }
67 66
68 // Updates a registry key |name| to be |value| for the given |app_reg_data|. 67 // 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 68 // 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 69 // 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. 70 // include the method to |aggregate| these values when reporting.
72 bool WriteGoogleUpdateStrKeyInternal(const AppRegistrationData& app_reg_data, 71 bool WriteGoogleUpdateStrKeyInternal(const AppRegistrationData& app_reg_data,
73 bool system_install, 72 bool system_install,
74 const wchar_t* const name, 73 const wchar_t* const name,
75 // presubmit: allow wstring 74 const base::string16& value,
76 const std::wstring& value,
77 const wchar_t* const aggregate) { 75 const wchar_t* const aggregate) {
78 const REGSAM kAccess = KEY_SET_VALUE | KEY_WOW64_32KEY; 76 const REGSAM kAccess = KEY_SET_VALUE | KEY_WOW64_32KEY;
79 if (system_install) { 77 if (system_install) {
80 DCHECK(aggregate); 78 DCHECK(aggregate);
81 // Machine installs require each OS user to write a unique key under a 79 // Machine installs require each OS user to write a unique key under a
82 // named key in HKLM as well as an "aggregation" function that describes 80 // named key in HKLM as well as an "aggregation" function that describes
83 // how the values of multiple users are to be combined. 81 // how the values of multiple users are to be combined.
84 std::wstring uniquename; // presubmit: allow wstring 82 base::string16 uniquename;
85 if (!base::win::GetUserSidString(&uniquename)) { 83 if (!base::win::GetUserSidString(&uniquename)) {
86 NOTREACHED(); 84 NOTREACHED();
87 return false; 85 return false;
88 } 86 }
89 87
90 base::string16 reg_path(app_reg_data.GetStateMediumKey()); 88 base::string16 reg_path(app_reg_data.GetStateMediumKey());
91 reg_path.append(L"\\"); 89 reg_path.append(L"\\");
92 reg_path.append(name); 90 reg_path.append(name);
93 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), kAccess); 91 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), kAccess);
94 key.WriteValue(google_update::kRegAggregateMethod, aggregate); 92 key.WriteValue(google_update::kRegAggregateMethod, aggregate);
95 return (key.WriteValue(uniquename.c_str(), value.c_str()) == ERROR_SUCCESS); 93 return (key.WriteValue(uniquename.c_str(), value.c_str()) == ERROR_SUCCESS);
96 } else { 94 } else {
97 // User installs are easy: just write the values to HKCU tree. 95 // User installs are easy: just write the values to HKCU tree.
98 RegKey key(HKEY_CURRENT_USER, app_reg_data.GetStateKey().c_str(), kAccess); 96 RegKey key(HKEY_CURRENT_USER, app_reg_data.GetStateKey().c_str(), kAccess);
99 return (key.WriteValue(name, value.c_str()) == ERROR_SUCCESS); 97 return (key.WriteValue(name, value.c_str()) == ERROR_SUCCESS);
100 } 98 }
101 } 99 }
102 100
103 bool WriteGoogleUpdateStrKey(const wchar_t* const name, 101 bool WriteGoogleUpdateStrKey(const wchar_t* const name,
104 const std::wstring& value) { 102 const base::string16& value) {
105 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 103 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
106 return WriteGoogleUpdateStrKeyInternal( 104 return WriteGoogleUpdateStrKeyInternal(
107 dist->GetAppRegistrationData(), false, name, value, NULL); 105 dist->GetAppRegistrationData(), false, name, value, NULL);
108 } 106 }
109 107
110 bool ClearGoogleUpdateStrKey(const wchar_t* const name) { 108 bool ClearGoogleUpdateStrKey(const wchar_t* const name) {
111 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 109 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
112 std::wstring reg_path = dist->GetStateKey(); 110 base::string16 reg_path = dist->GetStateKey();
113 RegKey key(HKEY_CURRENT_USER, 111 RegKey key(HKEY_CURRENT_USER,
114 reg_path.c_str(), 112 reg_path.c_str(),
115 KEY_READ | KEY_WRITE | KEY_WOW64_32KEY); 113 KEY_READ | KEY_WRITE | KEY_WOW64_32KEY);
116 std::wstring value; 114 base::string16 value;
117 if (key.ReadValue(name, &value) != ERROR_SUCCESS) 115 if (key.ReadValue(name, &value) != ERROR_SUCCESS)
118 return false; 116 return false;
119 return (key.WriteValue(name, L"") == ERROR_SUCCESS); 117 return (key.WriteValue(name, L"") == ERROR_SUCCESS);
120 } 118 }
121 119
122 bool RemoveGoogleUpdateStrKey(const wchar_t* const name) { 120 bool RemoveGoogleUpdateStrKey(const wchar_t* const name) {
123 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 121 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
124 std::wstring reg_path = dist->GetStateKey(); 122 base::string16 reg_path = dist->GetStateKey();
125 RegKey key(HKEY_CURRENT_USER, 123 RegKey key(HKEY_CURRENT_USER,
126 reg_path.c_str(), 124 reg_path.c_str(),
127 KEY_READ | KEY_WRITE | KEY_WOW64_32KEY); 125 KEY_READ | KEY_WRITE | KEY_WOW64_32KEY);
128 if (!key.HasValue(name)) 126 if (!key.HasValue(name))
129 return true; 127 return true;
130 return (key.DeleteValue(name) == ERROR_SUCCESS); 128 return (key.DeleteValue(name) == ERROR_SUCCESS);
131 } 129 }
132 130
133 bool GetChromeChannelInternal(bool system_install, 131 bool GetChromeChannelInternal(bool system_install,
134 bool add_multi_modifier, 132 bool add_multi_modifier,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 272 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
275 273
276 // Consent applies to all products in a multi-install package. 274 // Consent applies to all products in a multi-install package.
277 if (InstallUtil::IsMultiInstall(dist, system_install)) { 275 if (InstallUtil::IsMultiInstall(dist, system_install)) {
278 dist = BrowserDistribution::GetSpecificDistribution( 276 dist = BrowserDistribution::GetSpecificDistribution(
279 BrowserDistribution::CHROME_BINARIES); 277 BrowserDistribution::CHROME_BINARIES);
280 } 278 }
281 279
282 // Write to ClientStateMedium for system-level; ClientState otherwise. 280 // Write to ClientStateMedium for system-level; ClientState otherwise.
283 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 281 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
284 std::wstring reg_path = 282 base::string16 reg_path =
285 system_install ? dist->GetStateMediumKey() : dist->GetStateKey(); 283 system_install ? dist->GetStateMediumKey() : dist->GetStateKey();
286 RegKey key; 284 RegKey key;
287 LONG result = key.Create( 285 LONG result = key.Create(
288 root_key, reg_path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY); 286 root_key, reg_path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY);
289 if (result != ERROR_SUCCESS) { 287 if (result != ERROR_SUCCESS) {
290 LOG(ERROR) << "Failed opening key " << reg_path << " to set " 288 LOG(ERROR) << "Failed opening key " << reg_path << " to set "
291 << google_update::kRegUsageStatsField << "; result: " << result; 289 << google_update::kRegUsageStatsField << "; result: " << result;
292 } else { 290 } else {
293 result = key.WriteValue(google_update::kRegUsageStatsField, value); 291 result = key.WriteValue(google_update::kRegUsageStatsField, value);
294 LOG_IF(ERROR, result != ERROR_SUCCESS) << "Failed setting " 292 LOG_IF(ERROR, result != ERROR_SUCCESS) << "Failed setting "
295 << google_update::kRegUsageStatsField << " in key " << reg_path 293 << google_update::kRegUsageStatsField << " in key " << reg_path
296 << "; result: " << result; 294 << "; result: " << result;
297 } 295 }
298 return (result == ERROR_SUCCESS); 296 return (result == ERROR_SUCCESS);
299 } 297 }
300 298
301 bool GoogleUpdateSettings::GetMetricsId(std::string* metrics_id) { 299 bool GoogleUpdateSettings::GetMetricsId(std::string* metrics_id) {
302 std::wstring metrics_id_w; 300 base::string16 metrics_id_w;
grt (UTC plus 2) 2014/07/07 22:48:39 _w -> 16
huangs 2014/07/08 00:02:19 Done.
303 bool rv = ReadGoogleUpdateStrKey(google_update::kRegMetricsId, &metrics_id_w); 301 bool rv = ReadGoogleUpdateStrKey(google_update::kRegMetricsId, &metrics_id_w);
304 *metrics_id = base::WideToUTF8(metrics_id_w); 302 *metrics_id = base::WideToUTF8(metrics_id_w);
305 return rv; 303 return rv;
306 } 304 }
307 305
308 bool GoogleUpdateSettings::SetMetricsId(const std::string& metrics_id) { 306 bool GoogleUpdateSettings::SetMetricsId(const std::string& metrics_id) {
309 std::wstring metrics_id_w = base::UTF8ToWide(metrics_id); 307 base::string16 metrics_id_w = base::UTF8ToWide(metrics_id);
gab 2014/07/07 21:41:14 Please also update all UT8ToWide and WideToUTF8 ma
huangs 2014/07/08 00:02:19 Ah good catch. Done!
grt (UTC plus 2) 2014/07/07 22:48:39 _w -> 16
huangs 2014/07/08 00:02:19 Done.
310 return WriteGoogleUpdateStrKey(google_update::kRegMetricsId, metrics_id_w); 308 return WriteGoogleUpdateStrKey(google_update::kRegMetricsId, metrics_id_w);
311 } 309 }
312 310
313 // EULA consent is only relevant for system-level installs. 311 // EULA consent is only relevant for system-level installs.
314 bool GoogleUpdateSettings::SetEULAConsent( 312 bool GoogleUpdateSettings::SetEULAConsent(
315 const InstallationState& machine_state, 313 const InstallationState& machine_state,
316 BrowserDistribution* dist, 314 BrowserDistribution* dist,
317 bool consented) { 315 bool consented) {
318 DCHECK(dist); 316 DCHECK(dist);
319 const DWORD eula_accepted = consented ? 1 : 0; 317 const DWORD eula_accepted = consented ? 1 : 0;
320 const REGSAM kAccess = KEY_SET_VALUE | KEY_WOW64_32KEY; 318 const REGSAM kAccess = KEY_SET_VALUE | KEY_WOW64_32KEY;
321 std::wstring reg_path = dist->GetStateMediumKey(); 319 base::string16 reg_path = dist->GetStateMediumKey();
322 bool succeeded = true; 320 bool succeeded = true;
323 RegKey key; 321 RegKey key;
324 322
325 // Write the consent value into the product's ClientStateMedium key. 323 // Write the consent value into the product's ClientStateMedium key.
326 if (key.Create(HKEY_LOCAL_MACHINE, reg_path.c_str(), 324 if (key.Create(HKEY_LOCAL_MACHINE, reg_path.c_str(),
327 kAccess) != ERROR_SUCCESS || 325 kAccess) != ERROR_SUCCESS ||
328 key.WriteValue(google_update::kRegEULAAceptedField, 326 key.WriteValue(google_update::kRegEULAAceptedField,
329 eula_accepted) != ERROR_SUCCESS) { 327 eula_accepted) != ERROR_SUCCESS) {
330 succeeded = false; 328 succeeded = false;
331 } 329 }
(...skipping 12 matching lines...) Expand all
344 key.WriteValue(google_update::kRegEULAAceptedField, 342 key.WriteValue(google_update::kRegEULAAceptedField,
345 eula_accepted) != ERROR_SUCCESS) { 343 eula_accepted) != ERROR_SUCCESS) {
346 succeeded = false; 344 succeeded = false;
347 } 345 }
348 } 346 }
349 347
350 return succeeded; 348 return succeeded;
351 } 349 }
352 350
353 int GoogleUpdateSettings::GetLastRunTime() { 351 int GoogleUpdateSettings::GetLastRunTime() {
354 std::wstring time_s; 352 base::string16 time_s;
355 if (!ReadGoogleUpdateStrKey(google_update::kRegLastRunTimeField, &time_s)) 353 if (!ReadGoogleUpdateStrKey(google_update::kRegLastRunTimeField, &time_s))
356 return -1; 354 return -1;
357 int64 time_i; 355 int64 time_i;
358 if (!base::StringToInt64(time_s, &time_i)) 356 if (!base::StringToInt64(time_s, &time_i))
359 return -1; 357 return -1;
360 base::TimeDelta td = 358 base::TimeDelta td =
361 base::Time::NowFromSystemTime() - base::Time::FromInternalValue(time_i); 359 base::Time::NowFromSystemTime() - base::Time::FromInternalValue(time_i);
362 return td.InDays(); 360 return td.InDays();
363 } 361 }
364 362
365 bool GoogleUpdateSettings::SetLastRunTime() { 363 bool GoogleUpdateSettings::SetLastRunTime() {
366 int64 time = base::Time::NowFromSystemTime().ToInternalValue(); 364 int64 time = base::Time::NowFromSystemTime().ToInternalValue();
367 return WriteGoogleUpdateStrKey(google_update::kRegLastRunTimeField, 365 return WriteGoogleUpdateStrKey(google_update::kRegLastRunTimeField,
368 base::Int64ToString16(time)); 366 base::Int64ToString16(time));
369 } 367 }
370 368
371 bool GoogleUpdateSettings::RemoveLastRunTime() { 369 bool GoogleUpdateSettings::RemoveLastRunTime() {
372 return RemoveGoogleUpdateStrKey(google_update::kRegLastRunTimeField); 370 return RemoveGoogleUpdateStrKey(google_update::kRegLastRunTimeField);
373 } 371 }
374 372
375 bool GoogleUpdateSettings::GetBrowser(std::wstring* browser) { 373 bool GoogleUpdateSettings::GetBrowser(base::string16* browser) {
376 return ReadGoogleUpdateStrKey(google_update::kRegBrowserField, browser); 374 return ReadGoogleUpdateStrKey(google_update::kRegBrowserField, browser);
377 } 375 }
378 376
379 bool GoogleUpdateSettings::GetLanguage(std::wstring* language) { 377 bool GoogleUpdateSettings::GetLanguage(base::string16* language) {
380 return ReadGoogleUpdateStrKey(google_update::kRegLangField, language); 378 return ReadGoogleUpdateStrKey(google_update::kRegLangField, language);
381 } 379 }
382 380
383 bool GoogleUpdateSettings::GetBrand(std::wstring* brand) { 381 bool GoogleUpdateSettings::GetBrand(base::string16* brand) {
384 return ReadGoogleUpdateStrKey(google_update::kRegRLZBrandField, brand); 382 return ReadGoogleUpdateStrKey(google_update::kRegRLZBrandField, brand);
385 } 383 }
386 384
387 bool GoogleUpdateSettings::GetReactivationBrand(std::wstring* brand) { 385 bool GoogleUpdateSettings::GetReactivationBrand(base::string16* brand) {
388 return ReadGoogleUpdateStrKey(google_update::kRegRLZReactivationBrandField, 386 return ReadGoogleUpdateStrKey(google_update::kRegRLZReactivationBrandField,
389 brand); 387 brand);
390 } 388 }
391 389
392 bool GoogleUpdateSettings::GetClient(std::wstring* client) { 390 bool GoogleUpdateSettings::GetClient(base::string16* client) {
393 return ReadGoogleUpdateStrKey(google_update::kRegClientField, client); 391 return ReadGoogleUpdateStrKey(google_update::kRegClientField, client);
394 } 392 }
395 393
396 bool GoogleUpdateSettings::SetClient(const std::wstring& client) { 394 bool GoogleUpdateSettings::SetClient(const base::string16& client) {
397 return WriteGoogleUpdateStrKey(google_update::kRegClientField, client); 395 return WriteGoogleUpdateStrKey(google_update::kRegClientField, client);
398 } 396 }
399 397
400 bool GoogleUpdateSettings::GetReferral(std::wstring* referral) { 398 bool GoogleUpdateSettings::GetReferral(base::string16* referral) {
401 return ReadGoogleUpdateStrKey(google_update::kRegReferralField, referral); 399 return ReadGoogleUpdateStrKey(google_update::kRegReferralField, referral);
402 } 400 }
403 401
404 bool GoogleUpdateSettings::ClearReferral() { 402 bool GoogleUpdateSettings::ClearReferral() {
405 return ClearGoogleUpdateStrKey(google_update::kRegReferralField); 403 return ClearGoogleUpdateStrKey(google_update::kRegReferralField);
406 } 404 }
407 405
408 bool GoogleUpdateSettings::UpdateDidRunStateForApp( 406 bool GoogleUpdateSettings::UpdateDidRunStateForApp(
409 const AppRegistrationData& app_reg_data, 407 const AppRegistrationData& app_reg_data,
410 bool did_run) { 408 bool did_run) {
(...skipping 21 matching lines...) Expand all
432 } 430 }
433 431
434 bool GoogleUpdateSettings::GetChromeChannelAndModifiers( 432 bool GoogleUpdateSettings::GetChromeChannelAndModifiers(
435 bool system_install, 433 bool system_install,
436 base::string16* channel) { 434 base::string16* channel) {
437 return GetChromeChannelInternal(system_install, true, channel); 435 return GetChromeChannelInternal(system_install, true, channel);
438 } 436 }
439 437
440 void GoogleUpdateSettings::UpdateInstallStatus(bool system_install, 438 void GoogleUpdateSettings::UpdateInstallStatus(bool system_install,
441 installer::ArchiveType archive_type, int install_return_code, 439 installer::ArchiveType archive_type, int install_return_code,
442 const std::wstring& product_guid) { 440 const base::string16& product_guid) {
443 DCHECK(archive_type != installer::UNKNOWN_ARCHIVE_TYPE || 441 DCHECK(archive_type != installer::UNKNOWN_ARCHIVE_TYPE ||
444 install_return_code != 0); 442 install_return_code != 0);
445 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 443 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
446 444
447 RegKey key; 445 RegKey key;
448 installer::ChannelInfo channel_info; 446 installer::ChannelInfo channel_info;
449 std::wstring reg_key(google_update::kRegPathClientState); 447 base::string16 reg_key(google_update::kRegPathClientState);
450 reg_key.append(L"\\"); 448 reg_key.append(L"\\");
451 reg_key.append(product_guid); 449 reg_key.append(product_guid);
452 LONG result = key.Open(reg_root, 450 LONG result = key.Open(reg_root,
453 reg_key.c_str(), 451 reg_key.c_str(),
454 KEY_QUERY_VALUE | KEY_SET_VALUE | KEY_WOW64_32KEY); 452 KEY_QUERY_VALUE | KEY_SET_VALUE | KEY_WOW64_32KEY);
455 if (result == ERROR_SUCCESS) 453 if (result == ERROR_SUCCESS)
456 channel_info.Initialize(key); 454 channel_info.Initialize(key);
457 else if (result != ERROR_FILE_NOT_FOUND) 455 else if (result != ERROR_FILE_NOT_FOUND)
458 LOG(ERROR) << "Failed to open " << reg_key << "; Error: " << result; 456 LOG(ERROR) << "Failed to open " << reg_key << "; Error: " << result;
459 457
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 L"sum()"); 528 L"sum()");
531 WriteGoogleUpdateStrKeyInternal(dist->GetAppRegistrationData(), 529 WriteGoogleUpdateStrKeyInternal(dist->GetAppRegistrationData(),
532 system_install, 530 system_install,
533 google_update::kRegProfilesSignedIn, 531 google_update::kRegProfilesSignedIn,
534 base::Int64ToString16(profiles_signedin), 532 base::Int64ToString16(profiles_signedin),
535 L"sum()"); 533 L"sum()");
536 } 534 }
537 535
538 int GoogleUpdateSettings::DuplicateGoogleUpdateSystemClientKey() { 536 int GoogleUpdateSettings::DuplicateGoogleUpdateSystemClientKey() {
539 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 537 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
540 std::wstring reg_path = dist->GetStateKey(); 538 base::string16 reg_path = dist->GetStateKey();
541 539
542 // Minimum access needed is to be able to write to this key. 540 // Minimum access needed is to be able to write to this key.
543 RegKey reg_key( 541 RegKey reg_key(
544 HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY); 542 HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY);
545 if (!reg_key.Valid()) 543 if (!reg_key.Valid())
546 return 0; 544 return 0;
547 545
548 HANDLE target_handle = 0; 546 HANDLE target_handle = 0;
549 if (!DuplicateHandle(GetCurrentProcess(), reg_key.Handle(), 547 if (!DuplicateHandle(GetCurrentProcess(), reg_key.Handle(),
550 GetCurrentProcess(), &target_handle, KEY_SET_VALUE, 548 GetCurrentProcess(), &target_handle, KEY_SET_VALUE,
551 TRUE, DUPLICATE_SAME_ACCESS)) { 549 TRUE, DUPLICATE_SAME_ACCESS)) {
552 return 0; 550 return 0;
553 } 551 }
554 return reinterpret_cast<int>(target_handle); 552 return reinterpret_cast<int>(target_handle);
555 } 553 }
556 554
557 bool GoogleUpdateSettings::WriteGoogleUpdateSystemClientKey( 555 bool GoogleUpdateSettings::WriteGoogleUpdateSystemClientKey(
558 int handle, const std::wstring& key, const std::wstring& value) { 556 int handle, const base::string16& key, const base::string16& value) {
559 HKEY reg_key = reinterpret_cast<HKEY>(reinterpret_cast<void*>(handle)); 557 HKEY reg_key = reinterpret_cast<HKEY>(reinterpret_cast<void*>(handle));
560 DWORD size = static_cast<DWORD>(value.size()) * sizeof(wchar_t); 558 DWORD size = static_cast<DWORD>(value.size()) * sizeof(wchar_t);
561 LSTATUS status = RegSetValueEx(reg_key, key.c_str(), 0, REG_SZ, 559 LSTATUS status = RegSetValueEx(reg_key, key.c_str(), 0, REG_SZ,
562 reinterpret_cast<const BYTE*>(value.c_str()), size); 560 reinterpret_cast<const BYTE*>(value.c_str()), size);
563 return status == ERROR_SUCCESS; 561 return status == ERROR_SUCCESS;
564 } 562 }
565 563
566 GoogleUpdateSettings::UpdatePolicy GoogleUpdateSettings::GetAppUpdatePolicy( 564 GoogleUpdateSettings::UpdatePolicy GoogleUpdateSettings::GetAppUpdatePolicy(
567 const std::wstring& app_guid, 565 const base::string16& app_guid,
568 bool* is_overridden) { 566 bool* is_overridden) {
569 bool found_override = false; 567 bool found_override = false;
570 UpdatePolicy update_policy = kDefaultUpdatePolicy; 568 UpdatePolicy update_policy = kDefaultUpdatePolicy;
571 569
572 #if defined(GOOGLE_CHROME_BUILD) 570 #if defined(GOOGLE_CHROME_BUILD)
573 DCHECK(!app_guid.empty()); 571 DCHECK(!app_guid.empty());
574 RegKey policy_key; 572 RegKey policy_key;
575 573
576 // Google Update Group Policy settings are always in HKLM. 574 // Google Update Group Policy settings are always in HKLM.
577 // TODO(wfh): Check if policies should go into Wow6432Node or not. 575 // TODO(wfh): Check if policies should go into Wow6432Node or not.
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 } 884 }
887 885
888 // If the key or value was not present, return the empty string. 886 // If the key or value was not present, return the empty string.
889 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { 887 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) {
890 experiment_labels->clear(); 888 experiment_labels->clear();
891 return true; 889 return true;
892 } 890 }
893 891
894 return result == ERROR_SUCCESS; 892 return result == ERROR_SUCCESS;
895 } 893 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698