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

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 772253003: Create an autofill Suggestion class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge 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: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
index 45e023f6aa4e91bbf6ab2cffa113877a25079a0a..66e3a0aa66aff929161800992ac8e9032da98a1a 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
@@ -2125,32 +2125,30 @@ void AutofillDialogControllerImpl::UserEditedOrActivatedInput(
return;
}
- std::vector<base::string16> popup_values, popup_labels, popup_icons;
+ std::vector<autofill::Suggestion> popup_suggestions;
+ popup_suggestion_ids_.clear();
if (common::IsCreditCardType(type)) {
- GetManager()->GetCreditCardSuggestions(AutofillType(type),
- field_contents,
- &popup_values,
- &popup_labels,
- &popup_icons,
- &popup_guids_);
+ popup_suggestions = GetManager()->GetCreditCardSuggestions(
+ AutofillType(type), field_contents);
+ for (const auto& suggestion : popup_suggestions)
+ popup_suggestion_ids_.push_back(suggestion.backend_id);
} else {
- GetManager()->GetProfileSuggestions(
+ popup_suggestions = GetManager()->GetProfileSuggestions(
AutofillType(type),
field_contents,
false,
RequestedTypesForSection(section),
base::Bind(&AutofillDialogControllerImpl::ShouldSuggestProfile,
- base::Unretained(this), section),
- &popup_values,
- &popup_labels,
- &popup_icons,
- &popup_guids_);
+ base::Unretained(this), section));
+ for (const auto& suggestion : popup_suggestions)
+ popup_suggestion_ids_.push_back(suggestion.backend_id);
- GetI18nValidatorSuggestions(section, type, &popup_values, &popup_labels,
- &popup_icons);
+ // This will append to the popup_suggestions but not the IDs since there
+ // are no backend IDs for the I18N validator suggestions.
+ GetI18nValidatorSuggestions(section, type, &popup_suggestions);
}
- if (popup_values.empty()) {
+ if (popup_suggestions.empty()) {
HidePopup();
return;
}
@@ -2159,11 +2157,11 @@ void AutofillDialogControllerImpl::UserEditedOrActivatedInput(
popup_input_type_ = type;
popup_section_ = section;
+ // Use our own 0-based IDs for the items.
// TODO(estade): do we need separators and control rows like 'Clear
// Form'?
- std::vector<int> popup_ids;
- for (size_t i = 0; i < popup_values.size(); ++i) {
- popup_ids.push_back(i);
+ for (size_t i = 0; i < popup_suggestions.size(); ++i) {
+ popup_suggestions[i].frontend_id = i;
}
popup_controller_ = AutofillPopupControllerImpl::GetOrCreate(
@@ -2174,10 +2172,7 @@ void AutofillDialogControllerImpl::UserEditedOrActivatedInput(
content_bounds,
base::i18n::IsRTL() ?
base::i18n::RIGHT_TO_LEFT : base::i18n::LEFT_TO_RIGHT);
- popup_controller_->Show(popup_values,
- popup_labels,
- popup_icons,
- popup_ids);
+ popup_controller_->Show(popup_suggestions);
}
void AutofillDialogControllerImpl::FocusMoved() {
@@ -2410,20 +2405,21 @@ void AutofillDialogControllerImpl::DidAcceptSuggestion(
ScopedViewUpdates updates(view_.get());
scoped_ptr<DataModelWrapper> wrapper;
- if (static_cast<size_t>(identifier) < popup_guids_.size()) {
- const PersonalDataManager::GUIDPair& pair = popup_guids_[identifier];
+ if (static_cast<size_t>(identifier) < popup_suggestion_ids_.size()) {
+ const SuggestionBackendID& sid = popup_suggestion_ids_[identifier];
if (common::IsCreditCardType(popup_input_type)) {
wrapper.reset(new AutofillCreditCardWrapper(
- GetManager()->GetCreditCardByGUID(pair.first)));
+ GetManager()->GetCreditCardByGUID(sid.guid)));
} else {
wrapper.reset(new AutofillProfileWrapper(
- GetManager()->GetProfileByGUID(pair.first),
+ GetManager()->GetProfileByGUID(sid.guid),
AutofillType(popup_input_type),
- pair.second));
+ sid.variant));
}
} else {
wrapper.reset(new I18nAddressDataWrapper(
- &i18n_validator_suggestions_[identifier - popup_guids_.size()]));
+ &i18n_validator_suggestions_[
+ identifier - popup_suggestion_ids_.size()]));
}
// If the user hasn't switched away from the default country and |wrapper|'s
@@ -3385,9 +3381,7 @@ CountryComboboxModel* AutofillDialogControllerImpl::
void AutofillDialogControllerImpl::GetI18nValidatorSuggestions(
DialogSection section,
ServerFieldType type,
- std::vector<base::string16>* popup_values,
- std::vector<base::string16>* popup_labels,
- std::vector<base::string16>* popup_icons) {
+ std::vector<autofill::Suggestion>* popup_suggestions) {
AddressField focused_field;
if (!i18n::FieldForType(type, &focused_field))
return;
@@ -3412,24 +3406,23 @@ void AutofillDialogControllerImpl::GetI18nValidatorSuggestions(
return;
for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) {
- popup_values->push_back(base::UTF8ToUTF16(
- i18n_validator_suggestions_[i].GetFieldValue(focused_field)));
+ popup_suggestions->push_back(autofill::Suggestion(
+ base::UTF8ToUTF16(
+ i18n_validator_suggestions_[i].GetFieldValue(focused_field))));
// Disambiguate the suggestion by showing the smallest administrative
// region of the suggested address:
// ADMIN_AREA > LOCALITY > DEPENDENT_LOCALITY
- popup_labels->push_back(base::string16());
for (int field = DEPENDENT_LOCALITY; field >= ADMIN_AREA; --field) {
const std::string& field_value =
i18n_validator_suggestions_[i].GetFieldValue(
static_cast<AddressField>(field));
if (focused_field != field && !field_value.empty()) {
- popup_labels->back().assign(base::UTF8ToUTF16(field_value));
+ popup_suggestions->back().label = base::UTF8ToUTF16(field_value);
break;
}
}
}
- popup_icons->resize(popup_values->size());
}
DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection(
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_impl.h ('k') | chrome/browser/ui/autofill/autofill_popup_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698