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

base / android / token_android.h [blame]

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

#ifndef BASE_ANDROID_TOKEN_ANDROID_H_
#define BASE_ANDROID_TOKEN_ANDROID_H_

#include <jni.h>

#include <optional>

#include "base/android/scoped_java_ref.h"
#include "base/base_export.h"
#include "base/containers/span.h"
#include "base/token.h"

namespace base::android {

class BASE_EXPORT TokenAndroid {
 public:
  // Create a Java Token with the same value as `token`.
  static ScopedJavaLocalRef<jobject> Create(JNIEnv* env,
                                            const base::Token& token);

  // Creates a Token from `j_token`.
  static base::Token FromJavaToken(JNIEnv* env,
                                   const JavaRef<jobject>& j_token);

  TokenAndroid() = delete;
  TokenAndroid(const TokenAndroid&) = delete;
  TokenAndroid& operator=(const TokenAndroid&) = delete;
};

}  // namespace base::android

namespace jni_zero {
template <>
inline base::Token FromJniType<base::Token>(JNIEnv* env,
                                            const JavaRef<jobject>& j_object) {
  return base::android::TokenAndroid::FromJavaToken(env, j_object);
}
template <>
inline ScopedJavaLocalRef<jobject> ToJniType<base::Token>(
    JNIEnv* env,
    const base::Token& token) {
  return base::android::TokenAndroid::Create(env, token);
}
}  // namespace jni_zero

#endif  // BASE_ANDROID_TOKEN_ANDROID_H_