| Index: components/autofill/core/browser/form_structure.cc
|
| diff --git a/components/autofill/core/browser/form_structure.cc b/components/autofill/core/browser/form_structure.cc
|
| index 193a9b0ad6def0c084f5fb2d69310b8ce05ef03a..33b263ee37bab27fc04004bf59ff0d39c1c95eec 100644
|
| --- a/components/autofill/core/browser/form_structure.cc
|
| +++ b/components/autofill/core/browser/form_structure.cc
|
| @@ -321,7 +321,7 @@ FormStructure::FormStructure(const FormData& form)
|
| base::string16 unique_name =
|
| field.name + base::ASCIIToUTF16("_") +
|
| base::SizeTToString16(++unique_names[field.name]);
|
| - fields_.push_back(new AutofillField(field, unique_name));
|
| + fields_.push_back(base::MakeUnique<AutofillField>(field, unique_name));
|
| }
|
|
|
| form_signature_ = autofill::CalculateFormSignature(form);
|
| @@ -345,8 +345,8 @@ void FormStructure::DetermineHeuristicTypes() {
|
| if (active_field_count() >= kRequiredFieldsForPredictionRoutines &&
|
| (is_form_tag_ || is_formless_checkout_)) {
|
| const FieldCandidatesMap field_type_map =
|
| - FormField::ParseFormFields(fields_.get(), is_form_tag_);
|
| - for (AutofillField* field : fields_) {
|
| + FormField::ParseFormFields(fields_, is_form_tag_);
|
| + for (const auto& field : fields_) {
|
| const auto iter = field_type_map.find(field->unique_name());
|
| if (iter != field_type_map.end())
|
| field->set_heuristic_type(iter->second.BestHeuristicType());
|
| @@ -379,7 +379,7 @@ bool FormStructure::EncodeUploadRequest(
|
|
|
| // Verify that |available_field_types| agrees with the possible field types we
|
| // are uploading.
|
| - for (const AutofillField* field : *this) {
|
| + for (const auto& field : fields_) {
|
| for (const auto& type : field->possible_types()) {
|
| DCHECK(type == UNKNOWN_TYPE || type == EMPTY_TYPE ||
|
| available_field_types.count(type));
|
| @@ -468,7 +468,7 @@ void FormStructure::ParseQueryResponse(
|
| response.upload_required() ? UPLOAD_REQUIRED : UPLOAD_NOT_REQUIRED;
|
|
|
| bool query_response_has_no_server_data = true;
|
| - for (AutofillField* field : form->fields_) {
|
| + for (const auto& field : *form) {
|
| if (form->ShouldSkipField(*field))
|
| continue;
|
|
|
| @@ -533,7 +533,7 @@ std::vector<FormDataPredictions> FormStructure::GetFieldTypePredictions(
|
| form.data.is_form_tag = form_structure->is_form_tag_;
|
| form.signature = form_structure->FormSignatureAsStr();
|
|
|
| - for (const AutofillField* field : form_structure->fields_) {
|
| + for (const auto& field : *form_structure) {
|
| form.data.fields.push_back(FormFieldData(*field));
|
|
|
| FormFieldDataPredictions annotated_field;
|
| @@ -574,7 +574,7 @@ bool FormStructure::IsAutofillable() const {
|
| bool FormStructure::IsCompleteCreditCardForm() const {
|
| bool found_cc_number = false;
|
| bool found_cc_expiration = false;
|
| - for (const AutofillField* field : fields_) {
|
| + for (const auto& field : fields_) {
|
| ServerFieldType type = field->Type().GetStorableType();
|
| if (!found_cc_expiration && IsCreditCardExpirationType(type)) {
|
| found_cc_expiration = true;
|
| @@ -589,7 +589,7 @@ bool FormStructure::IsCompleteCreditCardForm() const {
|
|
|
| void FormStructure::UpdateAutofillCount() {
|
| autofill_count_ = 0;
|
| - for (const AutofillField* field : *this) {
|
| + for (const auto& field : fields_) {
|
| if (field && field->IsFieldFillable())
|
| ++autofill_count_;
|
| }
|
| @@ -610,7 +610,7 @@ bool FormStructure::ShouldBeParsed() const {
|
| return false;
|
|
|
| bool has_text_field = false;
|
| - for (const AutofillField* it : *this) {
|
| + for (const auto& it : fields_) {
|
| has_text_field |= it->form_control_type != "select-one";
|
| }
|
|
|
| @@ -631,7 +631,7 @@ void FormStructure::UpdateFromCache(const FormStructure& cached_form) {
|
| cached_fields[field->FieldSignatureAsStr()] = field;
|
| }
|
|
|
| - for (AutofillField* field : *this) {
|
| + for (const auto& field : fields_) {
|
| std::map<std::string, const AutofillField*>::const_iterator cached_field =
|
| cached_fields.find(field->FieldSignatureAsStr());
|
| if (cached_field != cached_fields.end()) {
|
| @@ -846,7 +846,7 @@ void FormStructure::LogQualityMetrics(const base::TimeTicks& load_time,
|
| }
|
|
|
| void FormStructure::LogQualityMetricsBasedOnAutocomplete() const {
|
| - for (const AutofillField* field : fields_) {
|
| + for (const auto& field : fields_) {
|
| if (field->html_type() != HTML_TYPE_UNSPECIFIED &&
|
| field->html_type() != HTML_TYPE_UNRECOGNIZED) {
|
| // The type inferred by the autocomplete attribute.
|
| @@ -887,7 +887,7 @@ void FormStructure::ParseFieldTypesFromAutocompleteAttributes() {
|
|
|
| has_author_specified_types_ = false;
|
| has_author_specified_sections_ = false;
|
| - for (AutofillField* field : fields_) {
|
| + for (const auto& field : fields_) {
|
| // To prevent potential section name collisions, add a default suffix for
|
| // other fields. Without this, 'autocomplete' attribute values
|
| // "section--shipping street-address" and "shipping street-address" would be
|
| @@ -1007,7 +1007,7 @@ bool FormStructure::FillFields(
|
| std::set<base::string16> FormStructure::PossibleValues(ServerFieldType type) {
|
| std::set<base::string16> values;
|
| AutofillType target_type(type);
|
| - for (const AutofillField* field : fields_) {
|
| + for (const auto& field : fields_) {
|
| if (field->Type().GetStorableType() != target_type.GetStorableType() ||
|
| field->Type().group() != target_type.group()) {
|
| continue;
|
| @@ -1035,7 +1035,7 @@ std::set<base::string16> FormStructure::PossibleValues(ServerFieldType type) {
|
|
|
| base::string16 FormStructure::GetUniqueValue(HtmlFieldType type) const {
|
| base::string16 value;
|
| - for (const AutofillField* field : fields_) {
|
| + for (const auto& field : fields_) {
|
| if (field->html_type() != type)
|
| continue;
|
|
|
| @@ -1057,7 +1057,7 @@ const AutofillField* FormStructure::field(size_t index) const {
|
| return NULL;
|
| }
|
|
|
| - return fields_[index];
|
| + return fields_[index].get();
|
| }
|
|
|
| AutofillField* FormStructure::field(size_t index) {
|
| @@ -1079,9 +1079,11 @@ FormData FormStructure::ToFormData() const {
|
| data.origin = source_url_;
|
| data.action = target_url_;
|
|
|
| - for (size_t i = 0; i < fields_.size(); ++i) {
|
| - data.fields.push_back(FormFieldData(*fields_[i]));
|
| - }
|
| + data.fields.resize(fields_.size());
|
| + std::transform(fields_.cbegin(), fields_.cend(), data.fields.begin(),
|
| + [](const std::unique_ptr<AutofillField>& field) {
|
| + return FormFieldData(*field);
|
| + });
|
|
|
| return data;
|
| }
|
| @@ -1108,7 +1110,7 @@ void FormStructure::EncodeFormForQuery(
|
| DCHECK(!IsMalformed());
|
|
|
| query_form->set_signature(form_signature());
|
| - for (const AutofillField* field : fields_) {
|
| + for (const auto& field : fields_) {
|
| if (ShouldSkipField(*field))
|
| continue;
|
|
|
| @@ -1129,7 +1131,7 @@ void FormStructure::EncodeFormForQuery(
|
| void FormStructure::EncodeFormForUpload(AutofillUploadContents* upload) const {
|
| DCHECK(!IsMalformed());
|
|
|
| - for (const AutofillField* field : fields_) {
|
| + for (const auto& field : fields_) {
|
| // Don't upload checkable fields.
|
| if (IsCheckable(field->check_status))
|
| continue;
|
| @@ -1197,7 +1199,7 @@ void FormStructure::IdentifySections(bool has_author_specified_sections) {
|
| std::set<ServerFieldType> seen_types;
|
| ServerFieldType previous_type = UNKNOWN_TYPE;
|
|
|
| - for (AutofillField* field : fields_) {
|
| + for (const auto& field : fields_) {
|
| const ServerFieldType current_type = field->Type().GetStorableType();
|
|
|
| bool already_saw_current_type = seen_types.count(current_type) > 0;
|
| @@ -1251,7 +1253,7 @@ void FormStructure::IdentifySections(bool has_author_specified_sections) {
|
|
|
| // Ensure that credit card and address fields are in separate sections.
|
| // This simplifies the section-aware logic in autofill_manager.cc.
|
| - for (AutofillField* field : fields_) {
|
| + for (const auto& field : fields_) {
|
| FieldTypeGroup field_type_group = field->Type().group();
|
| if (field_type_group == CREDIT_CARD)
|
| field->set_section(field->section() + "-cc");
|
| @@ -1273,7 +1275,7 @@ void FormStructure::ProcessExtractedFields() {
|
| // Find the longest common prefix within all the field names.
|
| std::vector<base::string16> names;
|
| names.reserve(field_count());
|
| - for (const AutofillField* field : *this)
|
| + for (const auto& field : fields_)
|
| names.push_back(field->name);
|
|
|
| const base::string16 longest_prefix = FindLongestCommonPrefix(names);
|
| @@ -1281,7 +1283,7 @@ void FormStructure::ProcessExtractedFields() {
|
| return;
|
|
|
| // The name without the prefix will be used for heuristics parsing.
|
| - for (AutofillField* field : *this) {
|
| + for (const auto& field : fields_) {
|
| if (field->name.size() > longest_prefix.size()) {
|
| field->set_parseable_name(
|
| field->name.substr(longest_prefix.size(), field->name.size()));
|
|
|