Chromium Code Reviews| Index: components/autofill/core/browser/autofill_profile_comparator.h |
| diff --git a/components/autofill/core/browser/autofill_profile_comparator.h b/components/autofill/core/browser/autofill_profile_comparator.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7664beb9f410435d77777a1d8e7df072ca606af5 |
| --- /dev/null |
| +++ b/components/autofill/core/browser/autofill_profile_comparator.h |
| @@ -0,0 +1,131 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_COMPARATOR_H_ |
| +#define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_COMPARATOR_H_ |
| + |
| +#include <memory> |
| +#include <set> |
| + |
| +#include "base/strings/string16.h" |
| +#include "base/strings/string_piece.h" |
| +#include "components/autofill/core/browser/autofill_profile.h" |
| +#include "components/autofill/core/common/autofill_l10n_util.h" |
| +#include "third_party/icu/source/i18n/unicode/translit.h" |
| + |
| +namespace autofill { |
| + |
| +// A utility class to assist in the comparison of AutofillProfile data. |
| +class AutofillProfileComparator { |
| + public: |
| + AutofillProfileComparator(); |
| + ~AutofillProfileComparator(); |
| + |
| + enum WhitespaceSpec { RETAIN_WHITESPACE, DISCARD_WHITESPACE }; |
| + |
| + // Returns a copy of |text| with uppercase converted to lowercase and |
| + // diacritics removed. |
| + // |
| + // If |whitespace_spec| is RETAIN_WHITESPACE, punctuation is converted to |
| + // spaces, and extraneous whitespace is trimmed and collapsed. For example, |
| + // "Jean- François" becomes "jean francois". |
| + // |
| + // If |whitespace_spec| is DISCARD_WHITESPACE, punctuation and whitespace are |
| + // discarded. For example, +1 (234) 567-8900 becomes 12345678900. |
| + base::string16 NormalizeForComparison( |
| + base::StringPiece16 text, |
| + WhitespaceSpec whitespace_spec = RETAIN_WHITESPACE) const; |
| + |
| + // Returns true if |p1| and |p2| are viable merge candidates. This means that |
| + // their names, addresses, email addreses, company names, and phone numbers |
| + // are all pairwise equivalent or mergeable. |
| + bool IsMergeable(const AutofillProfile& p1, const AutofillProfile& p2) const; |
|
sebsg
2016/06/08 19:03:54
nit: AreMergeable?
Roger McFarlane (Chromium)
2016/06/09 20:19:11
Done.
|
| + |
| + protected: |
| + // Returns the set of unique tokens in |s|. Note that the string data backing |
| + // |s| is expected to have a lifetime which exceeds the call to UniqueTokens. |
| + static std::set<base::StringPiece16> UniqueTokens(base::StringPiece16 s); |
| + |
| + // Returns true if all of the tokens in |s1| are in |s2| or vice versa. |
| + static bool HaveSameTokens(base::StringPiece16 s1, base::StringPiece16 s2); |
| + |
| + // Generate the set of full/initial variants for |name|. For example, given |
| + // "jean francois" (the normalized for comparison form of "Jean-François") |
| + // this function returns the set: |
| + // |
| + // { "", "f", "francois, |
| + // "j", "j f", "j francois", |
| + // "jean", "jean f", "jean francois" } |
| + // |
| + // Note: Expects that |name| is already normalized for comparison. |
| + std::set<base::string16> GetNameVariants(const base::string16& name) const; |
| + |
| + // Returns true of |full_name| is a variant of the full name in |profile|. |
|
sebsg
2016/06/08 19:03:55
nit: of -> if
Roger McFarlane (Chromium)
2016/06/09 20:19:11
Done.
|
| + // |
| + // This function generates all variations of the full name for |profile| and |
| + // returns true if one of these variants is equal to |full_name|. For example, |
| + // this function will return true if |full_name| is "John Q. Public" and the |
| + // name in |profile| is "John Quincy Public" because the name from |full_name| |
| + // can be derived from |profile| by using the middle initial. Note that the |
| + // reverse is not true, "John Quincy Public" is not a name variant of "John Q. |
| + // Public". |
| + // |
| + // Note: Expects that |full_name| is already normalized for comparison. |
| + bool IsNameVariantOf(const AutofillProfile& profile, |
| + const base::string16& full_name) const; |
| + |
| + // Returns true if |p1| and |p2| have names which are equivalent for the |
| + // purposes of merging the two profiles. This means one of the names is |
| + // empty, the names are the same, or one name is a variation of the other. |
|
sebsg
2016/06/08 19:03:55
no modulo case?
Roger McFarlane (Chromium)
2016/06/09 20:19:11
all comparisons are performed post normalization.
|
| + // |
| + // Note that this method does not provide any guidance on actually merging |
| + // the names. |
| + bool HaveMergeableNames(const AutofillProfile& p1, |
| + const AutofillProfile& p2) const; |
| + |
| + // Returns true if |p1| and |p2| have email addresses which are equivalent for |
| + // the purposes of merging the two profiles. This means one of the email |
| + // addresses is empty, or the email addresses are the same (modulo case). |
| + // |
| + // Note that this method does not provide any guidance on actually merging |
| + // the email addresses. |
| + bool HaveMergeableEmailAddresses(const AutofillProfile& p1, |
| + const AutofillProfile& p2) const; |
| + |
| + // Returns true if |p1| and |p2| have company names which are equivalent for |
| + // the purposes of merging the two profiles. This means one of the company |
| + // names is empty, or the normalized company names are the same (modulo case). |
| + // |
| + // Note that this method does not provide any guidance on actually merging |
| + // the company names. |
| + bool HaveMergeableCompanyNames(const AutofillProfile& p1, |
| + const AutofillProfile& p2) const; |
| + |
| + // Returns true if |p1| and |p2| have phone numbers which are equivalent for |
| + // the purposes of merging the two profiles. This means one of the phone |
| + // numbers is empty, or the phone names are the same. |
|
sebsg
2016/06/08 19:03:55
... phone names -> phone numbers.
Also from the
Roger McFarlane (Chromium)
2016/06/09 20:19:11
Done.
|
| + // |
| + // Note that this method does not provide any guidance on actually merging |
| + // the company names. |
| + bool HaveMergeablePhoneNumbers(const AutofillProfile& p1, |
| + const AutofillProfile& p2) const; |
| + |
| + // Returns true if |p1| and |p2| have addresses which are equivalent for the |
| + // purposes of merging the two profiles. This means one of the addresses is |
| + // empty, or the addresses are a match. This uses a number of normalization |
| + // and comparison heuristics to determine if to addresses match. |
|
sebsg
2016/06/08 19:03:54
nit: ... if to addresses -> ... if two addresses
Roger McFarlane (Chromium)
2016/06/09 20:19:11
Done.
|
| + // |
| + // Note that this method does not provide any guidance on actually merging |
| + // the email addresses. |
| + bool HaveMergeableAddresses(const AutofillProfile& p1, |
| + const AutofillProfile& p2) const; |
| + |
| + private: |
| + l10n::CaseInsensitiveCompare case_insensitive_compare_; |
| + std::unique_ptr<icu::Transliterator> transliterator_; |
| +}; |
| + |
| +} // namespace autofill |
| + |
| +#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_COMPARATOR_H_ |