Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(835)

Side by Side Diff: components/autofill/core/browser/autofill_profile_comparator.h

Issue 2088443002: Expand autofill profile merge logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tommy's comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_profile_comparator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_COMPARATOR_H_ 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_COMPARATOR_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_COMPARATOR_H_ 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_COMPARATOR_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 10
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/string_piece.h" 12 #include "base/strings/string_piece.h"
13 #include "components/autofill/core/browser/address.h"
13 #include "components/autofill/core/browser/autofill_profile.h" 14 #include "components/autofill/core/browser/autofill_profile.h"
15 #include "components/autofill/core/browser/contact_info.h"
14 #include "components/autofill/core/common/autofill_l10n_util.h" 16 #include "components/autofill/core/common/autofill_l10n_util.h"
15 #include "third_party/icu/source/i18n/unicode/translit.h" 17 #include "third_party/icu/source/i18n/unicode/translit.h"
16 18
17 namespace autofill { 19 namespace autofill {
18 20
19 // A utility class to assist in the comparison of AutofillProfile data. 21 // A utility class to assist in the comparison of AutofillProfile data.
20 class AutofillProfileComparator { 22 class AutofillProfileComparator {
21 public: 23 public:
22 explicit AutofillProfileComparator(const base::StringPiece& app_locale); 24 explicit AutofillProfileComparator(const base::StringPiece& app_locale);
23 ~AutofillProfileComparator(); 25 ~AutofillProfileComparator();
(...skipping 14 matching lines...) Expand all
38 WhitespaceSpec whitespace_spec = RETAIN_WHITESPACE) const; 40 WhitespaceSpec whitespace_spec = RETAIN_WHITESPACE) const;
39 41
40 // Returns true if |p1| and |p2| are viable merge candidates. This means that 42 // Returns true if |p1| and |p2| are viable merge candidates. This means that
41 // their names, addresses, email addreses, company names, and phone numbers 43 // their names, addresses, email addreses, company names, and phone numbers
42 // are all pairwise equivalent or mergeable. 44 // are all pairwise equivalent or mergeable.
43 // 45 //
44 // Note that mergeability is non-directional; merging two profiles will likely 46 // Note that mergeability is non-directional; merging two profiles will likely
45 // incorporate data from both profiles. 47 // incorporate data from both profiles.
46 bool AreMergeable(const AutofillProfile& p1, const AutofillProfile& p2) const; 48 bool AreMergeable(const AutofillProfile& p1, const AutofillProfile& p2) const;
47 49
50 // Populates |name_info| with the result of merging the names in |p1| and
51 // |p2|. Returns true if successful. Expects that |p1| and |p2| have already
52 // been found to be mergeable.
53 //
54 // Heuristic: If one name is empty, select the other; othwerwise, attempt to
55 // parse the names in each profile and determine if one name can be derived
56 // from the other. For example, J Smith can be derived from John Smith, so
57 // prefer the latter.
58 bool MergeNames(const AutofillProfile& p1,
59 const AutofillProfile& p2,
60 NameInfo* name_info) const;
61
62 // Populates |email_info| with the result of merging the email addresses in
63 // |p1| and |p2|. Returns true if successful. Expects that |p1| and |p2| have
64 // already been found to be mergeable.
65 //
66 // Heuristic: If one email address is empty, use the other; otherwise, prefer
67 // the most recently used version of the email address.
68 bool MergeEmailAddresses(const AutofillProfile& p1,
69 const AutofillProfile& p2,
70 EmailInfo* email_info) const;
71
72 // Populates |company_info| with the result of merging the company names in
73 // |p1| and |p2|. Returns true if successful. Expects that |p1| and |p2| have
74 // already been found to be mergeable.
75 //
76 // Heuristic: If one is empty, use the other; otherwise, if the tokens in one
77 // company name are a superset of those in the other, prefer the former; and,
78 // as a tiebreaker, prefer the most recently used version of the company name.
79 bool MergeCompanyNames(const AutofillProfile& p1,
80 const AutofillProfile& p2,
81 CompanyInfo* company_info) const;
82
83 // Populates |phone_number| with the result of merging the phone numbers in
84 // |p1| and |p2|. Returns true if successful. Expects that |p1| and |p2| have
85 // already been found to be mergeable.
86 //
87 // Heuristic: Populate the missing parts of each number from the other.
88 bool MergePhoneNumbers(const AutofillProfile& p1,
89 const AutofillProfile& p2,
90 PhoneNumber* phone_number) const;
91
92 // Populates |address| with the result of merging the addresses in |p1| and
93 // |p2|. Returns true if successful. Expects that |p1| and |p2| have already
94 // been found to be mergeable.
95 //
96 // Heuristic: Populate the missing parts of each address from the other.
97 // Prefer the abbreviated state, the shorter zip code and routing code, the
98 // more verbost city, dependent locality, and address.
99 bool MergeAddresses(const AutofillProfile& p1,
100 const AutofillProfile& p2,
101 Address* address) const;
102
48 protected: 103 protected:
104 // The result type returned by CompareTokens.
105 enum CompareTokensResult {
106 DIFFERENT_TOKENS,
107 SAME_TOKENS,
108 S1_CONTAINS_S2,
109 S2_CONTAINS_S1,
110 };
111
49 // Returns the set of unique tokens in |s|. Note that the string data backing 112 // Returns the set of unique tokens in |s|. Note that the string data backing
50 // |s| is expected to have a lifetime which exceeds the call to UniqueTokens. 113 // |s| is expected to have a lifetime which exceeds the call to UniqueTokens.
51 static std::set<base::StringPiece16> UniqueTokens(base::StringPiece16 s); 114 static std::set<base::StringPiece16> UniqueTokens(base::StringPiece16 s);
52 115
53 // Returns true if all of the tokens in |s1| are in |s2| or vice versa. 116 // Compares the unique tokens in s1 and s2.
54 static bool HaveSameTokens(base::StringPiece16 s1, base::StringPiece16 s2); 117 static CompareTokensResult CompareTokens(base::StringPiece16 s1,
118 base::StringPiece16 s2);
119
120 // Returns the value of |t| from |p1| or |p2| depending on which is non-empty.
121 // This method expects that the value is either the same in |p1| and |p2| or
122 // empty in one of them.
123 base::string16 GetNonEmptyOf(const AutofillProfile& p1,
124 const AutofillProfile& p2,
125 AutofillType t) const;
55 126
56 // Generate the set of full/initial variants for |name_part|, where 127 // Generate the set of full/initial variants for |name_part|, where
57 // |name_part| is the user's first or middle name. For example, given "jean 128 // |name_part| is the user's first or middle name. For example, given "jean
58 // francois" (the normalized for comparison form of "Jean-François") this 129 // francois" (the normalized for comparison form of "Jean-François") this
59 // function returns the set: 130 // function returns the set:
60 // 131 //
61 // { "", "f", "francois, 132 // { "", "f", "francois,
62 // "j", "j f", "j francois", 133 // "j", "j f", "j francois",
63 // "jean", "jean f", "jean francois", "jf" } 134 // "jean", "jean f", "jean francois", "jf" }
64 // 135 //
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // Returns true if |p1| and |p2| have addresses which are equivalent for the 193 // Returns true if |p1| and |p2| have addresses which are equivalent for the
123 // purposes of merging the two profiles. This means one of the addresses is 194 // purposes of merging the two profiles. This means one of the addresses is
124 // empty, or the addresses are a match. A number of normalization and 195 // empty, or the addresses are a match. A number of normalization and
125 // comparison heuristics are employed to determine if the addresses match. 196 // comparison heuristics are employed to determine if the addresses match.
126 // 197 //
127 // Note that this method does not provide any guidance on actually merging 198 // Note that this method does not provide any guidance on actually merging
128 // the email addresses. 199 // the email addresses.
129 bool HaveMergeableAddresses(const AutofillProfile& p1, 200 bool HaveMergeableAddresses(const AutofillProfile& p1,
130 const AutofillProfile& p2) const; 201 const AutofillProfile& p2) const;
131 202
203 // Returns true if |state1| and |state2| both represent the same state in
204 // |country_code|.
205 bool IsMatchingState(const base::string16& country_code,
206 const base::string16& state1,
207 const base::string16& state2) const;
208
132 private: 209 private:
133 l10n::CaseInsensitiveCompare case_insensitive_compare_; 210 l10n::CaseInsensitiveCompare case_insensitive_compare_;
134 std::unique_ptr<icu::Transliterator> transliterator_; 211 std::unique_ptr<icu::Transliterator> transliterator_;
135 const std::string app_locale_; 212 const std::string app_locale_;
136 213
137 DISALLOW_COPY_AND_ASSIGN(AutofillProfileComparator); 214 DISALLOW_COPY_AND_ASSIGN(AutofillProfileComparator);
138 }; 215 };
139 216
140 } // namespace autofill 217 } // namespace autofill
141 218
142 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_COMPARATOR_H_ 219 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_COMPARATOR_H_
OLDNEW
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_profile_comparator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698