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 #include "components/autofill/core/browser/autofill_profile_comparator.h" | 5 #include "components/autofill/core/browser/autofill_profile_comparator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 128 |
129 icu::UnicodeString value = icu::UnicodeString(result.data(), result.length()); | 129 icu::UnicodeString value = icu::UnicodeString(result.data(), result.length()); |
130 transliterator_->transliterate(value); | 130 transliterator_->transliterate(value); |
131 return base::string16(value.getBuffer(), value.length()); | 131 return base::string16(value.getBuffer(), value.length()); |
132 } | 132 } |
133 | 133 |
134 bool AutofillProfileComparator::AreMergeable(const AutofillProfile& p1, | 134 bool AutofillProfileComparator::AreMergeable(const AutofillProfile& p1, |
135 const AutofillProfile& p2) const { | 135 const AutofillProfile& p2) const { |
136 // Sorted in order to relative expense of the tests to fail early and cheaply | 136 // Sorted in order to relative expense of the tests to fail early and cheaply |
137 // if possible. | 137 // if possible. |
138 return HaveMergeableEmailAddresses(p1, p2) && | 138 DVLOG(1) << "Comparing profiles:\np1 = " << p1 << "\np2 = " << p2; |
139 HaveMergeableCompanyNames(p1, p2) && | 139 |
140 HaveMergeablePhoneNumbers(p1, p2) && HaveMergeableNames(p1, p2) && | 140 if (!HaveMergeableEmailAddresses(p1, p2)) { |
141 HaveMergeableAddresses(p1, p2); | 141 DVLOG(1) << "Different email addresses."; |
| 142 return false; |
| 143 } |
| 144 |
| 145 if (!HaveMergeableCompanyNames(p1, p2)) { |
| 146 DVLOG(1) << "Different email company names."; |
| 147 return false; |
| 148 } |
| 149 |
| 150 if (!HaveMergeablePhoneNumbers(p1, p2)) { |
| 151 DVLOG(1) << "Different phone numbers."; |
| 152 return false; |
| 153 } |
| 154 |
| 155 if (!HaveMergeableNames(p1, p2)) { |
| 156 DVLOG(1) << "Different names."; |
| 157 return false; |
| 158 } |
| 159 |
| 160 if (!HaveMergeableAddresses(p1, p2)) { |
| 161 DVLOG(1) << "Different addresses."; |
| 162 return false; |
| 163 } |
| 164 |
| 165 DVLOG(1) << "Profiles are mergeable."; |
| 166 return true; |
142 } | 167 } |
143 | 168 |
144 bool AutofillProfileComparator::MergeNames(const AutofillProfile& p1, | 169 bool AutofillProfileComparator::MergeNames(const AutofillProfile& p1, |
145 const AutofillProfile& p2, | 170 const AutofillProfile& p2, |
146 NameInfo* name_info) const { | 171 NameInfo* name_info) const { |
147 DCHECK(HaveMergeableNames(p1, p2)); | 172 DCHECK(HaveMergeableNames(p1, p2)); |
148 | 173 |
149 const AutofillType kFullName(NAME_FULL); | 174 const AutofillType kFullName(NAME_FULL); |
150 const base::string16& full_name_1 = p1.GetInfo(kFullName, app_locale_); | 175 const base::string16& full_name_1 = p1.GetInfo(kFullName, app_locale_); |
151 const base::string16& full_name_2 = p2.GetInfo(kFullName, app_locale_); | 176 const base::string16& full_name_2 = p2.GetInfo(kFullName, app_locale_); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 std::max(n1.number_of_leading_zeros(), n2.number_of_leading_zeros())); | 317 std::max(n1.number_of_leading_zeros(), n2.number_of_leading_zeros())); |
293 } | 318 } |
294 | 319 |
295 PhoneNumberUtil::PhoneNumberFormat format = | 320 PhoneNumberUtil::PhoneNumberFormat format = |
296 region.empty() ? PhoneNumberUtil::NATIONAL | 321 region.empty() ? PhoneNumberUtil::NATIONAL |
297 : PhoneNumberUtil::INTERNATIONAL; | 322 : PhoneNumberUtil::INTERNATIONAL; |
298 | 323 |
299 std::string new_number; | 324 std::string new_number; |
300 phone_util->Format(merged_number, format, &new_number); | 325 phone_util->Format(merged_number, format, &new_number); |
301 | 326 |
302 VLOG(1) << "n1 = {" << n1 << "}"; | 327 DVLOG(2) << "n1 = {" << n1 << "}"; |
303 VLOG(1) << "n2 = {" << n2 << "}"; | 328 DVLOG(2) << "n2 = {" << n2 << "}"; |
304 VLOG(1) << "merged_number = {" << merged_number << "}"; | 329 DVLOG(2) << "merged_number = {" << merged_number << "}"; |
305 VLOG(1) << "new_number = \"" << new_number << "\""; | 330 DVLOG(2) << "new_number = \"" << new_number << "\""; |
306 | 331 |
307 // Check if it's a North American number that's missing the area code. | 332 // Check if it's a North American number that's missing the area code. |
308 // Libphonenumber doesn't know how to format short numbers; it will still | 333 // Libphonenumber doesn't know how to format short numbers; it will still |
309 // include the country code prefix. | 334 // include the country code prefix. |
310 if (merged_number.country_code() == 1 && | 335 if (merged_number.country_code() == 1 && |
311 merged_number.national_number() <= 9999999 && | 336 merged_number.national_number() <= 9999999 && |
312 base::StartsWith(new_number, "+1", base::CompareCase::SENSITIVE)) { | 337 base::StartsWith(new_number, "+1", base::CompareCase::SENSITIVE)) { |
313 size_t offset = 2; // The char just after "+1". | 338 size_t offset = 2; // The char just after "+1". |
314 while (offset < new_number.size() && | 339 while (offset < new_number.size() && |
315 base::IsAsciiWhitespace(new_number[offset])) { | 340 base::IsAsciiWhitespace(new_number[offset])) { |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 const base::string16& address2 = rewriter.Rewrite(NormalizeForComparison( | 766 const base::string16& address2 = rewriter.Rewrite(NormalizeForComparison( |
742 p2.GetInfo(AutofillType(ADDRESS_HOME_STREET_ADDRESS), app_locale_))); | 767 p2.GetInfo(AutofillType(ADDRESS_HOME_STREET_ADDRESS), app_locale_))); |
743 if (CompareTokens(address1, address2) == DIFFERENT_TOKENS) { | 768 if (CompareTokens(address1, address2) == DIFFERENT_TOKENS) { |
744 return false; | 769 return false; |
745 } | 770 } |
746 | 771 |
747 return true; | 772 return true; |
748 } | 773 } |
749 | 774 |
750 } // namespace autofill | 775 } // namespace autofill |
OLD | NEW |