Commit 4ed36547 authored by Christoph Schwering's avatar Christoph Schwering Committed by Chromium LUCI CQ

[Autofill] Migrated sets of ServerFieldType to DenseSet.

Bug: 1007974
Change-Id: Ia50bbdef505695f29b9c924dfa4c62ffbd156be2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2630806
Commit-Queue: Christoph Schwering <schwering@google.com>
Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Cr-Commit-Position: refs/heads/master@{#844584}
parent 9085494b
...@@ -5489,9 +5489,8 @@ TEST_P(AutofillManagerStructuredProfileTest, FormSubmittedWithDefaultValues) { ...@@ -5489,9 +5489,8 @@ TEST_P(AutofillManagerStructuredProfileTest, FormSubmittedWithDefaultValues) {
struct ProfileMatchingTypesTestCase { struct ProfileMatchingTypesTestCase {
const char* input_value; // The value to input in the field. const char* input_value; // The value to input in the field.
std::set<ServerFieldType> ServerFieldTypeSet field_types; // The expected field types to be determined.
field_types; // The expected field types to be determined. ServerFieldTypeSet
std::set<ServerFieldType>
structured_field_types; // The expected field types to be determined. structured_field_types; // The expected field types to be determined.
}; };
...@@ -5655,7 +5654,7 @@ TEST_P(ProfileMatchingTypesTest, DeterminePossibleFieldTypesForUpload) { ...@@ -5655,7 +5654,7 @@ TEST_P(ProfileMatchingTypesTest, DeterminePossibleFieldTypesForUpload) {
// Take the field types depending on the state of the structured names // Take the field types depending on the state of the structured names
// feature. // feature.
const std::set<ServerFieldType>& expected_possible_types = const ServerFieldTypeSet& expected_possible_types =
StructuredNames() ? test_case.structured_field_types StructuredNames() ? test_case.structured_field_types
: test_case.field_types; : test_case.field_types;
......
...@@ -168,7 +168,7 @@ void GetFieldsForDistinguishingProfiles( ...@@ -168,7 +168,7 @@ void GetFieldsForDistinguishingProfiles(
// Keep track of which fields we've seen so that we avoid duplicate entries. // Keep track of which fields we've seen so that we avoid duplicate entries.
// Always ignore fields of unknown type and the excluded field. // Always ignore fields of unknown type and the excluded field.
std::set<ServerFieldType> seen_fields; ServerFieldTypeSet seen_fields;
seen_fields.insert(UNKNOWN_TYPE); seen_fields.insert(UNKNOWN_TYPE);
seen_fields.insert(GetStorableTypeCollapsingGroups(excluded_field)); seen_fields.insert(GetStorableTypeCollapsingGroups(excluded_field));
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/string_piece_forward.h" #include "base/strings/string_piece_forward.h"
#include "components/autofill/core/common/dense_set.h"
namespace autofill { namespace autofill {
...@@ -340,7 +341,7 @@ enum FieldTypeGroup { ...@@ -340,7 +341,7 @@ enum FieldTypeGroup {
UNFILLABLE, UNFILLABLE,
}; };
typedef std::set<ServerFieldType> ServerFieldTypeSet; using ServerFieldTypeSet = DenseSet<ServerFieldType, MAX_VALID_FIELD_TYPE>;
// Returns whether the field can be filled with data. // Returns whether the field can be filled with data.
bool IsFillableFieldType(ServerFieldType field_type); bool IsFillableFieldType(ServerFieldType field_type);
......
...@@ -52,7 +52,7 @@ using AddressImportRequirement = ...@@ -52,7 +52,7 @@ using AddressImportRequirement =
// Return true if the |field_type| and |value| are valid within the context // Return true if the |field_type| and |value| are valid within the context
// of importing a form. // of importing a form.
bool IsValidFieldTypeAndValue(const std::set<ServerFieldType>& types_seen, bool IsValidFieldTypeAndValue(const ServerFieldTypeSet types_seen,
ServerFieldType field_type, ServerFieldType field_type,
const base::string16& value, const base::string16& value,
LogBuffer* import_log_buffer) { LogBuffer* import_log_buffer) {
...@@ -525,7 +525,7 @@ bool FormDataImporter::ImportAddressProfileForSection( ...@@ -525,7 +525,7 @@ bool FormDataImporter::ImportAddressProfileForSection(
// Used to detect and discard address forms with multiple fields of the same // Used to detect and discard address forms with multiple fields of the same
// type. // type.
std::set<ServerFieldType> types_seen; ServerFieldTypeSet types_seen;
// Tracks if the form section contains multiple distinct email addresses. // Tracks if the form section contains multiple distinct email addresses.
bool has_multiple_distinct_email_addresses = false; bool has_multiple_distinct_email_addresses = false;
...@@ -845,7 +845,7 @@ CreditCard FormDataImporter::ExtractCreditCardFromForm( ...@@ -845,7 +845,7 @@ CreditCard FormDataImporter::ExtractCreditCardFromForm(
CreditCard candidate_credit_card; CreditCard candidate_credit_card;
std::set<ServerFieldType> types_seen; ServerFieldTypeSet types_seen;
for (const auto& field : form) { for (const auto& field : form) {
base::string16 value; base::string16 value;
base::TrimWhitespace(field->value, base::TRIM_ALL, &value); base::TrimWhitespace(field->value, base::TRIM_ALL, &value);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/base64.h" #include "base/base64.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/containers/fixed_flat_map.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/i18n/case_conversion.h" #include "base/i18n/case_conversion.h"
#include "base/logging.h" #include "base/logging.h"
...@@ -50,6 +51,7 @@ ...@@ -50,6 +51,7 @@
#include "components/autofill/core/common/autofill_payments_features.h" #include "components/autofill/core/common/autofill_payments_features.h"
#include "components/autofill/core/common/autofill_tick_clock.h" #include "components/autofill/core/common/autofill_tick_clock.h"
#include "components/autofill/core/common/autofill_util.h" #include "components/autofill/core/common/autofill_util.h"
#include "components/autofill/core/common/dense_set.h"
#include "components/autofill/core/common/form_data.h" #include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/form_data_predictions.h" #include "components/autofill/core/common/form_data_predictions.h"
#include "components/autofill/core/common/form_field_data.h" #include "components/autofill/core/common/form_field_data.h"
...@@ -558,14 +560,12 @@ void EncodeFieldMetadataForQuery(const FormFieldData& field, ...@@ -558,14 +560,12 @@ void EncodeFieldMetadataForQuery(const FormFieldData& field,
// For example, for Autofill to support fields of type // For example, for Autofill to support fields of type
// "PHONE_HOME_COUNTRY_CODE", there would need to be at least one other field // "PHONE_HOME_COUNTRY_CODE", there would need to be at least one other field
// of type "PHONE_HOME_NUMBER" or "PHONE_HOME_CITY_AND_NUMBER". // of type "PHONE_HOME_NUMBER" or "PHONE_HOME_CITY_AND_NUMBER".
const std::unordered_map<ServerFieldType, ServerFieldTypeSet>& const auto& GetTypeRelationshipMap() {
GetTypeRelationshipMap() { static const auto rules =
// Initialized and cached on first use. base::MakeFixedFlatMap<ServerFieldType, ServerFieldTypeSet>(
static const auto* const rules =
new std::unordered_map<ServerFieldType, ServerFieldTypeSet>(
{{PHONE_HOME_COUNTRY_CODE, {{PHONE_HOME_COUNTRY_CODE,
{PHONE_HOME_NUMBER, PHONE_HOME_CITY_AND_NUMBER}}}); {PHONE_HOME_NUMBER, PHONE_HOME_CITY_AND_NUMBER}}});
return *rules; return rules;
} }
} // namespace } // namespace
...@@ -2092,7 +2092,7 @@ void FormStructure::IdentifySectionsWithNewMethod() { ...@@ -2092,7 +2092,7 @@ void FormStructure::IdentifySectionsWithNewMethod() {
base::string16 current_section = get_section_name(*fields_.front()); base::string16 current_section = get_section_name(*fields_.front());
// Keep track of the types we've seen in this section. // Keep track of the types we've seen in this section.
std::set<ServerFieldType> seen_types; ServerFieldTypeSet seen_types;
ServerFieldType previous_type = UNKNOWN_TYPE; ServerFieldType previous_type = UNKNOWN_TYPE;
// Boolean flag that is set to true when a field in the current section // Boolean flag that is set to true when a field in the current section
...@@ -2269,7 +2269,7 @@ void FormStructure::IdentifySections(bool has_author_specified_sections) { ...@@ -2269,7 +2269,7 @@ void FormStructure::IdentifySections(bool has_author_specified_sections) {
base::string16 current_section = get_section_name(*fields_.front()); base::string16 current_section = get_section_name(*fields_.front());
// Keep track of the types we've seen in this section. // Keep track of the types we've seen in this section.
std::set<ServerFieldType> seen_types; ServerFieldTypeSet seen_types;
ServerFieldType previous_type = UNKNOWN_TYPE; ServerFieldType previous_type = UNKNOWN_TYPE;
bool is_hidden_section = false; bool is_hidden_section = false;
...@@ -2429,7 +2429,7 @@ void FormStructure::set_randomized_encoder( ...@@ -2429,7 +2429,7 @@ void FormStructure::set_randomized_encoder(
void FormStructure::RationalizeTypeRelationships() { void FormStructure::RationalizeTypeRelationships() {
// Create a local set of all the types for faster lookup. // Create a local set of all the types for faster lookup.
std::unordered_set<ServerFieldType> types; ServerFieldTypeSet types;
for (const auto& field : fields_) { for (const auto& field : fields_) {
types.insert(field->Type().GetStorableType()); types.insert(field->Type().GetStorableType());
} }
...@@ -2438,21 +2438,11 @@ void FormStructure::RationalizeTypeRelationships() { ...@@ -2438,21 +2438,11 @@ void FormStructure::RationalizeTypeRelationships() {
for (const auto& field : fields_) { for (const auto& field : fields_) {
ServerFieldType field_type = field->Type().GetStorableType(); ServerFieldType field_type = field->Type().GetStorableType();
const auto& ruleset_iterator = type_relationship_rules.find(field_type); const auto* ruleset_iterator = type_relationship_rules.find(field_type);
if (ruleset_iterator != type_relationship_rules.end()) { if (ruleset_iterator != type_relationship_rules.end()) {
// We have relationship rules for this type. Verify that at least one of // We have relationship rules for this type. Verify that at least one of
// the required related type is present. // the required related type is present.
bool found = false; if (!types.contains_any(ruleset_iterator->second)) {
for (ServerFieldType required_type : ruleset_iterator->second) {
if (types.find(required_type) != types.end()) {
// Found a required type, we can break as we only need one required
// type to respect the rule.
found = true;
break;
}
}
if (!found) {
// No required type was found, the current field failed the relationship // No required type was found, the current field failed the relationship
// requirements for its type. Disabling Autofill for this field. // requirements for its type. Disabling Autofill for this field.
field->SetTypeTo(AutofillType(UNKNOWN_TYPE)); field->SetTypeTo(AutofillType(UNKNOWN_TYPE));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment