Chromium Code Reviews| Index: components/autofill/core/browser/autofill_manager.cc |
| diff --git a/components/autofill/core/browser/autofill_manager.cc b/components/autofill/core/browser/autofill_manager.cc |
| index 1475748d1b4aded541d3cb9a8e2f46358184617f..57d13ae09309a86c4b64d7e7e7b8b2d224d53033 100644 |
| --- a/components/autofill/core/browser/autofill_manager.cc |
| +++ b/components/autofill/core/browser/autofill_manager.cc |
| @@ -123,29 +123,6 @@ base::string16 SanitizeCreditCardFieldValue(const base::string16& value) { |
| return sanitized; |
| } |
| -// If |name| consists of three whitespace-separated parts and the second of the |
| -// three parts is a single character or a single character followed by a period, |
| -// returns the result of joining the first and third parts with a space. |
| -// Otherwise, returns |name|. |
| -// |
| -// Note that a better way to do this would be to use SplitName from |
| -// src/components/autofill/core/browser/contact_info.cc. However, for now we |
| -// want the logic of which variations of names are considered to be the same to |
| -// exactly match the logic applied on the Payments server. |
| -base::string16 RemoveMiddleInitial(const base::string16& name) { |
| - std::vector<base::StringPiece16> parts = |
| - base::SplitStringPiece(name, base::kWhitespaceUTF16, |
| - base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| - if (parts.size() == 3 && (parts[1].length() == 1 || |
| - (parts[1].length() == 2 && |
| - base::EndsWith(parts[1], base::ASCIIToUTF16("."), |
| - base::CompareCase::SENSITIVE)))) { |
| - parts.erase(parts.begin() + 1); |
| - return base::JoinString(parts, base::ASCIIToUTF16(" ")); |
| - } |
| - return name; |
| -} |
| - |
| // Returns whether the |field| is predicted as being any kind of name. |
| bool IsNameType(const AutofillField& field) { |
| return field.Type().group() == NAME || field.Type().group() == NAME_BILLING || |
| @@ -1312,28 +1289,26 @@ int AutofillManager::GetProfilesForCreditCardUpload( |
| *rappor_metric_name = "Autofill.CardUploadNotOfferedNoAddress"; |
| } |
| - // If any of the names on the card or the addresses don't match (where |
| - // matching is case insensitive and ignores middle initials if present), the |
| + // If any of the names on the card or the addresses don't match the |
| // candidate set is invalid. This matches the rules for name matching applied |
| // server-side by Google Payments and ensures that we don't send upload |
| // requests that are guaranteed to fail. |
| - base::string16 verified_name; |
| const base::string16 card_name = |
| card.GetInfo(AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); |
| - if (!card_name.empty()) { |
| - verified_name = RemoveMiddleInitial(card_name); |
| - } |
| - for (const AutofillProfile& profile : candidate_profiles) { |
| - const base::string16 address_name = |
| - profile.GetInfo(AutofillType(NAME_FULL), app_locale_); |
| - if (!address_name.empty()) { |
| - if (verified_name.empty()) { |
| - verified_name = RemoveMiddleInitial(address_name); |
| - } else { |
| - // TODO(crbug.com/590307): We'll need to make the name comparison more |
| - // sophisticated. |
| - if (!base::EqualsCaseInsensitiveASCII( |
| - verified_name, RemoveMiddleInitial(address_name))) { |
| + base::string16 verified_name; |
| + if (candidate_profiles.empty()) { |
| + verified_name = card_name; |
| + } else { |
| + AutofillProfileComparator comparator(app_locale_); |
| + verified_name = comparator.NormalizeForComparison(card_name); |
| + for (const AutofillProfile& profile : candidate_profiles) { |
| + const base::string16 address_name = comparator.NormalizeForComparison( |
| + profile.GetInfo(AutofillType(NAME_FULL), app_locale_)); |
| + if (!address_name.empty()) { |
| + if (verified_name.empty() || |
| + comparator.IsNameVariantOf(address_name, verified_name)) { |
| + verified_name = address_name; |
| + } else if (!comparator.IsNameVariantOf(verified_name, address_name)) { |
|
Roger McFarlane (Chromium)
2017/05/05 16:05:30
Would it be helpful to add the bidirectional name
csashi
2017/05/05 16:22:30
I prefer the current version because I would like
|
| if (!upload_decision_metrics) |
| *rappor_metric_name = |
| "Autofill.CardUploadNotOfferedConflictingNames"; |
| @@ -1344,6 +1319,7 @@ int AutofillManager::GetProfilesForCreditCardUpload( |
| } |
| } |
| } |
| + |
| // If neither the card nor any of the addresses have a name associated with |
| // them, the candidate set is invalid. |
| if (verified_name.empty()) { |