| OLD | NEW |
| 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 Loading... |
| 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 bool MergeNames(const AutofillProfile& p1, |
| 54 const AutofillProfile& p2, |
| 55 NameInfo* name_info) const; |
| 56 |
| 57 // Populates |address| with the result of merging the addresses in |p1| and |
| 58 // |p2|. Returns true if successful. Expects that |p1| and |p2| have already |
| 59 // been found to be mergeable. |
| 60 bool MergeAddresses(const AutofillProfile& p1, |
| 61 const AutofillProfile& p2, |
| 62 Address* address) const; |
| 63 |
| 48 protected: | 64 protected: |
| 65 // The result type returned by CompareTokens. |
| 66 enum CompareTokensResult { |
| 67 DIFFERENT_TOKENS, |
| 68 SAME_TOKENS, |
| 69 S1_CONTAINS_S2, |
| 70 S2_CONTAINS_S1, |
| 71 }; |
| 72 |
| 49 // Returns the set of unique tokens in |s|. Note that the string data backing | 73 // 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. | 74 // |s| is expected to have a lifetime which exceeds the call to UniqueTokens. |
| 51 static std::set<base::StringPiece16> UniqueTokens(base::StringPiece16 s); | 75 static std::set<base::StringPiece16> UniqueTokens(base::StringPiece16 s); |
| 52 | 76 |
| 53 // Returns true if all of the tokens in |s1| are in |s2| or vice versa. | 77 // Compares the unique tokens in s1 and s2. |
| 54 static bool HaveSameTokens(base::StringPiece16 s1, base::StringPiece16 s2); | 78 static CompareTokensResult CompareTokens(base::StringPiece16 s1, |
| 79 base::StringPiece16 s2); |
| 55 | 80 |
| 56 // Generate the set of full/initial variants for |name_part|, where | 81 // 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 | 82 // |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 | 83 // francois" (the normalized for comparison form of "Jean-François") this |
| 59 // function returns the set: | 84 // function returns the set: |
| 60 // | 85 // |
| 61 // { "", "f", "francois, | 86 // { "", "f", "francois, |
| 62 // "j", "j f", "j francois", | 87 // "j", "j f", "j francois", |
| 63 // "jean", "jean f", "jean francois", "jf" } | 88 // "jean", "jean f", "jean francois", "jf" } |
| 64 // | 89 // |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 l10n::CaseInsensitiveCompare case_insensitive_compare_; | 158 l10n::CaseInsensitiveCompare case_insensitive_compare_; |
| 134 std::unique_ptr<icu::Transliterator> transliterator_; | 159 std::unique_ptr<icu::Transliterator> transliterator_; |
| 135 const std::string app_locale_; | 160 const std::string app_locale_; |
| 136 | 161 |
| 137 DISALLOW_COPY_AND_ASSIGN(AutofillProfileComparator); | 162 DISALLOW_COPY_AND_ASSIGN(AutofillProfileComparator); |
| 138 }; | 163 }; |
| 139 | 164 |
| 140 } // namespace autofill | 165 } // namespace autofill |
| 141 | 166 |
| 142 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_COMPARATOR_H_ | 167 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_COMPARATOR_H_ |
| OLD | NEW |