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

Side by Side Diff: base/android/locale_utils.cc

Issue 11038015: Android: lazy initialization for method id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moves to MethodID 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 "base/android/locale_utils.h" 5 #include "base/android/locale_utils.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/android/scoped_java_ref.h" 9 #include "base/android/scoped_java_ref.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 ConvertUTF8ToJavaString(env, variant).obj())); 62 ConvertUTF8ToJavaString(env, variant).obj()));
63 } 63 }
64 64
65 } // namespace 65 } // namespace
66 66
67 string16 GetDisplayNameForLocale(const std::string& locale, 67 string16 GetDisplayNameForLocale(const std::string& locale,
68 const std::string& display_locale) { 68 const std::string& display_locale) {
69 JNIEnv* env = AttachCurrentThread(); 69 JNIEnv* env = AttachCurrentThread();
70 70
71 ScopedJavaLocalRef<jclass> locale_class = GetClass(env, "java/util/Locale"); 71 ScopedJavaLocalRef<jclass> locale_class = GetClass(env, "java/util/Locale");
72 jmethodID constructor_id = GetMethodID( 72 jmethodID constructor_id = MethodID::Get<
73 env, locale_class, "<init>", 73 MethodID::METHODTYPE_NORMAL, MethodID::EXCEPTIONCHECK_YES>(
74 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); 74 env, locale_class.obj(), "<init>",
75 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
75 ScopedJavaLocalRef<jobject> java_locale = NewJavaLocale( 76 ScopedJavaLocalRef<jobject> java_locale = NewJavaLocale(
76 env, locale_class, constructor_id, locale); 77 env, locale_class, constructor_id, locale);
77 ScopedJavaLocalRef<jobject> java_display_locale = NewJavaLocale( 78 ScopedJavaLocalRef<jobject> java_display_locale = NewJavaLocale(
78 env, locale_class, constructor_id, display_locale); 79 env, locale_class, constructor_id, display_locale);
79 80
80 jmethodID method_id = GetMethodID(env, locale_class, "getDisplayName", 81 jmethodID method_id = MethodID::Get<
81 "(Ljava/util/Locale;)Ljava/lang/String;"); 82 MethodID::METHODTYPE_NORMAL, MethodID::EXCEPTIONCHECK_YES>(
83 env, locale_class.obj(), "getDisplayName",
84 "(Ljava/util/Locale;)Ljava/lang/String;");
82 ScopedJavaLocalRef<jstring> java_result( 85 ScopedJavaLocalRef<jstring> java_result(
83 env, 86 env,
84 static_cast<jstring>(env->CallObjectMethod(java_locale.obj(), method_id, 87 static_cast<jstring>(env->CallObjectMethod(java_locale.obj(), method_id,
85 java_display_locale.obj()))); 88 java_display_locale.obj())));
86 return ConvertJavaStringToUTF16(java_result); 89 return ConvertJavaStringToUTF16(java_result);
87 } 90 }
88 91
89 bool RegisterLocaleUtils(JNIEnv* env) { 92 bool RegisterLocaleUtils(JNIEnv* env) {
90 return RegisterNativesImpl(env); 93 return RegisterNativesImpl(env);
91 } 94 }
92 95
93 } // namespace android 96 } // namespace android
94 } // namespace base 97 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698