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

Unified Diff: components/autofill/core/browser/personal_data_manager.cc

Issue 772253003: Create an autofill Suggestion class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review 2 Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/personal_data_manager.cc
diff --git a/components/autofill/core/browser/personal_data_manager.cc b/components/autofill/core/browser/personal_data_manager.cc
index 9e2a4ecef411decb3c0295df8eb974e2f57f4e5d..48a2100dc0f59a4e24456baa5e7f2f156aa2d051 100644
--- a/components/autofill/core/browser/personal_data_manager.cc
+++ b/components/autofill/core/browser/personal_data_manager.cc
@@ -560,21 +560,11 @@ void PersonalDataManager::GetProfileSuggestions(
bool field_is_autofilled,
const std::vector<ServerFieldType>& other_field_types,
const base::Callback<bool(const AutofillProfile&)>& filter,
- std::vector<base::string16>* values,
- std::vector<base::string16>* labels,
- std::vector<base::string16>* icons,
- std::vector<GUIDPair>* guid_pairs) {
- values->clear();
- labels->clear();
- icons->clear();
- guid_pairs->clear();
-
- const std::vector<AutofillProfile*>& profiles = GetProfiles(true);
- std::vector<AutofillProfile*> matched_profiles;
- for (std::vector<AutofillProfile*>::const_iterator iter = profiles.begin();
- iter != profiles.end(); ++iter) {
- AutofillProfile* profile = *iter;
+ std::vector<Suggestion>* suggestions) {
+ suggestions->clear();
+ std::vector<AutofillProfile*> matched_profiles;
+ for (AutofillProfile* profile : GetProfiles(true)) {
// The value of the stored data for this field type in the |profile|.
std::vector<base::string16> multi_values;
AddressField address_field;
@@ -600,8 +590,9 @@ void PersonalDataManager::GetProfileSuggestions(
StartsWith(multi_values[i], field_contents, false) &&
(filter.is_null() || filter.Run(*profile))) {
matched_profiles.push_back(profile);
- values->push_back(multi_values[i]);
- guid_pairs->push_back(GUIDPair(profile->guid(), i));
+ suggestions->push_back(Suggestion(multi_values[i]));
+ suggestions->back().backend_id.guid = profile->guid();
+ suggestions->back().backend_id.variant = i;
}
} else {
if (multi_values[i].empty())
@@ -626,8 +617,9 @@ void PersonalDataManager::GetProfileSuggestions(
profile_value_lower_case == field_value_lower_case) {
for (size_t j = 0; j < multi_values.size(); ++j) {
if (!multi_values[j].empty()) {
- values->push_back(multi_values[j]);
- guid_pairs->push_back(GUIDPair(profile->guid(), j));
+ suggestions->push_back(Suggestion(multi_values[j]));
+ suggestions->back().backend_id.guid = profile->guid();
+ suggestions->back().backend_id.variant = j;
}
}
@@ -640,35 +632,23 @@ void PersonalDataManager::GetProfileSuggestions(
}
if (!field_is_autofilled) {
+ // Generate labels for the profiles we discovered above.
+ std::vector<base::string16> labels;
AutofillProfile::CreateInferredLabels(
matched_profiles, &other_field_types,
- type.GetStorableType(), 1, app_locale_, labels);
- } else {
- // No sub-labels for previously filled fields.
- labels->resize(values->size());
+ type.GetStorableType(), 1, app_locale_, &labels);
+ DCHECK_EQ(suggestions->size(), labels.size());
+ for (size_t i = 0; i < labels.size(); i++)
+ (*suggestions)[i].label = labels[i];
}
-
- // No icons for profile suggestions.
- icons->resize(values->size());
}
void PersonalDataManager::GetCreditCardSuggestions(
const AutofillType& type,
const base::string16& field_contents,
- std::vector<base::string16>* values,
- std::vector<base::string16>* labels,
- std::vector<base::string16>* icons,
- std::vector<GUIDPair>* guid_pairs) {
- values->clear();
- labels->clear();
- icons->clear();
- guid_pairs->clear();
-
- const std::vector<CreditCard*>& credit_cards = GetCreditCards();
- for (std::vector<CreditCard*>::const_iterator iter = credit_cards.begin();
- iter != credit_cards.end(); ++iter) {
- CreditCard* credit_card = *iter;
-
+ std::vector<Suggestion>* suggestions) {
+ suggestions->clear();
+ for (const CreditCard* credit_card : GetCreditCards()) {
// The value of the stored data for this field type in the |credit_card|.
base::string16 creditcard_field_value =
credit_card->GetInfo(type, app_locale_);
@@ -677,28 +657,30 @@ void PersonalDataManager::GetCreditCardSuggestions(
(type.GetStorableType() == CREDIT_CARD_NUMBER &&
base::string16::npos !=
creditcard_field_value.find(field_contents)))) {
+ // Make a new suggestion.
+ suggestions->push_back(Suggestion());
+ Suggestion* suggestion = &suggestions->back();
+
// If the value is the card number, the label is the expiration date.
// Otherwise the label is the card number, or if that is empty the
// cardholder name. The label should never repeat the value.
- base::string16 label;
if (type.GetStorableType() == CREDIT_CARD_NUMBER) {
creditcard_field_value = credit_card->ObfuscatedNumber();
- label = credit_card->GetInfo(
+ suggestion->label = credit_card->GetInfo(
AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), app_locale_);
} else if (credit_card->number().empty()) {
if (type.GetStorableType() != CREDIT_CARD_NAME) {
- label =
+ suggestion->label =
credit_card->GetInfo(AutofillType(CREDIT_CARD_NAME), app_locale_);
}
} else {
- label = kCreditCardPrefix;
- label.append(credit_card->LastFourDigits());
+ suggestion->label = kCreditCardPrefix;
+ suggestion->label.append(credit_card->LastFourDigits());
}
- values->push_back(creditcard_field_value);
- labels->push_back(label);
- icons->push_back(base::UTF8ToUTF16(credit_card->type()));
- guid_pairs->push_back(GUIDPair(credit_card->guid(), 0));
+ suggestion->value = creditcard_field_value;
+ suggestion->icon = base::UTF8ToUTF16(credit_card->type());
+ suggestion->backend_id.guid = credit_card->guid();
}
}
}

Powered by Google App Engine
This is Rietveld 408576698