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

[Autofill][Leipzig] Integrate structured address into AutofillProfile

This CL adds the structured address representation into the
AutofillProfile and implements functions to test the mergeability,
invoke the merging and return the structured address tree.

Bug: 1128367
Change-Id: I0c8704c49b59170261359478b03208f072ee83ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2418409Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Commit-Queue: Matthias Körber <koerber@google.com>
Cr-Commit-Position: refs/heads/master@{#808812}
parent f92938c9
......@@ -10,6 +10,7 @@
#include "base/compiler_specific.h"
#include "base/strings/string16.h"
#include "components/autofill/core/browser/data_model/autofill_structured_address.h"
#include "components/autofill/core/browser/data_model/form_group.h"
namespace autofill {
......@@ -37,6 +38,27 @@ class Address : public FormGroup {
void ResetStructuredTokes();
// Derives all missing tokens in the structured representation of the address
// either parsing missing tokens from their assigned parent or by formatting
// them from their assigned children.
bool FinalizeAfterImport(bool profile_is_verified);
// Convenience wrapper to invoke finalization for unverified profiles.
bool FinalizeAfterImport() { return FinalizeAfterImport(false); }
// For structured addresses, merges |newer| into |this|. For some values
// within the structured address tree the more recently used profile gets
// precedence. |newer_was_more_recently_used| indicates if the newer was also
// more recently used.
bool MergeStructuredAddress(const Address& newer,
bool newer_was_more_recently_used);
// For structured addresses, returns true if |this| is mergeable with |newer|.
bool IsStructuredAddressMergeable(const Address& newer) const;
// Returns a constant reference to |structured_address_|.
const structured_address::Address& GetStructuredAddress() const;
private:
// FormGroup:
void GetSupportedTypes(ServerFieldTypeSet* supported_types) const override;
......@@ -48,9 +70,15 @@ class Address : public FormGroup {
const std::string& locale,
structured_address::VerificationStatus status) override;
// Return the verification status of a structured name value.
structured_address::VerificationStatus GetVerificationStatusImpl(
ServerFieldType type) const override;
// Trims any trailing newlines from |street_address_|.
void TrimStreetAddress();
// TODO(crbug.com/1130194): Clean legacy implementation once structured
// addresses are fully launched.
// The lines of the street address.
std::vector<base::string16> street_address_;
// A subdivision of city, e.g. inner-city district or suburb.
......@@ -73,6 +101,10 @@ class Address : public FormGroup {
// The ISO 3166 2-letter country code, or an empty string if there is no
// country data specified for this address.
std::string country_code_;
// This data structure holds the address information if the structured address
// feature is enabled.
structured_address::Address structured_address_;
};
} // namespace autofill
......
......@@ -461,8 +461,11 @@ int AutofillProfile::Compare(const AutofillProfile& profile) const {
return 1;
}
// TODO(crbug.com/1130194): Remove feature check once structured addresses are
// fully launched.
if (base::FeatureList::IsEnabled(
features::kAutofillAddressEnhancementVotes)) {
features::kAutofillAddressEnhancementVotes) ||
structured_address::StructuredAddressesEnabled()) {
const ServerFieldType new_types[] = {
ADDRESS_HOME_HOUSE_NUMBER,
ADDRESS_HOME_STREET_NAME,
......@@ -1342,6 +1345,21 @@ std::ostream& operator<<(std::ostream& os, const AutofillProfile& profile) {
<< UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_LINE1)) << " "
<< UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_LINE2)) << " "
<< UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_LINE3)) << " "
<< UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)) << " "
<< "("
<< base::NumberToString(
profile.GetVerificationStatusInt(ADDRESS_HOME_STREET_ADDRESS))
<< ") " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STREET_NAME))
<< " "
<< "("
<< base::NumberToString(
profile.GetVerificationStatusInt(ADDRESS_HOME_STREET_NAME))
<< ") " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_HOUSE_NUMBER))
<< " "
<< "("
<< base::NumberToString(
profile.GetVerificationStatusInt(ADDRESS_HOME_HOUSE_NUMBER))
<< ") "
<< UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY))
<< " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " "
<< UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " "
......@@ -1359,6 +1377,8 @@ bool AutofillProfile::FinalizeAfterImport() {
bool success = true;
if (!name_.FinalizeAfterImport(IsVerified()))
success = false;
if (!address_.FinalizeAfterImport(IsVerified()))
success = false;
return success;
}
......
......@@ -296,6 +296,9 @@ class AutofillProfile : public AutofillDataModel {
// Returns a constant reference to the |name_| field.
const NameInfo& GetNameInfo() const { return name_; }
// Returns a constant reference to the |address_| field.
const Address& GetAddress() const { return address_; }
private:
typedef std::vector<const FormGroup*> FormGroupList;
......
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