OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/android/rappor/rappor_service_bridge.h" | 5 #include "chrome/browser/android/rappor/rappor_service_bridge.h" |
6 | 6 |
7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "components/rappor/rappor_utils.h" | 9 #include "components/rappor/rappor_utils.h" |
10 #include "jni/RapporServiceBridge_jni.h" | 10 #include "jni/RapporServiceBridge_jni.h" |
11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
12 | 12 |
| 13 using base::android::JavaParamRef; |
| 14 |
13 namespace rappor { | 15 namespace rappor { |
14 | 16 |
15 void SampleDomainAndRegistryFromURL(JNIEnv* env, | 17 void SampleDomainAndRegistryFromURL(JNIEnv* env, |
16 const JavaParamRef<jclass>& caller, | 18 const JavaParamRef<jclass>& caller, |
17 const JavaParamRef<jstring>& j_metric, | 19 const JavaParamRef<jstring>& j_metric, |
18 const JavaParamRef<jstring>& j_url) { | 20 const JavaParamRef<jstring>& j_url) { |
19 // TODO(knn): UMA metrics hash the string to prevent frequent re-encoding, | 21 // TODO(knn): UMA metrics hash the string to prevent frequent re-encoding, |
20 // perhaps we should do that as well. | 22 // perhaps we should do that as well. |
21 std::string metric(base::android::ConvertJavaStringToUTF8(env, j_metric)); | 23 std::string metric(base::android::ConvertJavaStringToUTF8(env, j_metric)); |
22 GURL gurl(base::android::ConvertJavaStringToUTF8(env, j_url)); | 24 GURL gurl(base::android::ConvertJavaStringToUTF8(env, j_url)); |
23 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), | 25 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), |
24 metric, gurl); | 26 metric, gurl); |
25 } | 27 } |
26 | 28 |
27 void SampleString(JNIEnv* env, | 29 void SampleString(JNIEnv* env, |
28 const JavaParamRef<jclass>& caller, | 30 const JavaParamRef<jclass>& caller, |
29 const JavaParamRef<jstring>& j_metric, | 31 const JavaParamRef<jstring>& j_metric, |
30 const JavaParamRef<jstring>& j_value) { | 32 const JavaParamRef<jstring>& j_value) { |
31 std::string metric(base::android::ConvertJavaStringToUTF8(env, j_metric)); | 33 std::string metric(base::android::ConvertJavaStringToUTF8(env, j_metric)); |
32 std::string value(base::android::ConvertJavaStringToUTF8(env, j_value)); | 34 std::string value(base::android::ConvertJavaStringToUTF8(env, j_value)); |
33 rappor::SampleString(g_browser_process->rappor_service(), | 35 rappor::SampleString(g_browser_process->rappor_service(), |
34 metric, rappor::UMA_RAPPOR_TYPE, value); | 36 metric, rappor::UMA_RAPPOR_TYPE, value); |
35 } | 37 } |
36 | 38 |
37 bool RegisterRapporServiceBridge(JNIEnv* env) { | 39 bool RegisterRapporServiceBridge(JNIEnv* env) { |
38 return RegisterNativesImpl(env); | 40 return RegisterNativesImpl(env); |
39 } | 41 } |
40 | 42 |
41 } // namespace rappor | 43 } // namespace rappor |
OLD | NEW |