summaryrefslogtreecommitdiffstats
path: root/sync/util
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 /sync/util
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 'sync/util')
-rw-r--r--sync/util/session_utils_android.cc12
1 files changed, 8 insertions, 4 deletions
diff --git a/sync/util/session_utils_android.cc b/sync/util/session_utils_android.cc
index 69f1ae4..7be415d 100644
--- a/sync/util/session_utils_android.cc
+++ b/sync/util/session_utils_android.cc
@@ -17,6 +17,7 @@ using base::android::CheckException;
using base::android::ConvertUTF8ToJavaString;
using base::android::GetApplicationContext;
using base::android::GetClass;
+using base::android::MethodID;
using base::android::JavaRef;
using base::android::ScopedJavaLocalRef;
@@ -26,9 +27,10 @@ ScopedJavaLocalRef<jstring> GetAndroidIdJNI(
JNIEnv* env, const JavaRef<jobject>& content_resolver) {
ScopedJavaLocalRef<jclass> clazz(
GetClass(env, "android/provider/Settings$Secure"));
- jmethodID j_get_string = GetStaticMethodID(env, clazz, "getString",
+ jmethodID j_get_string = MethodID::Get<MethodID::TYPE_STATIC>(
+ env, clazz.obj(), "getString",
"(Landroid/content/ContentResolver;Ljava/lang/String;)"
- "Ljava/lang/String;");
+ "Ljava/lang/String;");
ScopedJavaLocalRef<jstring> j_android_id =
ConvertUTF8ToJavaString(env, "android_id");
jstring android_id = static_cast<jstring>(
@@ -41,8 +43,10 @@ ScopedJavaLocalRef<jstring> GetAndroidIdJNI(
ScopedJavaLocalRef<jobject> GetContentResolver(JNIEnv* env) {
ScopedJavaLocalRef<jclass> clazz(GetClass(env, "android/content/Context"));
- jmethodID j_get_content_resolver_method = GetMethodID(
- env, clazz,"getContentResolver", "()Landroid/content/ContentResolver;");
+ jmethodID j_get_content_resolver_method = MethodID::Get<
+ MethodID::TYPE_INSTANCE>(
+ env, clazz.obj(), "getContentResolver",
+ "()Landroid/content/ContentResolver;");
jobject content_resolver = env->CallObjectMethod(
GetApplicationContext(), j_get_content_resolver_method);
CheckException(env);