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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 } | 243 } |
244 | 244 |
245 std::wstring GetChromeInstallRegistryPath() { | 245 std::wstring GetChromeInstallRegistryPath() { |
246 std::wstring registry_path = L"Software\\"; | 246 std::wstring registry_path = L"Software\\"; |
247 registry_path += GetChromeInstallSubDirectory(); | 247 registry_path += GetChromeInstallSubDirectory(); |
248 return registry_path; | 248 return registry_path; |
249 } | 249 } |
250 | 250 |
251 bool GetCollectStatsConsentImpl(const std::wstring& exe_path) { | 251 bool GetCollectStatsConsentImpl(const std::wstring& exe_path) { |
252 bool enabled = true; | 252 bool enabled = true; |
253 bool controlled_by_policy = ReportingIsEnforcedByPolicy(&enabled); | |
254 | 253 |
255 if (controlled_by_policy && !enabled) | 254 if (ReportingIsEnforcedByPolicy(&enabled)) |
256 return false; | 255 return enabled; |
257 | 256 |
258 bool system_install = IsSystemInstall(exe_path.c_str()); | 257 bool system_install = IsSystemInstall(exe_path.c_str()); |
259 std::wstring app_guid; | 258 std::wstring app_guid; |
260 | 259 |
261 if (IsSxSChrome(exe_path.c_str())) { | 260 if (IsSxSChrome(exe_path.c_str())) { |
262 app_guid = kAppGuidCanary; | 261 app_guid = kAppGuidCanary; |
263 } else { | 262 } else { |
264 app_guid = IsMultiInstall(system_install) ? kAppGuidGoogleBinaries | 263 app_guid = IsMultiInstall(system_install) ? kAppGuidGoogleBinaries |
265 : kAppGuidGoogleChrome; | 264 : kAppGuidGoogleChrome; |
266 } | 265 } |
267 | 266 |
268 DWORD out_value = 0; | 267 DWORD out_value = 0; |
269 | 268 |
270 // If system_install, first try kRegPathClientStateMedium. | 269 // If system_install, first try kRegPathClientStateMedium. |
271 std::wstring full_key_path(kRegPathClientStateMedium); | 270 std::wstring full_key_path(kRegPathClientStateMedium); |
272 full_key_path.append(1, L'\\'); | 271 full_key_path.append(1, L'\\'); |
273 full_key_path.append(app_guid); | 272 full_key_path.append(app_guid); |
274 if (system_install && nt::QueryRegValueDWORD(nt::HKLM, full_key_path.c_str(), | 273 if (system_install && |
275 kRegValueUsageStats, &out_value)) | 274 nt::QueryRegValueDWORD(nt::HKLM, nt::WOW6432, full_key_path.c_str(), |
| 275 kRegValueUsageStats, &out_value)) |
276 return (out_value == 1); | 276 return (out_value == 1); |
277 | 277 |
278 // Second, try kRegPathClientState. | 278 // Second, try kRegPathClientState. |
279 full_key_path = kRegPathClientState; | 279 full_key_path = kRegPathClientState; |
280 full_key_path.append(1, L'\\'); | 280 full_key_path.append(1, L'\\'); |
281 full_key_path.append(app_guid); | 281 full_key_path.append(app_guid); |
282 return (nt::QueryRegValueDWORD((system_install ? nt::HKLM : nt::HKCU), | 282 return (nt::QueryRegValueDWORD((system_install ? nt::HKLM : nt::HKCU), |
283 full_key_path.c_str(), kRegValueUsageStats, | 283 nt::WOW6432, full_key_path.c_str(), |
284 &out_value) && | 284 kRegValueUsageStats, &out_value) && |
285 out_value == 1); | 285 out_value == 1); |
286 } | 286 } |
287 | 287 |
288 // Returns true if the |source| string matches the |pattern|. The pattern | 288 // Returns true if the |source| string matches the |pattern|. The pattern |
289 // may contain wildcards like '?' which matches one character or a '*' | 289 // may contain wildcards like '?' which matches one character or a '*' |
290 // which matches 0 or more characters. | 290 // which matches 0 or more characters. |
291 // 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 |
292 // 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 |
293 // as '*xyz*'. | 293 // as '*xyz*'. |
294 // |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... |
404 return false; | 404 return false; |
405 } | 405 } |
406 | 406 |
407 bool IsMultiInstall(bool is_system_install) { | 407 bool IsMultiInstall(bool is_system_install) { |
408 std::wstring args; | 408 std::wstring args; |
409 | 409 |
410 std::wstring full_key_path(kRegPathClientState); | 410 std::wstring full_key_path(kRegPathClientState); |
411 full_key_path.append(1, L'\\'); | 411 full_key_path.append(1, L'\\'); |
412 full_key_path.append(kAppGuidGoogleChrome); | 412 full_key_path.append(kAppGuidGoogleChrome); |
413 if (!nt::QueryRegValueSZ((is_system_install ? nt::HKLM : nt::HKCU), | 413 if (!nt::QueryRegValueSZ((is_system_install ? nt::HKLM : nt::HKCU), |
414 full_key_path.c_str(), kUninstallArgumentsField, | 414 nt::WOW6432, full_key_path.c_str(), |
415 &args)) | 415 kUninstallArgumentsField, &args)) |
416 return false; | 416 return false; |
417 | 417 |
418 return (args.find(L"--multi-install") != std::wstring::npos); | 418 return (args.find(L"--multi-install") != std::wstring::npos); |
419 } | 419 } |
420 | 420 |
421 bool GetCollectStatsConsent() { | 421 bool GetCollectStatsConsent() { |
422 return GetCollectStatsConsentImpl(GetCurrentProcessExePath()); | 422 return GetCollectStatsConsentImpl(GetCurrentProcessExePath()); |
423 } | 423 } |
424 | 424 |
425 bool GetCollectStatsConsentForTesting(const std::wstring& exe_path) { | 425 bool GetCollectStatsConsentForTesting(const std::wstring& exe_path) { |
426 return GetCollectStatsConsentImpl(exe_path); | 426 return GetCollectStatsConsentImpl(exe_path); |
427 } | 427 } |
428 | 428 |
429 bool GetCollectStatsInSample() { | 429 bool GetCollectStatsInSample() { |
430 std::wstring registry_path = GetChromeInstallRegistryPath(); | 430 std::wstring registry_path = GetChromeInstallRegistryPath(); |
431 | 431 |
432 DWORD out_value = 0; | 432 DWORD out_value = 0; |
433 if (!nt::QueryRegValueDWORD(nt::HKCU, registry_path.c_str(), | 433 if (!nt::QueryRegValueDWORD(nt::HKCU, nt::WOW6432, registry_path.c_str(), |
434 kRegValueChromeStatsSample, &out_value)) { | 434 kRegValueChromeStatsSample, &out_value)) { |
435 // 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, |
436 // implicitly meaning this install is in the sample. | 436 // implicitly meaning this install is in the sample. |
437 return true; | 437 return true; |
438 } | 438 } |
439 return out_value == 1; | 439 return out_value == 1; |
440 } | 440 } |
441 | 441 |
442 bool SetCollectStatsInSample(bool in_sample) { | 442 bool SetCollectStatsInSample(bool in_sample) { |
443 std::wstring registry_path = GetChromeInstallRegistryPath(); | 443 std::wstring registry_path = GetChromeInstallRegistryPath(); |
444 | 444 |
445 HANDLE key_handle = INVALID_HANDLE_VALUE; | 445 HANDLE key_handle = INVALID_HANDLE_VALUE; |
446 if (!nt::CreateRegKey(nt::HKCU, registry_path.c_str(), KEY_SET_VALUE, | 446 if (!nt::CreateRegKey(nt::HKCU, registry_path.c_str(), |
447 &key_handle)) { | 447 KEY_SET_VALUE | KEY_WOW64_32KEY, &key_handle)) { |
448 nt::CloseRegKey(key_handle); | 448 nt::CloseRegKey(key_handle); |
449 return false; | 449 return false; |
450 } | 450 } |
451 | 451 |
452 return nt::SetRegValueDWORD(key_handle, kRegValueChromeStatsSample, | 452 return nt::SetRegValueDWORD(key_handle, kRegValueChromeStatsSample, |
453 in_sample ? 1 : 0); | 453 in_sample ? 1 : 0); |
454 } | 454 } |
455 | 455 |
456 bool ReportingIsEnforcedByPolicy(bool* metrics_is_enforced_by_policy) { | 456 bool ReportingIsEnforcedByPolicy(bool* metrics_is_enforced_by_policy) { |
457 DWORD value = 0; | 457 DWORD value = 0; |
458 | 458 |
459 // First, try HKLM. | 459 // First, try HKLM. |
460 if (nt::QueryRegValueDWORD(nt::HKLM, kRegPathChromePolicy, | 460 if (nt::QueryRegValueDWORD(nt::HKLM, nt::NONE, kRegPathChromePolicy, |
461 kMetricsReportingEnabled, &value)) { | 461 kMetricsReportingEnabled, &value)) { |
462 *metrics_is_enforced_by_policy = (value != 0); | 462 *metrics_is_enforced_by_policy = (value != 0); |
463 return true; | 463 return true; |
464 } | 464 } |
465 | 465 |
466 // Second, try HKCU. | 466 // Second, try HKCU. |
467 if (nt::QueryRegValueDWORD(nt::HKCU, kRegPathChromePolicy, | 467 if (nt::QueryRegValueDWORD(nt::HKCU, nt::NONE, kRegPathChromePolicy, |
468 kMetricsReportingEnabled, &value)) { | 468 kMetricsReportingEnabled, &value)) { |
469 *metrics_is_enforced_by_policy = (value != 0); | 469 *metrics_is_enforced_by_policy = (value != 0); |
470 return true; | 470 return true; |
471 } | 471 } |
472 | 472 |
473 return false; | 473 return false; |
474 } | 474 } |
475 | 475 |
476 void InitializeProcessType() { | 476 void InitializeProcessType() { |
477 assert(g_process_type == ProcessType::UNINITIALIZED); | 477 assert(g_process_type == ProcessType::UNINITIALIZED); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 if (IsSxSChrome(GetCurrentProcessExePath().c_str())) { | 633 if (IsSxSChrome(GetCurrentProcessExePath().c_str())) { |
634 *channel_name = L"canary"; | 634 *channel_name = L"canary"; |
635 } else { | 635 } else { |
636 std::wstring value; | 636 std::wstring value; |
637 bool channel_available = false; | 637 bool channel_available = false; |
638 bool is_multi_install = IsMultiInstall(!is_per_user_install); | 638 bool is_multi_install = IsMultiInstall(!is_per_user_install); |
639 if (is_multi_install) { | 639 if (is_multi_install) { |
640 std::wstring full_key_path(kRegPathClientState); | 640 std::wstring full_key_path(kRegPathClientState); |
641 full_key_path.append(1, L'\\'); | 641 full_key_path.append(1, L'\\'); |
642 full_key_path.append(kAppGuidGoogleBinaries); | 642 full_key_path.append(kAppGuidGoogleBinaries); |
643 channel_available = | 643 channel_available = nt::QueryRegValueSZ( |
644 nt::QueryRegValueSZ(is_per_user_install ? nt::HKCU : nt::HKLM, | 644 is_per_user_install ? nt::HKCU : nt::HKLM, nt::WOW6432, |
645 full_key_path.c_str(), kRegApField, &value); | 645 full_key_path.c_str(), kRegApField, &value); |
646 } else { | 646 } else { |
647 std::wstring full_key_path(kRegPathClientState); | 647 std::wstring full_key_path(kRegPathClientState); |
648 full_key_path.append(1, L'\\'); | 648 full_key_path.append(1, L'\\'); |
649 full_key_path.append(kAppGuidGoogleChrome); | 649 full_key_path.append(kAppGuidGoogleChrome); |
650 channel_available = | 650 channel_available = nt::QueryRegValueSZ( |
651 nt::QueryRegValueSZ(is_per_user_install ? nt::HKCU : nt::HKLM, | 651 is_per_user_install ? nt::HKCU : nt::HKLM, nt::WOW6432, |
652 full_key_path.c_str(), kRegApField, &value); | 652 full_key_path.c_str(), kRegApField, &value); |
653 } | 653 } |
654 if (channel_available) { | 654 if (channel_available) { |
655 static const wchar_t kChromeChannelBetaPattern[] = L"1?1-*"; | 655 static const wchar_t kChromeChannelBetaPattern[] = L"1?1-*"; |
656 static const wchar_t kChromeChannelBetaX64Pattern[] = L"*x64-beta*"; | 656 static const wchar_t kChromeChannelBetaX64Pattern[] = L"*x64-beta*"; |
657 static const wchar_t kChromeChannelDevPattern[] = L"2?0-d*"; | 657 static const wchar_t kChromeChannelDevPattern[] = L"2?0-d*"; |
658 static const wchar_t kChromeChannelDevX64Pattern[] = L"*x64-dev*"; | 658 static const wchar_t kChromeChannelDevX64Pattern[] = L"*x64-dev*"; |
659 | 659 |
660 std::transform(value.begin(), value.end(), value.begin(), ::tolower); | 660 std::transform(value.begin(), value.end(), value.begin(), ::tolower); |
661 | 661 |
662 // Empty channel names or those containing "stable" should be reported as | 662 // Empty channel names or those containing "stable" should be reported as |
(...skipping 28 matching lines...) Expand all Loading... |
691 *channel_name = kChromeChannelUnknown; | 691 *channel_name = kChromeChannelUnknown; |
692 } | 692 } |
693 } | 693 } |
694 } | 694 } |
695 | 695 |
696 std::string GetGoogleUpdateVersion() { | 696 std::string GetGoogleUpdateVersion() { |
697 // TODO(ananta) | 697 // TODO(ananta) |
698 // Consider whether Chromium should connect to Google update to manage | 698 // Consider whether Chromium should connect to Google update to manage |
699 // updates. Should this be returning an empty string for Chromium builds?. | 699 // updates. Should this be returning an empty string for Chromium builds?. |
700 std::wstring update_version; | 700 std::wstring update_version; |
701 if (nt::QueryRegValueSZ(nt::AUTO, kRegPathGoogleUpdate, | 701 if (nt::QueryRegValueSZ(nt::AUTO, nt::WOW6432, kRegPathGoogleUpdate, |
702 kRegGoogleUpdateVersion, &update_version)) | 702 kRegGoogleUpdateVersion, &update_version)) |
703 return UTF16ToUTF8(update_version); | 703 return UTF16ToUTF8(update_version); |
704 | 704 |
705 return std::string(); | 705 return std::string(); |
706 } | 706 } |
707 | 707 |
708 std::wstring GetChromeInstallSubDirectory() { | 708 std::wstring GetChromeInstallSubDirectory() { |
709 #if defined(GOOGLE_CHROME_BUILD) | 709 #if defined(GOOGLE_CHROME_BUILD) |
710 std::wstring result = kGoogleChromeInstallSubDir1; | 710 std::wstring result = kGoogleChromeInstallSubDir1; |
711 result += L"\\"; | 711 result += L"\\"; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 switch_value_end_offset = command_line_copy.length(); | 889 switch_value_end_offset = command_line_copy.length(); |
890 | 890 |
891 std::string switch_value = command_line_copy.substr( | 891 std::string switch_value = command_line_copy.substr( |
892 switch_value_start_offset, | 892 switch_value_start_offset, |
893 switch_value_end_offset - (switch_offset + switch_token.length())); | 893 switch_value_end_offset - (switch_offset + switch_token.length())); |
894 TrimT<std::string>(&switch_value); | 894 TrimT<std::string>(&switch_value); |
895 return switch_value; | 895 return switch_value; |
896 } | 896 } |
897 | 897 |
898 } // namespace install_static | 898 } // namespace install_static |
OLD | NEW |