Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(700)

Unified Diff: android_webview/native/aw_metrics_service_client_impl.cc

Issue 2611883002: Prepare to call GMS APIs from WebView (Closed)
Patch Set: explicit destructor for style checker Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « android_webview/native/aw_metrics_service_client_impl.h ('k') | android_webview/native/aw_metrics_switch.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/native/aw_metrics_service_client_impl.cc
diff --git a/android_webview/browser/aw_metrics_service_client.cc b/android_webview/native/aw_metrics_service_client_impl.cc
similarity index 70%
copy from android_webview/browser/aw_metrics_service_client.cc
copy to android_webview/native/aw_metrics_service_client_impl.cc
index facd0fe4d23ad7b68f0bef109b2b6c6feb1d2139..3668f26c40df9164a5c8d70228017886fd04051c 100644
--- a/android_webview/browser/aw_metrics_service_client.cc
+++ b/android_webview/native/aw_metrics_service_client_impl.cc
@@ -1,10 +1,11 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "android_webview/browser/aw_metrics_service_client.h"
+#include "android_webview/native/aw_metrics_service_client_impl.h"
#include "android_webview/common/aw_version_info_values.h"
+#include "android_webview/jni/AwMetricsServiceClient_jni.h"
#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/guid.h"
@@ -24,7 +25,7 @@
namespace android_webview {
-base::LazyInstance<AwMetricsServiceClient>::Leaky g_lazy_instance_;
+base::LazyInstance<AwMetricsServiceClientImpl>::Leaky g_lazy_instance_;
namespace {
@@ -51,13 +52,16 @@ void GetOrCreateGUID(const base::FilePath guid_file_path, std::string* guid) {
if (base::IsValidGUID(*guid))
return;
else
- LOG(ERROR) << "Found invalid GUID";
+ LOG(ERROR) << "Overwriting invalid GUID";
}
// We must write a new GUID.
*guid = base::GenerateGUID();
- if (!base::WriteFile(guid_file_path, guid->c_str(), guid->size()))
+ if (!base::WriteFile(guid_file_path, guid->c_str(), guid->size())) {
+ // If writing fails, proceed anyway with the new GUID. It won't be persisted
+ // to the next run, but we can still collect metrics with this 1-time GUID.
LOG(ERROR) << "Failed to write new GUID";
+ }
return;
}
@@ -69,13 +73,14 @@ AwMetricsServiceClient* AwMetricsServiceClient::GetInstance() {
return g_lazy_instance_.Pointer();
}
-void AwMetricsServiceClient::Initialize(
+void AwMetricsServiceClientImpl::Initialize(
PrefService* pref_service,
net::URLRequestContextGetter* request_context,
const base::FilePath guid_file_path) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- DCHECK(!is_initialized_);
+ DCHECK(pref_service_ == nullptr); // Initialize should only happen once.
+ DCHECK(request_context_ == nullptr);
pref_service_ = pref_service;
request_context_ = request_context;
@@ -88,13 +93,12 @@ void AwMetricsServiceClient::Initialize(
content::BrowserThread::FILE,
FROM_HERE,
base::Bind(&GetOrCreateGUID, guid_file_path, guid),
- base::Bind(&AwMetricsServiceClient::InitializeWithGUID,
+ base::Bind(&AwMetricsServiceClientImpl::InitializeWithGUID,
base::Unretained(this), base::Owned(guid)));
}
-void AwMetricsServiceClient::InitializeWithGUID(std::string* guid) {
+void AwMetricsServiceClientImpl::InitializeWithGUID(std::string* guid) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- DCHECK(!is_initialized_);
pref_service_->SetString(metrics::prefs::kMetricsClientID, *guid);
@@ -128,32 +132,30 @@ void AwMetricsServiceClient::InitializeWithGUID(std::string* guid) {
metrics_service_->InitializeMetricsRecordingState();
- is_initialized_ = true;
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_AwMetricsServiceClient_nativeInitialized(env);
+}
- if (IsReportingEnabled())
- metrics_service_->Start();
+bool AwMetricsServiceClientImpl::IsConsentGiven() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ return is_enabled_;
}
-void AwMetricsServiceClient::SetMetricsEnabled(bool enabled) {
+void AwMetricsServiceClientImpl::SetMetricsEnabled(bool enabled) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- // If the client is already initialized, apply the setting immediately.
- // Otherwise, it will be applied on initialization.
- if (is_initialized_ && is_enabled_ != enabled) {
- if (enabled)
- metrics_service_->Start();
- else
+ if (is_enabled_ != enabled) {
+ if (enabled) {
+ // TODO(paulmiller): Actually enable metrics when the server-side is ready
+ //metrics_service_->Start();
+ } else {
metrics_service_->Stop();
+ }
+ is_enabled_ = enabled;
}
- is_enabled_ = enabled;
}
-bool AwMetricsServiceClient::IsConsentGiven() {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- return is_enabled_;
-}
-
-metrics::MetricsService* AwMetricsServiceClient::GetMetricsService() {
+metrics::MetricsService* AwMetricsServiceClientImpl::GetMetricsService() {
return metrics_service_.get();
}
@@ -161,44 +163,44 @@ metrics::MetricsService* AwMetricsServiceClient::GetMetricsService() {
// checkbox and they share the same client ID (a.k.a. GUID). SetMetricsClientId
// is intended to provide the ID to Breakpad. In WebView, UMA and Breakpad are
// independent, so this is a no-op.
+void AwMetricsServiceClientImpl::SetMetricsClientId(
+ const std::string& client_id) {}
-void AwMetricsServiceClient::SetMetricsClientId(const std::string& client_id) {}
-
-int32_t AwMetricsServiceClient::GetProduct() {
+int32_t AwMetricsServiceClientImpl::GetProduct() {
return ::metrics::ChromeUserMetricsExtension::ANDROID_WEBVIEW;
}
-std::string AwMetricsServiceClient::GetApplicationLocale() {
+std::string AwMetricsServiceClientImpl::GetApplicationLocale() {
return base::i18n::GetConfiguredLocale();
}
-bool AwMetricsServiceClient::GetBrand(std::string* brand_code) {
+bool AwMetricsServiceClientImpl::GetBrand(std::string* brand_code) {
// WebView doesn't use brand codes.
return false;
}
-metrics::SystemProfileProto::Channel AwMetricsServiceClient::GetChannel() {
+metrics::SystemProfileProto::Channel AwMetricsServiceClientImpl::GetChannel() {
// "Channel" means stable, beta, etc. WebView doesn't have channel info yet.
// TODO(paulmiller) Update this once we have channel info.
return metrics::SystemProfileProto::CHANNEL_UNKNOWN;
}
-std::string AwMetricsServiceClient::GetVersionString() {
+std::string AwMetricsServiceClientImpl::GetVersionString() {
return PRODUCT_VERSION;
}
-void AwMetricsServiceClient::InitializeSystemProfileMetrics(
+void AwMetricsServiceClientImpl::InitializeSystemProfileMetrics(
const base::Closure& done_callback) {
done_callback.Run();
}
-void AwMetricsServiceClient::CollectFinalMetricsForLog(
+void AwMetricsServiceClientImpl::CollectFinalMetricsForLog(
const base::Closure& done_callback) {
done_callback.Run();
}
std::unique_ptr<metrics::MetricsLogUploader>
-AwMetricsServiceClient::CreateUploader(
+AwMetricsServiceClientImpl::CreateUploader(
const std::string& server_url,
const std::string& mime_type,
const base::Callback<void(int)>& on_upload_complete) {
@@ -207,16 +209,27 @@ AwMetricsServiceClient::CreateUploader(
request_context_, server_url, mime_type, on_upload_complete));
}
-base::TimeDelta AwMetricsServiceClient::GetStandardUploadInterval() {
+base::TimeDelta AwMetricsServiceClientImpl::GetStandardUploadInterval() {
return base::TimeDelta::FromMinutes(kUploadIntervalMinutes);
}
-AwMetricsServiceClient::AwMetricsServiceClient()
- : is_initialized_(false),
- is_enabled_(false),
+AwMetricsServiceClientImpl::AwMetricsServiceClientImpl()
+ : is_enabled_(false),
pref_service_(nullptr),
request_context_(nullptr) {}
-AwMetricsServiceClient::~AwMetricsServiceClient() {}
+AwMetricsServiceClientImpl::~AwMetricsServiceClientImpl() {}
+
+// static
+void SetMetricsEnabled(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jclass>& jcaller,
+ jboolean enabled) {
+ g_lazy_instance_.Pointer()->SetMetricsEnabled(enabled);
+}
+
+bool RegisterAwMetricsServiceClient(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
} // namespace android_webview
« no previous file with comments | « android_webview/native/aw_metrics_service_client_impl.h ('k') | android_webview/native/aw_metrics_switch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698