blob: 5145c108e66ad2c3da1e8ae91ca1d574a5c05f1f [file] [log] [blame]
magjed768c6482016-12-06 04:29:37 -08001/*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11// Android's FindClass() is trickier than usual because the app-specific
12// ClassLoader is not consulted when there is no app-specific frame on the
13// stack. Consequently, we only look up all classes once in app/webrtc.
14// http://developer.android.com/training/articles/perf-jni.html#faq_FindClass
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#ifndef SDK_ANDROID_SRC_JNI_CLASSREFERENCEHOLDER_H_
17#define SDK_ANDROID_SRC_JNI_CLASSREFERENCEHOLDER_H_
magjed768c6482016-12-06 04:29:37 -080018
Magnus Jedvert3111e5f2017-11-07 12:33:43 +010019// TODO(magjed): Remove this whole file and replace with either generated JNI
20// code or class_loader.h.
21
magjed768c6482016-12-06 04:29:37 -080022#include <jni.h>
23#include <map>
24#include <string>
25
magjeda3d4f682017-08-28 16:24:06 -070026namespace webrtc {
27namespace jni {
magjed768c6482016-12-06 04:29:37 -080028
29// LoadGlobalClassReferenceHolder must be called in JNI_OnLoad.
30void LoadGlobalClassReferenceHolder();
31// FreeGlobalClassReferenceHolder must be called in JNI_UnLoad.
32void FreeGlobalClassReferenceHolder();
33
Magnus Jedvert3111e5f2017-11-07 12:33:43 +010034// Deprecated. Most cases of finding classes should be done with generated JNI
35// code, and the few remaining cases should use the function from
36// class_loader.h.
magjed768c6482016-12-06 04:29:37 -080037// Returns a global reference guaranteed to be valid for the lifetime of the
38// process.
39jclass FindClass(JNIEnv* jni, const char* name);
40
magjeda3d4f682017-08-28 16:24:06 -070041} // namespace jni
42} // namespace webrtc
43
44// TODO(magjed): Remove once external clients are updated.
45namespace webrtc_jni {
46
47using webrtc::jni::LoadGlobalClassReferenceHolder;
48using webrtc::jni::FreeGlobalClassReferenceHolder;
49
magjed768c6482016-12-06 04:29:37 -080050} // namespace webrtc_jni
51
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020052#endif // SDK_ANDROID_SRC_JNI_CLASSREFERENCEHOLDER_H_