Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: components/variations/android/variations_seed_bridge.cc

Issue 1417733008: Java code for fetching variations first run seed after receiving chrome.TOS_ACKED broadcast. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unnecessary exception throw declaration Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/variations/android/variations_seed_bridge.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/variations/android/variations_seed_bridge.cc
diff --git a/components/variations/android/variations_seed_bridge.cc b/components/variations/android/variations_seed_bridge.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cf5cbe41db3ac65ff1fe91a503f42eb94c976575
--- /dev/null
+++ b/components/variations/android/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 "components/variations/android/variations_seed_bridge.h"
+
+#include <jni.h>
+#include <vector>
+
+#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::ConvertJavaStringToUTF8;
+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
+
+namespace variations {
+namespace android {
+
+bool RegisterVariationsSeedBridge(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+void 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);
+}
+
+} // namespace android
+} // namespace variations
« no previous file with comments | « components/variations/android/variations_seed_bridge.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698