Commit a5febff9 authored by paulmiller's avatar paulmiller Committed by Commit bot

WebView: Create UMA uploader

WebView uses an unspecified platform mechanism to upload UMA logs,
rather than the typical cronet path. This creates a WebView-specific
MetricsLogUploader, which sends logs to PlatformServiceBridge, which
connects to the platform mechanism.

BUG=698047

Review-Url: https://codereview.chromium.org/2778203003
Cr-Commit-Position: refs/heads/master@{#460649}
parent 23c9664f
......@@ -634,6 +634,7 @@ android_library("android_webview_java") {
"java/src/org/chromium/android_webview/AwGLFunctor.java",
"java/src/org/chromium/android_webview/AwHttpAuthHandler.java",
"java/src/org/chromium/android_webview/AwLayoutSizer.java",
"java/src/org/chromium/android_webview/AwMetricsLogUploader.java",
"java/src/org/chromium/android_webview/AwMetricsServiceClient.java",
"java/src/org/chromium/android_webview/AwNetworkChangeNotifierRegistrationPolicy.java",
"java/src/org/chromium/android_webview/AwPdfExporter.java",
......
......@@ -24,6 +24,7 @@ include_rules = [
"+net",
"+skia",
"+third_party/skia/include",
"+third_party/zlib/google",
"+ui/android",
"+ui/base",
"+ui/gfx",
......
// 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.
package org.chromium.android_webview;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
/**
* Passes UMA logs from native to PlatformServiceBridge.
*/
@JNINamespace("android_webview")
public class AwMetricsLogUploader {
@CalledByNative
public static void uploadLog(byte[] data) {
// getInstance only needs a Context on the first call. WebViewChromiumFactoryProvider will
// have already called it, so we can pass null here.
PlatformServiceBridge.getInstance(null).logMetrics(data);
}
}
......@@ -68,4 +68,7 @@ public class PlatformServiceBridge {
ThreadUtils.assertOnUiThread();
callback.onReceiveValue(false);
}
// Takes an uncompressed, serialized UMA proto and logs it via a platform-specific mechanism.
public void logMetrics(byte[] data) {}
}
......@@ -68,6 +68,8 @@ source_set("native") {
"aw_locale_manager_impl.h",
"aw_media_url_interceptor.cc",
"aw_media_url_interceptor.h",
"aw_metrics_log_uploader.cc",
"aw_metrics_log_uploader.h",
"aw_metrics_service_client_impl.cc",
"aw_metrics_service_client_impl.h",
"aw_pdf_exporter.cc",
......@@ -139,6 +141,7 @@ generate_jni("native_jni") {
"../java/src/org/chromium/android_webview/AwFormDatabase.java",
"../java/src/org/chromium/android_webview/AwGLFunctor.java",
"../java/src/org/chromium/android_webview/AwHttpAuthHandler.java",
"../java/src/org/chromium/android_webview/AwMetricsLogUploader.java",
"../java/src/org/chromium/android_webview/AwMetricsServiceClient.java",
"../java/src/org/chromium/android_webview/AwPdfExporter.java",
"../java/src/org/chromium/android_webview/AwPicture.java",
......
// 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/native/aw_metrics_log_uploader.h"
#include "android_webview/jni/AwMetricsLogUploader_jni.h"
#include "base/android/jni_array.h"
#include "third_party/zlib/google/compression_utils.h"
using base::android::ScopedJavaLocalRef;
using base::android::ToJavaByteArray;
namespace android_webview {
AwMetricsLogUploader::AwMetricsLogUploader(
const base::Callback<void(int)>& on_upload_complete)
: on_upload_complete_(on_upload_complete) {}
AwMetricsLogUploader::~AwMetricsLogUploader() {}
void AwMetricsLogUploader::UploadLog(const std::string& compressed_log_data,
const std::string& log_hash) {
// WebView uses the platform logging mechanism instead of the normal UMA
// server. The platform mechanism does its own compression, so undo the
// previous compression.
std::string log_data;
compression::GzipUncompress(compressed_log_data, &log_data);
JNIEnv* env = base::android::AttachCurrentThread();
ScopedJavaLocalRef<jbyteArray> java_data = ToJavaByteArray(
env, reinterpret_cast<const uint8_t*>(log_data.data()), log_data.size());
Java_AwMetricsLogUploader_uploadLog(env, java_data);
// The platform mechanism doesn't provide a response code or any way to handle
// failures, so we have nothing to pass to on_upload_complete. Just pass 200
// (HTTP OK) and pretend everything is peachy.
on_upload_complete_.Run(200);
}
} // namespace android_webview
// 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.
#ifndef ANDROID_WEBVIEW_NATIVE_AW_METRICS_LOG_UPLOADER_H_
#define ANDROID_WEBVIEW_NATIVE_AW_METRICS_LOG_UPLOADER_H_
#include <jni.h>
#include <string>
#include "components/metrics/metrics_log_uploader.h"
namespace android_webview {
// Uploads UMA logs for WebView using the platform logging mechanism.
class AwMetricsLogUploader : public ::metrics::MetricsLogUploader {
public:
explicit AwMetricsLogUploader(
const base::Callback<void(int)>& on_upload_complete);
~AwMetricsLogUploader() override;
// ::metrics::MetricsLogUploader:
void UploadLog(const std::string& compressed_log_data,
const std::string& log_hash) override;
private:
const base::Callback<void(int)> on_upload_complete_;
DISALLOW_COPY_AND_ASSIGN(AwMetricsLogUploader);
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_NATIVE_AW_METRICS_LOG_UPLOADER_H_
......@@ -6,6 +6,8 @@
#include "android_webview/common/aw_version_info_values.h"
#include "android_webview/jni/AwMetricsServiceClient_jni.h"
#include "android_webview/native/aw_metrics_log_uploader.h"
#include "base/android/build_info.h"
#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/guid.h"
......@@ -18,7 +20,6 @@
#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/metrics_service.h"
#include "components/metrics/metrics_state_manager.h"
#include "components/metrics/net/net_metrics_log_uploader.h"
#include "components/metrics/profiler/profiler_metrics_provider.h"
#include "components/metrics/ui/screen_info_metrics_provider.h"
#include "components/metrics/url_constants.h"
......@@ -146,10 +147,15 @@ bool AwMetricsServiceClientImpl::IsConsentGiven() {
void AwMetricsServiceClientImpl::SetMetricsEnabled(bool enabled) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// For now, UMA is only enabled on future versions.
if (base::android::BuildInfo::GetInstance()->sdk_int() <=
base::android::SDK_VERSION_NOUGAT) {
return;
}
if (is_enabled_ != enabled) {
if (enabled) {
// TODO(paulmiller): Actually enable metrics when the server-side is ready
//metrics_service_->Start();
metrics_service_->Start();
} else {
metrics_service_->Stop();
}
......@@ -207,13 +213,15 @@ AwMetricsServiceClientImpl::CreateUploader(
base::StringPiece mime_type,
metrics::MetricsLogUploader::MetricServiceType service_type,
const base::Callback<void(int)>& on_upload_complete) {
// |server_url| and |mime_type| are unused because WebView uses the platform
// logging mechanism instead of the normal UMA server.
return std::unique_ptr<::metrics::MetricsLogUploader>(
new metrics::NetMetricsLogUploader(request_context_, server_url,
mime_type, service_type,
on_upload_complete));
new AwMetricsLogUploader(on_upload_complete));
}
base::TimeDelta AwMetricsServiceClientImpl::GetStandardUploadInterval() {
// The platform logging mechanism is responsible for upload frequency; this
// just specifies how frequently to provide logs to the platform.
return base::TimeDelta::FromMinutes(kUploadIntervalMinutes);
}
......
......@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ANDROID_WEBVIEW_NATIVE_AW_METRICS_SERVICE_CLIENT_IMPL_
#define ANDROID_WEBVIEW_NATIVE_AW_METRICS_SERVICE_CLIENT_IMPL_
#include "android_webview/browser/aw_metrics_service_client.h"
#ifndef ANDROID_WEBVIEW_NATIVE_AW_METRICS_SERVICE_CLIENT_IMPL_H_
#define ANDROID_WEBVIEW_NATIVE_AW_METRICS_SERVICE_CLIENT_IMPL_H_
#include <jni.h>
#include <memory>
#include <string>
#include "android_webview/browser/aw_metrics_service_client.h"
#include "base/lazy_instance.h"
#include "base/macros.h"
#include "components/metrics/metrics_log_uploader.h"
......@@ -79,4 +79,4 @@ bool RegisterAwMetricsServiceClient(JNIEnv* env);
} // namespace android_webview
#endif // ANDROID_WEBVIEW_NATIVE_AW_METRICS_SERVICE_CLIENT_IMPL_
#endif // ANDROID_WEBVIEW_NATIVE_AW_METRICS_SERVICE_CLIENT_IMPL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment