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

Unified Diff: components/autofill/core/browser/autofill_profile_comparator.cc

Issue 2125383002: Revert of Embed address normalization rewriting rules. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/autofill/core/browser/autofill_profile_comparator.h ('k') | components/components_tests.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/core/browser/autofill_profile_comparator.cc
diff --git a/components/autofill/core/browser/autofill_profile_comparator.cc b/components/autofill/core/browser/autofill_profile_comparator.cc
index ee70468ff2c802adaaa5478a8cc746842a74e409..2fd4209fc16463d0532097504d9f1db03ebe101f 100644
--- a/components/autofill/core/browser/autofill_profile_comparator.cc
+++ b/components/autofill/core/browser/autofill_profile_comparator.cc
@@ -14,7 +14,6 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversion_utils.h"
#include "base/strings/utf_string_conversions.h"
-#include "components/autofill/core/browser/address_rewriter.h"
#include "components/autofill/core/browser/autofill_country.h"
#include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/state_names.h"
@@ -28,6 +27,7 @@
namespace {
const base::char16 kSpace[] = {L' ', L'\0'};
+const base::char16 kUS[] = {L'U', L'S', L'\0'};
bool ContainsNewline(base::StringPiece16 text) {
return text.find('\n') != base::StringPiece16::npos;
@@ -689,9 +689,6 @@
return false;
}
- AddressRewriter rewriter =
- AddressRewriter::ForCountryCode(country1.empty() ? country2 : country1);
-
// State
// ------
// Heuristic: States are mergeable if one is a (possibly empty) bag of words
@@ -703,10 +700,11 @@
// state values (like "Select one", or "CA - California").
const AutofillType kState(ADDRESS_HOME_STATE);
const base::string16& state1 =
- rewriter.Rewrite(NormalizeForComparison(p1.GetInfo(kState, app_locale_)));
+ NormalizeForComparison(p1.GetInfo(kState, app_locale_));
const base::string16& state2 =
- rewriter.Rewrite(NormalizeForComparison(p2.GetInfo(kState, app_locale_)));
- if (CompareTokens(state1, state2) == DIFFERENT_TOKENS) {
+ NormalizeForComparison(p2.GetInfo(kState, app_locale_));
+ if (!IsMatchingState(GetNonEmptyOf(p1, p2, kCountryCode), state1, state2) &&
+ CompareTokens(state1, state2) == DIFFERENT_TOKENS) {
return false;
}
@@ -718,10 +716,10 @@
// TODO(rogerm): If the match is between non-empty zip codes then we can infer
// that the two city strings are intended to have the same meaning. This
// handles the cases where we have a city vs one of its suburbs.
- const base::string16& city1 = rewriter.Rewrite(NormalizeForComparison(
- p1.GetInfo(AutofillType(ADDRESS_HOME_CITY), app_locale_)));
- const base::string16& city2 = rewriter.Rewrite(NormalizeForComparison(
- p2.GetInfo(AutofillType(ADDRESS_HOME_CITY), app_locale_)));
+ const base::string16& city1 = NormalizeForComparison(
+ p1.GetInfo(AutofillType(ADDRESS_HOME_CITY), app_locale_));
+ const base::string16& city2 = NormalizeForComparison(
+ p2.GetInfo(AutofillType(ADDRESS_HOME_CITY), app_locale_));
if (CompareTokens(city1, city2) == DIFFERENT_TOKENS) {
return false;
}
@@ -730,10 +728,10 @@
// --------
// Heuristic: Street addresses are mergeable if one is a (possibly empty) bag
// of words subset of the other.
- const base::string16& address1 = rewriter.Rewrite(NormalizeForComparison(
- p1.GetInfo(AutofillType(ADDRESS_HOME_STREET_ADDRESS), app_locale_)));
- const base::string16& address2 = rewriter.Rewrite(NormalizeForComparison(
- p2.GetInfo(AutofillType(ADDRESS_HOME_STREET_ADDRESS), app_locale_)));
+ const base::string16& address1 = NormalizeForComparison(
+ p1.GetInfo(AutofillType(ADDRESS_HOME_STREET_ADDRESS), app_locale_));
+ const base::string16& address2 = NormalizeForComparison(
+ p2.GetInfo(AutofillType(ADDRESS_HOME_STREET_ADDRESS), app_locale_));
if (CompareTokens(address1, address2) == DIFFERENT_TOKENS) {
return false;
}
@@ -741,4 +739,25 @@
return true;
}
+bool AutofillProfileComparator::IsMatchingState(
+ const base::string16& country_code,
+ const base::string16& state1,
+ const base::string16& state2) const {
+ if (state1 == state2)
+ return true;
+
+ if (country_code != kUS)
+ return false;
+
+ // TODO(rogerm): Generalize this to all locals using string equivalence rules.
+ base::string16 name, abbreviation;
+ autofill::state_names::GetNameAndAbbreviation(state1, &name, &abbreviation);
+ if (abbreviation.empty()) {
+ // state1 wasn't recognized. There's no need to compare it to state2
+ return false;
+ }
+
+ return state2 == name || state2 == abbreviation;
+}
+
} // namespace autofill
« no previous file with comments | « components/autofill/core/browser/autofill_profile_comparator.h ('k') | components/components_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698