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

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

Issue 8894002: Clean up base::android::Init/GetApplicationContext() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/android/jni_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/android/scoped_java_ref.h"
12
11 namespace base { 13 namespace base {
12 namespace android { 14 namespace android {
13 15
14 // Attach the current thread to the VM (if necessary) and return the JNIEnv*. 16 // Attach the current thread to the VM (if necessary) and return the JNIEnv*.
15 JNIEnv* AttachCurrentThread(); 17 JNIEnv* AttachCurrentThread();
16 18
17 // Detach the current thread from VM if it is attached. 19 // Detach the current thread from VM if it is attached.
18 void DetachFromVM(); 20 void DetachFromVM();
19 21
20 // Initializes the global JVM. It is not necessarily called before 22 // Initializes the global JVM. It is not necessarily called before
21 // InitApplicationContext(). 23 // InitApplicationContext().
22 void InitVM(JavaVM* vm); 24 void InitVM(JavaVM* vm);
23 25
24 // Initializes the global application context object. The |context| should be 26 // Initializes the global application context object. The |context| can be any
25 // the global reference of application context object. It is not necessarily 27 // valid reference to the application context. Internally holds a global ref to
26 // called after InitVM(). 28 // the context. InitVM and InitApplicationContext maybe called in either order.
27 // TODO: We might combine InitVM() and InitApplicationContext() into one method. 29 // TODO: We might combine InitVM() and InitApplicationContext() into one method.
28 void InitApplicationContext(jobject context); 30 void InitApplicationContext(const JavaRef<jobject>& context);
29 31
30 // Returns the application context assigned by InitApplicationContext(). 32 // Gets a global ref to the application context set with
33 // InitApplicationContext(). Ownership is retained by the function - the caller
34 // must NOT release it.
31 jobject GetApplicationContext(); 35 jobject GetApplicationContext();
32 36
33 // Gets the method ID from the class name. Clears the pending Java exception 37 // Gets the method ID from the class name. Clears the pending Java exception
34 // and returns NULL if the method is not found. Caches results. Note that 38 // and returns NULL if the method is not found. Caches results. Note that
35 // GetMethodID() below avoids a class lookup, but does not cache results. 39 // GetMethodID() below avoids a class lookup, but does not cache results.
36 // Strings passed to this function are held in the cache and MUST remain valid 40 // Strings passed to this function are held in the cache and MUST remain valid
37 // beyond the duration of all future calls to this function, across all 41 // beyond the duration of all future calls to this function, across all
38 // threads. In practice, this means that the function should only be used with 42 // threads. In practice, this means that the function should only be used with
39 // string constants. 43 // string constants.
40 jmethodID GetMethodIDFromClassName(JNIEnv* env, 44 jmethodID GetMethodIDFromClassName(JNIEnv* env,
(...skipping 23 matching lines...) Expand all
64 const char* jni_signature); 68 const char* jni_signature);
65 69
66 // Returns true if an exception is pending in the provided JNIEnv*. If an 70 // Returns true if an exception is pending in the provided JNIEnv*. If an
67 // exception is pending, this function prints and then clears it. 71 // exception is pending, this function prints and then clears it.
68 bool CheckException(JNIEnv* env); 72 bool CheckException(JNIEnv* env);
69 73
70 } // namespace android 74 } // namespace android
71 } // namespace base 75 } // namespace base
72 76
73 #endif // BASE_ANDROID_JNI_ANDROID_H_ 77 #endif // BASE_ANDROID_JNI_ANDROID_H_
OLDNEW
« no previous file with comments | « no previous file | base/android/jni_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698