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

Side by Side Diff: chrome/browser/metrics/chrome_metrics_services_manager_client.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: rkaplow'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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/browser/metrics/chrome_metrics_services_manager_client.h" 5 #include "chrome/browser/metrics/chrome_metrics_services_manager_client.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/feature_list.h" 8 #include "base/feature_list.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" 13 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
14 #include "chrome/browser/metrics/chrome_metrics_service_client.h" 14 #include "chrome/browser/metrics/chrome_metrics_service_client.h"
15 #include "chrome/browser/metrics/variations/chrome_variations_service_client.h" 15 #include "chrome/browser/metrics/variations/chrome_variations_service_client.h"
16 #include "chrome/browser/metrics/variations/ui_string_overrider_factory.h" 16 #include "chrome/browser/metrics/variations/ui_string_overrider_factory.h"
17 #include "chrome/browser/ui/browser_otr_state.h" 17 #include "chrome/browser/ui/browser_otr_state.h"
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/installer/util/google_update_settings.h" 19 #include "chrome/installer/util/google_update_settings.h"
20 #include "components/metrics/enabled_state_provider.h" 20 #include "components/metrics/enabled_state_provider.h"
21 #include "components/metrics/metrics_state_manager.h" 21 #include "components/metrics/metrics_state_manager.h"
22 #include "components/prefs/pref_service.h" 22 #include "components/prefs/pref_service.h"
23 #include "components/rappor/rappor_service.h" 23 #include "components/rappor/rappor_service.h"
24 #include "components/variations/service/variations_service.h" 24 #include "components/variations/service/variations_service.h"
25 #include "components/variations/variations_associated_data.h" 25 #include "components/variations/variations_associated_data.h"
26 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
27 27
28 #if defined(OS_WIN)
29 #include "base/win/registry.h"
30 #include "chrome/common/chrome_constants.h"
31 #include "chrome/installer/util/browser_distribution.h"
32 #include "components/crash/content/app/crashpad.h"
33 #endif // OS_WIN
34
28 namespace { 35 namespace {
29 36
37 #if defined(OS_WIN)
38 // Type for the function pointer to enable and disable crash reporting on
39 // windows. Needed because the function is loaded from chrome_elf.
40 typedef void (*SetCrashUploadsEnabledPointer)(bool);
41
42 // Registry path for metrics registry values.
43 const wchar_t kChromeMetricsRegPath[] = L"\\MetricsReporting";
44
45 // Registry key for sampling state. This is used to communicate with crashpad.
Mark Mentovai 2016/08/11 18:32:24 Capital C here and on line 213 too.
scottmg 2016/08/11 21:38:03 and line 202
jwd 2016/08/11 21:41:03 Done.
jwd 2016/08/11 22:02:52 Done.
46 const wchar_t kRegUsageStatsInSample[] = L"UsageStatsInSample";
47
48 // The name of the function used to set the uploads enabled state in
49 // components/crash/content/app/crashpad.cc. This is used to call the function
50 // through the chrome_elf dll.
51 const char kCrashpadSetEnabledFunctionName[] = "SetUploadsEnabledImpl";
52 #endif // OS_WIN
53
30 // Name of the variations param that defines the sampling rate. 54 // Name of the variations param that defines the sampling rate.
31 const char kRateParamName[] = "sampling_rate_per_mille"; 55 const char kRateParamName[] = "sampling_rate_per_mille";
32 56
33 // Metrics reporting feature. This feature, along with user consent, controls if 57 // Metrics reporting feature. This feature, along with user consent, controls if
34 // recording and reporting are enabled. If the feature is enabled, but no 58 // recording and reporting are enabled. If the feature is enabled, but no
35 // consent is given, then there will be no recording or reporting. 59 // consent is given, then there will be no recording or reporting.
36 const base::Feature kMetricsReportingFeature{"MetricsReporting", 60 const base::Feature kMetricsReportingFeature{"MetricsReporting",
37 base::FEATURE_ENABLED_BY_DEFAULT}; 61 base::FEATURE_ENABLED_BY_DEFAULT};
38 62
39 // Posts |GoogleUpdateSettings::StoreMetricsClientInfo| on blocking pool thread 63 // Posts |GoogleUpdateSettings::StoreMetricsClientInfo| on blocking pool thread
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 bool ChromeMetricsServicesManagerClient::IsMetricsReportingEnabled() { 188 bool ChromeMetricsServicesManagerClient::IsMetricsReportingEnabled() {
165 return enabled_state_provider_->IsReportingEnabled(); 189 return enabled_state_provider_->IsReportingEnabled();
166 } 190 }
167 191
168 bool ChromeMetricsServicesManagerClient::OnlyDoMetricsRecording() { 192 bool ChromeMetricsServicesManagerClient::OnlyDoMetricsRecording() {
169 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); 193 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
170 return cmdline->HasSwitch(switches::kMetricsRecordingOnly) || 194 return cmdline->HasSwitch(switches::kMetricsRecordingOnly) ||
171 cmdline->HasSwitch(switches::kEnableBenchmarking); 195 cmdline->HasSwitch(switches::kEnableBenchmarking);
172 } 196 }
173 197
198 #if defined(OS_WIN)
199 void ChromeMetricsServicesManagerClient::UpdateRunningServices(
200 bool may_record,
201 bool may_upload) {
202 // First, set the registry value so that crashpad will have the sampling state
203 // now and for subsequent runs.
204 const base::string16 registry_path =
205 BrowserDistribution::GetDistribution()->GetRegistryPath() +
206 kChromeMetricsRegPath;
207
208 base::win::RegKey reg_key;
209 if (reg_key.Create(HKEY_CURRENT_USER, registry_path.c_str(), KEY_SET_VALUE) ==
210 ERROR_SUCCESS)
scottmg 2016/08/11 21:38:03 nit; {} around multiline if
jwd 2016/08/11 22:02:53 Done.
211 reg_key.WriteValue(kRegUsageStatsInSample, IsClientInSample() ? 1 : 0);
212
213 // Next, get crashpad to pickup the sampling state for this session.
scottmg 2016/08/11 21:38:03 pick up
jwd 2016/08/11 22:02:53 Done.
214 static SetCrashUploadsEnabledPointer set_crash_enabled = []() {
215 // The crash reporting is handled by chrome_elf.dll.
216 HMODULE elf_module = GetModuleHandle(chrome::kChromeElfDllName);
217 return reinterpret_cast<SetCrashUploadsEnabledPointer>(
218 GetProcAddress(elf_module, kCrashpadSetEnabledFunctionName));
219 }();
220
221 if (set_crash_enabled) {
222 // Crashpad will use the kRegUsageStatsInSample registry value to apply
223 // sampling correctly, but may_record already reflects the sampling state.
224 // This isn't a problem though, since they will be consistent.
scottmg 2016/08/11 21:38:03 It seems like instead of this comment, it'd be bet
jwd 2016/08/11 22:02:53 Not too sure exactly what you mean. The value pass
225 set_crash_enabled(may_record && may_upload);
226 }
227 }
228 #endif // defined(OS_WIN)
229
174 metrics::MetricsStateManager* 230 metrics::MetricsStateManager*
175 ChromeMetricsServicesManagerClient::GetMetricsStateManager() { 231 ChromeMetricsServicesManagerClient::GetMetricsStateManager() {
176 DCHECK(thread_checker_.CalledOnValidThread()); 232 DCHECK(thread_checker_.CalledOnValidThread());
177 if (!metrics_state_manager_) { 233 if (!metrics_state_manager_) {
178 metrics_state_manager_ = metrics::MetricsStateManager::Create( 234 metrics_state_manager_ = metrics::MetricsStateManager::Create(
179 local_state_, enabled_state_provider_.get(), 235 local_state_, enabled_state_provider_.get(),
180 base::Bind(&PostStoreMetricsClientInfo), 236 base::Bind(&PostStoreMetricsClientInfo),
181 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); 237 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo));
182 } 238 }
183 return metrics_state_manager_.get(); 239 return metrics_state_manager_.get();
184 } 240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698