Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/autofill/android/personal_data_manager_android.h" | 5 #include "chrome/browser/autofill/android/personal_data_manager_android.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 | 303 |
| 304 ScopedJavaGlobalRef<jobject> jdelegate_; | 304 ScopedJavaGlobalRef<jobject> jdelegate_; |
| 305 std::string guid_; | 305 std::string guid_; |
| 306 std::string region_code_; | 306 std::string region_code_; |
| 307 base::WeakPtr<PersonalDataManagerAndroid> personal_data_manager_android_; | 307 base::WeakPtr<PersonalDataManagerAndroid> personal_data_manager_android_; |
| 308 JNIEnv* env_; | 308 JNIEnv* env_; |
| 309 | 309 |
| 310 DISALLOW_COPY_AND_ASSIGN(AddressNormalizationRequester); | 310 DISALLOW_COPY_AND_ASSIGN(AddressNormalizationRequester); |
| 311 }; | 311 }; |
| 312 | 312 |
| 313 class GetSubKeysRequester : public PersonalDataManagerAndroid::Delegate, | |
| 314 public base::SupportsWeakPtr<GetSubKeysRequester> { | |
| 315 public: | |
| 316 GetSubKeysRequester( | |
| 317 JNIEnv* env, | |
| 318 const base::android::JavaParamRef<jobject>& jdelegate, | |
| 319 const std::string& region_code, | |
| 320 base::WeakPtr<PersonalDataManagerAndroid> personal_data_manager_android) { | |
| 321 jdelegate_.Reset(env, jdelegate); | |
| 322 region_code_ = region_code; | |
| 323 personal_data_manager_android_ = personal_data_manager_android; | |
| 324 env_ = env; | |
| 325 } | |
| 326 | |
| 327 private: | |
| 328 ~GetSubKeysRequester() override {} | |
| 329 | |
| 330 void OnRulesSuccessfullyLoaded() override { | |
| 331 if (personal_data_manager_android_) { | |
| 332 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 333 Java_GetSubKeysRequestDelegate_onSubKeysReceived( | |
| 334 env, jdelegate_, | |
| 335 personal_data_manager_android_->GetSubKeys(env, region_code_)); | |
| 336 } | |
| 337 } | |
| 338 | |
| 339 ScopedJavaGlobalRef<jobject> jdelegate_; | |
| 340 std::string region_code_; | |
| 341 base::WeakPtr<PersonalDataManagerAndroid> personal_data_manager_android_; | |
| 342 JNIEnv* env_; | |
| 343 | |
| 344 DISALLOW_COPY_AND_ASSIGN(GetSubKeysRequester); | |
| 345 }; | |
| 346 | |
| 313 } // namespace | 347 } // namespace |
| 314 | 348 |
| 315 PersonalDataManagerAndroid::PersonalDataManagerAndroid(JNIEnv* env, jobject obj) | 349 PersonalDataManagerAndroid::PersonalDataManagerAndroid(JNIEnv* env, jobject obj) |
| 316 : weak_java_obj_(env, obj), | 350 : weak_java_obj_(env, obj), |
| 317 personal_data_manager_(PersonalDataManagerFactory::GetForProfile( | 351 personal_data_manager_(PersonalDataManagerFactory::GetForProfile( |
| 318 ProfileManager::GetActiveUserProfile())), | 352 ProfileManager::GetActiveUserProfile())), |
| 319 address_validator_( | 353 address_validator_( |
| 320 std::unique_ptr<::i18n::addressinput::Source>( | 354 std::unique_ptr<::i18n::addressinput::Source>( |
| 321 new autofill::ChromeMetadataSource( | 355 new autofill::ChromeMetadataSource( |
| 322 I18N_ADDRESS_VALIDATION_DATA_URL, | 356 I18N_ADDRESS_VALIDATION_DATA_URL, |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 785 | 819 |
| 786 return CreateJavaProfileFromNative(env, *profile); | 820 return CreateJavaProfileFromNative(env, *profile); |
| 787 } | 821 } |
| 788 | 822 |
| 789 void PersonalDataManagerAndroid::CancelPendingAddressNormalizations( | 823 void PersonalDataManagerAndroid::CancelPendingAddressNormalizations( |
| 790 JNIEnv* env, | 824 JNIEnv* env, |
| 791 const base::android::JavaParamRef<jobject>& unused_obj) { | 825 const base::android::JavaParamRef<jobject>& unused_obj) { |
| 792 pending_normalization_.clear(); | 826 pending_normalization_.clear(); |
| 793 } | 827 } |
| 794 | 828 |
| 829 base::android::ScopedJavaLocalRef<jobjectArray> | |
| 830 PersonalDataManagerAndroid::GetSubKeys(JNIEnv* env, | |
| 831 const std::string& region_code) { | |
| 832 std::vector<std::string> sub_keys = | |
| 833 address_validator_.GetRegionSubKeys(region_code); | |
| 834 return base::android::ToJavaArrayOfStrings(env, sub_keys); | |
| 835 } | |
| 836 | |
| 837 void PersonalDataManagerAndroid::OnGettingSubKeysRulesLoaded( | |
|
sebsg
2017/02/10 16:00:32
You probably don't need a second function here. Wh
Parastoo
2017/02/13 21:57:23
As discussed, we will keep the functions separated
| |
| 838 const std::string& region_code, | |
| 839 bool success) { | |
| 840 // Check if there is any sub-key request. | |
| 841 auto it = pending_subkeys_request_.find(region_code); | |
| 842 if (it != pending_subkeys_request_.end()) { | |
| 843 for (size_t i = 0; i < it->second.size(); ++i) { | |
| 844 it->second[i]->OnRulesSuccessfullyLoaded(); | |
| 845 } | |
| 846 pending_subkeys_request_.erase(it); | |
| 847 } | |
| 848 } | |
| 849 | |
| 850 void PersonalDataManagerAndroid::StartGettingRegionSubKeys( | |
| 851 JNIEnv* env, | |
| 852 const JavaParamRef<jobject>& unused_obj, | |
| 853 const JavaParamRef<jstring>& jregion_code, | |
| 854 const JavaParamRef<jobject>& jdelegate) { | |
| 855 const std::string region_code = ConvertJavaStringToUTF8(env, jregion_code); | |
| 856 std::unique_ptr<Delegate> requester( | |
| 857 new GetSubKeysRequester(env, jdelegate, region_code, AsWeakPtr())); | |
| 858 | |
| 859 if (AreRulesLoadedForRegion(region_code)) { | |
| 860 requester->OnRulesSuccessfullyLoaded(); | |
|
sebsg
2017/02/10 16:00:32
Since both RegionSubKeys and ValidationRules reque
Parastoo
2017/02/13 21:57:23
Same here.
| |
| 861 } else { | |
| 862 // Setup the variables so that the sub-keys request is sent, when the rules | |
| 863 // are loaded. | |
| 864 auto it = pending_subkeys_request_.find(region_code); | |
| 865 if (it == pending_subkeys_request_.end()) { | |
| 866 // If no entry exists, create the entry and assign it to |it|. | |
| 867 it = pending_subkeys_request_ | |
| 868 .insert(std::make_pair(region_code, | |
| 869 std::vector<std::unique_ptr<Delegate>>())) | |
| 870 .first; | |
| 871 } | |
| 872 it->second.push_back(std::move(requester)); | |
| 873 } | |
| 874 } | |
| 875 | |
| 876 void PersonalDataManagerAndroid::CancelPendingGetSubKeys( | |
| 877 JNIEnv* env, | |
| 878 const base::android::JavaParamRef<jobject>& unused_obj) { | |
| 879 pending_subkeys_request_.clear(); | |
| 880 } | |
| 881 | |
| 795 ScopedJavaLocalRef<jobjectArray> PersonalDataManagerAndroid::GetProfileGUIDs( | 882 ScopedJavaLocalRef<jobjectArray> PersonalDataManagerAndroid::GetProfileGUIDs( |
| 796 JNIEnv* env, | 883 JNIEnv* env, |
| 797 const std::vector<AutofillProfile*>& profiles) { | 884 const std::vector<AutofillProfile*>& profiles) { |
| 798 std::vector<base::string16> guids; | 885 std::vector<base::string16> guids; |
| 799 for (AutofillProfile* profile : profiles) | 886 for (AutofillProfile* profile : profiles) |
| 800 guids.push_back(base::UTF8ToUTF16(profile->guid())); | 887 guids.push_back(base::UTF8ToUTF16(profile->guid())); |
| 801 | 888 |
| 802 return base::android::ToJavaArrayOfStrings(env, guids); | 889 return base::android::ToJavaArrayOfStrings(env, guids); |
| 803 } | 890 } |
| 804 | 891 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 927 base::android::ConvertJavaStringToUTF16(env, jcountry_name))); | 1014 base::android::ConvertJavaStringToUTF16(env, jcountry_name))); |
| 928 } | 1015 } |
| 929 | 1016 |
| 930 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 1017 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 931 PersonalDataManagerAndroid* personal_data_manager_android = | 1018 PersonalDataManagerAndroid* personal_data_manager_android = |
| 932 new PersonalDataManagerAndroid(env, obj); | 1019 new PersonalDataManagerAndroid(env, obj); |
| 933 return reinterpret_cast<intptr_t>(personal_data_manager_android); | 1020 return reinterpret_cast<intptr_t>(personal_data_manager_android); |
| 934 } | 1021 } |
| 935 | 1022 |
| 936 } // namespace autofill | 1023 } // namespace autofill |
| OLD | NEW |