| 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/native/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/common/aw_version_info_values.h" | 8 #include "android_webview/common/aw_version_info_values.h" |
| 8 #include "android_webview/jni/AwMetricsServiceClient_jni.h" | 9 #include "android_webview/jni/AwMetricsServiceClient_jni.h" |
| 9 #include "android_webview/native/aw_metrics_log_uploader.h" | |
| 10 #include "base/android/build_info.h" | 10 #include "base/android/build_info.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/guid.h" | 13 #include "base/guid.h" |
| 14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
| 15 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| 16 #include "components/metrics/call_stack_profile_metrics_provider.h" | 16 #include "components/metrics/call_stack_profile_metrics_provider.h" |
| 17 #include "components/metrics/enabled_state_provider.h" | 17 #include "components/metrics/enabled_state_provider.h" |
| 18 #include "components/metrics/gpu/gpu_metrics_provider.h" | 18 #include "components/metrics/gpu/gpu_metrics_provider.h" |
| 19 #include "components/metrics/metrics_log_uploader.h" | 19 #include "components/metrics/metrics_log_uploader.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 75 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 76 return g_lazy_instance_.Pointer(); | 76 return g_lazy_instance_.Pointer(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void AwMetricsServiceClientImpl::Initialize( | 79 void AwMetricsServiceClientImpl::Initialize( |
| 80 PrefService* pref_service, | 80 PrefService* pref_service, |
| 81 net::URLRequestContextGetter* request_context, | 81 net::URLRequestContextGetter* request_context, |
| 82 const base::FilePath guid_file_path) { | 82 const base::FilePath guid_file_path) { |
| 83 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 83 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 84 | 84 |
| 85 DCHECK(pref_service_ == nullptr); // Initialize should only happen once. | 85 DCHECK(pref_service_ == nullptr); // Initialize should only happen once. |
| 86 DCHECK(request_context_ == nullptr); | 86 DCHECK(request_context_ == nullptr); |
| 87 pref_service_ = pref_service; | 87 pref_service_ = pref_service; |
| 88 request_context_ = request_context; | 88 request_context_ = request_context; |
| 89 | 89 |
| 90 std::string* guid = new std::string; | 90 std::string* guid = new std::string; |
| 91 // Initialization happens on the UI thread, but getting the GUID should happen | 91 // 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 | 92 // 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 | 93 // GUID, and then pick up where we left off, back on the UI thread, in |
| 94 // InitializeWithGUID. | 94 // InitializeWithGUID. |
| 95 content::BrowserThread::PostTaskAndReply( | 95 content::BrowserThread::PostTaskAndReply( |
| 96 content::BrowserThread::FILE, | 96 content::BrowserThread::FILE, FROM_HERE, |
| 97 FROM_HERE, | |
| 98 base::Bind(&GetOrCreateGUID, guid_file_path, guid), | 97 base::Bind(&GetOrCreateGUID, guid_file_path, guid), |
| 99 base::Bind(&AwMetricsServiceClientImpl::InitializeWithGUID, | 98 base::Bind(&AwMetricsServiceClientImpl::InitializeWithGUID, |
| 100 base::Unretained(this), base::Owned(guid))); | 99 base::Unretained(this), base::Owned(guid))); |
| 101 } | 100 } |
| 102 | 101 |
| 103 void AwMetricsServiceClientImpl::InitializeWithGUID(std::string* guid) { | 102 void AwMetricsServiceClientImpl::InitializeWithGUID(std::string* guid) { |
| 104 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 103 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 105 | 104 |
| 106 pref_service_->SetString(metrics::prefs::kMetricsClientID, *guid); | 105 pref_service_->SetString(metrics::prefs::kMetricsClientID, *guid); |
| 107 | 106 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 new AwMetricsLogUploader(on_upload_complete)); | 218 new AwMetricsLogUploader(on_upload_complete)); |
| 220 } | 219 } |
| 221 | 220 |
| 222 base::TimeDelta AwMetricsServiceClientImpl::GetStandardUploadInterval() { | 221 base::TimeDelta AwMetricsServiceClientImpl::GetStandardUploadInterval() { |
| 223 // The platform logging mechanism is responsible for upload frequency; this | 222 // The platform logging mechanism is responsible for upload frequency; this |
| 224 // just specifies how frequently to provide logs to the platform. | 223 // just specifies how frequently to provide logs to the platform. |
| 225 return base::TimeDelta::FromMinutes(kUploadIntervalMinutes); | 224 return base::TimeDelta::FromMinutes(kUploadIntervalMinutes); |
| 226 } | 225 } |
| 227 | 226 |
| 228 AwMetricsServiceClientImpl::AwMetricsServiceClientImpl() | 227 AwMetricsServiceClientImpl::AwMetricsServiceClientImpl() |
| 229 : is_enabled_(false), | 228 : is_enabled_(false), pref_service_(nullptr), request_context_(nullptr) {} |
| 230 pref_service_(nullptr), | |
| 231 request_context_(nullptr) {} | |
| 232 | 229 |
| 233 AwMetricsServiceClientImpl::~AwMetricsServiceClientImpl() {} | 230 AwMetricsServiceClientImpl::~AwMetricsServiceClientImpl() {} |
| 234 | 231 |
| 235 // static | 232 // static |
| 236 void SetMetricsEnabled( | 233 void SetMetricsEnabled(JNIEnv* env, |
| 237 JNIEnv* env, | 234 const base::android::JavaParamRef<jclass>& jcaller, |
| 238 const base::android::JavaParamRef<jclass>& jcaller, | 235 jboolean enabled) { |
| 239 jboolean enabled) { | |
| 240 g_lazy_instance_.Pointer()->SetMetricsEnabled(enabled); | 236 g_lazy_instance_.Pointer()->SetMetricsEnabled(enabled); |
| 241 } | 237 } |
| 242 | 238 |
| 243 bool RegisterAwMetricsServiceClient(JNIEnv* env) { | 239 bool RegisterAwMetricsServiceClient(JNIEnv* env) { |
| 244 return RegisterNativesImpl(env); | 240 return RegisterNativesImpl(env); |
| 245 } | 241 } |
| 246 | 242 |
| 247 } // namespace android_webview | 243 } // namespace android_webview |
| OLD | NEW |