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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 delete this; | 260 delete this; |
| 261 } | 261 } |
| 262 | 262 |
| 263 std::unique_ptr<CreditCard> card_; | 263 std::unique_ptr<CreditCard> card_; |
| 264 ScopedJavaGlobalRef<jobject> jdelegate_; | 264 ScopedJavaGlobalRef<jobject> jdelegate_; |
| 265 | 265 |
| 266 DISALLOW_COPY_AND_ASSIGN(FullCardRequester); | 266 DISALLOW_COPY_AND_ASSIGN(FullCardRequester); |
| 267 }; | 267 }; |
| 268 | 268 |
| 269 // Self-deleting requester of address normalization. | 269 // Self-deleting requester of address normalization. |
| 270 class AddressNormalizationRequester | 270 class AddressNormalizationRequester |
|
please use gerrit instead
2016/10/18 17:30:32
personal_data_manager_android controls the life-cy
sebsg
2016/10/18 22:44:32
Done.
| |
| 271 : public PersonalDataManagerAndroid::Delegate, | 271 : public PersonalDataManagerAndroid::Delegate, |
| 272 public base::SupportsWeakPtr<AddressNormalizationRequester> { | 272 public base::SupportsWeakPtr<AddressNormalizationRequester> { |
| 273 public: | 273 public: |
| 274 AddressNormalizationRequester( | 274 AddressNormalizationRequester( |
| 275 JNIEnv* env, | 275 JNIEnv* env, |
| 276 const base::android::JavaParamRef<jobject>& jdelegate, | 276 const base::android::JavaParamRef<jobject>& jdelegate, |
| 277 const std::string& region_code, | 277 const std::string& region_code, |
| 278 const std::string& guid, | 278 const std::string& guid, |
| 279 base::WeakPtr<PersonalDataManagerAndroid> personal_data_manager_android) { | 279 base::WeakPtr<PersonalDataManagerAndroid> personal_data_manager_android) { |
| 280 jdelegate_.Reset(env, jdelegate); | 280 jdelegate_.Reset(env, jdelegate); |
| 281 region_code_ = region_code; | 281 region_code_ = region_code; |
| 282 guid_ = guid; | 282 guid_ = guid; |
| 283 personal_data_manager_android_ = personal_data_manager_android; | 283 personal_data_manager_android_ = personal_data_manager_android; |
| 284 env_ = env; | 284 env_ = env; |
| 285 } | 285 } |
| 286 | 286 |
| 287 private: | 287 private: |
| 288 virtual ~AddressNormalizationRequester() {} | 288 ~AddressNormalizationRequester() override {} |
| 289 | 289 |
| 290 void OnRulesSuccessfullyLoaded() override { | 290 void OnRulesSuccessfullyLoaded() override { |
| 291 if (personal_data_manager_android_) { | 291 if (personal_data_manager_android_) { |
| 292 JNIEnv* env = base::android::AttachCurrentThread(); | 292 JNIEnv* env = base::android::AttachCurrentThread(); |
| 293 Java_NormalizedAddressRequestDelegate_onAddressNormalized( | 293 Java_NormalizedAddressRequestDelegate_onAddressNormalized( |
| 294 env, jdelegate_, personal_data_manager_android_->NormalizeAddress( | 294 env, jdelegate_, personal_data_manager_android_->NormalizeAddress( |
| 295 guid_, region_code_, env)); | 295 guid_, region_code_, env)); |
| 296 } | 296 } |
| 297 | 297 |
| 298 delete this; | 298 delete this; |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 const JavaParamRef<jobject>& unused_obj, | 573 const JavaParamRef<jobject>& unused_obj, |
| 574 const JavaParamRef<jstring>& jguid, | 574 const JavaParamRef<jstring>& jguid, |
| 575 jint count, | 575 jint count, |
| 576 jint date) { | 576 jint date) { |
| 577 DCHECK(count >= 0 && date >= 0); | 577 DCHECK(count >= 0 && date >= 0); |
| 578 | 578 |
| 579 AutofillProfile* profile = personal_data_manager_->GetProfileByGUID( | 579 AutofillProfile* profile = personal_data_manager_->GetProfileByGUID( |
| 580 ConvertJavaStringToUTF8(env, jguid)); | 580 ConvertJavaStringToUTF8(env, jguid)); |
| 581 profile->set_use_count(static_cast<size_t>(count)); | 581 profile->set_use_count(static_cast<size_t>(count)); |
| 582 profile->set_use_date(base::Time::FromTimeT(date)); | 582 profile->set_use_date(base::Time::FromTimeT(date)); |
| 583 | |
| 584 personal_data_manager_->UpdateProfileForTest(*profile); | |
|
please use gerrit instead
2016/10/18 17:30:32
No tests here, so let's not add this call until we
sebsg
2016/10/18 22:44:32
Done.
| |
| 583 personal_data_manager_->NotifyPersonalDataChangedForTest(); | 585 personal_data_manager_->NotifyPersonalDataChangedForTest(); |
| 584 } | 586 } |
| 585 | 587 |
| 586 jint PersonalDataManagerAndroid::GetProfileUseCountForTesting( | 588 jint PersonalDataManagerAndroid::GetProfileUseCountForTesting( |
| 587 JNIEnv* env, | 589 JNIEnv* env, |
| 588 const base::android::JavaParamRef<jobject>& unused_obj, | 590 const base::android::JavaParamRef<jobject>& unused_obj, |
| 589 const base::android::JavaParamRef<jstring>& jguid) { | 591 const base::android::JavaParamRef<jstring>& jguid) { |
| 590 AutofillProfile* profile = personal_data_manager_->GetProfileByGUID( | 592 AutofillProfile* profile = personal_data_manager_->GetProfileByGUID( |
| 591 ConvertJavaStringToUTF8(env, jguid)); | 593 ConvertJavaStringToUTF8(env, jguid)); |
| 592 return profile->use_count(); | 594 return profile->use_count(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 616 const JavaParamRef<jobject>& unused_obj, | 618 const JavaParamRef<jobject>& unused_obj, |
| 617 const JavaParamRef<jstring>& jguid, | 619 const JavaParamRef<jstring>& jguid, |
| 618 jint count, | 620 jint count, |
| 619 jint date) { | 621 jint date) { |
| 620 DCHECK(count >= 0 && date >= 0); | 622 DCHECK(count >= 0 && date >= 0); |
| 621 | 623 |
| 622 CreditCard* card = personal_data_manager_->GetCreditCardByGUID( | 624 CreditCard* card = personal_data_manager_->GetCreditCardByGUID( |
| 623 ConvertJavaStringToUTF8(env, jguid)); | 625 ConvertJavaStringToUTF8(env, jguid)); |
| 624 card->set_use_count(static_cast<size_t>(count)); | 626 card->set_use_count(static_cast<size_t>(count)); |
| 625 card->set_use_date(base::Time::FromTimeT(date)); | 627 card->set_use_date(base::Time::FromTimeT(date)); |
| 628 | |
| 629 personal_data_manager_->UpdateCreditCardForTest(*card); | |
|
please use gerrit instead
2016/10/18 17:30:32
Ditto
sebsg
2016/10/18 22:44:32
Done.
| |
| 626 personal_data_manager_->NotifyPersonalDataChangedForTest(); | 630 personal_data_manager_->NotifyPersonalDataChangedForTest(); |
| 627 } | 631 } |
| 628 | 632 |
| 629 jint PersonalDataManagerAndroid::GetCreditCardUseCountForTesting( | 633 jint PersonalDataManagerAndroid::GetCreditCardUseCountForTesting( |
| 630 JNIEnv* env, | 634 JNIEnv* env, |
| 631 const base::android::JavaParamRef<jobject>& unused_obj, | 635 const base::android::JavaParamRef<jobject>& unused_obj, |
| 632 const base::android::JavaParamRef<jstring>& jguid) { | 636 const base::android::JavaParamRef<jstring>& jguid) { |
| 633 CreditCard* card = personal_data_manager_->GetCreditCardByGUID( | 637 CreditCard* card = personal_data_manager_->GetCreditCardByGUID( |
| 634 ConvertJavaStringToUTF8(env, jguid)); | 638 ConvertJavaStringToUTF8(env, jguid)); |
| 635 return card->use_count(); | 639 return card->use_count(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 655 JNIEnv* env, | 659 JNIEnv* env, |
| 656 const base::android::JavaParamRef<jobject>& unused_obj, | 660 const base::android::JavaParamRef<jobject>& unused_obj, |
| 657 const base::android::JavaParamRef<jstring>& jregion_code) { | 661 const base::android::JavaParamRef<jstring>& jregion_code) { |
| 658 address_validator_.LoadRules(ConvertJavaStringToUTF8(env, jregion_code)); | 662 address_validator_.LoadRules(ConvertJavaStringToUTF8(env, jregion_code)); |
| 659 } | 663 } |
| 660 | 664 |
| 661 void PersonalDataManagerAndroid::OnAddressValidationRulesLoaded( | 665 void PersonalDataManagerAndroid::OnAddressValidationRulesLoaded( |
| 662 const std::string& region_code, | 666 const std::string& region_code, |
| 663 bool success) { | 667 bool success) { |
| 664 // Check if an address normalization is pending. | 668 // Check if an address normalization is pending. |
| 665 std::map<std::string, Delegate*>::iterator it = | 669 std::map<std::string, std::vector<Delegate*>>::iterator it = |
|
please use gerrit instead
2016/10/18 17:30:32
s/std::map<std::string, std::vector<Delegate*>>::i
sebsg
2016/10/18 22:44:32
Done.
| |
| 666 pending_normalization_.find(region_code); | 670 pending_normalization_.find(region_code); |
| 667 if (it != pending_normalization_.end()) { | 671 if (it != pending_normalization_.end()) { |
| 668 // The Delegate will self delete after normalizing. | 672 // Each Delegate will self delete after normalizing. |
|
please use gerrit instead
2016/10/18 17:30:32
Remove this comment, please.
sebsg
2016/10/18 22:44:32
Done.
| |
| 669 it->second->OnRulesSuccessfullyLoaded(); | 673 std::vector<Delegate*> delegates = it->second; |
|
please use gerrit instead
2016/10/18 17:30:32
std::vector<std::unique_ptr<Delegate>>
sebsg
2016/10/18 22:44:32
Done.
| |
| 674 for (size_t i = 0; i < it->second.size(); ++i) | |
|
please use gerrit instead
2016/10/18 17:30:32
s/it->second/delegates/
sebsg
2016/10/18 22:44:32
Done.
| |
| 675 it->second[i]->OnRulesSuccessfullyLoaded(); | |
|
please use gerrit instead
2016/10/18 17:30:32
s/it->second/delegates/
sebsg
2016/10/18 22:44:32
Done.
| |
| 670 pending_normalization_.erase(it); | 676 pending_normalization_.erase(it); |
|
please use gerrit instead
2016/10/18 17:30:32
This is the line that deletes the Delegate objects
sebsg
2016/10/18 22:44:32
Done.
| |
| 671 } | 677 } |
| 672 } | 678 } |
| 673 | 679 |
| 674 jboolean PersonalDataManagerAndroid::StartAddressNormalization( | 680 jboolean PersonalDataManagerAndroid::StartAddressNormalization( |
| 675 JNIEnv* env, | 681 JNIEnv* env, |
| 676 const JavaParamRef<jobject>& unused_obj, | 682 const JavaParamRef<jobject>& unused_obj, |
| 677 const JavaParamRef<jstring>& jguid, | 683 const JavaParamRef<jstring>& jguid, |
| 678 const JavaParamRef<jstring>& jregion_code, | 684 const JavaParamRef<jstring>& jregion_code, |
| 679 const JavaParamRef<jobject>& jdelegate) { | 685 const JavaParamRef<jobject>& jdelegate) { |
| 680 const std::string region_code = ConvertJavaStringToUTF8(env, jregion_code); | 686 const std::string region_code = ConvertJavaStringToUTF8(env, jregion_code); |
| 681 const std::string guid = ConvertJavaStringToUTF8(env, jguid); | 687 const std::string guid = ConvertJavaStringToUTF8(env, jguid); |
| 682 | 688 |
| 683 Delegate* requester = new AddressNormalizationRequester( | 689 Delegate* requester = new AddressNormalizationRequester( |
|
please use gerrit instead
2016/10/18 17:30:32
std::unique_ptr<Delegate> requester = ...
sebsg
2016/10/18 22:44:32
Done.
| |
| 684 env, jdelegate, region_code, guid, AsWeakPtr()); | 690 env, jdelegate, region_code, guid, AsWeakPtr()); |
| 685 | 691 |
| 686 // Check if the rules are already loaded. | 692 // Check if the rules are already loaded. |
| 687 if (AreRulesLoadedForRegion(region_code)) { | 693 if (AreRulesLoadedForRegion(region_code)) { |
| 688 requester->OnRulesSuccessfullyLoaded(); | 694 requester->OnRulesSuccessfullyLoaded(); |
| 689 return false; | 695 return false; |
| 690 } else { | 696 } else { |
| 691 // Setup the variables so the profile gets normalized when the rules have | 697 // Setup the variables so the profile gets normalized when the rules have |
| 692 // finished loading. | 698 // finished loading. |
| 693 pending_normalization_.insert( | 699 if (pending_normalization_.find(region_code) == |
| 694 std::pair<std::string, Delegate*>(region_code, requester)); | 700 pending_normalization_.end()) { |
| 701 pending_normalization_.insert( | |
| 702 std::pair<std::string, std::vector<Delegate*>>( | |
|
please use gerrit instead
2016/10/18 17:30:32
pending_normalization_.insert(std::make_pair(regio
sebsg
2016/10/18 22:44:32
It seems you cannot use initializer lists with mov
| |
| 703 region_code, std::vector<Delegate*>())); | |
| 704 } | |
| 705 | |
| 706 std::map<std::string, std::vector<Delegate*>>::iterator it = | |
| 707 pending_normalization_.find(region_code); | |
| 708 it->second.push_back(requester); | |
| 709 | |
| 695 return true; | 710 return true; |
| 696 } | 711 } |
| 697 } | 712 } |
| 698 | 713 |
| 699 ScopedJavaLocalRef<jobject> PersonalDataManagerAndroid::NormalizeAddress( | 714 ScopedJavaLocalRef<jobject> PersonalDataManagerAndroid::NormalizeAddress( |
| 700 const std::string& guid, | 715 const std::string& guid, |
| 701 const std::string& region_code, | 716 const std::string& region_code, |
| 702 JNIEnv* env) { | 717 JNIEnv* env) { |
| 703 AutofillProfile* profile = personal_data_manager_->GetProfileByGUID(guid); | 718 AutofillProfile* profile = personal_data_manager_->GetProfileByGUID(guid); |
| 704 | 719 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 716 base::UTF8ToUTF16(address_data.administrative_area)); | 731 base::UTF8ToUTF16(address_data.administrative_area)); |
| 717 profile->SetRawInfo(ADDRESS_HOME_CITY, | 732 profile->SetRawInfo(ADDRESS_HOME_CITY, |
| 718 base::UTF8ToUTF16(address_data.locality)); | 733 base::UTF8ToUTF16(address_data.locality)); |
| 719 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, | 734 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, |
| 720 base::UTF8ToUTF16(address_data.dependent_locality)); | 735 base::UTF8ToUTF16(address_data.dependent_locality)); |
| 721 } | 736 } |
| 722 | 737 |
| 723 return CreateJavaProfileFromNative(env, *profile); | 738 return CreateJavaProfileFromNative(env, *profile); |
| 724 } | 739 } |
| 725 | 740 |
| 726 void PersonalDataManagerAndroid::CancelPendingAddressNormalization( | 741 void PersonalDataManagerAndroid::CancelPendingAddressNormalizations( |
| 727 JNIEnv* env, | 742 JNIEnv* env, |
| 728 const base::android::JavaParamRef<jobject>& unused_obj) { | 743 const base::android::JavaParamRef<jobject>& unused_obj) { |
| 744 // Delete all the pending normalization delegates. | |
| 745 for (auto it = pending_normalization_.begin(); | |
|
please use gerrit instead
2016/10/18 17:30:32
Since PersonalDataManagerAndroid now owns all of t
sebsg
2016/10/18 22:44:32
Done.
| |
| 746 it != pending_normalization_.end(); it++) { | |
| 747 for (size_t i = 0; i < it->second.size(); ++i) { | |
| 748 delete it->second[i]; | |
| 749 } | |
| 750 } | |
| 751 | |
| 729 pending_normalization_.clear(); | 752 pending_normalization_.clear(); |
| 730 } | 753 } |
| 731 | 754 |
| 732 ScopedJavaLocalRef<jobjectArray> PersonalDataManagerAndroid::GetProfileGUIDs( | 755 ScopedJavaLocalRef<jobjectArray> PersonalDataManagerAndroid::GetProfileGUIDs( |
| 733 JNIEnv* env, | 756 JNIEnv* env, |
| 734 const std::vector<AutofillProfile*>& profiles) { | 757 const std::vector<AutofillProfile*>& profiles) { |
| 735 std::vector<base::string16> guids; | 758 std::vector<base::string16> guids; |
| 736 for (AutofillProfile* profile : profiles) | 759 for (AutofillProfile* profile : profiles) |
| 737 guids.push_back(base::UTF8ToUTF16(profile->guid())); | 760 guids.push_back(base::UTF8ToUTF16(profile->guid())); |
| 738 | 761 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 831 base::android::ConvertJavaStringToUTF16(env, jcountry_name))); | 854 base::android::ConvertJavaStringToUTF16(env, jcountry_name))); |
| 832 } | 855 } |
| 833 | 856 |
| 834 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 857 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 835 PersonalDataManagerAndroid* personal_data_manager_android = | 858 PersonalDataManagerAndroid* personal_data_manager_android = |
| 836 new PersonalDataManagerAndroid(env, obj); | 859 new PersonalDataManagerAndroid(env, obj); |
| 837 return reinterpret_cast<intptr_t>(personal_data_manager_android); | 860 return reinterpret_cast<intptr_t>(personal_data_manager_android); |
| 838 } | 861 } |
| 839 | 862 |
| 840 } // namespace autofill | 863 } // namespace autofill |
| OLD | NEW |