summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill
diff options
context:
space:
mode:
authorisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 00:10:45 +0000
committerisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 00:10:45 +0000
commit0cffe5f51763cb050e689831fe1658bd23769869 (patch)
tree1eec9bcf130cae87654b49c4aadfa5c3cbcbfd33 /chrome/browser/autofill
parentd14c014bbd06caef193759a0e7bcef9eafd980a6 (diff)
downloadchromium_src-0cffe5f51763cb050e689831fe1658bd23769869.zip
chromium_src-0cffe5f51763cb050e689831fe1658bd23769869.tar.gz
chromium_src-0cffe5f51763cb050e689831fe1658bd23769869.tar.bz2
Clean up Autofill address code.
* Merge HomeAddress into Address, since there are no other subclasses. * Eliminate unhelpful wrapper functions * Get rid of Apartment Number code, since we always store that as generic line 2 data. BUG=none TEST=none Review URL: http://codereview.chromium.org/6533011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75207 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill')
-rw-r--r--chrome/browser/autofill/address.cc127
-rw-r--r--chrome/browser/autofill/address.h41
-rw-r--r--chrome/browser/autofill/address_field.cc3
-rw-r--r--chrome/browser/autofill/autofill_profile.cc3
-rw-r--r--chrome/browser/autofill/home_address.cc41
-rw-r--r--chrome/browser/autofill/home_address.h35
6 files changed, 57 insertions, 193 deletions
diff --git a/chrome/browser/autofill/address.cc b/chrome/browser/autofill/address.cc
index 8e75eec..7465279 100644
--- a/chrome/browser/autofill/address.cc
+++ b/chrome/browser/autofill/address.cc
@@ -16,7 +16,6 @@ const char16 kAddressSplitChars[] = {'-', ',', '#', '.', ' ', 0};
const AutoFillType::FieldTypeSubGroup kAutoFillAddressTypes[] = {
AutoFillType::ADDRESS_LINE1,
AutoFillType::ADDRESS_LINE2,
- AutoFillType::ADDRESS_APT_NUM,
AutoFillType::ADDRESS_CITY,
AutoFillType::ADDRESS_STATE,
AutoFillType::ADDRESS_ZIP,
@@ -31,6 +30,10 @@ Address::Address() {}
Address::~Address() {}
+FormGroup* Address::Clone() const {
+ return new Address(*this);
+}
+
void Address::GetPossibleFieldTypes(const string16& text,
FieldTypeSet* possible_types) const {
DCHECK(possible_types);
@@ -41,50 +44,44 @@ void Address::GetPossibleFieldTypes(const string16& text,
return;
if (IsLine1(text))
- possible_types->insert(GetLine1Type());
+ possible_types->insert(ADDRESS_HOME_LINE1);
if (IsLine2(text))
- possible_types->insert(GetLine2Type());
-
- if (IsAptNum(text))
- possible_types->insert(GetAptNumType());
+ possible_types->insert(ADDRESS_HOME_LINE2);
if (IsCity(text))
- possible_types->insert(GetCityType());
+ possible_types->insert(ADDRESS_HOME_CITY);
if (IsState(text))
- possible_types->insert(GetStateType());
+ possible_types->insert(ADDRESS_HOME_STATE);
if (IsZipCode(text))
- possible_types->insert(GetZipCodeType());
+ possible_types->insert(ADDRESS_HOME_ZIP);
if (IsCountry(text))
- possible_types->insert(GetCountryType());
+ possible_types->insert(ADDRESS_HOME_COUNTRY);
}
void Address::GetAvailableFieldTypes(FieldTypeSet* available_types) const {
DCHECK(available_types);
- if (!line1().empty())
- available_types->insert(GetLine1Type());
+ if (!line1_.empty())
+ available_types->insert(ADDRESS_HOME_LINE1);
- if (!line2().empty())
- available_types->insert(GetLine2Type());
+ if (!line2_.empty())
+ available_types->insert(ADDRESS_HOME_LINE2);
- if (!apt_num().empty())
- available_types->insert(GetAptNumType());
+ if (!city_.empty())
+ available_types->insert(ADDRESS_HOME_CITY);
- if (!city().empty())
- available_types->insert(GetCityType());
+ if (!state_.empty())
+ available_types->insert(ADDRESS_HOME_STATE);
- if (!state().empty())
- available_types->insert(GetStateType());
+ if (!zip_code_.empty())
+ available_types->insert(ADDRESS_HOME_ZIP);
- if (!zip_code().empty())
- available_types->insert(GetZipCodeType());
-
- if (!country().empty())
- available_types->insert(GetCountryType());
+ if (!country_.empty())
+ available_types->insert(ADDRESS_HOME_COUNTRY);
}
void Address::FindInfoMatches(const AutoFillType& type,
@@ -106,26 +103,23 @@ void Address::FindInfoMatches(const AutoFillType& type,
string16 Address::GetFieldText(const AutoFillType& type) const {
AutoFillFieldType field_type = type.field_type();
- if (field_type == GetLine1Type())
- return line1();
-
- if (field_type == GetLine2Type())
- return line2();
+ if (field_type == ADDRESS_HOME_LINE1)
+ return line1_;
- if (field_type == GetAptNumType())
- return apt_num();
+ if (field_type == ADDRESS_HOME_LINE2)
+ return line2_;
- if (field_type == GetCityType())
- return city();
+ if (field_type == ADDRESS_HOME_CITY)
+ return city_;
- if (field_type == GetStateType())
- return state();
+ if (field_type == ADDRESS_HOME_STATE)
+ return state_;
- if (field_type == GetZipCodeType())
- return zip_code();
+ if (field_type == ADDRESS_HOME_ZIP)
+ return zip_code_;
- if (field_type == GetCountryType())
- return country();
+ if (field_type == ADDRESS_HOME_COUNTRY)
+ return country_;
return string16();
}
@@ -136,16 +130,14 @@ void Address::SetInfo(const AutoFillType& type, const string16& value) {
set_line1(value);
else if (subgroup == AutoFillType::ADDRESS_LINE2)
set_line2(value);
- else if (subgroup == AutoFillType::ADDRESS_APT_NUM)
- set_apt_num(value);
else if (subgroup == AutoFillType::ADDRESS_CITY)
- set_city(value);
+ city_ = value;
else if (subgroup == AutoFillType::ADDRESS_STATE)
- set_state(value);
+ state_ = value;
else if (subgroup == AutoFillType::ADDRESS_COUNTRY)
- set_country(value);
+ country_ = value;
else if (subgroup == AutoFillType::ADDRESS_ZIP)
- set_zip_code(value);
+ zip_code_ = value;
else
NOTREACHED();
}
@@ -155,30 +147,18 @@ void Address::Clear() {
line1_.clear();
line2_tokens_.clear();
line2_.clear();
- apt_num_.clear();
city_.clear();
state_.clear();
country_.clear();
zip_code_.clear();
}
-void Address::Clone(const Address& address) {
- set_line1(address.line1());
- set_line2(address.line2());
- set_apt_num(address.apt_num());
- set_city(address.city());
- set_state(address.state());
- set_country(address.country());
- set_zip_code(address.zip_code());
-}
-
Address::Address(const Address& address)
: FormGroup(),
line1_tokens_(address.line1_tokens_),
line2_tokens_(address.line2_tokens_),
line1_(address.line1_),
line2_(address.line2_),
- apt_num_(address.apt_num_),
city_(address.city_),
state_(address.state_),
country_(address.country_),
@@ -211,10 +191,6 @@ bool Address::IsLine2(const string16& text) const {
return IsLineMatch(text, line2_tokens_);
}
-bool Address::IsAptNum(const string16& text) const {
- return (StringToLowerASCII(apt_num_) == StringToLowerASCII(text));
-}
-
bool Address::IsCity(const string16& text) const {
return (StringToLowerASCII(city_) == StringToLowerASCII(text));
}
@@ -238,26 +214,23 @@ bool Address::FindInfoMatchesHelper(const FieldTypeSubGroup& subgroup,
match->clear();
if (subgroup == AutoFillType::ADDRESS_LINE1 &&
- StartsWith(line1(), info, false)) {
- *match = line1();
+ StartsWith(line1_, info, false)) {
+ *match = line1_;
} else if (subgroup == AutoFillType::ADDRESS_LINE2 &&
- StartsWith(line2(), info, false)) {
- *match = line2();
- } else if (subgroup == AutoFillType::ADDRESS_APT_NUM &&
- StartsWith(apt_num(), info, false)) {
- *match = apt_num();
+ StartsWith(line2_, info, false)) {
+ *match = line2_;
} else if (subgroup == AutoFillType::ADDRESS_CITY &&
- StartsWith(city(), info, false)) {
- *match = city();
+ StartsWith(city_, info, false)) {
+ *match = city_;
} else if (subgroup == AutoFillType::ADDRESS_STATE &&
- StartsWith(state(), info, false)) {
- *match = state();
+ StartsWith(state_, info, false)) {
+ *match = state_;
} else if (subgroup == AutoFillType::ADDRESS_COUNTRY &&
- StartsWith(country(), info, false)) {
- *match = country();
+ StartsWith(country_, info, false)) {
+ *match = country_;
} else if (subgroup == AutoFillType::ADDRESS_ZIP &&
- StartsWith(zip_code(), info, true)) {
- *match = zip_code();
+ StartsWith(zip_code_, info, true)) {
+ *match = zip_code_;
}
return !match->empty();
diff --git a/chrome/browser/autofill/address.h b/chrome/browser/autofill/address.h
index a2b4dd3..ff0c7f6 100644
--- a/chrome/browser/autofill/address.h
+++ b/chrome/browser/autofill/address.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -17,8 +17,8 @@ class Address : public FormGroup {
Address();
virtual ~Address();
- // FormGroup implementation:
- virtual FormGroup* Clone() const = 0;
+ // FormGroup:
+ virtual FormGroup* Clone() const;
virtual void GetPossibleFieldTypes(const string16& text,
FieldTypeSet* possible_types) const;
virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const;
@@ -31,54 +31,26 @@ class Address : public FormGroup {
// Sets all of the fields to the empty string.
void Clear();
- // Sets the values of this object to the values in |address|.
- void Clone(const Address& address);
-
- protected:
- explicit Address(const Address& address);
-
private:
// Vector of tokens in an address line.
typedef std::vector<string16> LineTokens;
- const string16& line1() const { return line1_; }
- const string16& line2() const { return line2_; }
- const string16& apt_num() const { return apt_num_; }
- const string16& city() const { return city_; }
- const string16& state() const { return state_; }
- const string16& country() const { return country_; }
- const string16& zip_code() const { return zip_code_; }
+ explicit Address(const Address& address);
+
+ void operator=(const Address& address);
void set_line1(const string16& line1);
void set_line2(const string16& line2);
- void set_apt_num(const string16& apt_num) { apt_num_ = apt_num; }
- void set_city(const string16& city) { city_ = city; }
- void set_state(const string16& state) { state_ = state; }
- void set_country(const string16& country) { country_ = country; }
- void set_zip_code(const string16& zip_code) { zip_code_ = zip_code; }
-
- void operator=(const Address& address);
// The following functions match |text| against the various values of the
// address, returning true on match.
virtual bool IsLine1(const string16& text) const;
virtual bool IsLine2(const string16& text) const;
- virtual bool IsAptNum(const string16& text) const;
virtual bool IsCity(const string16& text) const;
virtual bool IsState(const string16& text) const;
virtual bool IsCountry(const string16& text) const;
virtual bool IsZipCode(const string16& text) const;
- // The following functions should return the field type for each part of the
- // address. Currently, these are either home or billing address types.
- virtual AutoFillFieldType GetLine1Type() const = 0;
- virtual AutoFillFieldType GetLine2Type() const = 0;
- virtual AutoFillFieldType GetAptNumType() const = 0;
- virtual AutoFillFieldType GetCityType() const = 0;
- virtual AutoFillFieldType GetStateType() const = 0;
- virtual AutoFillFieldType GetZipCodeType() const = 0;
- virtual AutoFillFieldType GetCountryType() const = 0;
-
// A helper function for FindInfoMatches that only handles matching |info|
// with the requested field subgroup.
bool FindInfoMatchesHelper(const FieldTypeSubGroup& subgroup,
@@ -99,7 +71,6 @@ class Address : public FormGroup {
// The address.
string16 line1_;
string16 line2_;
- string16 apt_num_;
string16 city_;
string16 state_;
string16 country_;
diff --git a/chrome/browser/autofill/address_field.cc b/chrome/browser/autofill/address_field.cc
index e379c74..59f87b7 100644
--- a/chrome/browser/autofill/address_field.cc
+++ b/chrome/browser/autofill/address_field.cc
@@ -17,7 +17,6 @@ bool AddressField::GetFieldInfo(FieldTypeMap* field_type_map) const {
AutoFillFieldType address_company;
AutoFillFieldType address_line1;
AutoFillFieldType address_line2;
- AutoFillFieldType address_appt_num;
AutoFillFieldType address_city;
AutoFillFieldType address_state;
AutoFillFieldType address_zip;
@@ -30,7 +29,6 @@ bool AddressField::GetFieldInfo(FieldTypeMap* field_type_map) const {
address_company = COMPANY_NAME;
address_line1 = ADDRESS_HOME_LINE1;
address_line2 = ADDRESS_HOME_LINE2;
- address_appt_num = ADDRESS_HOME_APT_NUM;
address_city = ADDRESS_HOME_CITY;
address_state = ADDRESS_HOME_STATE;
address_zip = ADDRESS_HOME_ZIP;
@@ -41,7 +39,6 @@ bool AddressField::GetFieldInfo(FieldTypeMap* field_type_map) const {
address_company = COMPANY_NAME;
address_line1 = ADDRESS_BILLING_LINE1;
address_line2 = ADDRESS_BILLING_LINE2;
- address_appt_num = ADDRESS_BILLING_APT_NUM;
address_city = ADDRESS_BILLING_CITY;
address_state = ADDRESS_BILLING_STATE;
address_zip = ADDRESS_BILLING_ZIP;
diff --git a/chrome/browser/autofill/autofill_profile.cc b/chrome/browser/autofill/autofill_profile.cc
index f6bcb13..e147e93 100644
--- a/chrome/browser/autofill/autofill_profile.cc
+++ b/chrome/browser/autofill/autofill_profile.cc
@@ -14,7 +14,6 @@
#include "chrome/browser/autofill/autofill_type.h"
#include "chrome/browser/autofill/contact_info.h"
#include "chrome/browser/autofill/fax_number.h"
-#include "chrome/browser/autofill/home_address.h"
#include "chrome/browser/autofill/home_phone_number.h"
#include "chrome/common/guid.h"
#include "grit/generated_resources.h"
@@ -26,7 +25,7 @@ void InitPersonalInfo(FormGroupMap* personal_info) {
(*personal_info)[AutoFillType::CONTACT_INFO] = new ContactInfo();
(*personal_info)[AutoFillType::PHONE_HOME] = new HomePhoneNumber();
(*personal_info)[AutoFillType::PHONE_FAX] = new FaxNumber();
- (*personal_info)[AutoFillType::ADDRESS_HOME] = new HomeAddress();
+ (*personal_info)[AutoFillType::ADDRESS_HOME] = new Address();
}
// Like |AutoFillType::GetEquivalentFieldType()|, but also returns |NAME_FULL|
diff --git a/chrome/browser/autofill/home_address.cc b/chrome/browser/autofill/home_address.cc
deleted file mode 100644
index 5c036a1..0000000
--- a/chrome/browser/autofill/home_address.cc
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/autofill/home_address.h"
-
-HomeAddress::HomeAddress() {}
-
-HomeAddress::~HomeAddress() {}
-
-FormGroup* HomeAddress::Clone() const {
- return new HomeAddress(*this);
-}
-
-AutoFillFieldType HomeAddress::GetLine1Type() const {
- return ADDRESS_HOME_LINE1;
-}
-
-AutoFillFieldType HomeAddress::GetLine2Type() const {
- return ADDRESS_HOME_LINE2;
-}
-
-AutoFillFieldType HomeAddress::GetAptNumType() const {
- return ADDRESS_HOME_APT_NUM;
-}
-
-AutoFillFieldType HomeAddress::GetCityType() const {
- return ADDRESS_HOME_CITY;
-}
-
-AutoFillFieldType HomeAddress::GetStateType() const {
- return ADDRESS_HOME_STATE;
-}
-
-AutoFillFieldType HomeAddress::GetZipCodeType() const {
- return ADDRESS_HOME_ZIP;
-}
-
-AutoFillFieldType HomeAddress::GetCountryType() const {
- return ADDRESS_HOME_COUNTRY;
-}
diff --git a/chrome/browser/autofill/home_address.h b/chrome/browser/autofill/home_address.h
deleted file mode 100644
index 9f441f5..0000000
--- a/chrome/browser/autofill/home_address.h
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_AUTOFILL_HOME_ADDRESS_H_
-#define CHROME_BROWSER_AUTOFILL_HOME_ADDRESS_H_
-#pragma once
-
-#include "chrome/browser/autofill/address.h"
-#include "chrome/browser/autofill/field_types.h"
-
-class FormGroup;
-
-// A specialization of Address that identifies itself as a home address.
-class HomeAddress : public Address {
- public:
- HomeAddress();
- virtual ~HomeAddress();
- virtual FormGroup* Clone() const;
-
- protected:
- virtual AutoFillFieldType GetLine1Type() const;
- virtual AutoFillFieldType GetLine2Type() const;
- virtual AutoFillFieldType GetAptNumType() const;
- virtual AutoFillFieldType GetCityType() const;
- virtual AutoFillFieldType GetStateType() const;
- virtual AutoFillFieldType GetZipCodeType() const;
- virtual AutoFillFieldType GetCountryType() const;
-
- private:
- explicit HomeAddress(const HomeAddress& address) : Address(address) {}
- void operator=(const HomeAddress& address); // Not implemented.
-};
-
-#endif // CHROME_BROWSER_AUTOFILL_HOME_ADDRESS_H_