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/memory/ptr_util.h" | |
10 #include "components/metrics/call_stack_profile_metrics_provider.h" | |
11 #include "components/metrics/gpu/gpu_metrics_provider.h" | |
12 #include "components/metrics/metrics_service.h" | |
13 #include "components/metrics/metrics_state_manager.h" | |
14 #include "components/metrics/net/net_metrics_log_uploader.h" | |
15 #include "components/metrics/profiler/profiler_metrics_provider.h" | |
16 #include "components/metrics/ui/screen_info_metrics_provider.h" | |
17 #include "components/metrics/url_constants.h" | |
18 #include "components/prefs/pref_service.h" | |
19 #include "content/public/browser/browser_thread.h" | |
20 | |
21 namespace blimp { | |
22 namespace engine { | |
23 | |
24 base::LazyInstance<BlimpMetricsServiceClient>::Leaky g_lazy_instance_; | |
Wez
2016/04/26 01:38:17
This needs to be in the anonymous namespace, surel
Jess
2016/04/26 21:24:10
Done.
| |
25 | |
26 namespace { | |
27 | |
28 // Standard interval between log uploads, in minutes | |
Wez
2016/04/26 01:38:18
Can you reword this to explain what the "standard
Jess
2016/04/26 21:24:10
Done.
| |
29 const int kStandardUploadIntervalMinutes = 30; // Thirty minutes. | |
Wez
2016/04/26 01:38:18
nit: Trailing comment adds nothing ;)
Jess
2016/04/26 21:24:10
Removed.
| |
30 | |
31 bool IsReportingEnabled() { | |
Wez
2016/04/26 01:38:18
nit: Suggest providing a one-line comment explaini
Jess
2016/04/26 21:24:10
Done.
| |
32 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
Wez
2016/04/26 01:38:17
Why this thread-check here but nowhere else?
Jess
2016/04/26 21:24:10
Usually this call makes use of features the requir
| |
33 return true; | |
34 } | |
35 | |
36 // Callbacks for metrics::MetricsStateManager::Create. Store/LoadClientInfo | |
37 // allows Windows Chrome to back up ClientInfo. They're no-ops for Blimp. | |
Wez
2016/04/26 01:38:18
IsReportingEnabled also seems to be a callback for
Jess
2016/04/26 21:24:10
See comment above.
| |
38 void StoreClientInfo(const metrics::ClientInfo& client_info) {} | |
39 | |
40 std::unique_ptr<metrics::ClientInfo> LoadClientInfo() { | |
41 return nullptr; | |
42 } | |
43 | |
44 } // namespace | |
45 | |
46 // static | |
47 BlimpMetricsServiceClient* BlimpMetricsServiceClient::GetInstance() { | |
48 return g_lazy_instance_.Pointer(); | |
49 } | |
50 | |
51 // static | |
52 void BlimpMetricsServiceClient::Initialize( | |
53 PrefService* pref_service, | |
54 net::URLRequestContextGetter* request_context) { | |
55 DCHECK(!is_initialized_); | |
56 pref_service_ = pref_service; | |
57 request_context_ = request_context; | |
58 | |
59 metrics_state_manager_ = metrics::MetricsStateManager::Create( | |
60 pref_service_, | |
61 base::Bind(&IsReportingEnabled), | |
62 base::Bind(&StoreClientInfo), base::Bind(&LoadClientInfo)); | |
Wez
2016/04/26 01:38:18
nit: Is this the format "git cl format" gives? See
Jess
2016/04/26 21:24:10
Ran git cl format.
| |
63 | |
64 metrics_service_.reset(new ::metrics::MetricsService( | |
Wez
2016/04/26 01:38:18
nit: Do we need the leading ::?
Jess
2016/04/26 21:24:10
No. Removed.
| |
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()))); | |
Wez
2016/04/26 01:38:18
We should be very careful about using content::Bro
Jess
2016/04/26 21:24:10
Honestly I am not quite sure here. Perhaps remova
| |
71 | |
72 metrics_service_->RegisterMetricsProvider( | |
73 base::WrapUnique<metrics::MetricsProvider>( | |
74 new metrics::GPUMetricsProvider)); | |
Wez
2016/04/26 01:38:18
nit: Why are these two registrations grouped toget
Jess
2016/04/26 21:24:10
Separated.
| |
75 metrics_service_->RegisterMetricsProvider( | |
76 base::WrapUnique<metrics::MetricsProvider>( | |
77 new metrics::ScreenInfoMetricsProvider)); | |
78 | |
79 metrics_service_->RegisterMetricsProvider( | |
80 base::WrapUnique<metrics::MetricsProvider>( | |
81 new metrics::ProfilerMetricsProvider())); | |
82 | |
83 metrics_service_->RegisterMetricsProvider( | |
84 base::WrapUnique<metrics::MetricsProvider>( | |
85 new metrics::CallStackProfileMetricsProvider)); | |
86 | |
87 metrics_service_->InitializeMetricsRecordingState(); | |
88 | |
89 is_initialized_ = true; | |
90 | |
91 if (IsReportingEnabled()) { | |
92 metrics_service_->Start(); | |
93 } | |
94 } | |
95 | |
96 void BlimpMetricsServiceClient::Finalize() { | |
97 DCHECK(is_initialized_); | |
98 metrics_service_->Stop(); | |
99 } | |
100 | |
101 metrics::MetricsService* BlimpMetricsServiceClient::GetMetricsService() { | |
102 return metrics_service_.get(); | |
103 } | |
104 | |
105 // In Chrome, UMA and Breakpad are enabled/disabled together by the same | |
106 // checkbox and they share the same client ID (a.k.a. GUID). SetMetricsClientId | |
107 // and OnRecordingDisabled are intended to provide the ID to Breakpad. | |
108 // This is not used on required by Blimp, so these are no-ops. | |
Wez
2016/04/26 01:38:18
typo: on -> or
I think it's reasonable to just sa
Jess
2016/04/26 21:24:10
Based on Marcin's work I think we actually do use
| |
109 void BlimpMetricsServiceClient::SetMetricsClientId( | |
110 const std::string& client_id) {} | |
111 | |
112 void BlimpMetricsServiceClient::OnRecordingDisabled() {} | |
113 | |
114 bool BlimpMetricsServiceClient::IsOffTheRecordSessionActive() { | |
115 // Blimp does not have incognito mode. | |
116 return false; | |
117 } | |
118 | |
119 int32_t BlimpMetricsServiceClient::GetProduct() { | |
120 // Indicates product family, not reported platform. | |
Wez
2016/04/26 01:38:17
Not sure what this comment means by "reported plat
Jess
2016/04/26 21:24:10
Added exampled to help clarify. This Product is n
| |
121 return metrics::ChromeUserMetricsExtension::CHROME; | |
122 } | |
123 | |
124 std::string BlimpMetricsServiceClient::GetApplicationLocale() { | |
125 return base::i18n::GetConfiguredLocale(); | |
126 } | |
127 | |
128 bool BlimpMetricsServiceClient::GetBrand(std::string* brand_code) { | |
129 // Blimp doesn't use brand codes. | |
Wez
2016/04/26 01:38:18
Not clear from this comment what a brand-code even
Jess
2016/04/26 21:24:10
Acknowledged.
| |
130 return false; | |
131 } | |
132 | |
133 metrics::SystemProfileProto::Channel BlimpMetricsServiceClient::GetChannel() { | |
134 // Blimp engine does not have channel info yet. | |
135 return metrics::SystemProfileProto::CHANNEL_UNKNOWN; | |
Wez
2016/04/26 01:38:18
nit: Hmmm, tricky; channel is used elsewhere to de
Jess
2016/04/26 21:24:10
Do we have the concept of a channel within the eng
| |
136 } | |
137 | |
138 std::string BlimpMetricsServiceClient::GetVersionString() { | |
139 // TODO(jessicag): Add in a meaningful version string. | |
Wez
2016/04/26 01:38:17
Excitingly I'm working on a CL that will add such
Jess
2016/04/26 21:24:10
Acknowledged.
| |
140 return std::string(); | |
141 } | |
142 | |
143 void BlimpMetricsServiceClient::OnLogUploadComplete() {} | |
144 | |
145 void BlimpMetricsServiceClient::InitializeSystemProfileMetrics( | |
146 const base::Closure& done_callback) { | |
147 done_callback.Run(); | |
Wez
2016/04/26 01:38:18
Add one-line comment to clarify why it's OK to cal
Jess
2016/04/26 21:24:10
Done.
| |
148 } | |
149 | |
150 void BlimpMetricsServiceClient::CollectFinalMetricsForLog( | |
151 const base::Closure& done_callback) { | |
152 done_callback.Run(); | |
153 } | |
154 | |
155 std::unique_ptr<metrics::MetricsLogUploader> | |
156 BlimpMetricsServiceClient::CreateUploader( | |
157 const base::Callback<void(int)>& on_upload_complete) { | |
158 return base::WrapUnique<metrics::MetricsLogUploader>( | |
159 new metrics::NetMetricsLogUploader( | |
160 // URLRequestContextGetter* that remains valid for class lifetime | |
161 // In place of g_browser_process->system_request_context() | |
162 // In engine use subclass BlimpURLRequestContextGetter. | |
163 // Member of g/e/common/blimp_browser_context. | |
Wez
2016/04/26 01:38:18
This comment is already present in the class decla
Jess
2016/04/26 21:24:10
Cleaned up.
| |
164 request_context_, | |
165 metrics::kDefaultMetricsServerUrl, | |
166 metrics::kDefaultMetricsMimeType, | |
167 on_upload_complete)); | |
168 } | |
169 | |
170 base::TimeDelta BlimpMetricsServiceClient::GetStandardUploadInterval() { | |
171 return base::TimeDelta::FromMinutes(kStandardUploadIntervalMinutes); | |
172 } | |
173 | |
174 BlimpMetricsServiceClient::BlimpMetricsServiceClient() | |
175 : is_initialized_(false), | |
176 pref_service_(nullptr), | |
177 request_context_(nullptr) {} | |
178 | |
179 BlimpMetricsServiceClient::~BlimpMetricsServiceClient() {} | |
180 | |
181 } // namespace engine | |
182 } // namespace blimp | |
OLD | NEW |