OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_COMPARATOR_H_ | |
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_COMPARATOR_H_ | |
7 | |
8 #include <memory> | |
9 #include <set> | |
10 | |
11 #include "base/strings/string16.h" | |
12 #include "base/strings/string_piece.h" | |
13 #include "components/autofill/core/browser/autofill_profile.h" | |
14 #include "components/autofill/core/common/autofill_l10n_util.h" | |
15 #include "third_party/icu/source/i18n/unicode/translit.h" | |
16 | |
17 namespace autofill { | |
18 | |
19 // A utility class to assist in the comparison of AutofillProfile data. | |
20 class AutofillProfileComparator { | |
21 public: | |
22 AutofillProfileComparator(); | |
23 ~AutofillProfileComparator(); | |
24 | |
25 enum WhitespaceSpec { RETAIN_WHITESPACE, DISCARD_WHITESPACE }; | |
26 | |
27 // Returns a copy of |text| with uppercase converted to lowercase and | |
28 // diacritics removed. | |
29 // | |
30 // If |whitespace_spec| is RETAIN_WHITESPACE, punctuation is converted to | |
31 // spaces, and extraneous whitespace is trimmed and collapsed. For example, | |
32 // "Jean- François" becomes "jean francois". | |
33 // | |
34 // If |whitespace_spec| is DISCARD_WHITESPACE, punctuation and whitespace are | |
35 // discarded. For example, +1 (234) 567-8900 becomes 12345678900. | |
36 base::string16 NormalizeForComparison( | |
37 base::StringPiece16 text, | |
38 WhitespaceSpec whitespace_spec = RETAIN_WHITESPACE) const; | |
39 | |
40 // Returns true if |p1| and |p2| are viable merge candidates. This means that | |
41 // their names, addresses, email addreses, company names, and phone numbers | |
42 // are all pairwise equivalent or mergeable. | |
43 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.
| |
44 | |
45 protected: | |
46 // Returns the set of unique tokens in |s|. Note that the string data backing | |
47 // |s| is expected to have a lifetime which exceeds the call to UniqueTokens. | |
48 static std::set<base::StringPiece16> UniqueTokens(base::StringPiece16 s); | |
49 | |
50 // Returns true if all of the tokens in |s1| are in |s2| or vice versa. | |
51 static bool HaveSameTokens(base::StringPiece16 s1, base::StringPiece16 s2); | |
52 | |
53 // Generate the set of full/initial variants for |name|. For example, given | |
54 // "jean francois" (the normalized for comparison form of "Jean-François") | |
55 // this function returns the set: | |
56 // | |
57 // { "", "f", "francois, | |
58 // "j", "j f", "j francois", | |
59 // "jean", "jean f", "jean francois" } | |
60 // | |
61 // Note: Expects that |name| is already normalized for comparison. | |
62 std::set<base::string16> GetNameVariants(const base::string16& name) const; | |
63 | |
64 // 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.
| |
65 // | |
66 // This function generates all variations of the full name for |profile| and | |
67 // returns true if one of these variants is equal to |full_name|. For example, | |
68 // this function will return true if |full_name| is "John Q. Public" and the | |
69 // name in |profile| is "John Quincy Public" because the name from |full_name| | |
70 // can be derived from |profile| by using the middle initial. Note that the | |
71 // reverse is not true, "John Quincy Public" is not a name variant of "John Q. | |
72 // Public". | |
73 // | |
74 // Note: Expects that |full_name| is already normalized for comparison. | |
75 bool IsNameVariantOf(const AutofillProfile& profile, | |
76 const base::string16& full_name) const; | |
77 | |
78 // Returns true if |p1| and |p2| have names which are equivalent for the | |
79 // purposes of merging the two profiles. This means one of the names is | |
80 // 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.
| |
81 // | |
82 // Note that this method does not provide any guidance on actually merging | |
83 // the names. | |
84 bool HaveMergeableNames(const AutofillProfile& p1, | |
85 const AutofillProfile& p2) const; | |
86 | |
87 // Returns true if |p1| and |p2| have email addresses which are equivalent for | |
88 // the purposes of merging the two profiles. This means one of the email | |
89 // addresses is empty, or the email addresses are the same (modulo case). | |
90 // | |
91 // Note that this method does not provide any guidance on actually merging | |
92 // the email addresses. | |
93 bool HaveMergeableEmailAddresses(const AutofillProfile& p1, | |
94 const AutofillProfile& p2) const; | |
95 | |
96 // Returns true if |p1| and |p2| have company names which are equivalent for | |
97 // the purposes of merging the two profiles. This means one of the company | |
98 // names is empty, or the normalized company names are the same (modulo case). | |
99 // | |
100 // Note that this method does not provide any guidance on actually merging | |
101 // the company names. | |
102 bool HaveMergeableCompanyNames(const AutofillProfile& p1, | |
103 const AutofillProfile& p2) const; | |
104 | |
105 // Returns true if |p1| and |p2| have phone numbers which are equivalent for | |
106 // the purposes of merging the two profiles. This means one of the phone | |
107 // 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.
| |
108 // | |
109 // Note that this method does not provide any guidance on actually merging | |
110 // the company names. | |
111 bool HaveMergeablePhoneNumbers(const AutofillProfile& p1, | |
112 const AutofillProfile& p2) const; | |
113 | |
114 // Returns true if |p1| and |p2| have addresses which are equivalent for the | |
115 // purposes of merging the two profiles. This means one of the addresses is | |
116 // empty, or the addresses are a match. This uses a number of normalization | |
117 // 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.
| |
118 // | |
119 // Note that this method does not provide any guidance on actually merging | |
120 // the email addresses. | |
121 bool HaveMergeableAddresses(const AutofillProfile& p1, | |
122 const AutofillProfile& p2) const; | |
123 | |
124 private: | |
125 l10n::CaseInsensitiveCompare case_insensitive_compare_; | |
126 std::unique_ptr<icu::Transliterator> transliterator_; | |
127 }; | |
128 | |
129 } // namespace autofill | |
130 | |
131 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_COMPARATOR_H_ | |
OLD | NEW |