| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/variations/android/variations_seed_bridge.h" |
| 6 |
| 7 #include <jni.h> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/android/jni_android.h" |
| 11 #include "base/android/jni_array.h" |
| 12 #include "base/android/jni_string.h" |
| 13 #include "base/android/jni_weak_ref.h" |
| 14 #include "jni/VariationsSeedBridge_jni.h" |
| 15 |
| 16 using base::android::AttachCurrentThread; |
| 17 using base::android::ConvertJavaStringToUTF8; |
| 18 using base::android::GetApplicationContext; |
| 19 using base::android::ScopedJavaLocalRef; |
| 20 |
| 21 namespace { |
| 22 |
| 23 std::string JavaByteArrayToString(JNIEnv* env, jbyteArray byte_array) { |
| 24 if (!byte_array) |
| 25 return std::string(); |
| 26 std::vector<uint8> array_data; |
| 27 base::android::JavaByteArrayToByteVector(env, byte_array, &array_data); |
| 28 return std::string(array_data.begin(), array_data.end()); |
| 29 } |
| 30 |
| 31 } // namespace |
| 32 |
| 33 namespace variations { |
| 34 namespace android { |
| 35 |
| 36 bool RegisterVariationsSeedBridge(JNIEnv* env) { |
| 37 return RegisterNativesImpl(env); |
| 38 } |
| 39 |
| 40 void GetVariationsFirstRunSeed(std::string* seed_data, |
| 41 std::string* seed_signature, |
| 42 std::string* seed_country) { |
| 43 JNIEnv* env = AttachCurrentThread(); |
| 44 ScopedJavaLocalRef<jbyteArray> j_seed_data = |
| 45 Java_VariationsSeedBridge_getVariationsFirstRunSeedData( |
| 46 env, GetApplicationContext()); |
| 47 ScopedJavaLocalRef<jstring> j_seed_signature = |
| 48 Java_VariationsSeedBridge_getVariationsFirstRunSeedSignature( |
| 49 env, GetApplicationContext()); |
| 50 ScopedJavaLocalRef<jstring> j_seed_country = |
| 51 Java_VariationsSeedBridge_getVariationsFirstRunSeedCountry( |
| 52 env, GetApplicationContext()); |
| 53 *seed_data = JavaByteArrayToString(env, j_seed_data.obj()); |
| 54 *seed_signature = ConvertJavaStringToUTF8(j_seed_signature); |
| 55 *seed_country = ConvertJavaStringToUTF8(j_seed_country); |
| 56 } |
| 57 |
| 58 } // namespace android |
| 59 } // namespace variations |
| OLD | NEW |