Chromium Code Reviews| Index: chrome/browser/android/firstrun/variations/variations_seed_bridge.cc |
| diff --git a/chrome/browser/android/firstrun/variations/variations_seed_bridge.cc b/chrome/browser/android/firstrun/variations/variations_seed_bridge.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..95bb87e06fad0fd614d0c437dbcf94c541f1c162 |
| --- /dev/null |
| +++ b/chrome/browser/android/firstrun/variations/variations_seed_bridge.cc |
| @@ -0,0 +1,59 @@ |
| +// Copyright 2015 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 "chrome/browser/android/firstrun/variations/variations_seed_bridge.h" |
| + |
| +#include <jni.h> |
| +#include <vector> |
| + |
| +#include "base/android/build_info.h" |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_array.h" |
| +#include "base/android/jni_string.h" |
| +#include "base/android/jni_weak_ref.h" |
| +#include "jni/VariationsSeedBridge_jni.h" |
| + |
| +using base::android::AttachCurrentThread; |
| +using base::android::CheckException; |
|
Alexei Svitkine (slow)
2015/11/05 16:38:26
I don't see this being used. Please update the lis
Alexander Agulenko
2015/11/06 08:09:01
Done.
|
| +using base::android::ConvertJavaStringToUTF8; |
| +using base::android::ConvertUTF8ToJavaString; |
| +using base::android::GetApplicationContext; |
| +using base::android::ScopedJavaLocalRef; |
| + |
| +namespace { |
| + |
| +std::string JavaByteArrayToString(JNIEnv* env, jbyteArray byte_array) { |
| + if (!byte_array) |
| + return std::string(); |
| + std::vector<uint8> array_data; |
| + base::android::JavaByteArrayToByteVector(env, byte_array, &array_data); |
| + return std::string(array_data.begin(), array_data.end()); |
| +} |
| + |
| +} // namespace |
| + |
| +// static |
| +bool VariationsSeedBridge::RegisterVariationsSeedBridge(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +// static |
| +void VariationsSeedBridge::GetVariationsFirstRunSeed( |
| + std::string* seed_data, |
| + std::string* seed_signature, |
| + std::string* seed_country) { |
| + JNIEnv* env = AttachCurrentThread(); |
| + ScopedJavaLocalRef<jbyteArray> j_seed_data = |
| + Java_VariationsSeedBridge_getVariationsFirstRunSeedData( |
| + env, GetApplicationContext()); |
| + ScopedJavaLocalRef<jstring> j_seed_signature = |
| + Java_VariationsSeedBridge_getVariationsFirstRunSeedSignature( |
| + env, GetApplicationContext()); |
| + ScopedJavaLocalRef<jstring> j_seed_country = |
| + Java_VariationsSeedBridge_getVariationsFirstRunSeedCountry( |
| + env, GetApplicationContext()); |
| + *seed_data = JavaByteArrayToString(env, j_seed_data.obj()); |
| + *seed_signature = ConvertJavaStringToUTF8(j_seed_signature); |
| + *seed_country = ConvertJavaStringToUTF8(j_seed_country); |
| +} |