Commit f38ba6f5 authored by Matthias Körber's avatar Matthias Körber Committed by Commit Bot

[Autofill][Leipzig] Merging of structured addresses.

This CL adds merging support of structured address tokens.
When two profiles are merged, the substructure that corresponds
to address line that is merged into the new profile is used.
If the feature |kAutofillAddressEnhancementVotes| is disabled,
the structure is dropped in the merging process.

Change-Id: Ifc24c0a65b40fad0ae32b1001cc6560ad946cb6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2353267
Commit-Queue: Matthias Körber <koerber@google.com>
Reviewed-by: default avatarChristoph Schwering <schwering@google.com>
Cr-Commit-Position: refs/heads/master@{#798578}
parent f0a14007
......@@ -30,36 +30,29 @@ namespace autofill {
using structured_address::VerificationStatus;
Address::Address() {}
Address::Address() = default;
Address::Address(const Address& address) {
*this = address;
}
Address::~Address() {}
Address::Address(const Address& address) = default;
Address& Address::operator=(const Address& address) {
if (this == &address)
return *this;
Address::~Address() = default;
street_address_ = address.street_address_;
dependent_locality_ = address.dependent_locality_;
city_ = address.city_;
state_ = address.state_;
country_code_ = address.country_code_;
zip_code_ = address.zip_code_;
sorting_code_ = address.sorting_code_;
return *this;
}
Address& Address::operator=(const Address& address) = default;
bool Address::operator==(const Address& other) const {
if (this == &other)
return true;
// Note that the structured address tokens are not evaluated for profile
// comparison.
return street_address_ == other.street_address_ &&
dependent_locality_ == other.dependent_locality_ &&
city_ == other.city_ && state_ == other.state_ &&
zip_code_ == other.zip_code_ && sorting_code_ == other.sorting_code_ &&
country_code_ == other.country_code_;
country_code_ == other.country_code_ &&
street_name_ == other.street_name_ &&
dependent_street_name_ == other.dependent_street_name_ &&
house_number_ == other.house_number_ &&
premise_name_ == other.premise_name_ &&
subpremise_ == other.subpremise_;
}
base::string16 Address::GetRawInfo(ServerFieldType type) const {
......
......@@ -188,6 +188,25 @@ int32_t NormalizingIterator::GetNextChar() {
return iter_.get();
}
// Copies the address line information and structured tokens from |source| to
// |target|.
void CopyAddressLineInformationFromProfile(const AutofillProfile& source,
Address* target) {
ServerFieldTypeSet types_to_copy;
if (base::FeatureList::IsEnabled(
features::kAutofillAddressEnhancementVotes)) {
types_to_copy = {
ADDRESS_HOME_STREET_ADDRESS, ADDRESS_HOME_STREET_NAME,
ADDRESS_HOME_DEPENDENT_STREET_NAME, ADDRESS_HOME_HOUSE_NUMBER,
ADDRESS_HOME_PREMISE_NAME, ADDRESS_HOME_SUBPREMISE};
} else {
types_to_copy = {ADDRESS_HOME_STREET_ADDRESS};
}
for (const auto& type : types_to_copy)
target->SetRawInfo(type, source.GetRawInfo(type));
}
} // namespace
AutofillProfileComparator::AutofillProfileComparator(
......@@ -791,17 +810,17 @@ bool AutofillProfileComparator::MergeAddresses(const AutofillProfile& p1,
const base::string16& address2 = p2.GetInfo(kStreetAddress, app_locale_);
// If one of the addresses is empty then use the other.
if (address1.empty()) {
address->SetInfo(kStreetAddress, address2, app_locale_);
CopyAddressLineInformationFromProfile(p2, address);
} else if (address2.empty()) {
address->SetInfo(kStreetAddress, address1, app_locale_);
CopyAddressLineInformationFromProfile(p1, address);
} else {
// Prefer the multi-line address if one is multi-line and the other isn't.
bool address1_multiline = ContainsNewline(address1);
bool address2_multiline = ContainsNewline(address2);
if (address1_multiline && !address2_multiline) {
address->SetInfo(kStreetAddress, address1, app_locale_);
CopyAddressLineInformationFromProfile(p1, address);
} else if (address2_multiline && !address1_multiline) {
address->SetInfo(kStreetAddress, address2, app_locale_);
CopyAddressLineInformationFromProfile(p2, address);
} else {
// Prefer the one with more tokens if they're both single-line or both
// multi-line addresses, making sure to apply address normalization and
......@@ -812,19 +831,20 @@ bool AutofillProfileComparator::MergeAddresses(const AutofillProfile& p1,
switch (result) {
case SAME_TOKENS:
// They have the same set of unique tokens. Let's pick the one that's
// longer.
address->SetInfo(
kStreetAddress,
(p2.use_date() > p1.use_date() ? address2 : address1),
app_locale_);
// newer.
if (p2.use_date() > p1.use_date()) {
CopyAddressLineInformationFromProfile(p2, address);
} else {
CopyAddressLineInformationFromProfile(p1, address);
}
break;
case S1_CONTAINS_S2:
// address1 has more unique tokens than address2.
address->SetInfo(kStreetAddress, address1, app_locale_);
CopyAddressLineInformationFromProfile(p1, address);
break;
case S2_CONTAINS_S1:
// address2 has more unique tokens than address1.
address->SetInfo(kStreetAddress, address2, app_locale_);
CopyAddressLineInformationFromProfile(p2, address);
break;
case DIFFERENT_TOKENS:
default:
......
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