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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 #else | 80 #else |
81 const wchar_t kChromiumInstallSubDir[] = L"Chromium"; | 81 const wchar_t kChromiumInstallSubDir[] = L"Chromium"; |
82 #endif // defined(GOOGLE_CHROME_BUILD) | 82 #endif // defined(GOOGLE_CHROME_BUILD) |
83 | 83 |
84 const wchar_t kUserDataDirname[] = L"User Data"; | 84 const wchar_t kUserDataDirname[] = L"User Data"; |
85 const wchar_t kBrowserCrashDumpMetricsSubKey[] = L"\\BrowserCrashDumpAttempts"; | 85 const wchar_t kBrowserCrashDumpMetricsSubKey[] = L"\\BrowserCrashDumpAttempts"; |
86 | 86 |
87 const wchar_t kRegPathGoogleUpdate[] = L"Software\\Google\\Update"; | 87 const wchar_t kRegPathGoogleUpdate[] = L"Software\\Google\\Update"; |
88 const wchar_t kRegGoogleUpdateVersion[] = L"version"; | 88 const wchar_t kRegGoogleUpdateVersion[] = L"version"; |
89 | 89 |
| 90 // Registry key to store the stats/crash sampling state of Chrome. If set to 1, |
| 91 // stats and crash reports will be uploaded in line with the user's consent, |
| 92 // otherwise, uploads will be disabled. It is used to sample clients, to reduce |
| 93 // server load for metics and crashes. This is controlled by the |
| 94 // MetricsReporting feature in chrome_metrics_services_manager_client.cc and is |
| 95 // written when metrics services are started up and when consent changes. |
| 96 const wchar_t kRegValueChromeStatsSample[] = L"UsageStatsInSample"; |
| 97 |
90 void Trace(const wchar_t* format_string, ...) { | 98 void Trace(const wchar_t* format_string, ...) { |
91 static const int kMaxLogBufferSize = 1024; | 99 static const int kMaxLogBufferSize = 1024; |
92 static wchar_t buffer[kMaxLogBufferSize] = {}; | 100 static wchar_t buffer[kMaxLogBufferSize] = {}; |
93 | 101 |
94 va_list args = {}; | 102 va_list args = {}; |
95 | 103 |
96 va_start(args, format_string); | 104 va_start(args, format_string); |
97 vswprintf(buffer, kMaxLogBufferSize, format_string, args); | 105 vswprintf(buffer, kMaxLogBufferSize, format_string, args); |
98 OutputDebugStringW(buffer); | 106 OutputDebugStringW(buffer); |
99 va_end(args); | 107 va_end(args); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 } else { | 235 } else { |
228 Trace(L"Failed to create directory %ls, last error is %d\n", | 236 Trace(L"Failed to create directory %ls, last error is %d\n", |
229 full_path_str, error_code); | 237 full_path_str, error_code); |
230 return false; | 238 return false; |
231 } | 239 } |
232 } | 240 } |
233 } | 241 } |
234 return true; | 242 return true; |
235 } | 243 } |
236 | 244 |
| 245 std::wstring GetChromeInstallRegistryPath() { |
| 246 std::wstring registry_path = L"Software\\"; |
| 247 registry_path += GetChromeInstallSubDirectory(); |
| 248 return registry_path; |
| 249 } |
| 250 |
237 bool GetCollectStatsConsentImpl(const std::wstring& exe_path) { | 251 bool GetCollectStatsConsentImpl(const std::wstring& exe_path) { |
238 bool enabled = true; | 252 bool enabled = true; |
239 bool controlled_by_policy = ReportingIsEnforcedByPolicy(&enabled); | 253 bool controlled_by_policy = ReportingIsEnforcedByPolicy(&enabled); |
240 | 254 |
241 if (controlled_by_policy && !enabled) | 255 if (controlled_by_policy && !enabled) |
242 return false; | 256 return false; |
243 | 257 |
244 bool system_install = IsSystemInstall(exe_path.c_str()); | 258 bool system_install = IsSystemInstall(exe_path.c_str()); |
245 std::wstring app_guid; | 259 std::wstring app_guid; |
246 | 260 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 } | 419 } |
406 | 420 |
407 bool GetCollectStatsConsent() { | 421 bool GetCollectStatsConsent() { |
408 return GetCollectStatsConsentImpl(GetCurrentProcessExePath()); | 422 return GetCollectStatsConsentImpl(GetCurrentProcessExePath()); |
409 } | 423 } |
410 | 424 |
411 bool GetCollectStatsConsentForTesting(const std::wstring& exe_path) { | 425 bool GetCollectStatsConsentForTesting(const std::wstring& exe_path) { |
412 return GetCollectStatsConsentImpl(exe_path); | 426 return GetCollectStatsConsentImpl(exe_path); |
413 } | 427 } |
414 | 428 |
| 429 bool GetCollectStatsInSample() { |
| 430 std::wstring registry_path = GetChromeInstallRegistryPath(); |
| 431 |
| 432 DWORD out_value = 0; |
| 433 if (!nt::QueryRegValueDWORD(nt::HKCU, registry_path.c_str(), |
| 434 kRegValueChromeStatsSample, &out_value)) { |
| 435 // If reading the value failed, treat it as though sampling isn't in effect, |
| 436 // implicitly meaning this install is in the sample. |
| 437 return true; |
| 438 } |
| 439 return out_value == 1; |
| 440 } |
| 441 |
| 442 bool SetCollectStatsInSample(bool in_sample) { |
| 443 std::wstring registry_path = GetChromeInstallRegistryPath(); |
| 444 |
| 445 HANDLE key_handle = INVALID_HANDLE_VALUE; |
| 446 if (!nt::CreateRegKey(nt::HKCU, registry_path.c_str(), KEY_SET_VALUE, |
| 447 &key_handle)) { |
| 448 nt::CloseRegKey(key_handle); |
| 449 return false; |
| 450 } |
| 451 |
| 452 return nt::SetRegValueDWORD(key_handle, kRegValueChromeStatsSample, |
| 453 in_sample ? 1 : 0); |
| 454 } |
| 455 |
415 bool ReportingIsEnforcedByPolicy(bool* metrics_is_enforced_by_policy) { | 456 bool ReportingIsEnforcedByPolicy(bool* metrics_is_enforced_by_policy) { |
416 DWORD value = 0; | 457 DWORD value = 0; |
417 | 458 |
418 // First, try HKLM. | 459 // First, try HKLM. |
419 if (nt::QueryRegValueDWORD(nt::HKLM, kRegPathChromePolicy, | 460 if (nt::QueryRegValueDWORD(nt::HKLM, kRegPathChromePolicy, |
420 kMetricsReportingEnabled, &value)) { | 461 kMetricsReportingEnabled, &value)) { |
421 *metrics_is_enforced_by_policy = (value != 0); | 462 *metrics_is_enforced_by_policy = (value != 0); |
422 return true; | 463 return true; |
423 } | 464 } |
424 | 465 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 result += kGoogleChromeInstallSubDir2; | 712 result += kGoogleChromeInstallSubDir2; |
672 if (IsSxSChrome(GetCurrentProcessExePath().c_str())) | 713 if (IsSxSChrome(GetCurrentProcessExePath().c_str())) |
673 result += kSxSSuffix; | 714 result += kSxSSuffix; |
674 return result; | 715 return result; |
675 #else | 716 #else |
676 return std::wstring(kChromiumInstallSubDir); | 717 return std::wstring(kChromiumInstallSubDir); |
677 #endif | 718 #endif |
678 } | 719 } |
679 | 720 |
680 std::wstring GetBrowserCrashDumpAttemptsRegistryPath() { | 721 std::wstring GetBrowserCrashDumpAttemptsRegistryPath() { |
681 std::wstring registry_path = L"Software\\"; | 722 std::wstring registry_path = GetChromeInstallRegistryPath(); |
682 registry_path += GetChromeInstallSubDirectory(); | |
683 registry_path += kBrowserCrashDumpMetricsSubKey; | 723 registry_path += kBrowserCrashDumpMetricsSubKey; |
684 return registry_path; | 724 return registry_path; |
685 } | 725 } |
686 | 726 |
687 bool MatchPattern(const std::wstring& source, const std::wstring& pattern) { | 727 bool MatchPattern(const std::wstring& source, const std::wstring& pattern) { |
688 assert(pattern.find(L"**") == std::wstring::npos); | 728 assert(pattern.find(L"**") == std::wstring::npos); |
689 return MatchPatternImpl(source, pattern, 0, 0); | 729 return MatchPatternImpl(source, pattern, 0, 0); |
690 } | 730 } |
691 | 731 |
692 std::string UTF16ToUTF8(const std::wstring& source) { | 732 std::string UTF16ToUTF8(const std::wstring& source) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 switch_value_end_offset = command_line_copy.length(); | 889 switch_value_end_offset = command_line_copy.length(); |
850 | 890 |
851 std::string switch_value = command_line_copy.substr( | 891 std::string switch_value = command_line_copy.substr( |
852 switch_value_start_offset, | 892 switch_value_start_offset, |
853 switch_value_end_offset - (switch_offset + switch_token.length())); | 893 switch_value_end_offset - (switch_offset + switch_token.length())); |
854 TrimT<std::string>(&switch_value); | 894 TrimT<std::string>(&switch_value); |
855 return switch_value; | 895 return switch_value; |
856 } | 896 } |
857 | 897 |
858 } // namespace install_static | 898 } // namespace install_static |
OLD | NEW |