1 // Copyright 2016 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 "base/android/unguessable_token_android.h"
6
7 #include "jni/UnguessableToken_jni.h"
8
9 namespace base {
10 namespace android {
11
Create(JNIEnv * env,const base::UnguessableToken & token)12 ScopedJavaLocalRef<jobject> UnguessableTokenAndroid::Create(
13 JNIEnv* env,
14 const base::UnguessableToken& token) {
15 const uint64_t high = token.GetHighForSerialization();
16 const uint64_t low = token.GetLowForSerialization();
17 DCHECK(high);
18 DCHECK(low);
19 return Java_UnguessableToken_create(env, high, low);
20 }
21
FromJavaUnguessableToken(JNIEnv * env,const JavaRef<jobject> & token)22 base::UnguessableToken UnguessableTokenAndroid::FromJavaUnguessableToken(
23 JNIEnv* env,
24 const JavaRef<jobject>& token) {
25 const uint64_t high =
26 Java_UnguessableToken_getHighForSerialization(env, token);
27 const uint64_t low = Java_UnguessableToken_getLowForSerialization(env, token);
28 DCHECK(high);
29 DCHECK(low);
30 return base::UnguessableToken::Deserialize(high, low);
31 }
32
33 ScopedJavaLocalRef<jobject>
ParcelAndUnparcelForTesting(JNIEnv * env,const JavaRef<jobject> & token)34 UnguessableTokenAndroid::ParcelAndUnparcelForTesting(
35 JNIEnv* env,
36 const JavaRef<jobject>& token) {
37 return Java_UnguessableToken_parcelAndUnparcelForTesting(env, token);
38 }
39
40 } // namespace android
41 } // namespace base
42