summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill/address.cc
diff options
context:
space:
mode:
authorisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-22 08:29:32 +0000
committerisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-22 08:29:32 +0000
commitfcfece45185268c1a55260a1d5c0abfbceaffe1f (patch)
treebab09f97a07ef8931e297f3801d792f0067ae407 /chrome/browser/autofill/address.cc
parentb4291aefaf817107e62694d540c427a7d115bdea (diff)
downloadchromium_src-fcfece45185268c1a55260a1d5c0abfbceaffe1f.zip
chromium_src-fcfece45185268c1a55260a1d5c0abfbceaffe1f.tar.gz
chromium_src-fcfece45185268c1a55260a1d5c0abfbceaffe1f.tar.bz2
Consolidate Autofill possible type detection code, and enforce greater match precision.
* Only consider submitted field values to match locally stored data if the strings match exactly + This means we will send fewer false positives to the server, at the cost of some false negatives. Most importantly, we should stop identifying ADDRESS_LINE_2 fields as ADDRESS_LINE_1. + There are a few excpetions for structured fields with canonicalized values, like countries (which are canonicalized to country codes) * Eliminate FormGroup::GetMatchingTypes() -- all of this work is now done in a consistent way within AutofillManager * Refactor FormGroup::GetNonEmptyTypes() to be shared code. BUG=81867, 76992 TEST=unit_tests --gtest_filter=AutofillManagerTest.DeterminePossibleFieldTypesForUpload Review URL: http://codereview.chromium.org/7398019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93582 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill/address.cc')
-rw-r--r--chrome/browser/autofill/address.cc173
1 files changed, 25 insertions, 148 deletions
diff --git a/chrome/browser/autofill/address.cc b/chrome/browser/autofill/address.cc
index 0a687a1..6b2d345 100644
--- a/chrome/browser/autofill/address.cc
+++ b/chrome/browser/autofill/address.cc
@@ -28,6 +28,13 @@ const AutofillType::FieldTypeSubGroup kAutofillAddressTypes[] = {
const int kAutofillAddressLength = arraysize(kAutofillAddressTypes);
+// Returns the country code corresponding to |country|, which should be a
+// localized country name.
+std::string ToCountryCode(const string16& country) {
+ std::string app_locale = AutofillCountry::ApplicationLocale();
+ return AutofillCountry::GetCountryCode(country, app_locale);
+}
+
} // namespace
Address::Address() {}
@@ -42,8 +49,6 @@ Address& Address::operator=(const Address& address) {
if (this == &address)
return *this;
- line1_tokens_ = address.line1_tokens_;
- line2_tokens_= address.line2_tokens_;
line1_ = address.line1_;
line2_ = address.line2_;
city_ = address.city_;
@@ -53,54 +58,13 @@ Address& Address::operator=(const Address& address) {
return *this;
}
-void Address::GetMatchingTypes(const string16& text,
- FieldTypeSet* matching_types) const {
- DCHECK(matching_types);
-
- // If the text to match against the field types is empty, then no results will
- // match.
- if (text.empty())
- return;
-
- if (IsLine1(text))
- matching_types->insert(ADDRESS_HOME_LINE1);
-
- if (IsLine2(text))
- matching_types->insert(ADDRESS_HOME_LINE2);
-
- if (IsCity(text))
- matching_types->insert(ADDRESS_HOME_CITY);
-
- if (IsState(text))
- matching_types->insert(ADDRESS_HOME_STATE);
-
- if (IsZipCode(text))
- matching_types->insert(ADDRESS_HOME_ZIP);
-
- if (IsCountry(text))
- matching_types->insert(ADDRESS_HOME_COUNTRY);
-}
-
-void Address::GetNonEmptyTypes(FieldTypeSet* non_empty_types) const {
- DCHECK(non_empty_types);
-
- if (!line1_.empty())
- non_empty_types->insert(ADDRESS_HOME_LINE1);
-
- if (!line2_.empty())
- non_empty_types->insert(ADDRESS_HOME_LINE2);
-
- if (!city_.empty())
- non_empty_types->insert(ADDRESS_HOME_CITY);
-
- if (!state_.empty())
- non_empty_types->insert(ADDRESS_HOME_STATE);
-
- if (!zip_code_.empty())
- non_empty_types->insert(ADDRESS_HOME_ZIP);
-
- if (!country_code_.empty())
- non_empty_types->insert(ADDRESS_HOME_COUNTRY);
+void Address::GetSupportedTypes(FieldTypeSet* supported_types) const {
+ supported_types->insert(ADDRESS_HOME_LINE1);
+ supported_types->insert(ADDRESS_HOME_LINE2);
+ supported_types->insert(ADDRESS_HOME_CITY);
+ supported_types->insert(ADDRESS_HOME_STATE);
+ supported_types->insert(ADDRESS_HOME_ZIP);
+ supported_types->insert(ADDRESS_HOME_COUNTRY);
}
string16 Address::GetInfo(AutofillFieldType type) const {
@@ -128,30 +92,29 @@ string16 Address::GetInfo(AutofillFieldType type) const {
void Address::SetInfo(AutofillFieldType type, const string16& value) {
FieldTypeSubGroup subgroup = AutofillType(type).subgroup();
if (subgroup == AutofillType::ADDRESS_LINE1)
- set_line1(value);
+ line1_ = value;
else if (subgroup == AutofillType::ADDRESS_LINE2)
- set_line2(value);
+ line2_ = value;
else if (subgroup == AutofillType::ADDRESS_CITY)
city_ = value;
else if (subgroup == AutofillType::ADDRESS_STATE)
state_ = value;
else if (subgroup == AutofillType::ADDRESS_COUNTRY)
- SetCountry(value);
+ country_code_ = ToCountryCode(value);
else if (subgroup == AutofillType::ADDRESS_ZIP)
zip_code_ = value;
else
NOTREACHED();
}
-void Address::Clear() {
- line1_tokens_.clear();
- line1_.clear();
- line2_tokens_.clear();
- line2_.clear();
- city_.clear();
- state_.clear();
- country_code_.clear();
- zip_code_.clear();
+void Address::GetMatchingTypes(const string16& text,
+ FieldTypeSet* matching_types) const {
+ FormGroup::GetMatchingTypes(text, matching_types);
+
+ // Check to see if the |text| canonicalized as a country name is a match.
+ std::string country_code = ToCountryCode(text);
+ if (!country_code.empty() && country_code_ == country_code)
+ matching_types->insert(ADDRESS_HOME_COUNTRY);
}
string16 Address::Country() const {
@@ -161,89 +124,3 @@ string16 Address::Country() const {
std::string app_locale = AutofillCountry::ApplicationLocale();
return AutofillCountry(country_code(), app_locale).name();
}
-
-void Address::set_line1(const string16& line1) {
- line1_ = line1;
- line1_tokens_.clear();
- Tokenize(line1, kAddressSplitChars, &line1_tokens_);
- LineTokens::iterator iter;
- for (iter = line1_tokens_.begin(); iter != line1_tokens_.end(); ++iter)
- *iter = StringToLowerASCII(*iter);
-}
-
-void Address::set_line2(const string16& line2) {
- line2_ = line2;
- line2_tokens_.clear();
- Tokenize(line2, kAddressSplitChars, &line2_tokens_);
- LineTokens::iterator iter;
- for (iter = line2_tokens_.begin(); iter != line2_tokens_.end(); ++iter)
- *iter = StringToLowerASCII(*iter);
-}
-
-void Address::SetCountry(const string16& country) {
- std::string app_locale = AutofillCountry::ApplicationLocale();
- country_code_ = AutofillCountry::GetCountryCode(country, app_locale);
-}
-
-bool Address::IsLine1(const string16& text) const {
- return IsLineMatch(text, line1_tokens_);
-}
-
-bool Address::IsLine2(const string16& text) const {
- return IsLineMatch(text, line2_tokens_);
-}
-
-bool Address::IsCity(const string16& text) const {
- return (StringToLowerASCII(city_) == StringToLowerASCII(text));
-}
-
-bool Address::IsState(const string16& text) const {
- return (StringToLowerASCII(state_) == StringToLowerASCII(text));
-}
-
-bool Address::IsCountry(const string16& text) const {
- std::string app_locale = AutofillCountry::ApplicationLocale();
- std::string country_code = AutofillCountry::GetCountryCode(text, app_locale);
- return (!country_code.empty() && country_code_ == country_code);
-}
-
-bool Address::IsZipCode(const string16& text) const {
- return zip_code_ == text;
-}
-
-bool Address::IsLineMatch(const string16& text,
- const LineTokens& line_tokens) const {
- size_t line_tokens_size = line_tokens.size();
- if (line_tokens_size == 0)
- return false;
-
- LineTokens text_tokens;
- Tokenize(text, kAddressSplitChars, &text_tokens);
- size_t text_tokens_size = text_tokens.size();
- if (text_tokens_size == 0)
- return false;
-
- if (text_tokens_size > line_tokens_size)
- return false;
-
- // If each of the 'words' contained in the text are also present in the line,
- // then we will consider the text to match the line.
- LineTokens::iterator iter;
- for (iter = text_tokens.begin(); iter != text_tokens.end(); ++iter) {
- if (!IsWordInLine(*iter, line_tokens))
- return false;
- }
-
- return true;
-}
-
-bool Address::IsWordInLine(const string16& word,
- const LineTokens& line_tokens) const {
- LineTokens::const_iterator iter;
- for (iter = line_tokens.begin(); iter != line_tokens.end(); ++iter) {
- if (StringToLowerASCII(word) == *iter)
- return true;
- }
-
- return false;
-}