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

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: 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 "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<MethodID::TYPE_INSTANCE>(
73 env, locale_class, "<init>", 73 env, locale_class.obj(), "<init>",
74 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); 74 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
75 ScopedJavaLocalRef<jobject> java_locale = NewJavaLocale( 75 ScopedJavaLocalRef<jobject> java_locale = NewJavaLocale(
76 env, locale_class, constructor_id, locale); 76 env, locale_class, constructor_id, locale);
77 ScopedJavaLocalRef<jobject> java_display_locale = NewJavaLocale( 77 ScopedJavaLocalRef<jobject> java_display_locale = NewJavaLocale(
78 env, locale_class, constructor_id, display_locale); 78 env, locale_class, constructor_id, display_locale);
79 79
80 jmethodID method_id = GetMethodID(env, locale_class, "getDisplayName", 80 jmethodID method_id = MethodID::Get<MethodID::TYPE_INSTANCE>(
81 "(Ljava/util/Locale;)Ljava/lang/String;"); 81 env, locale_class.obj(), "getDisplayName",
82 "(Ljava/util/Locale;)Ljava/lang/String;");
82 ScopedJavaLocalRef<jstring> java_result( 83 ScopedJavaLocalRef<jstring> java_result(
83 env, 84 env,
84 static_cast<jstring>(env->CallObjectMethod(java_locale.obj(), method_id, 85 static_cast<jstring>(env->CallObjectMethod(java_locale.obj(), method_id,
85 java_display_locale.obj()))); 86 java_display_locale.obj())));
86 return ConvertJavaStringToUTF16(java_result); 87 return ConvertJavaStringToUTF16(java_result);
87 } 88 }
88 89
89 bool RegisterLocaleUtils(JNIEnv* env) { 90 bool RegisterLocaleUtils(JNIEnv* env) {
90 return RegisterNativesImpl(env); 91 return RegisterNativesImpl(env);
91 } 92 }
92 93
93 } // namespace android 94 } // namespace android
94 } // namespace base 95 } // namespace base
OLDNEW
« no previous file with comments | « base/android/jni_generator/jni_generator_tests.py ('k') | chrome/browser/android/chrome_web_contents_delegate_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698