| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/install_static/install_util.h" | 5 #include "chrome/install_static/install_util.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <assert.h> | 8 #include <assert.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <iostream> | 10 #include <iostream> |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 app_guid = IsMultiInstall(system_install) ? kAppGuidGoogleBinaries | 263 app_guid = IsMultiInstall(system_install) ? kAppGuidGoogleBinaries |
| 264 : kAppGuidGoogleChrome; | 264 : kAppGuidGoogleChrome; |
| 265 } | 265 } |
| 266 | 266 |
| 267 DWORD out_value = 0; | 267 DWORD out_value = 0; |
| 268 | 268 |
| 269 // If system_install, first try kRegPathClientStateMedium. | 269 // If system_install, first try kRegPathClientStateMedium. |
| 270 std::wstring full_key_path(kRegPathClientStateMedium); | 270 std::wstring full_key_path(kRegPathClientStateMedium); |
| 271 full_key_path.append(1, L'\\'); | 271 full_key_path.append(1, L'\\'); |
| 272 full_key_path.append(app_guid); | 272 full_key_path.append(app_guid); |
| 273 if (system_install && nt::QueryRegValueDWORD(nt::HKLM, full_key_path.c_str(), | 273 if (system_install && |
| 274 kRegValueUsageStats, &out_value)) | 274 nt::QueryRegValueDWORD(nt::HKLM, nt::WOW6432, full_key_path.c_str(), |
| 275 kRegValueUsageStats, &out_value)) |
| 275 return (out_value == 1); | 276 return (out_value == 1); |
| 276 | 277 |
| 277 // Second, try kRegPathClientState. | 278 // Second, try kRegPathClientState. |
| 278 full_key_path = kRegPathClientState; | 279 full_key_path = kRegPathClientState; |
| 279 full_key_path.append(1, L'\\'); | 280 full_key_path.append(1, L'\\'); |
| 280 full_key_path.append(app_guid); | 281 full_key_path.append(app_guid); |
| 281 return (nt::QueryRegValueDWORD((system_install ? nt::HKLM : nt::HKCU), | 282 return (nt::QueryRegValueDWORD((system_install ? nt::HKLM : nt::HKCU), |
| 282 full_key_path.c_str(), kRegValueUsageStats, | 283 nt::WOW6432, full_key_path.c_str(), |
| 283 &out_value) && | 284 kRegValueUsageStats, &out_value) && |
| 284 out_value == 1); | 285 out_value == 1); |
| 285 } | 286 } |
| 286 | 287 |
| 287 // Returns true if the |source| string matches the |pattern|. The pattern | 288 // Returns true if the |source| string matches the |pattern|. The pattern |
| 288 // may contain wildcards like '?' which matches one character or a '*' | 289 // may contain wildcards like '?' which matches one character or a '*' |
| 289 // which matches 0 or more characters. | 290 // which matches 0 or more characters. |
| 290 // Please note that pattern matches the whole string. If you want to find | 291 // Please note that pattern matches the whole string. If you want to find |
| 291 // something in the middle of the string then you need to specify the pattern | 292 // something in the middle of the string then you need to specify the pattern |
| 292 // as '*xyz*'. | 293 // as '*xyz*'. |
| 293 // |source_index| is the index of the current character being matched in | 294 // |source_index| is the index of the current character being matched in |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 return false; | 404 return false; |
| 404 } | 405 } |
| 405 | 406 |
| 406 bool IsMultiInstall(bool is_system_install) { | 407 bool IsMultiInstall(bool is_system_install) { |
| 407 std::wstring args; | 408 std::wstring args; |
| 408 | 409 |
| 409 std::wstring full_key_path(kRegPathClientState); | 410 std::wstring full_key_path(kRegPathClientState); |
| 410 full_key_path.append(1, L'\\'); | 411 full_key_path.append(1, L'\\'); |
| 411 full_key_path.append(kAppGuidGoogleChrome); | 412 full_key_path.append(kAppGuidGoogleChrome); |
| 412 if (!nt::QueryRegValueSZ((is_system_install ? nt::HKLM : nt::HKCU), | 413 if (!nt::QueryRegValueSZ((is_system_install ? nt::HKLM : nt::HKCU), |
| 413 full_key_path.c_str(), kUninstallArgumentsField, | 414 nt::WOW6432, full_key_path.c_str(), |
| 414 &args)) | 415 kUninstallArgumentsField, &args)) |
| 415 return false; | 416 return false; |
| 416 | 417 |
| 417 return (args.find(L"--multi-install") != std::wstring::npos); | 418 return (args.find(L"--multi-install") != std::wstring::npos); |
| 418 } | 419 } |
| 419 | 420 |
| 420 bool GetCollectStatsConsent() { | 421 bool GetCollectStatsConsent() { |
| 421 return GetCollectStatsConsentImpl(GetCurrentProcessExePath()); | 422 return GetCollectStatsConsentImpl(GetCurrentProcessExePath()); |
| 422 } | 423 } |
| 423 | 424 |
| 424 bool GetCollectStatsConsentForTesting(const std::wstring& exe_path) { | 425 bool GetCollectStatsConsentForTesting(const std::wstring& exe_path) { |
| 425 return GetCollectStatsConsentImpl(exe_path); | 426 return GetCollectStatsConsentImpl(exe_path); |
| 426 } | 427 } |
| 427 | 428 |
| 428 bool GetCollectStatsInSample() { | 429 bool GetCollectStatsInSample() { |
| 429 std::wstring registry_path = GetChromeInstallRegistryPath(); | 430 std::wstring registry_path = GetChromeInstallRegistryPath(); |
| 430 | 431 |
| 431 DWORD out_value = 0; | 432 DWORD out_value = 0; |
| 432 if (!nt::QueryRegValueDWORD(nt::HKCU, registry_path.c_str(), | 433 if (!nt::QueryRegValueDWORD(nt::HKCU, nt::WOW6432, registry_path.c_str(), |
| 433 kRegValueChromeStatsSample, &out_value)) { | 434 kRegValueChromeStatsSample, &out_value)) { |
| 434 // If reading the value failed, treat it as though sampling isn't in effect, | 435 // If reading the value failed, treat it as though sampling isn't in effect, |
| 435 // implicitly meaning this install is in the sample. | 436 // implicitly meaning this install is in the sample. |
| 436 return true; | 437 return true; |
| 437 } | 438 } |
| 438 return out_value == 1; | 439 return out_value == 1; |
| 439 } | 440 } |
| 440 | 441 |
| 441 bool SetCollectStatsInSample(bool in_sample) { | 442 bool SetCollectStatsInSample(bool in_sample) { |
| 442 std::wstring registry_path = GetChromeInstallRegistryPath(); | 443 std::wstring registry_path = GetChromeInstallRegistryPath(); |
| 443 | 444 |
| 444 HANDLE key_handle = INVALID_HANDLE_VALUE; | 445 HANDLE key_handle = INVALID_HANDLE_VALUE; |
| 445 if (!nt::CreateRegKey(nt::HKCU, registry_path.c_str(), KEY_SET_VALUE, | 446 if (!nt::CreateRegKey(nt::HKCU, registry_path.c_str(), |
| 446 &key_handle)) { | 447 KEY_SET_VALUE | KEY_WOW64_32KEY, &key_handle)) { |
| 447 nt::CloseRegKey(key_handle); | 448 nt::CloseRegKey(key_handle); |
| 448 return false; | 449 return false; |
| 449 } | 450 } |
| 450 | 451 |
| 451 return nt::SetRegValueDWORD(key_handle, kRegValueChromeStatsSample, | 452 return nt::SetRegValueDWORD(key_handle, kRegValueChromeStatsSample, |
| 452 in_sample ? 1 : 0); | 453 in_sample ? 1 : 0); |
| 453 } | 454 } |
| 454 | 455 |
| 455 bool ReportingIsEnforcedByPolicy(bool* crash_reporting_enabled) { | 456 bool ReportingIsEnforcedByPolicy(bool* crash_reporting_enabled) { |
| 456 DWORD value = 0; | 457 DWORD value = 0; |
| 457 | 458 |
| 458 // First, try HKLM. | 459 // First, try HKLM. |
| 459 if (nt::QueryRegValueDWORD(nt::HKLM, kRegPathChromePolicy, | 460 if (nt::QueryRegValueDWORD(nt::HKLM, nt::NONE, kRegPathChromePolicy, |
| 460 kMetricsReportingEnabled, &value)) { | 461 kMetricsReportingEnabled, &value)) { |
| 461 *crash_reporting_enabled = (value != 0); | 462 *crash_reporting_enabled = (value != 0); |
| 462 return true; | 463 return true; |
| 463 } | 464 } |
| 464 | 465 |
| 465 // Second, try HKCU. | 466 // Second, try HKCU. |
| 466 if (nt::QueryRegValueDWORD(nt::HKCU, kRegPathChromePolicy, | 467 if (nt::QueryRegValueDWORD(nt::HKCU, nt::NONE, kRegPathChromePolicy, |
| 467 kMetricsReportingEnabled, &value)) { | 468 kMetricsReportingEnabled, &value)) { |
| 468 *crash_reporting_enabled = (value != 0); | 469 *crash_reporting_enabled = (value != 0); |
| 469 return true; | 470 return true; |
| 470 } | 471 } |
| 471 | 472 |
| 472 return false; | 473 return false; |
| 473 } | 474 } |
| 474 | 475 |
| 475 void InitializeProcessType() { | 476 void InitializeProcessType() { |
| 476 assert(g_process_type == ProcessType::UNINITIALIZED); | 477 assert(g_process_type == ProcessType::UNINITIALIZED); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 // but that the "ap" value therein cannot be read due to some reason *other* | 637 // but that the "ap" value therein cannot be read due to some reason *other* |
| 637 // than it not being present. This should be exceedingly rare. For | 638 // than it not being present. This should be exceedingly rare. For |
| 638 // simplicity's sake, use an empty |value| in case of any error whatsoever | 639 // simplicity's sake, use an empty |value| in case of any error whatsoever |
| 639 // here. | 640 // here. |
| 640 std::wstring value; | 641 std::wstring value; |
| 641 bool is_multi_install = IsMultiInstall(!is_per_user_install); | 642 bool is_multi_install = IsMultiInstall(!is_per_user_install); |
| 642 if (is_multi_install) { | 643 if (is_multi_install) { |
| 643 std::wstring full_key_path(kRegPathClientState); | 644 std::wstring full_key_path(kRegPathClientState); |
| 644 full_key_path.append(1, L'\\'); | 645 full_key_path.append(1, L'\\'); |
| 645 full_key_path.append(kAppGuidGoogleBinaries); | 646 full_key_path.append(kAppGuidGoogleBinaries); |
| 646 nt::QueryRegValueSZ(is_per_user_install ? nt::HKCU : nt::HKLM, | 647 nt::QueryRegValueSZ(is_per_user_install ? nt::HKCU : nt::HKLM, nt::WOW6432, |
| 647 full_key_path.c_str(), kRegApField, &value); | 648 full_key_path.c_str(), kRegApField, &value); |
| 648 } else { | 649 } else { |
| 649 std::wstring full_key_path(kRegPathClientState); | 650 std::wstring full_key_path(kRegPathClientState); |
| 650 full_key_path.append(1, L'\\'); | 651 full_key_path.append(1, L'\\'); |
| 651 full_key_path.append(kAppGuidGoogleChrome); | 652 full_key_path.append(kAppGuidGoogleChrome); |
| 652 nt::QueryRegValueSZ(is_per_user_install ? nt::HKCU : nt::HKLM, | 653 nt::QueryRegValueSZ(is_per_user_install ? nt::HKCU : nt::HKLM, nt::WOW6432, |
| 653 full_key_path.c_str(), kRegApField, &value); | 654 full_key_path.c_str(), kRegApField, &value); |
| 654 } | 655 } |
| 655 | 656 |
| 656 static constexpr wchar_t kChromeChannelBetaPattern[] = L"1?1-*"; | 657 static constexpr wchar_t kChromeChannelBetaPattern[] = L"1?1-*"; |
| 657 static constexpr wchar_t kChromeChannelBetaX64Pattern[] = L"*x64-beta*"; | 658 static constexpr wchar_t kChromeChannelBetaX64Pattern[] = L"*x64-beta*"; |
| 658 static constexpr wchar_t kChromeChannelDevPattern[] = L"2?0-d*"; | 659 static constexpr wchar_t kChromeChannelDevPattern[] = L"2?0-d*"; |
| 659 static constexpr wchar_t kChromeChannelDevX64Pattern[] = L"*x64-dev*"; | 660 static constexpr wchar_t kChromeChannelDevX64Pattern[] = L"*x64-dev*"; |
| 660 | 661 |
| 661 std::transform(value.begin(), value.end(), value.begin(), ::tolower); | 662 std::transform(value.begin(), value.end(), value.begin(), ::tolower); |
| 662 | 663 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 688 channel_name->push_back(L'-'); | 689 channel_name->push_back(L'-'); |
| 689 channel_name->push_back(L'm'); | 690 channel_name->push_back(L'm'); |
| 690 } | 691 } |
| 691 } | 692 } |
| 692 | 693 |
| 693 std::string GetGoogleUpdateVersion() { | 694 std::string GetGoogleUpdateVersion() { |
| 694 // TODO(ananta) | 695 // TODO(ananta) |
| 695 // Consider whether Chromium should connect to Google update to manage | 696 // Consider whether Chromium should connect to Google update to manage |
| 696 // updates. Should this be returning an empty string for Chromium builds?. | 697 // updates. Should this be returning an empty string for Chromium builds?. |
| 697 std::wstring update_version; | 698 std::wstring update_version; |
| 698 if (nt::QueryRegValueSZ(nt::AUTO, kRegPathGoogleUpdate, | 699 if (nt::QueryRegValueSZ(nt::AUTO, nt::WOW6432, kRegPathGoogleUpdate, |
| 699 kRegGoogleUpdateVersion, &update_version)) | 700 kRegGoogleUpdateVersion, &update_version)) |
| 700 return UTF16ToUTF8(update_version); | 701 return UTF16ToUTF8(update_version); |
| 701 | 702 |
| 702 return std::string(); | 703 return std::string(); |
| 703 } | 704 } |
| 704 | 705 |
| 705 std::wstring GetChromeInstallSubDirectory() { | 706 std::wstring GetChromeInstallSubDirectory() { |
| 706 #if defined(GOOGLE_CHROME_BUILD) | 707 #if defined(GOOGLE_CHROME_BUILD) |
| 707 std::wstring result = kGoogleChromeInstallSubDir1; | 708 std::wstring result = kGoogleChromeInstallSubDir1; |
| 708 result += L"\\"; | 709 result += L"\\"; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 switch_value_end_offset = command_line_copy.length(); | 887 switch_value_end_offset = command_line_copy.length(); |
| 887 | 888 |
| 888 std::string switch_value = command_line_copy.substr( | 889 std::string switch_value = command_line_copy.substr( |
| 889 switch_value_start_offset, | 890 switch_value_start_offset, |
| 890 switch_value_end_offset - (switch_offset + switch_token.length())); | 891 switch_value_end_offset - (switch_offset + switch_token.length())); |
| 891 TrimT<std::string>(&switch_value); | 892 TrimT<std::string>(&switch_value); |
| 892 return switch_value; | 893 return switch_value; |
| 893 } | 894 } |
| 894 | 895 |
| 895 } // namespace install_static | 896 } // namespace install_static |
| OLD | NEW |