summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-07 23:13:09 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-07 23:13:09 +0000
commit0f1a680f6f449216c0318f4780502aa0c8bf5b84 (patch)
tree0d5aa9b83234aa5cacb6d18cb3c89a60152cef27
parent32b67942fa3a2f8781ad172a6526102e9ff5abb6 (diff)
downloadchromium_src-0f1a680f6f449216c0318f4780502aa0c8bf5b84.zip
chromium_src-0f1a680f6f449216c0318f4780502aa0c8bf5b84.tar.gz
chromium_src-0f1a680f6f449216c0318f4780502aa0c8bf5b84.tar.bz2
Implement AutoFillProfile, a collection of form groups that stores profile information.
BUG=none TEST=none Review URL: http://codereview.chromium.org/517066 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35751 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autofill/address.cc4
-rw-r--r--chrome/browser/autofill/address_field.cc4
-rw-r--r--chrome/browser/autofill/autofill_profile.cc128
-rw-r--r--chrome/browser/autofill/autofill_profile.h74
-rw-r--r--chrome/browser/autofill/autofill_type.cc4
-rw-r--r--chrome/browser/autofill/autofill_type.h2
-rw-r--r--chrome/browser/autofill/billing_address.h4
-rw-r--r--chrome/browser/autofill/fax_number.h1
-rw-r--r--chrome/browser/autofill/field_types.h4
-rw-r--r--chrome/browser/autofill/home_address.h4
-rw-r--r--chrome/browser/autofill/home_phone_number.h1
-rw-r--r--chrome/browser/autofill/phone_number.h3
-rwxr-xr-xchrome/chrome_browser.gypi2
13 files changed, 222 insertions, 13 deletions
diff --git a/chrome/browser/autofill/address.cc b/chrome/browser/autofill/address.cc
index 8e7201cc..fb06cf8 100644
--- a/chrome/browser/autofill/address.cc
+++ b/chrome/browser/autofill/address.cc
@@ -98,7 +98,7 @@ 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_APPT_NUM)
+ else if (subgroup == AutoFillType::ADDRESS_APT_NUM)
set_apt_num(value);
else if (subgroup == AutoFillType::ADDRESS_CITY)
set_city(value);
@@ -207,7 +207,7 @@ bool Address::FindInfoMatchesHelper(const FieldTypeSubGroup& subgroup,
} else if (subgroup == AutoFillType::ADDRESS_LINE2 &&
StartsWith(line2(), info, false)) {
*match = line2();
- } else if (subgroup == AutoFillType::ADDRESS_APPT_NUM &&
+ } else if (subgroup == AutoFillType::ADDRESS_APT_NUM &&
StartsWith(apt_num(), info, true)) {
*match = apt_num();
} else if (subgroup == AutoFillType::ADDRESS_CITY &&
diff --git a/chrome/browser/autofill/address_field.cc b/chrome/browser/autofill/address_field.cc
index f2a89c2..0994ac6 100644
--- a/chrome/browser/autofill/address_field.cc
+++ b/chrome/browser/autofill/address_field.cc
@@ -24,7 +24,7 @@ bool AddressField::GetFieldInfo(FieldTypeMap* field_type_map) const {
case kGenericAddress:
address_line1 = ADDRESS_HOME_LINE1;
address_line2 = ADDRESS_HOME_LINE2;
- address_appt_num = ADDRESS_HOME_APPT_NUM;
+ address_appt_num = ADDRESS_HOME_APT_NUM;
address_city = ADDRESS_HOME_CITY;
address_state = ADDRESS_HOME_STATE;
address_zip = ADDRESS_HOME_ZIP;
@@ -34,7 +34,7 @@ bool AddressField::GetFieldInfo(FieldTypeMap* field_type_map) const {
case kBillingAddress:
address_line1 = ADDRESS_BILLING_LINE1;
address_line2 = ADDRESS_BILLING_LINE2;
- address_appt_num = ADDRESS_BILLING_APPT_NUM;
+ 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
new file mode 100644
index 0000000..54f972e
--- /dev/null
+++ b/chrome/browser/autofill/autofill_profile.cc
@@ -0,0 +1,128 @@
+// 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/autofill_profile.h"
+
+#include <vector>
+
+#include "base/stl_util-inl.h"
+#include "base/string_util.h"
+#include "chrome/browser/autofill/address.h"
+#include "chrome/browser/autofill/autofill_manager.h"
+#include "chrome/browser/autofill/billing_address.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"
+
+AutoFillProfile::AutoFillProfile(const string16& label, int unique_id)
+ : label_(label),
+ unique_id_(unique_id),
+ use_billing_address_(true) {
+ 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_BILLING] = new BillingAddress();
+}
+
+AutoFillProfile::~AutoFillProfile() {
+ STLDeleteContainerPairSecondPointers(personal_info_.begin(),
+ personal_info_.end());
+}
+
+void AutoFillProfile::GetPossibleFieldTypes(
+ const string16& text,
+ FieldTypeSet* possible_types) const {
+ FormGroupMap::const_iterator iter;
+ for (iter = personal_info_.begin(); iter != personal_info_.end(); ++iter) {
+ FormGroup* data = iter->second;
+ DCHECK(data != NULL);
+ if (data != NULL)
+ data->GetPossibleFieldTypes(text, possible_types);
+ }
+}
+
+string16 AutoFillProfile::GetFieldText(const AutoFillType& type) const {
+ FormGroupMap::const_iterator iter = personal_info_.find(type.group());
+ if (iter == personal_info_.end() || iter->second == NULL)
+ return string16();
+
+ return iter->second->GetFieldText(type);
+}
+
+void AutoFillProfile::FindInfoMatches(
+ const AutoFillType& type,
+ const string16& info,
+ std::vector<string16>* matched_text) const {
+ if (matched_text == NULL) {
+ DLOG(ERROR) << "NULL matched text passed in";
+ return;
+ }
+
+ string16 clean_info = StringToLowerASCII(CollapseWhitespace(info, false));
+
+ // If the field_type is unknown, then match against all field types.
+ if (type.field_type() == UNKNOWN_TYPE) {
+ FormGroupMap::const_iterator iter;
+ for (iter = personal_info_.begin(); iter != personal_info_.end(); ++iter) {
+ iter->second->FindInfoMatches(type, clean_info, matched_text);
+ }
+ } else {
+ FormGroupMap::const_iterator iter = personal_info_.find(type.group());
+ DCHECK(iter != personal_info_.end() && iter->second != NULL);
+ if (iter != personal_info_.end() && iter->second != NULL)
+ iter->second->FindInfoMatches(type, clean_info, matched_text);
+ }
+}
+
+void AutoFillProfile::SetInfo(const AutoFillType& type, const string16& value) {
+ FormGroupMap::const_iterator iter = personal_info_.find(type.group());
+ if (iter == personal_info_.end() || iter->second == NULL)
+ return;
+
+ iter->second->SetInfo(type, CollapseWhitespace(value, false));
+}
+
+FormGroup* AutoFillProfile::Clone() const {
+ AutoFillProfile* profile = new AutoFillProfile();
+ profile->label_ = label_;
+ profile->unique_id_ = unique_id();
+ profile->use_billing_address_ = use_billing_address_;
+
+ FormGroupMap::const_iterator iter;
+ for (iter = personal_info_.begin(); iter != personal_info_.end(); ++iter) {
+ profile->personal_info_[iter->first] = iter->second->Clone();
+ }
+
+ return profile;
+}
+
+void AutoFillProfile::set_use_billing_address(bool use) {
+ if (use_billing_address_ == use)
+ return;
+
+ Address* billing_address = GetBillingAddress();
+
+ if (use) {
+ // If we were using the home address as a billing address then the home
+ // address information should be cleared out of the billing address object.
+ billing_address->Clear();
+ } else {
+ // If we no longer want to use an alternate billing address then clone the
+ // home address information for our billing address.
+ Address* home_address = GetHomeAddress();
+ billing_address->Clone(*home_address);
+ }
+
+ use_billing_address_ = use;
+}
+
+Address* AutoFillProfile::GetBillingAddress() {
+ return static_cast<Address*>(personal_info_[AutoFillType::ADDRESS_BILLING]);
+}
+
+Address* AutoFillProfile::GetHomeAddress() {
+ return static_cast<Address*>(personal_info_[AutoFillType::ADDRESS_HOME]);
+}
diff --git a/chrome/browser/autofill/autofill_profile.h b/chrome/browser/autofill/autofill_profile.h
new file mode 100644
index 0000000..eedc578
--- /dev/null
+++ b/chrome/browser/autofill/autofill_profile.h
@@ -0,0 +1,74 @@
+// 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_AUTOFILL_PROFILE_H_
+#define CHROME_BROWSER_AUTOFILL_AUTOFILL_PROFILE_H_
+
+#include <map>
+#include <vector>
+
+#include "base/string16.h"
+#include "chrome/browser/autofill/form_group.h"
+
+class Address;
+typedef std::map<FieldTypeGroup, FormGroup*> FormGroupMap;
+
+// A collection of FormGroups stored in a profile. AutoFillProfile also
+// implements the FormGroup interface so that owners of this object can request
+// form information from the profile, and the profile will delegate the request
+// to the requested form group type.
+class AutoFillProfile : public FormGroup {
+ public:
+ AutoFillProfile(const string16& label, int unique_id);
+ virtual ~AutoFillProfile();
+
+ // FormGroup implementation:
+ virtual void GetPossibleFieldTypes(const string16& text,
+ FieldTypeSet* possible_types) const;
+ virtual string16 GetFieldText(const AutoFillType& type) const;
+ // Returns true if the info matches the profile data corresponding to type.
+ // If the type is UNKNOWN_TYPE then info will be matched against all of the
+ // profile data.
+ virtual void FindInfoMatches(const AutoFillType& type,
+ const string16& info,
+ std::vector<string16>* matched_text) const;
+ virtual void SetInfo(const AutoFillType& type, const string16& value);
+ // Returns a copy of the profile it is called on. The caller is responsible
+ // for deleting profile when they are done with it.
+ virtual FormGroup* Clone() const;
+ virtual string16 Label() const { return label_; }
+
+ // NOTE: callers must write the profile to the WebDB after changing the value
+ // of use_billing_address.
+ void set_use_billing_address(bool use);
+ bool use_billing_address() const { return use_billing_address_; }
+
+ int unique_id() const { return unique_id_; }
+
+ // TODO(jhawkins): Implement RemoveProfile.
+
+ private:
+ // This constructor should only be used by the copy constructor.
+ AutoFillProfile() {}
+
+ Address* GetBillingAddress();
+ Address* GetHomeAddress();
+
+ // The label presented to the user when selecting a profile.
+ string16 label_;
+
+ // The unique ID of this profile.
+ int unique_id_;
+
+ // If true, the billing address will be used for the home address. Correlates
+ // with the "Use billing address" option on some billing forms.
+ bool use_billing_address_;
+
+ // Personal information for this profile.
+ FormGroupMap personal_info_;
+
+ DISALLOW_COPY_AND_ASSIGN(AutoFillProfile);
+};
+
+#endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_PROFILE_H_
diff --git a/chrome/browser/autofill/autofill_type.cc b/chrome/browser/autofill/autofill_type.cc
index f97ab42..46c2aef 100644
--- a/chrome/browser/autofill/autofill_type.cc
+++ b/chrome/browser/autofill/autofill_type.cc
@@ -39,7 +39,7 @@ AutoFillType::AutoFillTypeDefinition kAutoFillTypeDefinitions[] = {
{ ADDRESS_HOME_LINE1, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_LINE1, "Home Address Line 1" },
{ ADDRESS_HOME_LINE2, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_LINE2, "Home Address Line 2" },
- { ADDRESS_HOME_APPT_NUM, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_APPT_NUM, "Home Address Apartment Number" },
+ { ADDRESS_HOME_APT_NUM, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_APT_NUM, "Home Address Apartment Number" },
{ ADDRESS_HOME_CITY, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_CITY, "Home Address City" },
{ ADDRESS_HOME_STATE, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_STATE, "Home Address State" },
{ ADDRESS_HOME_ZIP, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_ZIP, "Home Address Zip Code" },
@@ -47,7 +47,7 @@ AutoFillType::AutoFillTypeDefinition kAutoFillTypeDefinitions[] = {
{ ADDRESS_BILLING_LINE1, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_LINE1, "Billing Address Line 1" },
{ ADDRESS_BILLING_LINE2, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_LINE2, "Billing Address Line 2" },
- { ADDRESS_BILLING_APPT_NUM, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_APPT_NUM, "Billing Address Apartment Number" },
+ { ADDRESS_BILLING_APT_NUM, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_APT_NUM, "Billing Address Apartment Number" },
{ ADDRESS_BILLING_CITY, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_CITY, "Billing Address City" },
{ ADDRESS_BILLING_STATE, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_STATE, "Billing Address State" },
{ ADDRESS_BILLING_ZIP, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_ZIP, "Billing Address Zip Code" },
diff --git a/chrome/browser/autofill/autofill_type.h b/chrome/browser/autofill/autofill_type.h
index 700f5ef..18d093c 100644
--- a/chrome/browser/autofill/autofill_type.h
+++ b/chrome/browser/autofill/autofill_type.h
@@ -31,7 +31,7 @@ class AutoFillType {
// Address subgroups.
ADDRESS_LINE1,
ADDRESS_LINE2,
- ADDRESS_APPT_NUM,
+ ADDRESS_APT_NUM,
ADDRESS_CITY,
ADDRESS_STATE,
ADDRESS_ZIP,
diff --git a/chrome/browser/autofill/billing_address.h b/chrome/browser/autofill/billing_address.h
index f0aae86..79cd90e 100644
--- a/chrome/browser/autofill/billing_address.h
+++ b/chrome/browser/autofill/billing_address.h
@@ -25,8 +25,8 @@ class BillingAddress : public Address {
return ADDRESS_BILLING_LINE2;
}
- virtual AutoFillFieldType GetApptNumType() const {
- return ADDRESS_BILLING_APPT_NUM;
+ virtual AutoFillFieldType GetAptNumType() const {
+ return ADDRESS_BILLING_APT_NUM;
}
virtual AutoFillFieldType GetCityType() const {
diff --git a/chrome/browser/autofill/fax_number.h b/chrome/browser/autofill/fax_number.h
index a034be6..5ebd11e 100644
--- a/chrome/browser/autofill/fax_number.h
+++ b/chrome/browser/autofill/fax_number.h
@@ -11,6 +11,7 @@ class FormGroup;
class FaxNumber : public PhoneNumber {
public:
+ FaxNumber() {}
virtual FormGroup* Clone() const { return new FaxNumber(*this); }
protected:
diff --git a/chrome/browser/autofill/field_types.h b/chrome/browser/autofill/field_types.h
index d202a2e..ff713c2 100644
--- a/chrome/browser/autofill/field_types.h
+++ b/chrome/browser/autofill/field_types.h
@@ -54,14 +54,14 @@ typedef enum _FieldType {
ADDRESS_HOME_LINE1 = 30,
ADDRESS_HOME_LINE2 = 31,
- ADDRESS_HOME_APPT_NUM = 32,
+ ADDRESS_HOME_APT_NUM = 32,
ADDRESS_HOME_CITY = 33,
ADDRESS_HOME_STATE = 34,
ADDRESS_HOME_ZIP = 35,
ADDRESS_HOME_COUNTRY = 36,
ADDRESS_BILLING_LINE1 = 37,
ADDRESS_BILLING_LINE2 = 38,
- ADDRESS_BILLING_APPT_NUM = 39,
+ ADDRESS_BILLING_APT_NUM = 39,
ADDRESS_BILLING_CITY = 40,
ADDRESS_BILLING_STATE = 41,
ADDRESS_BILLING_ZIP = 42,
diff --git a/chrome/browser/autofill/home_address.h b/chrome/browser/autofill/home_address.h
index 2d1709c..bf51dc5 100644
--- a/chrome/browser/autofill/home_address.h
+++ b/chrome/browser/autofill/home_address.h
@@ -25,8 +25,8 @@ class HomeAddress : public Address {
return ADDRESS_HOME_LINE2;
}
- virtual AutoFillFieldType GetApptNumType() const {
- return ADDRESS_HOME_APPT_NUM;
+ virtual AutoFillFieldType GetAptNumType() const {
+ return ADDRESS_HOME_APT_NUM;
}
virtual AutoFillFieldType GetCityType() const {
diff --git a/chrome/browser/autofill/home_phone_number.h b/chrome/browser/autofill/home_phone_number.h
index a3eaf9e..d4051c9 100644
--- a/chrome/browser/autofill/home_phone_number.h
+++ b/chrome/browser/autofill/home_phone_number.h
@@ -11,6 +11,7 @@ class FormGroup;
class HomePhoneNumber : public PhoneNumber {
public:
+ HomePhoneNumber() {}
virtual FormGroup* Clone() const { return new HomePhoneNumber(*this); }
protected:
diff --git a/chrome/browser/autofill/phone_number.h b/chrome/browser/autofill/phone_number.h
index 225214e..0850a94 100644
--- a/chrome/browser/autofill/phone_number.h
+++ b/chrome/browser/autofill/phone_number.h
@@ -13,6 +13,9 @@
// A form group that stores phone number information.
class PhoneNumber : public FormGroup {
public:
+ PhoneNumber() {}
+ virtual ~PhoneNumber() {}
+
// FormGroup implementation:
virtual FormGroup* Clone() const = 0;
virtual void GetPossibleFieldTypes(const string16& text,
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index f8f684e..5d1f3ec 100755
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -90,6 +90,8 @@
'browser/autofill/autofill_infobar_delegate.h',
'browser/autofill/autofill_manager.cc',
'browser/autofill/autofill_manager.h',
+ 'browser/autofill/autofill_profile.cc',
+ 'browser/autofill/autofill_profile.h',
'browser/autofill/autofill_type.cc',
'browser/autofill/autofill_type.h',
'browser/autofill/billing_address.h',