OLD | NEW |
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/install_static/install_util.h" |
| 32 #include "chrome/installer/util/browser_distribution.h" |
| 33 #include "components/crash/content/app/crashpad.h" |
| 34 #endif // OS_WIN |
| 35 |
28 namespace { | 36 namespace { |
29 | 37 |
| 38 #if defined(OS_WIN) |
| 39 // Type for the function pointer to enable and disable crash reporting on |
| 40 // windows. Needed because the function is loaded from chrome_elf. |
| 41 typedef void (*SetUploadConsentPointer)(bool); |
| 42 |
| 43 // The name of the function used to set the uploads enabled state in |
| 44 // components/crash/content/app/crashpad.cc. This is used to call the function |
| 45 // exported by the chrome_elf dll. |
| 46 const char kCrashpadUpdateConsentFunctionName[] = "SetUploadConsentImpl"; |
| 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 Loading... |
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 install_static::SetCollectStatsInSample(IsClientInSample()); |
| 200 |
| 201 // Next, get Crashpad to pick up the sampling state for this session. |
| 202 |
| 203 // The crash reporting is handled by chrome_elf.dll. |
| 204 HMODULE elf_module = GetModuleHandle(chrome::kChromeElfDllName); |
| 205 static SetUploadConsentPointer set_upload_consent = |
| 206 reinterpret_cast<SetUploadConsentPointer>( |
| 207 GetProcAddress(elf_module, kCrashpadUpdateConsentFunctionName)); |
| 208 |
| 209 if (set_upload_consent) { |
| 210 // Crashpad will use the kRegUsageStatsInSample registry value to apply |
| 211 // sampling correctly, but may_record already reflects the sampling state. |
| 212 // This isn't a problem though, since they will be consistent. |
| 213 set_upload_consent(may_record && may_upload); |
| 214 } |
| 215 } |
| 216 #endif // defined(OS_WIN) |
| 217 |
174 metrics::MetricsStateManager* | 218 metrics::MetricsStateManager* |
175 ChromeMetricsServicesManagerClient::GetMetricsStateManager() { | 219 ChromeMetricsServicesManagerClient::GetMetricsStateManager() { |
176 DCHECK(thread_checker_.CalledOnValidThread()); | 220 DCHECK(thread_checker_.CalledOnValidThread()); |
177 if (!metrics_state_manager_) { | 221 if (!metrics_state_manager_) { |
178 metrics_state_manager_ = metrics::MetricsStateManager::Create( | 222 metrics_state_manager_ = metrics::MetricsStateManager::Create( |
179 local_state_, enabled_state_provider_.get(), | 223 local_state_, enabled_state_provider_.get(), |
180 base::Bind(&PostStoreMetricsClientInfo), | 224 base::Bind(&PostStoreMetricsClientInfo), |
181 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); | 225 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); |
182 } | 226 } |
183 return metrics_state_manager_.get(); | 227 return metrics_state_manager_.get(); |
184 } | 228 } |
OLD | NEW |