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