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

Side by Side Diff: components/autofill/core/browser/personal_data_manager.cc

Issue 622773002: [Autofill] Autofill fails to show suggestions for credit card split across fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unit-tests. Created 6 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
OLDNEW
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 "components/autofill/core/browser/personal_data_manager.h" 5 #include "components/autofill/core/browser/personal_data_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <iterator> 9 #include <iterator>
10 10
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 660
661 const std::vector<CreditCard*>& credit_cards = GetCreditCards(); 661 const std::vector<CreditCard*>& credit_cards = GetCreditCards();
662 for (std::vector<CreditCard*>::const_iterator iter = credit_cards.begin(); 662 for (std::vector<CreditCard*>::const_iterator iter = credit_cards.begin();
663 iter != credit_cards.end(); ++iter) { 663 iter != credit_cards.end(); ++iter) {
664 CreditCard* credit_card = *iter; 664 CreditCard* credit_card = *iter;
665 665
666 // The value of the stored data for this field type in the |credit_card|. 666 // The value of the stored data for this field type in the |credit_card|.
667 base::string16 creditcard_field_value = 667 base::string16 creditcard_field_value =
668 credit_card->GetInfo(type, app_locale_); 668 credit_card->GetInfo(type, app_locale_);
669 if (!creditcard_field_value.empty() && 669 if (!creditcard_field_value.empty() &&
670 StartsWith(creditcard_field_value, field_contents, false)) { 670 StartsWith(creditcard_field_value, field_contents, false))
671 if (type.GetStorableType() == CREDIT_CARD_NUMBER) 671 AppendCreditCardSuggetions(credit_card,
672 creditcard_field_value = credit_card->ObfuscatedNumber(); 672 type,
673 673 creditcard_field_value,
674 // If the value is the card number, the label is the expiration date. 674 values,
675 // Otherwise the label is the card number, or if that is empty the 675 labels,
676 // cardholder name. The label should never repeat the value. 676 icons,
677 base::string16 label; 677 guid_pairs);
678 if (type.GetStorableType() == CREDIT_CARD_NUMBER) {
679 label = credit_card->GetInfo(
680 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), app_locale_);
681 } else if (credit_card->number().empty()) {
682 if (type.GetStorableType() != CREDIT_CARD_NAME) {
683 label =
684 credit_card->GetInfo(AutofillType(CREDIT_CARD_NAME), app_locale_);
685 }
686 } else {
687 label = kCreditCardPrefix;
688 label.append(credit_card->LastFourDigits());
689 }
690
691 values->push_back(creditcard_field_value);
692 labels->push_back(label);
693 icons->push_back(base::UTF8ToUTF16(credit_card->type()));
694 guid_pairs->push_back(GUIDPair(credit_card->guid(), 0));
695 }
696 } 678 }
697 } 679 }
698 680
699 bool PersonalDataManager::IsAutofillEnabled() const { 681 bool PersonalDataManager::IsAutofillEnabled() const {
700 DCHECK(pref_service_); 682 DCHECK(pref_service_);
701 return pref_service_->GetBoolean(prefs::kAutofillEnabled); 683 return pref_service_->GetBoolean(prefs::kAutofillEnabled);
702 } 684 }
703 685
704 std::string PersonalDataManager::CountryCodeForCurrentTimezone() const { 686 std::string PersonalDataManager::CountryCodeForCurrentTimezone() const {
705 return base::CountryCodeForCurrentTimezone(); 687 return base::CountryCodeForCurrentTimezone();
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 1091
1110 // Populates |auxiliary_profiles_|. 1092 // Populates |auxiliary_profiles_|.
1111 LoadAuxiliaryProfiles(record_metrics); 1093 LoadAuxiliaryProfiles(record_metrics);
1112 1094
1113 profiles_.insert(profiles_.end(), web_profiles_.begin(), web_profiles_.end()); 1095 profiles_.insert(profiles_.end(), web_profiles_.begin(), web_profiles_.end());
1114 profiles_.insert( 1096 profiles_.insert(
1115 profiles_.end(), auxiliary_profiles_.begin(), auxiliary_profiles_.end()); 1097 profiles_.end(), auxiliary_profiles_.begin(), auxiliary_profiles_.end());
1116 return profiles_; 1098 return profiles_;
1117 } 1099 }
1118 1100
1101 void PersonalDataManager::AppendCreditCardSuggetions(
1102 const CreditCard* credit_card,
1103 const AutofillType& type,
1104 const base::string16 field_contents,
1105 std::vector<base::string16>* values,
1106 std::vector<base::string16>* labels,
1107 std::vector<base::string16>* icons,
1108 std::vector<GUIDPair>* guid_pairs) {
1109 if (credit_card->GetInfo(type, app_locale_).empty())
1110 return;
1111
1112 base::string16 user_input = field_contents;
1113 if (type.GetStorableType() == CREDIT_CARD_NUMBER)
1114 user_input = credit_card->ObfuscatedNumber();
1115
1116 // If the value is the card number, the label is the expiration date.
1117 // Otherwise the label is the card number, or if that is empty the
1118 // cardholder name. The label should never repeat the value.
1119 base::string16 label;
1120 if (type.GetStorableType() == CREDIT_CARD_NUMBER) {
1121 label = credit_card->GetInfo(
1122 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), app_locale_);
1123 } else if (credit_card->number().empty()) {
1124 if (type.GetStorableType() != CREDIT_CARD_NAME) {
1125 label = credit_card->GetInfo(AutofillType(CREDIT_CARD_NAME), app_locale_);
1126 }
1127 } else {
1128 label = kCreditCardPrefix;
1129 label.append(credit_card->LastFourDigits());
1130 }
1131
1132 values->push_back(user_input);
1133 labels->push_back(label);
1134 icons->push_back(base::UTF8ToUTF16(credit_card->type()));
1135 guid_pairs->push_back(GUIDPair(credit_card->guid(), 0));
1136 }
1137
1119 } // namespace autofill 1138 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698