OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "android_webview/native/aw_metrics_log_uploader.h" | |
6 | |
7 #include "android_webview/jni/AwMetricsLogUploader_jni.h" | |
8 #include "base/android/jni_array.h" | |
9 #include "components/metrics/log_decoder.h" | |
10 | |
11 using base::android::ScopedJavaLocalRef; | |
12 using base::android::ToJavaByteArray; | |
13 | |
14 namespace android_webview { | |
15 | |
16 AwMetricsLogUploader::AwMetricsLogUploader( | |
17 const metrics::MetricsLogUploader::UploadCallback& on_upload_complete) | |
18 : on_upload_complete_(on_upload_complete) {} | |
19 | |
20 AwMetricsLogUploader::~AwMetricsLogUploader() {} | |
21 | |
22 void AwMetricsLogUploader::UploadLog(const std::string& compressed_log_data, | |
23 const std::string& log_hash) { | |
24 // WebView uses the platform logging mechanism instead of the normal UMA | |
25 // server. The platform mechanism does its own compression, so undo the | |
26 // previous compression. | |
27 std::string log_data; | |
28 if (!metrics::DecodeLogData(compressed_log_data, &log_data)) { | |
29 // If the log is corrupt, pretend the server rejected it (HTTP Bad Request). | |
30 on_upload_complete_.Run(400, 0); | |
31 return; | |
32 } | |
33 | |
34 JNIEnv* env = base::android::AttachCurrentThread(); | |
35 ScopedJavaLocalRef<jbyteArray> java_data = ToJavaByteArray( | |
36 env, reinterpret_cast<const uint8_t*>(log_data.data()), log_data.size()); | |
37 Java_AwMetricsLogUploader_uploadLog(env, java_data); | |
38 | |
39 // The platform mechanism doesn't provide a response code or any way to handle | |
40 // failures, so we have nothing to pass to on_upload_complete. Just pass 200 | |
41 // (HTTP OK) with error code 0 and pretend everything is peachy. | |
42 on_upload_complete_.Run(200, 0); | |
43 } | |
44 | |
45 } // namespace android_webview | |
OLD | NEW |