Chromium Code Reviews| Index: android_webview/native/aw_metrics_log_uploader.cc |
| diff --git a/android_webview/native/aw_metrics_log_uploader.cc b/android_webview/native/aw_metrics_log_uploader.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fa74c7d5b70ad686eb02a8209e48aaa3cbe777d1 |
| --- /dev/null |
| +++ b/android_webview/native/aw_metrics_log_uploader.cc |
| @@ -0,0 +1,41 @@ |
| +// 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); |
|
Alexei Svitkine (slow)
2017/03/29 19:19:17
I agree about your point about this leaking implem
paulmiller
2017/03/29 19:52:38
Okay, I'll do that separately.
|
| + |
| + 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 |