Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: base/android/jni_android.h

Issue 1407233017: Define a Java-side global application context. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Undo changes to ApplicationStatus Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include <string> 11 #include <string>
12 12
13 // TODO(torne): remove this when callers of GetApplicationContext have been
14 // fixed to include context_utils.h. http://crbug.com/552419
15 #include "base/android/context_utils.h"
13 #include "base/android/scoped_java_ref.h" 16 #include "base/android/scoped_java_ref.h"
14 #include "base/atomicops.h" 17 #include "base/atomicops.h"
15 #include "base/base_export.h" 18 #include "base/base_export.h"
16 #include "base/compiler_specific.h" 19 #include "base/compiler_specific.h"
17 20
18 namespace base { 21 namespace base {
19 namespace android { 22 namespace android {
20 23
21 // Used to mark symbols to be exported in a shared library's symbol table. 24 // Used to mark symbols to be exported in a shared library's symbol table.
22 #define JNI_EXPORT __attribute__ ((visibility("default"))) 25 #define JNI_EXPORT __attribute__ ((visibility("default")))
(...skipping 17 matching lines...) Expand all
40 // Same to AttachCurrentThread except that thread name will be set to 43 // Same to AttachCurrentThread except that thread name will be set to
41 // |thread_name| if it is the first call. Otherwise, thread_name won't be 44 // |thread_name| if it is the first call. Otherwise, thread_name won't be
42 // changed. AttachCurrentThread() doesn't regard underlying platform thread 45 // changed. AttachCurrentThread() doesn't regard underlying platform thread
43 // name, but just resets it to "Thread-???". This function should be called 46 // name, but just resets it to "Thread-???". This function should be called
44 // right after new thread is created if it is important to keep thread name. 47 // right after new thread is created if it is important to keep thread name.
45 BASE_EXPORT JNIEnv* AttachCurrentThreadWithName(const std::string& thread_name); 48 BASE_EXPORT JNIEnv* AttachCurrentThreadWithName(const std::string& thread_name);
46 49
47 // Detaches the current thread from VM if it is attached. 50 // Detaches the current thread from VM if it is attached.
48 BASE_EXPORT void DetachFromVM(); 51 BASE_EXPORT void DetachFromVM();
49 52
50 // Initializes the global JVM. It is not necessarily called before 53 // Initializes the global JVM.
51 // InitApplicationContext().
52 BASE_EXPORT void InitVM(JavaVM* vm); 54 BASE_EXPORT void InitVM(JavaVM* vm);
53 55
54 // Returns true if the global JVM has been initialized. 56 // Returns true if the global JVM has been initialized.
55 BASE_EXPORT bool IsVMInitialized(); 57 BASE_EXPORT bool IsVMInitialized();
56 58
57 // Initializes the global application context object. The |context| can be any
58 // valid reference to the application context. Internally holds a global ref to
59 // the context. InitVM and InitApplicationContext maybe called in either order.
60 BASE_EXPORT void InitApplicationContext(JNIEnv* env,
61 const JavaRef<jobject>& context);
62
63 // Initializes the global ClassLoader used by the GetClass and LazyGetClass 59 // Initializes the global ClassLoader used by the GetClass and LazyGetClass
64 // methods. This is needed because JNI will use the base ClassLoader when there 60 // methods. This is needed because JNI will use the base ClassLoader when there
65 // is no Java code on the stack. The base ClassLoader doesn't know about any of 61 // is no Java code on the stack. The base ClassLoader doesn't know about any of
66 // the application classes and will fail to lookup anything other than system 62 // the application classes and will fail to lookup anything other than system
67 // classes. 63 // classes.
68 BASE_EXPORT void InitReplacementClassLoader( 64 BASE_EXPORT void InitReplacementClassLoader(
69 JNIEnv* env, 65 JNIEnv* env,
70 const JavaRef<jobject>& class_loader); 66 const JavaRef<jobject>& class_loader);
71 67
72 // Gets a global ref to the application context set with
73 // InitApplicationContext(). Ownership is retained by the function - the caller
74 // must NOT release it.
75 const BASE_EXPORT jobject GetApplicationContext();
76
77 // Finds the class named |class_name| and returns it. 68 // Finds the class named |class_name| and returns it.
78 // Use this method instead of invoking directly the JNI FindClass method (to 69 // Use this method instead of invoking directly the JNI FindClass method (to
79 // prevent leaking local references). 70 // prevent leaking local references).
80 // This method triggers a fatal assertion if the class could not be found. 71 // This method triggers a fatal assertion if the class could not be found.
81 // Use HasClass if you need to check whether the class exists. 72 // Use HasClass if you need to check whether the class exists.
82 BASE_EXPORT ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env, 73 BASE_EXPORT ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env,
83 const char* class_name); 74 const char* class_name);
84 75
85 // The method will initialize |atomic_class_id| to contain a global ref to the 76 // The method will initialize |atomic_class_id| to contain a global ref to the
86 // class. And will return that ref on subsequent calls. It's the caller's 77 // class. And will return that ref on subsequent calls. It's the caller's
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 BASE_EXPORT void CheckException(JNIEnv* env); 122 BASE_EXPORT void CheckException(JNIEnv* env);
132 123
133 // This returns a string representation of the java stack trace. 124 // This returns a string representation of the java stack trace.
134 BASE_EXPORT std::string GetJavaExceptionInfo(JNIEnv* env, 125 BASE_EXPORT std::string GetJavaExceptionInfo(JNIEnv* env,
135 jthrowable java_throwable); 126 jthrowable java_throwable);
136 127
137 } // namespace android 128 } // namespace android
138 } // namespace base 129 } // namespace base
139 130
140 #endif // BASE_ANDROID_JNI_ANDROID_H_ 131 #endif // BASE_ANDROID_JNI_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698