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

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: Adding support for sampling crashes in Chrome on Windows. 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 uesd to communicate with crashpad.
rkaplow 2016/08/10 20:16:28 used
jwd 2016/08/10 22:10:02 Done.
46 const wchar_t kRegUsageStatsInSample[] = L"usagestatsinsample";
rkaplow 2016/08/10 20:16:28 is lowercasestyle the right style for keys? Poking
jwd 2016/08/10 22:10:02 hm, I was using the usagestats key as example. Don
47 #endif // OS_WIN
48
30 // Name of the variations param that defines the sampling rate. 49 // Name of the variations param that defines the sampling rate.
31 const char kRateParamName[] = "sampling_rate_per_mille"; 50 const char kRateParamName[] = "sampling_rate_per_mille";
32 51
33 // Metrics reporting feature. This feature, along with user consent, controls if 52 // Metrics reporting feature. This feature, along with user consent, controls if
34 // recording and reporting are enabled. If the feature is enabled, but no 53 // recording and reporting are enabled. If the feature is enabled, but no
35 // consent is given, then there will be no recording or reporting. 54 // consent is given, then there will be no recording or reporting.
36 const base::Feature kMetricsReportingFeature{"MetricsReporting", 55 const base::Feature kMetricsReportingFeature{"MetricsReporting",
37 base::FEATURE_ENABLED_BY_DEFAULT}; 56 base::FEATURE_ENABLED_BY_DEFAULT};
38 57
39 // Posts |GoogleUpdateSettings::StoreMetricsClientInfo| on blocking pool thread 58 // Posts |GoogleUpdateSettings::StoreMetricsClientInfo| on blocking pool thread
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 bool ChromeMetricsServicesManagerClient::IsMetricsReportingEnabled() { 183 bool ChromeMetricsServicesManagerClient::IsMetricsReportingEnabled() {
165 return enabled_state_provider_->IsReportingEnabled(); 184 return enabled_state_provider_->IsReportingEnabled();
166 } 185 }
167 186
168 bool ChromeMetricsServicesManagerClient::OnlyDoMetricsRecording() { 187 bool ChromeMetricsServicesManagerClient::OnlyDoMetricsRecording() {
169 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); 188 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
170 return cmdline->HasSwitch(switches::kMetricsRecordingOnly) || 189 return cmdline->HasSwitch(switches::kMetricsRecordingOnly) ||
171 cmdline->HasSwitch(switches::kEnableBenchmarking); 190 cmdline->HasSwitch(switches::kEnableBenchmarking);
172 } 191 }
173 192
193 #if defined(OS_WIN)
194 void ChromeMetricsServicesManagerClient::UpdateRunningServices(
195 bool may_record,
196 bool may_upload) {
197 // First, set the registry value so that crashpad will have the sampling state
198 // now and for subsequent runs.
199 const base::string16 registry_path =
200 BrowserDistribution::GetDistribution()->GetRegistryPath() +
201 kChromeMetricsRegPath;
202
203 base::win::RegKey reg_key(HKEY_CURRENT_USER, registry_path.c_str(),
rkaplow 2016/08/10 20:16:28 it looks like we can check for creation success of
jwd 2016/08/10 22:10:02 Done.
204 KEY_SET_VALUE);
205
206 reg_key.WriteValue(kRegUsageStatsInSample, IsClientInSample() ? 1 : 0);
Alexei Svitkine (slow) 2016/08/10 21:49:33 Can the registry code be a helper function in inst
jwd 2016/08/11 21:41:02 Done.
207
208 // Next, get crashpad to pickup the sampling state for this run.
rkaplow 2016/08/10 20:16:28 what do you mean here 'this run'? Do you mean sess
jwd 2016/08/10 22:10:02 yes, went with 'this run' as in the same vein as "
209 static SetCrashUploadsEnabledPointer set_crash_enabled = []() {
210 // The crash reporting is handled by chrome_elf.dll.
211 HMODULE elf_module = GetModuleHandle(chrome::kChromeElfDllName);
212 return reinterpret_cast<SetCrashUploadsEnabledPointer>(
213 GetProcAddress(elf_module, "SetUploadsEnabledImpl"));
rkaplow 2016/08/10 20:16:28 should we define this as a const and make a note h
jwd 2016/08/10 22:10:02 Sure, why not.
214 }();
215
216 if (set_crash_enabled) {
217 // Crashpad will use the kRegUsageStatsInSample registry value to apply
218 // sampling correctly, but may_record already reflects the sampling state.
219 // This isn't a problem though, since they will be consistent.
rkaplow 2016/08/10 20:16:28 hm... not fully following the point of the comment
jwd 2016/08/10 22:10:02 set_crash_enabled needs a bool argument to be able
220 set_crash_enabled(may_record && may_upload);
221 }
222 }
223 #endif // defined(OS_WIN)
224
174 metrics::MetricsStateManager* 225 metrics::MetricsStateManager*
175 ChromeMetricsServicesManagerClient::GetMetricsStateManager() { 226 ChromeMetricsServicesManagerClient::GetMetricsStateManager() {
176 DCHECK(thread_checker_.CalledOnValidThread()); 227 DCHECK(thread_checker_.CalledOnValidThread());
177 if (!metrics_state_manager_) { 228 if (!metrics_state_manager_) {
178 metrics_state_manager_ = metrics::MetricsStateManager::Create( 229 metrics_state_manager_ = metrics::MetricsStateManager::Create(
179 local_state_, enabled_state_provider_.get(), 230 local_state_, enabled_state_provider_.get(),
180 base::Bind(&PostStoreMetricsClientInfo), 231 base::Bind(&PostStoreMetricsClientInfo),
181 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); 232 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo));
182 } 233 }
183 return metrics_state_manager_.get(); 234 return metrics_state_manager_.get();
184 } 235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698