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

Side by Side Diff: chrome/install_static/install_util.cc

Issue 2221833005: Adding support for sampling crashes in Chrome on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scottmg's comments Created 4 years, 4 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
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 const wchar_t kRegValueUsageStats[] = L"usagestats"; 48 const wchar_t kRegValueUsageStats[] = L"usagestats";
49 const wchar_t kUninstallArgumentsField[] = L"UninstallArguments"; 49 const wchar_t kUninstallArgumentsField[] = L"UninstallArguments";
50 const wchar_t kMetricsReportingEnabled[] = L"MetricsReportingEnabled"; 50 const wchar_t kMetricsReportingEnabled[] = L"MetricsReportingEnabled";
51 51
52 const wchar_t kAppGuidCanary[] = L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}"; 52 const wchar_t kAppGuidCanary[] = L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}";
53 const wchar_t kAppGuidGoogleChrome[] = 53 const wchar_t kAppGuidGoogleChrome[] =
54 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; 54 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
55 const wchar_t kAppGuidGoogleBinaries[] = 55 const wchar_t kAppGuidGoogleBinaries[] =
56 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; 56 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
57 57
58 const wchar_t kChromeStatsSampleKey[] = L"UsageStatsInSample";
Alexei Svitkine (slow) 2016/08/12 17:47:48 How about using a similar variable naming conventi
jwd 2016/08/12 20:04:30 Done.
59
58 const wchar_t kHeadless[] = L"CHROME_HEADLESS"; 60 const wchar_t kHeadless[] = L"CHROME_HEADLESS";
59 const wchar_t kShowRestart[] = L"CHROME_CRASHED"; 61 const wchar_t kShowRestart[] = L"CHROME_CRASHED";
60 const wchar_t kRestartInfo[] = L"CHROME_RESTART"; 62 const wchar_t kRestartInfo[] = L"CHROME_RESTART";
61 const wchar_t kRtlLocale[] = L"RIGHT_TO_LEFT"; 63 const wchar_t kRtlLocale[] = L"RIGHT_TO_LEFT";
62 64
63 const char kGpuProcess[] = "gpu-process"; 65 const char kGpuProcess[] = "gpu-process";
64 const char kPpapiPluginProcess[] = "ppapi"; 66 const char kPpapiPluginProcess[] = "ppapi";
65 const char kRendererProcess[] = "renderer"; 67 const char kRendererProcess[] = "renderer";
66 const char kUtilityProcess[] = "utility"; 68 const char kUtilityProcess[] = "utility";
67 const char kProcessType[] = "type"; 69 const char kProcessType[] = "type";
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } else { 229 } else {
228 Trace(L"Failed to create directory %ls, last error is %d\n", 230 Trace(L"Failed to create directory %ls, last error is %d\n",
229 full_path_str, error_code); 231 full_path_str, error_code);
230 return false; 232 return false;
231 } 233 }
232 } 234 }
233 } 235 }
234 return true; 236 return true;
235 } 237 }
236 238
239 std::wstring GetChromeInstallRegistryPath() {
240 std::wstring registry_path = L"Software\\";
241 registry_path += GetChromeInstallSubDirectory();
242 return registry_path;
243 }
244
237 bool GetCollectStatsConsentImpl(const std::wstring& exe_path) { 245 bool GetCollectStatsConsentImpl(const std::wstring& exe_path) {
238 bool enabled = true; 246 bool enabled = true;
239 bool controlled_by_policy = ReportingIsEnforcedByPolicy(&enabled); 247 bool controlled_by_policy = ReportingIsEnforcedByPolicy(&enabled);
240 248
241 if (controlled_by_policy && !enabled) 249 if (controlled_by_policy && !enabled)
242 return false; 250 return false;
243 251
244 bool system_install = IsSystemInstall(exe_path.c_str()); 252 bool system_install = IsSystemInstall(exe_path.c_str());
245 std::wstring app_guid; 253 std::wstring app_guid;
246 254
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 } 413 }
406 414
407 bool GetCollectStatsConsent() { 415 bool GetCollectStatsConsent() {
408 return GetCollectStatsConsentImpl(GetCurrentProcessExePath()); 416 return GetCollectStatsConsentImpl(GetCurrentProcessExePath());
409 } 417 }
410 418
411 bool GetCollectStatsConsentForTesting(const std::wstring& exe_path) { 419 bool GetCollectStatsConsentForTesting(const std::wstring& exe_path) {
412 return GetCollectStatsConsentImpl(exe_path); 420 return GetCollectStatsConsentImpl(exe_path);
413 } 421 }
414 422
423 bool GetCollectStatsInSample() {
424 std::wstring registry_path = GetChromeInstallRegistryPath();
425
426 DWORD out_value = 0;
427 if (!nt::QueryRegValueDWORD(nt::HKCU, registry_path.c_str(),
428 kChromeStatsSampleKey, &out_value)) {
429 // If reading the value failed, treat it as though sampling isn't in effect,
430 // implicitly meaning this install in in-sample.
Alexei Svitkine (slow) 2016/08/12 17:47:48 Nit: "this install in sample" -> "this install is
jwd 2016/08/12 20:04:30 Done.
431 return true;
432 }
433 return out_value == 1;
434 }
435
436 bool SetCollectStatsInSample(bool in_sample) {
437 std::wstring registry_path = GetChromeInstallRegistryPath();
438
439 HANDLE key_handle = INVALID_HANDLE_VALUE;
440 if (!nt::CreateRegKey(nt::HKCU, registry_path.c_str(), KEY_SET_VALUE,
441 &key_handle)) {
442 nt::CloseRegKey(key_handle);
443 return false;
444 }
445
446 return nt::SetRegValueDWORD(key_handle, kChromeStatsSampleKey,
447 in_sample ? 1 : 0);
448 }
449
415 bool ReportingIsEnforcedByPolicy(bool* metrics_is_enforced_by_policy) { 450 bool ReportingIsEnforcedByPolicy(bool* metrics_is_enforced_by_policy) {
416 DWORD value = 0; 451 DWORD value = 0;
417 452
418 // First, try HKLM. 453 // First, try HKLM.
419 if (nt::QueryRegValueDWORD(nt::HKLM, kRegPathChromePolicy, 454 if (nt::QueryRegValueDWORD(nt::HKLM, kRegPathChromePolicy,
420 kMetricsReportingEnabled, &value)) { 455 kMetricsReportingEnabled, &value)) {
421 *metrics_is_enforced_by_policy = (value != 0); 456 *metrics_is_enforced_by_policy = (value != 0);
422 return true; 457 return true;
423 } 458 }
424 459
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 result += kGoogleChromeInstallSubDir2; 706 result += kGoogleChromeInstallSubDir2;
672 if (IsSxSChrome(GetCurrentProcessExePath().c_str())) 707 if (IsSxSChrome(GetCurrentProcessExePath().c_str()))
673 result += kSxSSuffix; 708 result += kSxSSuffix;
674 return result; 709 return result;
675 #else 710 #else
676 return std::wstring(kChromiumInstallSubDir); 711 return std::wstring(kChromiumInstallSubDir);
677 #endif 712 #endif
678 } 713 }
679 714
680 std::wstring GetBrowserCrashDumpAttemptsRegistryPath() { 715 std::wstring GetBrowserCrashDumpAttemptsRegistryPath() {
681 std::wstring registry_path = L"Software\\"; 716 std::wstring registry_path = GetChromeInstallRegistryPath();
682 registry_path += GetChromeInstallSubDirectory();
683 registry_path += kBrowserCrashDumpMetricsSubKey; 717 registry_path += kBrowserCrashDumpMetricsSubKey;
684 return registry_path; 718 return registry_path;
685 } 719 }
686 720
687 bool MatchPattern(const std::wstring& source, const std::wstring& pattern) { 721 bool MatchPattern(const std::wstring& source, const std::wstring& pattern) {
688 assert(pattern.find(L"**") == std::wstring::npos); 722 assert(pattern.find(L"**") == std::wstring::npos);
689 return MatchPatternImpl(source, pattern, 0, 0); 723 return MatchPatternImpl(source, pattern, 0, 0);
690 } 724 }
691 725
692 std::string UTF16ToUTF8(const std::wstring& source) { 726 std::string UTF16ToUTF8(const std::wstring& source) {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 switch_value_end_offset = command_line_copy.length(); 883 switch_value_end_offset = command_line_copy.length();
850 884
851 std::string switch_value = command_line_copy.substr( 885 std::string switch_value = command_line_copy.substr(
852 switch_value_start_offset, 886 switch_value_start_offset,
853 switch_value_end_offset - (switch_offset + switch_token.length())); 887 switch_value_end_offset - (switch_offset + switch_token.length()));
854 TrimT<std::string>(&switch_value); 888 TrimT<std::string>(&switch_value);
855 return switch_value; 889 return switch_value;
856 } 890 }
857 891
858 } // namespace install_static 892 } // namespace install_static
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698