OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 "blimp/engine/app/blimp_metrics_service_client.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/i18n/rtl.h" | |
9 #include "base/lazy_instance.h" | |
10 #include "base/memory/ptr_util.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "components/metrics/call_stack_profile_metrics_provider.h" | |
13 #include "components/metrics/gpu/gpu_metrics_provider.h" | |
14 #include "components/metrics/metrics_service.h" | |
15 #include "components/metrics/metrics_service_client.h" | |
16 #include "components/metrics/metrics_state_manager.h" | |
17 #include "components/metrics/net/net_metrics_log_uploader.h" | |
18 #include "components/metrics/profiler/profiler_metrics_provider.h" | |
19 #include "components/metrics/ui/screen_info_metrics_provider.h" | |
20 #include "components/metrics/url_constants.h" | |
21 #include "components/prefs/pref_service.h" | |
22 #include "components/version_info/version_info.h" | |
23 #include "content/public/browser/browser_thread.h" | |
24 #include "net/url_request/url_request_context_getter.h" | |
25 | |
26 namespace blimp { | |
27 namespace engine { | |
28 namespace { | |
29 // How often after initial logging metrics results should be uploaded to the | |
30 // metrics service. | |
31 const int kStandardUploadIntervalMinutes = 30; | |
32 | |
33 // Returns if the MetricsService should be recording metrics information for | |
34 // the client. | |
35 // This callback is required by MetricsStateManager::Create. | |
36 bool IsReportingEnabled() { | |
37 return true; | |
38 } | |
39 | |
40 // Store/LoadClientInfo allows Windows Chrome to back up ClientInfo. | |
41 // Both are no-ops for Blimp. | |
42 // These callbacks are required by MetricsStateManager::Create. | |
43 void StoreClientInfo(const metrics::ClientInfo& client_info) {} | |
44 | |
45 std::unique_ptr<metrics::ClientInfo> LoadClientInfo() { | |
46 return nullptr; | |
47 } | |
48 | |
49 } // namespace | |
50 | |
51 BlimpMetricsServiceClient::BlimpMetricsServiceClient( | |
52 PrefService* pref_service, | |
53 scoped_refptr<net::URLRequestContextGetter> request_context_getter) { | |
54 request_context_getter_ = request_context_getter; | |
55 | |
56 metrics_state_manager_ = metrics::MetricsStateManager::Create( | |
57 pref_service, base::Bind(&IsReportingEnabled), | |
58 base::Bind(&StoreClientInfo), base::Bind(&LoadClientInfo)); | |
59 | |
60 // Metrics state manager created while other class instances exist. | |
61 // Sign of multiple initializations. | |
62 DCHECK(metrics_state_manager_.get()); | |
Bernhard Bauer
2016/05/10 08:51:42
Nit: std::unique_ptr has a bool conversion operato
Jess
2016/05/10 17:30:03
Done.
| |
63 | |
64 metrics_service_.reset(new metrics::MetricsService( | |
65 metrics_state_manager_.get(), this, pref_service)); | |
66 | |
67 metrics_service_->RegisterMetricsProvider( | |
68 base::WrapUnique<metrics::MetricsProvider>( | |
69 new metrics::NetworkMetricsProvider( | |
70 content::BrowserThread::GetBlockingPool()))); | |
71 metrics_service_->RegisterMetricsProvider( | |
72 base::WrapUnique<metrics::MetricsProvider>( | |
73 new metrics::GPUMetricsProvider)); | |
74 metrics_service_->RegisterMetricsProvider( | |
75 base::WrapUnique<metrics::MetricsProvider>( | |
76 new metrics::ScreenInfoMetricsProvider)); | |
77 metrics_service_->RegisterMetricsProvider( | |
78 base::WrapUnique<metrics::MetricsProvider>( | |
79 new metrics::ProfilerMetricsProvider())); | |
80 metrics_service_->RegisterMetricsProvider( | |
81 base::WrapUnique<metrics::MetricsProvider>( | |
82 new metrics::CallStackProfileMetricsProvider)); | |
83 | |
84 metrics_service_->InitializeMetricsRecordingState(); | |
85 | |
86 if (IsReportingEnabled()) | |
87 metrics_service_->Start(); | |
88 } | |
89 | |
90 BlimpMetricsServiceClient::~BlimpMetricsServiceClient() { | |
91 metrics_service_->Stop(); | |
92 } | |
93 | |
94 metrics::MetricsService* BlimpMetricsServiceClient::GetMetricsService() { | |
95 return metrics_service_.get(); | |
96 } | |
97 | |
98 // In Chrome, UMA and Breakpad are enabled/disabled together by the same | |
99 // checkbox and they share the same client ID (a.k.a. GUID). | |
100 // This is not required by Blimp, so these are no-ops. | |
101 void BlimpMetricsServiceClient::SetMetricsClientId( | |
102 const std::string& client_id) {} | |
103 | |
104 // Recording can not be disabled in Blimp, so this function is a no-op. | |
105 void BlimpMetricsServiceClient::OnRecordingDisabled() {} | |
106 | |
107 bool BlimpMetricsServiceClient::IsOffTheRecordSessionActive() { | |
108 // Blimp does not have incognito mode. | |
109 return false; | |
110 } | |
111 | |
112 int32_t BlimpMetricsServiceClient::GetProduct() { | |
113 // Indicates product family (e.g. Chrome v Android Webview), not reported | |
114 // platform (e.g. Chrome_Linux, Chrome_Mac). | |
115 return metrics::ChromeUserMetricsExtension::CHROME; | |
116 } | |
117 | |
118 std::string BlimpMetricsServiceClient::GetApplicationLocale() { | |
119 return base::i18n::GetConfiguredLocale(); | |
120 } | |
121 | |
122 bool BlimpMetricsServiceClient::GetBrand(std::string* brand_code) { | |
123 // Blimp doesn't use brand codes. | |
124 return false; | |
125 } | |
126 | |
127 metrics::SystemProfileProto::Channel BlimpMetricsServiceClient::GetChannel() { | |
128 // Blimp engine does not have channel info yet. | |
129 return metrics::SystemProfileProto::CHANNEL_UNKNOWN; | |
130 } | |
131 | |
132 std::string BlimpMetricsServiceClient::GetVersionString() { | |
133 return version_info::GetVersionNumber(); | |
134 } | |
135 | |
136 void BlimpMetricsServiceClient::OnLogUploadComplete() {} | |
137 | |
138 void BlimpMetricsServiceClient::InitializeSystemProfileMetrics( | |
139 const base::Closure& done_callback) { | |
140 // Blimp requires no additional work to InitializeSystemProfileMetrics | |
141 // and should proceed to the next call in the chain. | |
142 done_callback.Run(); | |
143 } | |
144 | |
145 void BlimpMetricsServiceClient::CollectFinalMetricsForLog( | |
146 const base::Closure& done_callback) { | |
147 // Blimp requires no additional work to CollectFinalMetricsForLog | |
148 // and should proceed to the next call in the chain | |
149 done_callback.Run(); | |
150 } | |
151 | |
152 std::unique_ptr<metrics::MetricsLogUploader> | |
153 BlimpMetricsServiceClient::CreateUploader( | |
154 const base::Callback<void(int)>& on_upload_complete) { | |
155 return base::WrapUnique<metrics::MetricsLogUploader>( | |
156 new metrics::NetMetricsLogUploader( | |
157 request_context_getter_.get(), metrics::kDefaultMetricsServerUrl, | |
158 metrics::kDefaultMetricsMimeType, on_upload_complete)); | |
159 } | |
160 | |
161 base::TimeDelta BlimpMetricsServiceClient::GetStandardUploadInterval() { | |
162 return base::TimeDelta::FromMinutes(kStandardUploadIntervalMinutes); | |
163 } | |
164 | |
165 metrics::MetricsServiceClient::EnableMetricsDefault | |
166 BlimpMetricsServiceClient::GetDefaultOptIn() { | |
167 return OPT_IN; | |
168 } | |
169 | |
170 } // namespace engine | |
171 } // namespace blimp | |
OLD | NEW |