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

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: 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: 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 9c7b599705a34098f7c2de881c6eafdc5cfe3350..f63091850ecb002056b742b60491ff676b3d27e0 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
@@ -2128,14 +2128,13 @@ void AutofillDialogControllerImpl::UserEditedOrActivatedInput(
return;
}
- std::vector<base::string16> popup_values, popup_labels, popup_icons;
+ std::vector<autofill::Suggestion> popup_suggestions;
if (common::IsCreditCardType(type)) {
GetManager()->GetCreditCardSuggestions(AutofillType(type),
field_contents,
- &popup_values,
- &popup_labels,
- &popup_icons,
- &popup_guids_);
+ &popup_suggestions);
+ for (size_t i = 0; i < popup_suggestions.size(); i++)
Evan Stade 2014/12/10 23:11:14 range based loop?
+ popup_suggestion_ids_.push_back(popup_suggestions[i].backend_id);
} else {
GetManager()->GetProfileSuggestions(
AutofillType(type),
@@ -2144,16 +2143,16 @@ void AutofillDialogControllerImpl::UserEditedOrActivatedInput(
RequestedTypesForSection(section),
base::Bind(&AutofillDialogControllerImpl::ShouldSuggestProfile,
base::Unretained(this), section),
- &popup_values,
- &popup_labels,
- &popup_icons,
- &popup_guids_);
+ &popup_suggestions);
+ for (size_t i = 0; i < popup_suggestions.size(); i++)
+ popup_suggestion_ids_.push_back(popup_suggestions[i].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;
}
@@ -2162,11 +2161,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(
@@ -2177,10 +2176,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() {
@@ -2414,20 +2410,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
@@ -3393,9 +3390,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;
@@ -3420,24 +3415,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(

Powered by Google App Engine
This is Rietveld 408576698