| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_ANDROID_JNI_ANDROID_H_ | 5 #ifndef BASE_ANDROID_JNI_ANDROID_H_ |
| 6 #define BASE_ANDROID_JNI_ANDROID_H_ | 6 #define BASE_ANDROID_JNI_ANDROID_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 // Returns true if the global JVM has been initialized. | 47 // Returns true if the global JVM has been initialized. |
| 48 BASE_EXPORT bool IsVMInitialized(); | 48 BASE_EXPORT bool IsVMInitialized(); |
| 49 | 49 |
| 50 // Initializes the global application context object. The |context| can be any | 50 // Initializes the global application context object. The |context| can be any |
| 51 // valid reference to the application context. Internally holds a global ref to | 51 // valid reference to the application context. Internally holds a global ref to |
| 52 // the context. InitVM and InitApplicationContext maybe called in either order. | 52 // the context. InitVM and InitApplicationContext maybe called in either order. |
| 53 BASE_EXPORT void InitApplicationContext(JNIEnv* env, | 53 BASE_EXPORT void InitApplicationContext(JNIEnv* env, |
| 54 const JavaRef<jobject>& context); | 54 const JavaRef<jobject>& context); |
| 55 | 55 |
| 56 // Initializes the global ClassLoader used by the GetClass and LazyGetClass |
| 57 // methods. This is needed because JNI will use the base ClassLoader when there |
| 58 // is no Java code on the stack. The base ClassLoader doesn't know about any of |
| 59 // the application classes and will fail to lookup anything other than system |
| 60 // classes. |
| 61 BASE_EXPORT void InitReplacementClassLoader( |
| 62 JNIEnv* env, |
| 63 const JavaRef<jobject>& class_loader); |
| 64 |
| 56 // Gets a global ref to the application context set with | 65 // Gets a global ref to the application context set with |
| 57 // InitApplicationContext(). Ownership is retained by the function - the caller | 66 // InitApplicationContext(). Ownership is retained by the function - the caller |
| 58 // must NOT release it. | 67 // must NOT release it. |
| 59 const BASE_EXPORT jobject GetApplicationContext(); | 68 const BASE_EXPORT jobject GetApplicationContext(); |
| 60 | 69 |
| 61 // Finds the class named |class_name| and returns it. | 70 // Finds the class named |class_name| and returns it. |
| 62 // Use this method instead of invoking directly the JNI FindClass method (to | 71 // Use this method instead of invoking directly the JNI FindClass method (to |
| 63 // prevent leaking local references). | 72 // prevent leaking local references). |
| 64 // This method triggers a fatal assertion if the class could not be found. | 73 // This method triggers a fatal assertion if the class could not be found. |
| 65 // Use HasClass if you need to check whether the class exists. | 74 // Use HasClass if you need to check whether the class exists. |
| 66 BASE_EXPORT ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env, | 75 BASE_EXPORT ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env, |
| 67 const char* class_name); | 76 const char* class_name); |
| 68 | 77 |
| 78 // The method will initialize |atomic_class_id| to contain a global ref to the |
| 79 // class. And will return that ref on subsequent calls. It's the caller's |
| 80 // responsibility to release the ref when it is no longer needed. |
| 81 // The caller is responsible to zero-initialize |atomic_method_id|. |
| 82 // It's fine to simultaneously call this on multiple threads referencing the |
| 83 // same |atomic_method_id|. |
| 84 BASE_EXPORT jclass LazyGetClass( |
| 85 JNIEnv* env, |
| 86 const char* class_name, |
| 87 base::subtle::AtomicWord* atomic_class_id); |
| 88 |
| 69 // This class is a wrapper for JNIEnv Get(Static)MethodID. | 89 // This class is a wrapper for JNIEnv Get(Static)MethodID. |
| 70 class BASE_EXPORT MethodID { | 90 class BASE_EXPORT MethodID { |
| 71 public: | 91 public: |
| 72 enum Type { | 92 enum Type { |
| 73 TYPE_STATIC, | 93 TYPE_STATIC, |
| 74 TYPE_INSTANCE, | 94 TYPE_INSTANCE, |
| 75 }; | 95 }; |
| 76 | 96 |
| 77 // Returns the method ID for the method with the specified name and signature. | 97 // Returns the method ID for the method with the specified name and signature. |
| 78 // This method triggers a fatal assertion if the method could not be found. | 98 // This method triggers a fatal assertion if the method could not be found. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 100 // and returns true. | 120 // and returns true. |
| 101 BASE_EXPORT bool ClearException(JNIEnv* env); | 121 BASE_EXPORT bool ClearException(JNIEnv* env); |
| 102 | 122 |
| 103 // This function will call CHECK() macro if there's any pending exception. | 123 // This function will call CHECK() macro if there's any pending exception. |
| 104 BASE_EXPORT void CheckException(JNIEnv* env); | 124 BASE_EXPORT void CheckException(JNIEnv* env); |
| 105 | 125 |
| 106 } // namespace android | 126 } // namespace android |
| 107 } // namespace base | 127 } // namespace base |
| 108 | 128 |
| 109 #endif // BASE_ANDROID_JNI_ANDROID_H_ | 129 #endif // BASE_ANDROID_JNI_ANDROID_H_ |
| OLD | NEW |