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

Side by Side Diff: content/browser/renderer_host/java/java_method.cc

Issue 11038015: Android: lazy initialization for method id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 2 months 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
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 #include "content/browser/renderer_host/java/java_method.h" 5 #include "content/browser/renderer_host/java/java_method.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
11 #include "base/string_util.h" // For ReplaceSubstringsAfterOffset 11 #include "base/string_util.h" // For ReplaceSubstringsAfterOffset
12 12
13 using base::android::AttachCurrentThread; 13 using base::android::AttachCurrentThread;
14 using base::android::ConvertJavaStringToUTF8; 14 using base::android::ConvertJavaStringToUTF8;
15 using base::android::GetClass; 15 using base::android::GetClass;
16 using base::android::GetMethodID;
17 using base::android::GetMethodIDFromClassName; 16 using base::android::GetMethodIDFromClassName;
18 using base::android::GetStaticMethodID; 17 using base::android::MethodID;
19 using base::android::ScopedJavaGlobalRef; 18 using base::android::ScopedJavaGlobalRef;
20 using base::android::ScopedJavaLocalRef; 19 using base::android::ScopedJavaLocalRef;
21 20
22 namespace { 21 namespace {
23 22
24 const char kGetName[] = "getName"; 23 const char kGetName[] = "getName";
25 const char kGetDeclaringClass[] = "getDeclaringClass"; 24 const char kGetDeclaringClass[] = "getDeclaringClass";
26 const char kGetModifiers[] = "getModifiers"; 25 const char kGetModifiers[] = "getModifiers";
27 const char kGetParameterTypes[] = "getParameterTypes"; 26 const char kGetParameterTypes[] = "getParameterTypes";
28 const char kGetReturnType[] = "getReturnType"; 27 const char kGetReturnType[] = "getReturnType";
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 &return_type_); 206 &return_type_);
208 207
209 // Determine whether the method is static. 208 // Determine whether the method is static.
210 jint modifiers = env->CallIntMethod( 209 jint modifiers = env->CallIntMethod(
211 java_method_.obj(), GetMethodIDFromClassName(env, 210 java_method_.obj(), GetMethodIDFromClassName(env,
212 kJavaLangReflectMethod, 211 kJavaLangReflectMethod,
213 kGetModifiers, 212 kGetModifiers,
214 kReturningInteger)); 213 kReturningInteger));
215 bool is_static = env->CallStaticBooleanMethod( 214 bool is_static = env->CallStaticBooleanMethod(
216 g_java_lang_reflect_modifier_class.Get().obj(), 215 g_java_lang_reflect_modifier_class.Get().obj(),
217 GetStaticMethodID(env, g_java_lang_reflect_modifier_class.Get(), 216 MethodID::Get<MethodID::TYPE_STATIC>(
218 kIsStatic, 217 env, g_java_lang_reflect_modifier_class.Get().obj(), kIsStatic,
219 kIntegerReturningBoolean), 218 kIntegerReturningBoolean),
220 modifiers); 219 modifiers);
221 220
222 // Get the ID for this method. 221 // Get the ID for this method.
223 ScopedJavaLocalRef<jclass> declaring_class(env, static_cast<jclass>( 222 ScopedJavaLocalRef<jclass> declaring_class(env, static_cast<jclass>(
224 env->CallObjectMethod(java_method_.obj(), GetMethodIDFromClassName( 223 env->CallObjectMethod(java_method_.obj(), GetMethodIDFromClassName(
225 env, 224 env,
226 kJavaLangReflectMethod, 225 kJavaLangReflectMethod,
227 kGetDeclaringClass, 226 kGetDeclaringClass,
228 kReturningJavaLangClass)))); 227 kReturningJavaLangClass))));
229 id_ = is_static ? 228 id_ = is_static ?
230 GetStaticMethodID(env, declaring_class, name_.c_str(), 229 MethodID::Get<MethodID::TYPE_STATIC>(
231 signature.c_str()) : 230 env, declaring_class.obj(), name_.c_str(), signature.c_str()) :
232 GetMethodID(env, declaring_class, name_.c_str(), signature.c_str()); 231 MethodID::Get<MethodID::TYPE_INSTANCE>(
232 env, declaring_class.obj(), name_.c_str(), signature.c_str());
233 java_method_.Reset(); 233 java_method_.Reset();
234 } 234 }
OLDNEW
« no previous file with comments | « content/browser/geolocation/location_api_adapter_android.cc ('k') | content/common/android/surface_callback.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698