summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-16 18:35:10 +0000
committerbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-16 18:35:10 +0000
commitc410a2cb9f7120b5c1e6a83ff54b53b19cae79d3 (patch)
treeea2a3871c5bae617dd9ceb8e8418f84cd60e74bd /ui
parent784ba78a56c2e541bff04fdc54e8ea8a235c14f0 (diff)
downloadchromium_src-c410a2cb9f7120b5c1e6a83ff54b53b19cae79d3.zip
chromium_src-c410a2cb9f7120b5c1e6a83ff54b53b19cae79d3.tar.gz
chromium_src-c410a2cb9f7120b5c1e6a83ff54b53b19cae79d3.tar.bz2
Android: lazy initialization for method id.
Rather than requiring early registration for all method id, we can initialize them lazily as required. This solves the problem of building against SDK X but running against X - 1. Also adds a microbenchmark to ensure there are no considerable regressions. Results are a bit variable, but it hovers over: [ERROR:jni_android_unittest.cc(125)] JNI LazyMethodIDCall (us) 1983 [ERROR:jni_android_unittest.cc(127)] JNI MethodIDCall (us) 1862 BUG=152987 TEST=JNIAndroidMicrobenchmark.MethodId TBR=akalin Review URL: https://chromiumcodereview.appspot.com/11038015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162186 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/base/clipboard/clipboard_android.cc23
-rw-r--r--ui/base/clipboard/clipboard_unittest.cc10
2 files changed, 18 insertions, 15 deletions
diff --git a/ui/base/clipboard/clipboard_android.cc b/ui/base/clipboard/clipboard_android.cc
index 19d5752..4d310fb 100644
--- a/ui/base/clipboard/clipboard_android.cc
+++ b/ui/base/clipboard/clipboard_android.cc
@@ -25,7 +25,7 @@ using base::android::ClearException;
using base::android::ConvertJavaStringToUTF16;
using base::android::ConvertJavaStringToUTF8;
using base::android::GetClass;
-using base::android::GetMethodID;
+using base::android::MethodID;
using base::android::ScopedJavaLocalRef;
namespace ui {
@@ -75,8 +75,9 @@ ClipboardMap::ClipboardMap() {
GetClass(env, "android/content/Context");
// Get the system service method.
- jmethodID get_system_service = GetMethodID(env, context_class,
- "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");
+ jmethodID get_system_service = MethodID::Get<MethodID::TYPE_INSTANCE>(
+ env, context_class.obj(), "getSystemService",
+ "(Ljava/lang/String;)Ljava/lang/Object;");
// Retrieve the system service.
ScopedJavaLocalRef<jstring> service_name(env, env->NewStringUTF("clipboard"));
@@ -87,18 +88,18 @@ ClipboardMap::ClipboardMap() {
// Retain a few methods we'll keep using.
ScopedJavaLocalRef<jclass> clipboard_class =
GetClass(env, "android/text/ClipboardManager");
- set_text_ = GetMethodID(env, clipboard_class,
- "setText", "(Ljava/lang/CharSequence;)V");
- get_text_ = GetMethodID(env, clipboard_class,
- "getText", "()Ljava/lang/CharSequence;");
- has_text_ = GetMethodID(env, clipboard_class,
- "hasText", "()Z");
+ set_text_ = MethodID::Get<MethodID::TYPE_INSTANCE>(
+ env, clipboard_class.obj(), "setText", "(Ljava/lang/CharSequence;)V");
+ get_text_ = MethodID::Get<MethodID::TYPE_INSTANCE>(
+ env, clipboard_class.obj(), "getText", "()Ljava/lang/CharSequence;");
+ has_text_ = MethodID::Get<MethodID::TYPE_INSTANCE>(
+ env, clipboard_class.obj(), "hasText", "()Z");
// Will need to call toString as CharSequence is not always a String.
ScopedJavaLocalRef<jclass> charsequence_class =
GetClass(env, "java/lang/CharSequence");
- to_string_ = GetMethodID(env, charsequence_class,
- "toString", "()Ljava/lang/String;");
+ to_string_ = MethodID::Get<MethodID::TYPE_INSTANCE>(
+ env, charsequence_class.obj(), "toString", "()Ljava/lang/String;");
}
std::string ClipboardMap::Get(const std::string& format) {
diff --git a/ui/base/clipboard/clipboard_unittest.cc b/ui/base/clipboard/clipboard_unittest.cc
index e8b3d39..14a8915 100644
--- a/ui/base/clipboard/clipboard_unittest.cc
+++ b/ui/base/clipboard/clipboard_unittest.cc
@@ -646,6 +646,7 @@ TEST_F(ClipboardTest, InternalClipboardInvalidation) {
// Simulate that another application copied something in the Clipboard
//
std::string new_value("Some text copied by some other app");
+ using base::android::MethodID;
using base::android::ScopedJavaLocalRef;
JNIEnv* env = base::android::AttachCurrentThread();
@@ -657,8 +658,9 @@ TEST_F(ClipboardTest, InternalClipboardInvalidation) {
ScopedJavaLocalRef<jclass> context_class =
base::android::GetClass(env, "android/content/Context");
- jmethodID get_system_service = base::android::GetMethodID(env, context_class,
- "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");
+ jmethodID get_system_service = MethodID::Get<MethodID::TYPE_INSTANCE>(
+ env, context_class.obj(), "getSystemService",
+ "(Ljava/lang/String;)Ljava/lang/Object;");
// Retrieve the system service.
ScopedJavaLocalRef<jstring> service_name(env, env->NewStringUTF("clipboard"));
@@ -669,8 +671,8 @@ TEST_F(ClipboardTest, InternalClipboardInvalidation) {
ScopedJavaLocalRef<jclass> clipboard_class =
base::android::GetClass(env, "android/text/ClipboardManager");
- jmethodID set_text = base::android::GetMethodID(env, clipboard_class,
- "setText", "(Ljava/lang/CharSequence;)V");
+ jmethodID set_text = MethodID::Get<MethodID::TYPE_INSTANCE>(
+ env, clipboard_class.obj(), "setText", "(Ljava/lang/CharSequence;)V");
// Will need to call toString as CharSequence is not always a String.
env->CallVoidMethod(clipboard_manager.obj(),