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

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

Issue 8769005: Don't use Singleton to cache JNI method IDs in Java Bridge (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated comments, share some constants 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') | base/android/jni_android.cc » ('J')
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
(...skipping 12 matching lines...) Expand all
23 23
24 // Initializes the global application context object. The |context| should be 24 // Initializes the global application context object. The |context| should be
25 // the global reference of application context object. It is not necessarily 25 // the global reference of application context object. It is not necessarily
26 // called after InitVM(). 26 // called after InitVM().
27 // TODO: We might combine InitVM() and InitApplicationContext() into one method. 27 // TODO: We might combine InitVM() and InitApplicationContext() into one method.
28 void InitApplicationContext(jobject context); 28 void InitApplicationContext(jobject context);
29 29
30 // Returns the application context assigned by InitApplicationContext(). 30 // Returns the application context assigned by InitApplicationContext().
31 jobject GetApplicationContext(); 31 jobject GetApplicationContext();
32 32
33 // Wraps a method ID. 33 // Gets the method ID from the class name. class_name and method must be valid
34 class MethodID { 34 // Java identifiers and jni_signature must a valid JNI signature. Clears the
35 public: 35 // pending Java exception and returns NULL if the method is not found. Caches
36 jmethodID id() { return id_; } 36 // results. Note that GetMethodID() below avoids a class lookup, but does not
37 protected: 37 // cache results.
38 // Gets the method ID from the class name. Clears the pending Java exception 38 jmethodID GetMethodIDFromClassName(JNIEnv* env,
39 // and returns NULL if the method is not found. Note that GetMethodID() below 39 const char* class_name,
40 // avoids a class lookup, so should be used in preference when possible. 40 const char* method,
41 MethodID(JNIEnv* env, const char* class_name, const char* method, 41 const char* jni_signature);
42 const char* jni_signature);
43 private:
44 jmethodID id_;
45 };
46 42
47 // Get the method ID for a method. Will clear the pending Java 43 // Get the method ID for a method. Will clear the pending Java
48 // exception and return 0 if the method is not found. 44 // exception and return 0 if the method is not found.
49 jmethodID GetMethodID(JNIEnv* env, 45 jmethodID GetMethodID(JNIEnv* env,
50 jclass clazz, 46 jclass clazz,
51 const char* const method, 47 const char* const method,
52 const char* const jni_signature); 48 const char* const jni_signature);
53 49
54 // Get the method ID for a class static method. Will clear the pending Java 50 // Get the method ID for a class static method. Will clear the pending Java
55 // exception and return 0 if the method is not found. 51 // exception and return 0 if the method is not found.
(...skipping 10 matching lines...) Expand all
66 const char* jni_signature); 62 const char* jni_signature);
67 63
68 // Returns true if an exception is pending in the provided JNIEnv*. If an 64 // Returns true if an exception is pending in the provided JNIEnv*. If an
69 // exception is pending, this function prints and then clears it. 65 // exception is pending, this function prints and then clears it.
70 bool CheckException(JNIEnv* env); 66 bool CheckException(JNIEnv* env);
71 67
72 } // namespace android 68 } // namespace android
73 } // namespace base 69 } // namespace base
74 70
75 #endif // BASE_ANDROID_JNI_ANDROID_H_ 71 #endif // BASE_ANDROID_JNI_ANDROID_H_
OLDNEW
« no previous file with comments | « no previous file | base/android/jni_android.cc » ('j') | base/android/jni_android.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698