OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/metrics/chrome_metrics_services_manager_client.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/logging.h" | |
9 #include "base/prefs/pref_service.h" | |
10 #include "chrome/browser/browser_process.h" | |
11 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | |
12 #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/ui_string_overrider_factory.h" | |
15 #include "chrome/browser/ui/browser_otr_state.h" | |
16 #include "chrome/common/chrome_switches.h" | |
17 #include "chrome/installer/util/google_update_settings.h" | |
18 #include "components/metrics/metrics_state_manager.h" | |
19 #include "components/rappor/rappor_service.h" | |
20 #include "components/variations/service/variations_service.h" | |
21 #include "content/public/browser/browser_thread.h" | |
22 | |
23 // Posts |GoogleUpdateSettings::StoreMetricsClientInfo| on blocking pool thread | |
24 // because it needs access to IO and cannot work from UI thread. | |
25 void PostStoreMetricsClientInfo(const metrics::ClientInfo& client_info) { | |
Alexei Svitkine (slow)
2015/10/19 16:47:19
Nit: Put anon namespace around this.
blundell
2015/10/20 10:36:45
Done.
| |
26 content::BrowserThread::GetBlockingPool()->PostTask( | |
27 FROM_HERE, | |
28 base::Bind(&GoogleUpdateSettings::StoreMetricsClientInfo, client_info)); | |
29 } | |
30 | |
31 ChromeMetricsServicesManagerClient::ChromeMetricsServicesManagerClient( | |
32 PrefService* local_state) | |
33 : local_state_(local_state) { | |
34 DCHECK(local_state); | |
35 } | |
36 | |
37 ChromeMetricsServicesManagerClient::~ChromeMetricsServicesManagerClient() {} | |
38 | |
39 scoped_ptr<rappor::RapporService> | |
40 ChromeMetricsServicesManagerClient::CreateRapporService() { | |
41 DCHECK(thread_checker_.CalledOnValidThread()); | |
42 return make_scoped_ptr(new rappor::RapporService( | |
43 local_state_, base::Bind(&chrome::IsOffTheRecordSessionActive))); | |
44 } | |
45 | |
46 scoped_ptr<variations::VariationsService> | |
47 ChromeMetricsServicesManagerClient::CreateVariationsService() { | |
48 DCHECK(thread_checker_.CalledOnValidThread()); | |
49 return variations::VariationsService::Create( | |
50 make_scoped_ptr(new ChromeVariationsServiceClient()), local_state_, | |
51 GetMetricsStateManager(), switches::kDisableBackgroundNetworking, | |
52 chrome_variations::CreateUIStringOverrider()); | |
53 } | |
54 | |
55 scoped_ptr<metrics::MetricsServiceClient> | |
56 ChromeMetricsServicesManagerClient::CreateMetricsServiceClient() { | |
57 DCHECK(thread_checker_.CalledOnValidThread()); | |
58 return ChromeMetricsServiceClient::Create(GetMetricsStateManager(), | |
59 local_state_); | |
60 } | |
61 | |
62 metrics::MetricsService* ChromeMetricsServicesManagerClient::GetMetricsService( | |
63 metrics::MetricsServiceClient* metrics_service_client) { | |
64 return static_cast<ChromeMetricsServiceClient*>(metrics_service_client) | |
65 ->metrics_service(); | |
66 } | |
67 | |
68 net::URLRequestContextGetter* | |
69 ChromeMetricsServicesManagerClient::GetURLRequestContext() { | |
70 return g_browser_process->system_request_context(); | |
71 } | |
72 | |
73 bool ChromeMetricsServicesManagerClient::IsSafeBrowsingEnabled( | |
74 const base::Closure& on_update_callback) { | |
75 // Start listening for updates to SB service state. This is done here instead | |
76 // of in the constructor to avoid errors from trying to instantiate SB | |
77 // service before the IO thread exists. | |
78 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); | |
79 if (!sb_state_subscription_ && sb_service) { | |
80 // It is safe to pass the callback received from the | |
81 // MetricsServicesManager here since the MetricsServicesManager owns | |
82 // this object, which owns the sb_state_subscription_, which owns the | |
83 // pointer to the MetricsServicesManager. | |
84 sb_state_subscription_ = | |
85 sb_service->RegisterStateCallback(on_update_callback); | |
86 } | |
87 | |
88 return sb_service && sb_service->enabled_by_prefs(); | |
89 } | |
90 | |
91 bool ChromeMetricsServicesManagerClient::IsMetricsReportingEnabled() { | |
92 return ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); | |
93 } | |
94 | |
95 bool ChromeMetricsServicesManagerClient::OnlyDoMetricsRecording() { | |
96 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | |
97 return cmdline->HasSwitch(switches::kMetricsRecordingOnly) || | |
98 cmdline->HasSwitch(switches::kEnableBenchmarking); | |
99 } | |
100 | |
101 metrics::MetricsStateManager* | |
102 ChromeMetricsServicesManagerClient::GetMetricsStateManager() { | |
103 DCHECK(thread_checker_.CalledOnValidThread()); | |
104 if (!metrics_state_manager_) { | |
105 metrics_state_manager_ = metrics::MetricsStateManager::Create( | |
106 local_state_, | |
107 base::Bind( | |
108 &ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled), | |
109 base::Bind(&PostStoreMetricsClientInfo), | |
110 base::Bind(&GoogleUpdateSettings::LoadMetricsClientInfo)); | |
111 } | |
112 return metrics_state_manager_.get(); | |
113 } | |
OLD | NEW |