| 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/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 10 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 12 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
| 12 #include "chrome/browser/metrics/chrome_metrics_service_client.h" | 13 #include "chrome/browser/metrics/chrome_metrics_service_client.h" |
| 13 #include "chrome/browser/metrics/variations/chrome_variations_service_client.h" | 14 #include "chrome/browser/metrics/variations/chrome_variations_service_client.h" |
| 14 #include "chrome/browser/metrics/variations/ui_string_overrider_factory.h" | 15 #include "chrome/browser/metrics/variations/ui_string_overrider_factory.h" |
| 15 #include "chrome/browser/ui/browser_otr_state.h" | 16 #include "chrome/browser/ui/browser_otr_state.h" |
| 16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/installer/util/google_update_settings.h" | 18 #include "chrome/installer/util/google_update_settings.h" |
| 18 #include "components/metrics/enabled_state_provider.h" | 19 #include "components/metrics/enabled_state_provider.h" |
| 19 #include "components/metrics/metrics_state_manager.h" | 20 #include "components/metrics/metrics_state_manager.h" |
| 20 #include "components/prefs/pref_service.h" | 21 #include "components/prefs/pref_service.h" |
| 21 #include "components/rappor/rappor_service.h" | 22 #include "components/rappor/rappor_service.h" |
| 22 #include "components/variations/service/variations_service.h" | 23 #include "components/variations/service/variations_service.h" |
| 23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // Posts |GoogleUpdateSettings::StoreMetricsClientInfo| on blocking pool thread | 28 // Posts |GoogleUpdateSettings::StoreMetricsClientInfo| on blocking pool thread |
| 28 // because it needs access to IO and cannot work from UI thread. | 29 // because it needs access to IO and cannot work from UI thread. |
| 29 void PostStoreMetricsClientInfo(const metrics::ClientInfo& client_info) { | 30 void PostStoreMetricsClientInfo(const metrics::ClientInfo& client_info) { |
| 30 content::BrowserThread::GetBlockingPool()->PostTask( | 31 content::BrowserThread::GetBlockingPool()->PostTask( |
| 31 FROM_HERE, | 32 FROM_HERE, |
| 32 base::Bind(&GoogleUpdateSettings::StoreMetricsClientInfo, client_info)); | 33 base::Bind(&GoogleUpdateSettings::StoreMetricsClientInfo, client_info)); |
| 33 } | 34 } |
| 34 | 35 |
| 35 } // namespace | 36 } // namespace |
| 36 | 37 |
| 38 const base::Feature kMetricsReportingFeature{"MetricsReporting", |
| 39 base::FEATURE_ENABLED_BY_DEFAULT}; |
| 40 |
| 37 class ChromeMetricsServicesManagerClient::ChromeEnabledStateProvider | 41 class ChromeMetricsServicesManagerClient::ChromeEnabledStateProvider |
| 38 : public metrics::EnabledStateProvider { | 42 : public metrics::EnabledStateProvider { |
| 39 public: | 43 public: |
| 40 ChromeEnabledStateProvider() {} | 44 ChromeEnabledStateProvider() {} |
| 41 ~ChromeEnabledStateProvider() override {} | 45 ~ChromeEnabledStateProvider() override {} |
| 42 | 46 |
| 43 bool IsConsentGiven() override { | 47 bool IsConsentGiven() override { |
| 44 return ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); | 48 return ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); |
| 45 } | 49 } |
| 46 | 50 |
| 51 bool IsReportingEnabled() override { |
| 52 return IsConsentGiven() && |
| 53 base::FeatureList::IsEnabled(kMetricsReportingFeature); |
| 54 } |
| 55 |
| 47 DISALLOW_COPY_AND_ASSIGN(ChromeEnabledStateProvider); | 56 DISALLOW_COPY_AND_ASSIGN(ChromeEnabledStateProvider); |
| 48 }; | 57 }; |
| 49 | 58 |
| 50 ChromeMetricsServicesManagerClient::ChromeMetricsServicesManagerClient( | 59 ChromeMetricsServicesManagerClient::ChromeMetricsServicesManagerClient( |
| 51 PrefService* local_state) | 60 PrefService* local_state) |
| 52 : enabled_state_provider_(new ChromeEnabledStateProvider()), | 61 : enabled_state_provider_(new ChromeEnabledStateProvider()), |
| 53 local_state_(local_state) { | 62 local_state_(local_state) { |
| 54 DCHECK(local_state); | 63 DCHECK(local_state); |
| 55 | 64 |
| 56 SetupMetricsStateForChromeOS(); | 65 SetupMetricsStateForChromeOS(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 ChromeMetricsServicesManagerClient::GetMetricsStateManager() { | 128 ChromeMetricsServicesManagerClient::GetMetricsStateManager() { |
| 120 DCHECK(thread_checker_.CalledOnValidThread()); | 129 DCHECK(thread_checker_.CalledOnValidThread()); |
| 121 if (!metrics_state_manager_) { | 130 if (!metrics_state_manager_) { |
| 122 metrics_state_manager_ = metrics::MetricsStateManager::Create( | 131 metrics_state_manager_ = metrics::MetricsStateManager::Create( |
| 123 local_state_, enabled_state_provider_.get(), | 132 local_state_, enabled_state_provider_.get(), |
| 124 base::Bind(&PostStoreMetricsClientInfo), | 133 base::Bind(&PostStoreMetricsClientInfo), |
| 125 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); | 134 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); |
| 126 } | 135 } |
| 127 return metrics_state_manager_.get(); | 136 return metrics_state_manager_.get(); |
| 128 } | 137 } |
| OLD | NEW |