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/logging.h" | 8 #include "base/logging.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 11 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
12 #include "chrome/browser/metrics/chrome_metrics_service_client.h" | 12 #include "chrome/browser/metrics/chrome_metrics_service_client.h" |
13 #include "chrome/browser/metrics/variations/chrome_variations_service_client.h" | 13 #include "chrome/browser/metrics/variations/chrome_variations_service_client.h" |
14 #include "chrome/browser/metrics/variations/ui_string_overrider_factory.h" | 14 #include "chrome/browser/metrics/variations/ui_string_overrider_factory.h" |
15 #include "chrome/browser/ui/browser_otr_state.h" | 15 #include "chrome/browser/ui/browser_otr_state.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/installer/util/google_update_settings.h" | 17 #include "chrome/installer/util/google_update_settings.h" |
18 #include "components/metrics/metrics_state_manager.h" | 18 #include "components/metrics/metrics_state_manager.h" |
19 #include "components/rappor/rappor_service.h" | 19 #include "components/rappor/rappor_service.h" |
20 #include "components/variations/service/variations_service.h" | 20 #include "components/variations/service/variations_service.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 | 22 |
23 #if defined(OS_CHROMEOS) | |
24 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
25 #include "chromeos/settings/cros_settings_names.h" | |
26 #endif // defined(OS_CHROMEOS) | |
27 | |
23 namespace { | 28 namespace { |
24 | 29 |
25 // Posts |GoogleUpdateSettings::StoreMetricsClientInfo| on blocking pool thread | 30 // Posts |GoogleUpdateSettings::StoreMetricsClientInfo| on blocking pool thread |
26 // because it needs access to IO and cannot work from UI thread. | 31 // because it needs access to IO and cannot work from UI thread. |
27 void PostStoreMetricsClientInfo(const metrics::ClientInfo& client_info) { | 32 void PostStoreMetricsClientInfo(const metrics::ClientInfo& client_info) { |
28 content::BrowserThread::GetBlockingPool()->PostTask( | 33 content::BrowserThread::GetBlockingPool()->PostTask( |
29 FROM_HERE, | 34 FROM_HERE, |
30 base::Bind(&GoogleUpdateSettings::StoreMetricsClientInfo, client_info)); | 35 base::Bind(&GoogleUpdateSettings::StoreMetricsClientInfo, client_info)); |
31 } | 36 } |
32 | 37 |
38 // Initialize kMetricsReportingEnabled based on kStatsReportingPref device | |
39 // setting and add an observer as it is the source of truth on Chrome OS. | |
40 void SetupMetricsStateForChromeOS() { | |
Alexei Svitkine (slow)
2015/11/02 21:50:32
Suggest moving this to metrics_reporting_state.cc
gayane -on leave until 09-2017
2015/11/03 19:46:17
Done.
| |
41 #if defined(OS_CHROMEOS) | |
42 chromeos::CrosSettings::Get()->AddSettingsObserver( | |
43 chromeos::kStatsReportingPref, base::Bind(&onDeviceSettingsChange)); | |
44 | |
45 onDeviceSettingsChange(); | |
46 #endif // defined(OS_CHROMEOS) | |
47 } | |
48 | |
33 } // namespace | 49 } // namespace |
34 | 50 |
35 ChromeMetricsServicesManagerClient::ChromeMetricsServicesManagerClient( | 51 ChromeMetricsServicesManagerClient::ChromeMetricsServicesManagerClient( |
36 PrefService* local_state) | 52 PrefService* local_state) |
37 : local_state_(local_state) { | 53 : local_state_(local_state) { |
38 DCHECK(local_state); | 54 DCHECK(local_state); |
55 | |
56 SetupMetricsStateForChromeOS(); | |
39 } | 57 } |
40 | 58 |
41 ChromeMetricsServicesManagerClient::~ChromeMetricsServicesManagerClient() {} | 59 ChromeMetricsServicesManagerClient::~ChromeMetricsServicesManagerClient() {} |
42 | 60 |
43 scoped_ptr<rappor::RapporService> | 61 scoped_ptr<rappor::RapporService> |
44 ChromeMetricsServicesManagerClient::CreateRapporService() { | 62 ChromeMetricsServicesManagerClient::CreateRapporService() { |
45 DCHECK(thread_checker_.CalledOnValidThread()); | 63 DCHECK(thread_checker_.CalledOnValidThread()); |
46 return make_scoped_ptr(new rappor::RapporService( | 64 return make_scoped_ptr(new rappor::RapporService( |
47 local_state_, base::Bind(&chrome::IsOffTheRecordSessionActive))); | 65 local_state_, base::Bind(&chrome::IsOffTheRecordSessionActive))); |
48 } | 66 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 if (!metrics_state_manager_) { | 120 if (!metrics_state_manager_) { |
103 metrics_state_manager_ = metrics::MetricsStateManager::Create( | 121 metrics_state_manager_ = metrics::MetricsStateManager::Create( |
104 local_state_, | 122 local_state_, |
105 base::Bind( | 123 base::Bind( |
106 &ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled), | 124 &ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled), |
107 base::Bind(&PostStoreMetricsClientInfo), | 125 base::Bind(&PostStoreMetricsClientInfo), |
108 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); | 126 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); |
109 } | 127 } |
110 return metrics_state_manager_.get(); | 128 return metrics_state_manager_.get(); |
111 } | 129 } |
OLD | NEW |