Chromium Code Reviews| Index: chrome/browser/metrics/chrome_metrics_services_manager_client.cc |
| diff --git a/chrome/browser/metrics/chrome_metrics_services_manager_client.cc b/chrome/browser/metrics/chrome_metrics_services_manager_client.cc |
| index c1224a28180afad63684aa45e5b12ca5efec652b..a34827be512953e0586527dd1fa6ca0488ec3021 100644 |
| --- a/chrome/browser/metrics/chrome_metrics_services_manager_client.cc |
| +++ b/chrome/browser/metrics/chrome_metrics_services_manager_client.cc |
| @@ -25,8 +25,27 @@ |
| #include "components/variations/variations_associated_data.h" |
| #include "content/public/browser/browser_thread.h" |
| +#if defined(OS_WIN) |
| +#include "base/win/registry.h" |
| +#include "chrome/common/chrome_constants.h" |
| +#include "chrome/install_static/install_util.h" |
| +#include "chrome/installer/util/browser_distribution.h" |
| +#include "components/crash/content/app/crashpad.h" |
| +#endif // OS_WIN |
| + |
| namespace { |
| +#if defined(OS_WIN) |
| +// Type for the function pointer to enable and disable crash reporting on |
| +// windows. Needed because the function is loaded from chrome_elf. |
| +typedef void (*SetCrashUploadConsentPointer)(bool); |
|
scottmg
2016/08/18 19:49:10
SetUploadConsentPointer
jwd
2016/08/18 21:07:34
Done.
|
| + |
| +// The name of the function used to set the uploads enabled state in |
| +// components/crash/content/app/crashpad.cc. This is used to call the function |
| +// exported by the chrome_elf dll. |
| +const char kCrashpadUpdateConsentFunctionName[] = "SetUploadConsentImpl"; |
| +#endif // OS_WIN |
| + |
| // Name of the variations param that defines the sampling rate. |
| const char kRateParamName[] = "sampling_rate_per_mille"; |
| @@ -171,6 +190,31 @@ bool ChromeMetricsServicesManagerClient::OnlyDoMetricsRecording() { |
| cmdline->HasSwitch(switches::kEnableBenchmarking); |
| } |
| +#if defined(OS_WIN) |
| +void ChromeMetricsServicesManagerClient::UpdateRunningServices( |
| + bool may_record, |
| + bool may_upload) { |
| + // First, set the registry value so that Crashpad will have the sampling state |
| + // now and for subsequent runs. |
| + install_static::SetCollectStatsInSample(IsClientInSample()); |
| + |
| + // Next, get Crashpad to pick up the sampling state for this session. |
| + |
| + // The crash reporting is handled by chrome_elf.dll. |
| + HMODULE elf_module = GetModuleHandle(chrome::kChromeElfDllName); |
| + static SetCrashUploadConsentPointer set_crash_enabled = |
|
scottmg
2016/08/18 19:49:10
set_upload_consent instead of set_crash_enabled.
jwd
2016/08/18 21:07:34
Done.
|
| + reinterpret_cast<SetCrashUploadConsentPointer>( |
| + GetProcAddress(elf_module, kCrashpadUpdateConsentFunctionName)); |
| + |
| + if (set_crash_enabled) { |
| + // Crashpad will use the kRegUsageStatsInSample registry value to apply |
| + // sampling correctly, but may_record already reflects the sampling state. |
| + // This isn't a problem though, since they will be consistent. |
| + set_crash_enabled(may_record && may_upload); |
| + } |
| +} |
| +#endif // defined(OS_WIN) |
| + |
| metrics::MetricsStateManager* |
| ChromeMetricsServicesManagerClient::GetMetricsStateManager() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |