OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/android/autofill/country_adapter_android.h" | |
6 | |
7 #include "base/android/jni_array.h" | |
8 #include "base/android/jni_string.h" | |
9 #include "base/strings/utf_string_conversions.h" | |
10 #include "chrome/browser/autofill/personal_data_manager_factory.h" | |
11 #include "chrome/browser/profiles/profile_manager.h" | |
12 #include "components/autofill/core/browser/autofill_country.h" | |
13 #include "jni/CountryAdapter_jni.h" | |
14 | |
15 namespace autofill { | |
16 | |
17 CountryAdapterAndroid::CountryAdapterAndroid(JNIEnv* env, jobject obj) | |
18 : weak_java_obj_(env, obj) { | |
19 country_combobox_model_.SetCountries( | |
20 *PersonalDataManagerFactory::GetForProfile( | |
21 ProfileManager::GetActiveUserProfile()), | |
22 base::Callback<bool(const std::string&)>()); | |
23 } | |
24 | |
25 CountryAdapterAndroid::~CountryAdapterAndroid() {} | |
26 | |
27 ScopedJavaLocalRef<jobjectArray> CountryAdapterAndroid::GetItems( | |
28 JNIEnv* env, | |
29 jobject unused_obj) { | |
30 std::vector<base::string16> country_names_and_codes; | |
31 country_names_and_codes.reserve( | |
32 2 * country_combobox_model_.countries().size()); | |
33 | |
34 for (size_t i = 0; i < country_combobox_model_.countries().size(); ++i) { | |
35 country_names_and_codes.push_back( | |
36 country_combobox_model_.countries()[i]->name()); | |
37 country_names_and_codes.push_back(base::ASCIIToUTF16( | |
38 country_combobox_model_.countries()[i]->country_code())); | |
39 } | |
40 | |
41 return base::android::ToJavaArrayOfStrings(env, country_names_and_codes); | |
42 } | |
43 | |
44 // static | |
45 bool CountryAdapterAndroid::Register(JNIEnv* env) { | |
46 return RegisterNativesImpl(env); | |
47 } | |
48 | |
49 static jlong Init(JNIEnv* env, jobject obj) { | |
50 CountryAdapterAndroid* country_adapter_android = | |
51 new CountryAdapterAndroid(env, obj); | |
52 return reinterpret_cast<intptr_t>(country_adapter_android); | |
53 } | |
54 | |
55 } // namespace autofill | |
OLD | NEW |