OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "android_webview/browser/aw_metrics_service_client_impl.h" | 5 #include "android_webview/browser/aw_metrics_service_client_impl.h" |
6 | 6 |
7 #include "android_webview/browser/aw_metrics_log_uploader.h" | 7 #include "android_webview/browser/aw_metrics_log_uploader.h" |
8 #include "android_webview/common/aw_version_info_values.h" | 8 #include "android_webview/common/aw_version_info_values.h" |
9 #include "android_webview/jni/AwMetricsServiceClient_jni.h" | 9 #include "android_webview/jni/AwMetricsServiceClient_jni.h" |
10 #include "base/android/build_info.h" | 10 #include "base/android/build_info.h" |
11 #include "base/android/jni_string.h" | |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
13 #include "base/guid.h" | 14 #include "base/guid.h" |
14 #include "base/i18n/rtl.h" | 15 #include "base/i18n/rtl.h" |
15 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" |
16 #include "components/metrics/call_stack_profile_metrics_provider.h" | 17 #include "components/metrics/call_stack_profile_metrics_provider.h" |
17 #include "components/metrics/enabled_state_provider.h" | 18 #include "components/metrics/enabled_state_provider.h" |
18 #include "components/metrics/gpu/gpu_metrics_provider.h" | 19 #include "components/metrics/gpu/gpu_metrics_provider.h" |
19 #include "components/metrics/metrics_log_uploader.h" | 20 #include "components/metrics/metrics_log_uploader.h" |
20 #include "components/metrics/metrics_pref_names.h" | 21 #include "components/metrics/metrics_pref_names.h" |
21 #include "components/metrics/metrics_service.h" | 22 #include "components/metrics/metrics_service.h" |
22 #include "components/metrics/metrics_state_manager.h" | 23 #include "components/metrics/metrics_state_manager.h" |
23 #include "components/metrics/profiler/profiler_metrics_provider.h" | 24 #include "components/metrics/profiler/profiler_metrics_provider.h" |
24 #include "components/metrics/ui/screen_info_metrics_provider.h" | 25 #include "components/metrics/ui/screen_info_metrics_provider.h" |
25 #include "components/metrics/url_constants.h" | 26 #include "components/metrics/url_constants.h" |
27 #include "components/metrics/version_utils.h" | |
26 #include "components/prefs/pref_service.h" | 28 #include "components/prefs/pref_service.h" |
29 #include "components/version_info/channel_android.h" | |
30 #include "components/version_info/version_info.h" | |
27 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
28 | 32 |
29 namespace android_webview { | 33 namespace android_webview { |
30 | 34 |
31 base::LazyInstance<AwMetricsServiceClientImpl>::Leaky g_lazy_instance_; | 35 base::LazyInstance<AwMetricsServiceClientImpl>::Leaky g_lazy_instance_; |
32 | 36 |
33 namespace { | 37 namespace { |
34 | 38 |
35 const int kUploadIntervalMinutes = 30; | 39 const int kUploadIntervalMinutes = 30; |
36 | 40 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 PrefService* pref_service, | 84 PrefService* pref_service, |
81 net::URLRequestContextGetter* request_context, | 85 net::URLRequestContextGetter* request_context, |
82 const base::FilePath guid_file_path) { | 86 const base::FilePath guid_file_path) { |
83 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
84 | 88 |
85 DCHECK(pref_service_ == nullptr); // Initialize should only happen once. | 89 DCHECK(pref_service_ == nullptr); // Initialize should only happen once. |
86 DCHECK(request_context_ == nullptr); | 90 DCHECK(request_context_ == nullptr); |
87 pref_service_ = pref_service; | 91 pref_service_ = pref_service; |
88 request_context_ = request_context; | 92 request_context_ = request_context; |
89 | 93 |
94 // The channel will always be "unknown" when using stand-alone WebView, since | |
95 // stand-alone WebView has the same package name across channels. | |
96 JNIEnv* env = base::android::AttachCurrentThread(); | |
97 std::string package_name = base::android::ConvertJavaStringToUTF8( | |
98 env, Java_AwMetricsServiceClient_getWebViewPackageName(env)); | |
99 channel_ = version_info::ChannelFromPackageName(package_name.c_str()); | |
Alexei Svitkine (slow)
2017/05/12 14:26:22
Nit: This seems like a good candidate for a helper
paulmiller
2017/05/12 19:45:35
Done.
| |
100 | |
90 std::string* guid = new std::string; | 101 std::string* guid = new std::string; |
91 // Initialization happens on the UI thread, but getting the GUID should happen | 102 // Initialization happens on the UI thread, but getting the GUID should happen |
92 // on the file I/O thread. So we start to initialize, then post to get the | 103 // on the file I/O thread. So we start to initialize, then post to get the |
93 // GUID, and then pick up where we left off, back on the UI thread, in | 104 // GUID, and then pick up where we left off, back on the UI thread, in |
94 // InitializeWithGUID. | 105 // InitializeWithGUID. |
95 content::BrowserThread::PostTaskAndReply( | 106 content::BrowserThread::PostTaskAndReply( |
96 content::BrowserThread::FILE, FROM_HERE, | 107 content::BrowserThread::FILE, FROM_HERE, |
97 base::Bind(&GetOrCreateGUID, guid_file_path, guid), | 108 base::Bind(&GetOrCreateGUID, guid_file_path, guid), |
98 base::Bind(&AwMetricsServiceClientImpl::InitializeWithGUID, | 109 base::Bind(&AwMetricsServiceClientImpl::InitializeWithGUID, |
99 base::Unretained(this), base::Owned(guid))); | 110 base::Unretained(this), base::Owned(guid))); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 std::string AwMetricsServiceClientImpl::GetApplicationLocale() { | 191 std::string AwMetricsServiceClientImpl::GetApplicationLocale() { |
181 return base::i18n::GetConfiguredLocale(); | 192 return base::i18n::GetConfiguredLocale(); |
182 } | 193 } |
183 | 194 |
184 bool AwMetricsServiceClientImpl::GetBrand(std::string* brand_code) { | 195 bool AwMetricsServiceClientImpl::GetBrand(std::string* brand_code) { |
185 // WebView doesn't use brand codes. | 196 // WebView doesn't use brand codes. |
186 return false; | 197 return false; |
187 } | 198 } |
188 | 199 |
189 metrics::SystemProfileProto::Channel AwMetricsServiceClientImpl::GetChannel() { | 200 metrics::SystemProfileProto::Channel AwMetricsServiceClientImpl::GetChannel() { |
190 // "Channel" means stable, beta, etc. WebView doesn't have channel info yet. | 201 return metrics::AsProtobufChannel(channel_); |
191 // TODO(paulmiller) Update this once we have channel info. | |
192 return metrics::SystemProfileProto::CHANNEL_UNKNOWN; | |
193 } | 202 } |
194 | 203 |
195 std::string AwMetricsServiceClientImpl::GetVersionString() { | 204 std::string AwMetricsServiceClientImpl::GetVersionString() { |
196 return PRODUCT_VERSION; | 205 return PRODUCT_VERSION; |
197 } | 206 } |
198 | 207 |
199 void AwMetricsServiceClientImpl::InitializeSystemProfileMetrics( | 208 void AwMetricsServiceClientImpl::InitializeSystemProfileMetrics( |
200 const base::Closure& done_callback) { | 209 const base::Closure& done_callback) { |
201 done_callback.Run(); | 210 done_callback.Run(); |
202 } | 211 } |
(...skipping 15 matching lines...) Expand all Loading... | |
218 new AwMetricsLogUploader(on_upload_complete)); | 227 new AwMetricsLogUploader(on_upload_complete)); |
219 } | 228 } |
220 | 229 |
221 base::TimeDelta AwMetricsServiceClientImpl::GetStandardUploadInterval() { | 230 base::TimeDelta AwMetricsServiceClientImpl::GetStandardUploadInterval() { |
222 // The platform logging mechanism is responsible for upload frequency; this | 231 // The platform logging mechanism is responsible for upload frequency; this |
223 // just specifies how frequently to provide logs to the platform. | 232 // just specifies how frequently to provide logs to the platform. |
224 return base::TimeDelta::FromMinutes(kUploadIntervalMinutes); | 233 return base::TimeDelta::FromMinutes(kUploadIntervalMinutes); |
225 } | 234 } |
226 | 235 |
227 AwMetricsServiceClientImpl::AwMetricsServiceClientImpl() | 236 AwMetricsServiceClientImpl::AwMetricsServiceClientImpl() |
228 : is_enabled_(false), pref_service_(nullptr), request_context_(nullptr) {} | 237 : is_enabled_(false), |
238 pref_service_(nullptr), | |
239 request_context_(nullptr), | |
240 channel_(version_info::Channel::UNKNOWN) {} | |
229 | 241 |
230 AwMetricsServiceClientImpl::~AwMetricsServiceClientImpl() {} | 242 AwMetricsServiceClientImpl::~AwMetricsServiceClientImpl() {} |
231 | 243 |
232 // static | 244 // static |
233 void SetMetricsEnabled(JNIEnv* env, | 245 void SetMetricsEnabled(JNIEnv* env, |
234 const base::android::JavaParamRef<jclass>& jcaller, | 246 const base::android::JavaParamRef<jclass>& jcaller, |
235 jboolean enabled) { | 247 jboolean enabled) { |
236 g_lazy_instance_.Pointer()->SetMetricsEnabled(enabled); | 248 g_lazy_instance_.Pointer()->SetMetricsEnabled(enabled); |
237 } | 249 } |
238 | 250 |
239 bool RegisterAwMetricsServiceClient(JNIEnv* env) { | 251 bool RegisterAwMetricsServiceClient(JNIEnv* env) { |
240 return RegisterNativesImpl(env); | 252 return RegisterNativesImpl(env); |
241 } | 253 } |
242 | 254 |
243 } // namespace android_webview | 255 } // namespace android_webview |
OLD | NEW |