1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53

base / android / unguessable_token_android.cc [blame]

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/android/unguessable_token_android.h"

#include "build/robolectric_buildflags.h"

// Must come after all headers that specialize FromJniType() / ToJniType().
#if BUILDFLAG(IS_ROBOLECTRIC)
#include "base/base_robolectric_jni/TokenBase_jni.h"  // nogncheck
#include "base/base_robolectric_jni/UnguessableToken_jni.h"  // nogncheck
#else
#include "base/base_jni/TokenBase_jni.h"
#include "base/base_jni/UnguessableToken_jni.h"
#endif


namespace base {
namespace android {

jni_zero::ScopedJavaLocalRef<jobject> UnguessableTokenAndroid::Create(
    JNIEnv* env,
    const base::UnguessableToken& token) {
  const uint64_t high = token.GetHighForSerialization();
  const uint64_t low = token.GetLowForSerialization();
  DCHECK(high);
  DCHECK(low);
  return Java_UnguessableToken_Constructor(env, static_cast<jlong>(high),
                                           static_cast<jlong>(low));
}

base::UnguessableToken UnguessableTokenAndroid::FromJavaUnguessableToken(
    JNIEnv* env,
    const jni_zero::JavaRef<jobject>& token) {
  const uint64_t high =
      static_cast<uint64_t>(Java_TokenBase_getHighForSerialization(env, token));
  const uint64_t low =
      static_cast<uint64_t>(Java_TokenBase_getLowForSerialization(env, token));
  DCHECK(high);
  DCHECK(low);
  return base::UnguessableToken::Deserialize(high, low).value();
}

jni_zero::ScopedJavaLocalRef<jobject>
UnguessableTokenAndroid::ParcelAndUnparcelForTesting(
    JNIEnv* env,
    const jni_zero::JavaRef<jobject>& token) {
  return Java_UnguessableToken_parcelAndUnparcelForTesting(env, token);
}

}  // namespace android
}  // namespace base