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

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: More name tests. 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
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.
tmartino 2016/06/27 17:56:46 Can you add a brief description to these docs of t
Roger McFarlane (Chromium) 2016/06/28 17:26:47 Done.
53 bool MergeNames(const AutofillProfile& p1,
54 const AutofillProfile& p2,
55 NameInfo* name_info) const;
56
57 // Populates |email_info| with the result of merging the email addresses in
58 // |p1| and |p2|. Returns true if successful. Expects that |p1| and |p2| have
59 // already been found to be mergeable.
60 bool MergeEmailAddresses(const AutofillProfile& p1,
61 const AutofillProfile& p2,
62 EmailInfo* email_info) const;
63
64 // Populates |company_info| with the result of merging the company names in
65 // |p1| and |p2|. Returns true if successful. Expects that |p1| and |p2| have
66 // already been found to be mergeable.
67 bool MergeCompanyNames(const AutofillProfile& p1,
68 const AutofillProfile& p2,
69 CompanyInfo* company_info) const;
70
71 // Populates |phone_number| with the result of merging the phone numbers in
72 // |p1| and |p2|. Returns true if successful. Expects that |p1| and |p2| have
73 // already been found to be mergeable.
74 bool MergePhoneNumbers(const AutofillProfile& p1,
75 const AutofillProfile& p2,
76 PhoneNumber* phone_number) const;
77
78 // Populates |address| with the result of merging the addresses in |p1| and
79 // |p2|. Returns true if successful. Expects that |p1| and |p2| have already
80 // been found to be mergeable.
81 bool MergeAddresses(const AutofillProfile& p1,
82 const AutofillProfile& p2,
83 Address* address) const;
84
48 protected: 85 protected:
86 // The result type returned by CompareTokens.
87 enum CompareTokensResult {
88 DIFFERENT_TOKENS,
89 SAME_TOKENS,
90 S1_CONTAINS_S2,
91 S2_CONTAINS_S1,
92 };
93
49 // Returns the set of unique tokens in |s|. Note that the string data backing 94 // 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. 95 // |s| is expected to have a lifetime which exceeds the call to UniqueTokens.
51 static std::set<base::StringPiece16> UniqueTokens(base::StringPiece16 s); 96 static std::set<base::StringPiece16> UniqueTokens(base::StringPiece16 s);
52 97
53 // Returns true if all of the tokens in |s1| are in |s2| or vice versa. 98 // Compares the unique tokens in s1 and s2.
54 static bool HaveSameTokens(base::StringPiece16 s1, base::StringPiece16 s2); 99 static CompareTokensResult CompareTokens(base::StringPiece16 s1,
100 base::StringPiece16 s2);
101
102 // Returns the value of |t| from |p1| or |p2| depending on which is non-empty.
103 // This method expects that the value is either the same in |p1| or |p2| or
tmartino 2016/06/27 17:56:46 nit: Should this read "either the same in |p1| AND
Roger McFarlane (Chromium) 2016/06/28 17:26:47 Done.
104 // empty in one of them.
105 base::string16 GetNonEmptyOf(const AutofillProfile& p1,
106 const AutofillProfile& p2,
107 AutofillType t) const;
55 108
56 // Generate the set of full/initial variants for |name_part|, where 109 // 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 110 // |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 111 // francois" (the normalized for comparison form of "Jean-François") this
59 // function returns the set: 112 // function returns the set:
60 // 113 //
61 // { "", "f", "francois, 114 // { "", "f", "francois,
62 // "j", "j f", "j francois", 115 // "j", "j f", "j francois",
63 // "jean", "jean f", "jean francois", "jf" } 116 // "jean", "jean f", "jean francois", "jf" }
64 // 117 //
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 l10n::CaseInsensitiveCompare case_insensitive_compare_; 186 l10n::CaseInsensitiveCompare case_insensitive_compare_;
134 std::unique_ptr<icu::Transliterator> transliterator_; 187 std::unique_ptr<icu::Transliterator> transliterator_;
135 const std::string app_locale_; 188 const std::string app_locale_;
136 189
137 DISALLOW_COPY_AND_ASSIGN(AutofillProfileComparator); 190 DISALLOW_COPY_AND_ASSIGN(AutofillProfileComparator);
138 }; 191 };
139 192
140 } // namespace autofill 193 } // namespace autofill
141 194
142 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_COMPARATOR_H_ 195 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_COMPARATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698