summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/autofill/address.cc31
-rw-r--r--chrome/browser/autofill/address.h8
-rw-r--r--chrome/browser/autofill/autofill_manager_unittest.cc7
-rw-r--r--chrome/browser/autofill/autofill_profile.cc146
-rw-r--r--chrome/browser/autofill/autofill_profile.h39
-rw-r--r--chrome/browser/autofill/autofill_profile_unittest.cc6
-rw-r--r--chrome/browser/autofill/autofill_type.cc16
-rw-r--r--chrome/browser/autofill/autofill_type.h4
-rw-r--r--chrome/browser/autofill/autofill_type_unittest.cc4
-rw-r--r--chrome/browser/autofill/contact_info.cc339
-rw-r--r--chrome/browser/autofill/contact_info.h89
-rw-r--r--chrome/browser/autofill/contact_info_unittest.cc78
-rw-r--r--chrome/browser/autofill/credit_card.cc4
-rw-r--r--chrome/browser/autofill/credit_card.h1
-rw-r--r--chrome/browser/autofill/fax_number.cc9
-rw-r--r--chrome/browser/autofill/fax_number.h9
-rw-r--r--chrome/browser/autofill/form_group.h3
-rw-r--r--chrome/browser/autofill/home_phone_number.cc15
-rw-r--r--chrome/browser/autofill/home_phone_number.h13
-rw-r--r--chrome/browser/autofill/phone_number.cc22
-rw-r--r--chrome/browser/autofill/phone_number.h9
21 files changed, 472 insertions, 380 deletions
diff --git a/chrome/browser/autofill/address.cc b/chrome/browser/autofill/address.cc
index 59d1b1e..183b5e1 100644
--- a/chrome/browser/autofill/address.cc
+++ b/chrome/browser/autofill/address.cc
@@ -29,10 +29,25 @@ const int kAutoFillAddressLength = arraysize(kAutoFillAddressTypes);
Address::Address() {}
+Address::Address(const Address& address) : FormGroup() {
+ *this = address;
+}
+
Address::~Address() {}
-FormGroup* Address::Clone() const {
- return new Address(*this);
+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_;
+ state_ = address.state_;
+ country_code_ = address.country_code_;
+ zip_code_ = address.zip_code_;
+ return *this;
}
void Address::GetPossibleFieldTypes(const string16& text,
@@ -154,18 +169,6 @@ void Address::Clear() {
zip_code_.clear();
}
-Address::Address(const Address& address)
- : FormGroup(),
- line1_tokens_(address.line1_tokens_),
- line2_tokens_(address.line2_tokens_),
- line1_(address.line1_),
- line2_(address.line2_),
- city_(address.city_),
- state_(address.state_),
- country_code_(address.country_code_),
- zip_code_(address.zip_code_) {
-}
-
string16 Address::Country() const {
if (country_code().empty())
return string16();
diff --git a/chrome/browser/autofill/address.h b/chrome/browser/autofill/address.h
index 8040c69..6e33878 100644
--- a/chrome/browser/autofill/address.h
+++ b/chrome/browser/autofill/address.h
@@ -16,10 +16,12 @@
class Address : public FormGroup {
public:
Address();
+ explicit Address(const Address& address);
virtual ~Address();
+ Address& operator=(const Address& address);
+
// FormGroup:
- virtual FormGroup* Clone() const;
virtual void GetPossibleFieldTypes(const string16& text,
FieldTypeSet* possible_types) const;
virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const;
@@ -41,10 +43,6 @@ class Address : public FormGroup {
// Vector of tokens in an address line.
typedef std::vector<string16> LineTokens;
- explicit Address(const Address& address);
-
- void operator=(const Address& address);
-
// Returns the localized country name corresponding to |country_code_|.
string16 Country() const;
diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
index e3d912b..ed23d54 100644
--- a/chrome/browser/autofill/autofill_manager_unittest.cc
+++ b/chrome/browser/autofill/autofill_manager_unittest.cc
@@ -672,9 +672,10 @@ TEST_F(AutofillManagerTest, GetProfileSuggestionsWithDuplicates) {
FormsSeen(forms);
// Add a duplicate profile.
- AutoFillProfile* duplicate_profile = static_cast<AutoFillProfile*>(
- autofill_manager_->GetProfileWithGUID(
- "00000000-0000-0000-0000-000000000001")->Clone());
+ AutoFillProfile* duplicate_profile =
+ new AutoFillProfile(
+ *(autofill_manager_->GetProfileWithGUID(
+ "00000000-0000-0000-0000-000000000001")));
autofill_manager_->AddProfile(duplicate_profile);
const FormField& field = form.fields[0];
diff --git a/chrome/browser/autofill/autofill_profile.cc b/chrome/browser/autofill/autofill_profile.cc
index fbdb0da..f30aba4 100644
--- a/chrome/browser/autofill/autofill_profile.cc
+++ b/chrome/browser/autofill/autofill_profile.cc
@@ -102,12 +102,10 @@ void GetFieldsForDistinguishingProfiles(
AutoFillProfile::AutoFillProfile(const std::string& guid)
: guid_(guid) {
- InitPersonalInfo(&personal_info_);
}
AutoFillProfile::AutoFillProfile()
: guid_(guid::GenerateGUID()) {
- InitPersonalInfo(&personal_info_);
}
AutoFillProfile::AutoFillProfile(const AutoFillProfile& source)
@@ -116,77 +114,82 @@ AutoFillProfile::AutoFillProfile(const AutoFillProfile& source)
}
AutoFillProfile::~AutoFillProfile() {
- STLDeleteContainerPairSecondPointers(personal_info_.begin(),
- personal_info_.end());
+}
+
+AutoFillProfile& AutoFillProfile::operator=(const AutoFillProfile& profile) {
+ if (this == &profile)
+ return *this;
+
+ label_ = profile.label_;
+ guid_ = profile.guid_;
+
+ name_ = profile.name_;
+ email_ = profile.email_;
+ company_ = profile.company_;
+ home_number_ = profile.home_number_;
+ fax_number_ = profile.fax_number_;
+ address_ = profile.address_;
+
+ return *this;
}
void AutoFillProfile::GetPossibleFieldTypes(
const string16& text,
FieldTypeSet* possible_types) const {
- for (FormGroupMap::const_iterator iter = personal_info_.begin();
- iter != personal_info_.end(); ++iter) {
- FormGroup* data = iter->second;
- DCHECK(data != NULL);
- data->GetPossibleFieldTypes(text, possible_types);
- }
+ FormGroupList info = info_list();
+ for (FormGroupList::const_iterator it = info.begin(); it != info.end(); ++it)
+ (*it)->GetPossibleFieldTypes(text, possible_types);
}
void AutoFillProfile::GetAvailableFieldTypes(
FieldTypeSet* available_types) const {
- for (FormGroupMap::const_iterator iter = personal_info_.begin();
- iter != personal_info_.end(); ++iter) {
- FormGroup* data = iter->second;
- DCHECK(data != NULL);
- data->GetAvailableFieldTypes(available_types);
- }
+ FormGroupList info = info_list();
+ for (FormGroupList::const_iterator it = info.begin(); it != info.end(); ++it)
+ (*it)->GetAvailableFieldTypes(available_types);
}
string16 AutoFillProfile::GetFieldText(const AutofillType& type) const {
AutofillType return_type(
AutofillType::GetEquivalentFieldType(type.field_type()));
- FormGroupMap::const_iterator iter = personal_info_.find(return_type.group());
- if (iter == personal_info_.end() || iter->second == NULL)
+ FormGroupMap info = info_map();
+ FormGroupMap::const_iterator it = info.find(return_type.group());
+ if (it == info.end())
return string16();
- return iter->second->GetFieldText(return_type);
+ return it->second->GetFieldText(return_type);
}
void AutoFillProfile::FindInfoMatches(
const AutofillType& type,
- const string16& info,
+ const string16& value,
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));
+ string16 clean_info = StringToLowerASCII(CollapseWhitespace(value, 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);
- }
+ FormGroupList info = info_list();
+ for (FormGroupList::const_iterator it = info.begin();
+ it != info.end(); ++it)
+ (*it)->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);
+ FormGroupMap info = info_map();
+ FormGroupMap::const_iterator it = info.find(type.group());
+ DCHECK(it != info.end());
+ it->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 {
- return new AutoFillProfile(*this);
+ MutableFormGroupMap info = mutable_info_map();
+ MutableFormGroupMap::iterator it = info.find(type.group());
+ DCHECK(it != info.end());
+ it->second->SetInfo(type, CollapseWhitespace(value, false));
}
const string16 AutoFillProfile::Label() const {
@@ -194,19 +197,11 @@ const string16 AutoFillProfile::Label() const {
}
const std::string AutoFillProfile::CountryCode() const {
- FormGroup* form_group =
- personal_info_.find(AutofillType::ADDRESS_HOME)->second;
- DCHECK(form_group);
- Address* address = static_cast<Address*>(form_group);
- return address->country_code();
+ return address_.country_code();
}
void AutoFillProfile::SetCountryCode(const std::string& country_code) {
- FormGroup* form_group =
- personal_info_.find(AutofillType::ADDRESS_HOME)->second;
- DCHECK(form_group);
- Address* address = static_cast<Address*>(form_group);
- address->set_country_code(country_code);
+ address_.set_country_code(country_code);
}
// static
@@ -278,25 +273,6 @@ bool AutoFillProfile::IsEmpty() const {
return types.empty();
}
-void AutoFillProfile::operator=(const AutoFillProfile& source) {
- if (this == &source)
- return;
-
- label_ = source.label_;
- guid_ = source.guid_;
-
- STLDeleteContainerPairSecondPointers(personal_info_.begin(),
- personal_info_.end());
- personal_info_.clear();
-
- FormGroupMap::const_iterator iter;
- for (iter = source.personal_info_.begin();
- iter != source.personal_info_.end();
- ++iter) {
- personal_info_[iter->first] = iter->second->Clone();
- }
-}
-
int AutoFillProfile::Compare(const AutoFillProfile& profile) const {
// The following AutoFill field types are the only types we store in the WebDB
// so far, so we're only concerned with matching these types in the profile.
@@ -446,12 +422,36 @@ void AutoFillProfile::CreateDifferentiatingLabels(
}
}
-// static
-void AutoFillProfile::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 Address();
+AutoFillProfile::FormGroupList AutoFillProfile::info_list() const {
+ FormGroupList v(6);
+ v[0] = &name_;
+ v[1] = &email_;
+ v[2] = &company_;
+ v[3] = &home_number_;
+ v[4] = &fax_number_;
+ v[5] = &address_;
+ return v;
+}
+
+AutoFillProfile::FormGroupMap AutoFillProfile::info_map() const {
+ FormGroupMap m;
+ m[AutofillType::NAME] = &name_;
+ m[AutofillType::EMAIL] = &email_;
+ m[AutofillType::COMPANY] = &company_;
+ m[AutofillType::PHONE_HOME] = &home_number_;
+ m[AutofillType::PHONE_FAX] = &fax_number_;
+ m[AutofillType::ADDRESS_HOME] = &address_;
+ return m;
+}
+
+AutoFillProfile::MutableFormGroupMap AutoFillProfile::mutable_info_map() {
+ FormGroupMap m_const = info_map();
+ MutableFormGroupMap m;
+ for (FormGroupMap::const_iterator it = m_const.begin();
+ it != m_const.end(); ++it) {
+ m[it->first] = const_cast<FormGroup*>(it->second);
+ }
+ return m;
}
// So we can compare AutoFillProfiles with EXPECT_EQ().
diff --git a/chrome/browser/autofill/autofill_profile.h b/chrome/browser/autofill/autofill_profile.h
index 72a7273..3465c11 100644
--- a/chrome/browser/autofill/autofill_profile.h
+++ b/chrome/browser/autofill/autofill_profile.h
@@ -11,7 +11,11 @@
#include <vector>
#include "base/string16.h"
+#include "chrome/browser/autofill/address.h"
+#include "chrome/browser/autofill/contact_info.h"
+#include "chrome/browser/autofill/fax_number.h"
#include "chrome/browser/autofill/form_group.h"
+#include "chrome/browser/autofill/home_phone_number.h"
// A collection of FormGroups stored in a profile. AutoFillProfile also
// implements the FormGroup interface so that owners of this object can request
@@ -26,21 +30,21 @@ class AutoFillProfile : public FormGroup {
AutoFillProfile(const AutoFillProfile&);
virtual ~AutoFillProfile();
- // FormGroup implementation:
+ AutoFillProfile& operator=(const AutoFillProfile& profile);
+
+ // FormGroup:
virtual void GetPossibleFieldTypes(const string16& text,
FieldTypeSet* possible_types) const;
virtual void GetAvailableFieldTypes(FieldTypeSet* available_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
+ // Returns true if the |value| matches the profile data corresponding to type.
+ // If the type is UNKNOWN_TYPE then |value| will be matched against all of the
// profile data.
virtual void FindInfoMatches(const AutofillType& type,
- const string16& info,
+ const string16& value,
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;
+
// The user-visible label of the profile, generated in relation to other
// profiles. Shows at least 2 fields that differentiate profile from other
// profiles. See AdjustInferredLabels() further down for more description.
@@ -86,9 +90,6 @@ class AutoFillProfile : public FormGroup {
// Returns true if there are no values (field types) set.
bool IsEmpty() const;
- // For use in STL containers.
- void operator=(const AutoFillProfile&);
-
// Comparison for Sync. Returns 0 if the profile is the same as |this|,
// or < 0, or > 0 if it is different. The implied ordering can be used for
// culling duplicates. The ordering is based on collation order of the
@@ -106,7 +107,9 @@ class AutoFillProfile : public FormGroup {
const string16 PrimaryValue() const;
private:
- typedef std::map<FieldTypeGroup, FormGroup*> FormGroupMap;
+ typedef std::vector<const FormGroup*> FormGroupList;
+ typedef std::map<FieldTypeGroup, const FormGroup*> FormGroupMap;
+ typedef std::map<FieldTypeGroup, FormGroup*> MutableFormGroupMap;
// Builds inferred label from the first |num_fields_to_include| non-empty
// fields in |label_fields|. Uses as many fields as possible if there are not
@@ -127,8 +130,11 @@ class AutoFillProfile : public FormGroup {
size_t num_fields_to_include,
std::vector<string16>* created_labels);
- // Utility to initialize a |FormGroupMap|.
- static void InitPersonalInfo(FormGroupMap* personal_info);
+ // Utilities for listing and lookup of the data members that constitute
+ // user-visible profile information.
+ FormGroupList info_list() const;
+ FormGroupMap info_map() const;
+ MutableFormGroupMap mutable_info_map();
// The label presented to the user when selecting a profile.
string16 label_;
@@ -137,7 +143,12 @@ class AutoFillProfile : public FormGroup {
std::string guid_;
// Personal information for this profile.
- FormGroupMap personal_info_;
+ NameInfo name_;
+ EmailInfo email_;
+ CompanyInfo company_;
+ HomePhoneNumber home_number_;
+ FaxNumber fax_number_;
+ Address address_;
};
// So we can compare AutoFillProfiles with EXPECT_EQ().
diff --git a/chrome/browser/autofill/autofill_profile_unittest.cc b/chrome/browser/autofill/autofill_profile_unittest.cc
index 982bcb7..a84453b 100644
--- a/chrome/browser/autofill/autofill_profile_unittest.cc
+++ b/chrome/browser/autofill/autofill_profile_unittest.cc
@@ -603,7 +603,7 @@ TEST(AutoFillProfileTest, AssignmentOperator){
EXPECT_TRUE(a == b);
}
-TEST(AutoFillProfileTest, Clone) {
+TEST(AutoFillProfileTest, Copy) {
AutoFillProfile a;
// Clone should be logically equal to the original.
@@ -611,8 +611,8 @@ TEST(AutoFillProfileTest, Clone) {
"marion@me.xyz", "Fox", "123 Zoo St.", "unit 5",
"Hollywood", "CA", "91601", "US", "12345678910",
"01987654321");
- scoped_ptr<AutoFillProfile> b(static_cast<AutoFillProfile*>(a.Clone()));
- EXPECT_TRUE(a == *b);
+ AutoFillProfile b(a);
+ EXPECT_TRUE(a == b);
}
TEST(AutoFillProfileTest, Compare) {
diff --git a/chrome/browser/autofill/autofill_type.cc b/chrome/browser/autofill/autofill_type.cc
index 7ca8c7c..b9c1618 100644
--- a/chrome/browser/autofill/autofill_type.cc
+++ b/chrome/browser/autofill/autofill_type.cc
@@ -22,20 +22,20 @@ AutofillType::AutofillTypeDefinition kAutofillTypeDefinitions[] = {
{ AutofillType::NO_GROUP, AutofillType::NO_SUBGROUP },
// NAME_FIRST
- { AutofillType::CONTACT_INFO, AutofillType::NO_SUBGROUP },
+ { AutofillType::NAME, AutofillType::NO_SUBGROUP },
// NAME_MIDDLE
- { AutofillType::CONTACT_INFO, AutofillType::NO_SUBGROUP },
+ { AutofillType::NAME, AutofillType::NO_SUBGROUP },
// NAME_LAST
- { AutofillType::CONTACT_INFO, AutofillType::NO_SUBGROUP },
+ { AutofillType::NAME, AutofillType::NO_SUBGROUP },
// NAME_MIDDLE_INITIAL
- { AutofillType::CONTACT_INFO, AutofillType::NO_SUBGROUP },
+ { AutofillType::NAME, AutofillType::NO_SUBGROUP },
// NAME_FULL
- { AutofillType::CONTACT_INFO, AutofillType::NO_SUBGROUP },
+ { AutofillType::NAME, AutofillType::NO_SUBGROUP },
// NAME_SUFFIX
- { AutofillType::CONTACT_INFO, AutofillType::NO_SUBGROUP },
+ { AutofillType::NAME, AutofillType::NO_SUBGROUP },
// EMAIL_ADDRESS
- { AutofillType::CONTACT_INFO, AutofillType::NO_SUBGROUP },
+ { AutofillType::EMAIL, AutofillType::NO_SUBGROUP },
// PHONE_HOME_NUMBER
{ AutofillType::PHONE_HOME, AutofillType::PHONE_NUMBER },
@@ -132,7 +132,7 @@ AutofillType::AutofillTypeDefinition kAutofillTypeDefinitions[] = {
{ AutofillType::CREDIT_CARD, AutofillType::NO_SUBGROUP },
// COMPANY_NAME
- { AutofillType::CONTACT_INFO, AutofillType::NO_SUBGROUP },
+ { AutofillType::COMPANY, AutofillType::NO_SUBGROUP },
};
} // namespace
diff --git a/chrome/browser/autofill/autofill_type.h b/chrome/browser/autofill/autofill_type.h
index dc24c86..9aef7b3 100644
--- a/chrome/browser/autofill/autofill_type.h
+++ b/chrome/browser/autofill/autofill_type.h
@@ -19,7 +19,9 @@ class AutofillType {
public:
enum FieldTypeGroup {
NO_GROUP,
- CONTACT_INFO,
+ NAME,
+ EMAIL,
+ COMPANY,
ADDRESS_HOME,
ADDRESS_BILLING,
PHONE_HOME,
diff --git a/chrome/browser/autofill/autofill_type_unittest.cc b/chrome/browser/autofill/autofill_type_unittest.cc
index 6f812e2..4f5d401 100644
--- a/chrome/browser/autofill/autofill_type_unittest.cc
+++ b/chrome/browser/autofill/autofill_type_unittest.cc
@@ -23,7 +23,7 @@ TEST(AutofillTypeTest, Basic) {
// Type with group but no subgroup.
AutofillType first(NAME_FIRST);
EXPECT_EQ(NAME_FIRST, first.field_type());
- EXPECT_EQ(AutofillType::CONTACT_INFO, first.group());
+ EXPECT_EQ(AutofillType::NAME, first.group());
EXPECT_EQ(AutofillType::NO_SUBGROUP, first.subgroup());
// Type with group and subgroup.
@@ -35,7 +35,7 @@ TEST(AutofillTypeTest, Basic) {
// Last value, to check any offset errors.
AutofillType last(COMPANY_NAME);
EXPECT_EQ(COMPANY_NAME, last.field_type());
- EXPECT_EQ(AutofillType::CONTACT_INFO, last.group());
+ EXPECT_EQ(AutofillType::COMPANY, last.group());
EXPECT_EQ(AutofillType::NO_SUBGROUP, last.subgroup());
// Boundary (error) condition.
diff --git a/chrome/browser/autofill/contact_info.cc b/chrome/browser/autofill/contact_info.cc
index c951d660..1ff74ee 100644
--- a/chrome/browser/autofill/contact_info.cc
+++ b/chrome/browser/autofill/contact_info.cc
@@ -12,26 +12,37 @@
static const string16 kNameSplitChars = ASCIIToUTF16("-'. ");
-static const AutofillFieldType kAutoFillContactInfoTypes[] = {
+static const AutofillFieldType kAutoFillNameInfoTypes[] = {
NAME_FIRST,
NAME_MIDDLE,
- NAME_LAST,
- EMAIL_ADDRESS,
- COMPANY_NAME,
+ NAME_LAST
};
-static const size_t kAutoFillContactInfoLength =
- arraysize(kAutoFillContactInfoTypes);
+static const size_t kAutoFillNameInfoLength =
+ arraysize(kAutoFillNameInfoTypes);
-ContactInfo::ContactInfo() {}
+NameInfo::NameInfo() {}
-ContactInfo::~ContactInfo() {}
+NameInfo::NameInfo(const NameInfo& info) : FormGroup() {
+ *this = info;
+}
+
+NameInfo::~NameInfo() {}
+
+NameInfo& NameInfo::operator=(const NameInfo& info) {
+ if (this == &info)
+ return *this;
-FormGroup* ContactInfo::Clone() const {
- return new ContactInfo(*this);
+ first_tokens_ = info.first_tokens_;
+ middle_tokens_ = info.middle_tokens_;
+ last_tokens_ = info.last_tokens_;
+ first_ = info.first_;
+ middle_ = info.middle_;
+ last_ = info.last_;
+ return *this;
}
-void ContactInfo::GetPossibleFieldTypes(const string16& text,
+void NameInfo::GetPossibleFieldTypes(const string16& text,
FieldTypeSet* possible_types) const {
DCHECK(possible_types);
@@ -47,20 +58,11 @@ void ContactInfo::GetPossibleFieldTypes(const string16& text,
if (IsMiddleInitial(text))
possible_types->insert(NAME_MIDDLE_INITIAL);
- if (IsSuffix(text))
- possible_types->insert(NAME_SUFFIX);
-
if (IsFullName(text))
possible_types->insert(NAME_FULL);
-
- if (email_ == text)
- possible_types->insert(EMAIL_ADDRESS);
-
- if (company_name_ == text)
- possible_types->insert(COMPANY_NAME);
}
-void ContactInfo::GetAvailableFieldTypes(FieldTypeSet* available_types) const {
+void NameInfo::GetAvailableFieldTypes(FieldTypeSet* available_types) const {
DCHECK(available_types);
if (!first().empty())
@@ -77,26 +79,17 @@ void ContactInfo::GetAvailableFieldTypes(FieldTypeSet* available_types) const {
if (!FullName().empty())
available_types->insert(NAME_FULL);
-
- if (!suffix().empty())
- available_types->insert(NAME_SUFFIX);
-
- if (!email().empty())
- available_types->insert(EMAIL_ADDRESS);
-
- if (!company_name().empty())
- available_types->insert(COMPANY_NAME);
}
-void ContactInfo::FindInfoMatches(const AutofillType& type,
+void NameInfo::FindInfoMatches(const AutofillType& type,
const string16& info,
std::vector<string16>* matched_text) const {
DCHECK(matched_text);
string16 match;
if (type.field_type() == UNKNOWN_TYPE) {
- for (size_t i = 0; i < kAutoFillContactInfoLength; i++) {
- if (FindInfoMatchesHelper(kAutoFillContactInfoTypes[i], info, &match))
+ for (size_t i = 0; i < kAutoFillNameInfoLength; i++) {
+ if (FindInfoMatchesHelper(kAutoFillNameInfoTypes[i], info, &match))
matched_text->push_back(match);
}
} else if (FindInfoMatchesHelper(type.field_type(), info, &match)) {
@@ -104,7 +97,7 @@ void ContactInfo::FindInfoMatches(const AutofillType& type,
}
}
-string16 ContactInfo::GetFieldText(const AutofillType& type) const {
+string16 NameInfo::GetFieldText(const AutofillType& type) const {
AutofillFieldType field_type = type.field_type();
if (field_type == NAME_FIRST)
return first();
@@ -121,82 +114,25 @@ string16 ContactInfo::GetFieldText(const AutofillType& type) const {
if (field_type == NAME_FULL)
return FullName();
- if (field_type == NAME_SUFFIX)
- return suffix();
-
- if (field_type == EMAIL_ADDRESS)
- return email();
-
- if (field_type == COMPANY_NAME)
- return company_name();
-
return string16();
}
-void ContactInfo::SetInfo(const AutofillType& type, const string16& value) {
+void NameInfo::SetInfo(const AutofillType& type, const string16& value) {
AutofillFieldType field_type = type.field_type();
- DCHECK_EQ(AutofillType::CONTACT_INFO, type.group());
+ DCHECK_EQ(AutofillType::NAME, type.group());
if (field_type == NAME_FIRST)
SetFirst(value);
else if (field_type == NAME_MIDDLE || field_type == NAME_MIDDLE_INITIAL)
SetMiddle(value);
else if (field_type == NAME_LAST)
SetLast(value);
- else if (field_type == NAME_SUFFIX)
- set_suffix(value);
- else if (field_type == EMAIL_ADDRESS)
- email_ = value;
- else if (field_type == COMPANY_NAME)
- company_name_ = value;
else if (field_type == NAME_FULL)
SetFullName(value);
else
NOTREACHED();
}
-ContactInfo::ContactInfo(const ContactInfo& contact_info)
- : FormGroup(),
- first_tokens_(contact_info.first_tokens_),
- middle_tokens_(contact_info.middle_tokens_),
- last_tokens_(contact_info.last_tokens_),
- first_(contact_info.first_),
- middle_(contact_info.middle_),
- last_(contact_info.last_),
- suffix_(contact_info.suffix_),
- email_(contact_info.email_),
- company_name_(contact_info.company_name_) {
-}
-
-string16 ContactInfo::FullName() const {
- if (first_.empty())
- return string16();
-
- std::vector<string16> full_name;
- full_name.push_back(first_);
-
- if (!middle_.empty())
- full_name.push_back(middle_);
-
- if (!last_.empty())
- full_name.push_back(last_);
-
- if (!suffix_.empty())
- full_name.push_back(suffix_);
-
- return JoinString(full_name, ' ');
-}
-
-string16 ContactInfo::MiddleInitial() const {
- if (middle_.empty())
- return string16();
-
- string16 middle_name(middle());
- string16 initial;
- initial.push_back(middle_name[0]);
- return initial;
-}
-
-bool ContactInfo::FindInfoMatchesHelper(const AutofillFieldType& field_type,
+bool NameInfo::FindInfoMatchesHelper(const AutofillFieldType& field_type,
const string16& info,
string16* match) const {
if (match == NULL) {
@@ -214,51 +150,63 @@ bool ContactInfo::FindInfoMatchesHelper(const AutofillFieldType& field_type,
} else if (field_type == NAME_LAST &&
StartsWith(last(), info, false)) {
*match = last();
- } else if (field_type == NAME_SUFFIX &&
- StartsWith(suffix(), info, false)) {
- *match = suffix();
} else if (field_type == NAME_MIDDLE_INITIAL && IsMiddleInitial(info)) {
*match = MiddleInitial();
} else if (field_type == NAME_FULL &&
StartsWith(FullName(), info, false)) {
*match = FullName();
- } else if (field_type == EMAIL_ADDRESS &&
- StartsWith(email(), info, false)) {
- *match = email();
- } else if (field_type == COMPANY_NAME &&
- StartsWith(company_name(), info, false)) {
- *match = company_name();
}
return !match->empty();
}
+string16 NameInfo::FullName() const {
+ if (first_.empty())
+ return string16();
+
+ std::vector<string16> full_name;
+ full_name.push_back(first_);
+
+ if (!middle_.empty())
+ full_name.push_back(middle_);
+
+ if (!last_.empty())
+ full_name.push_back(last_);
+
+ return JoinString(full_name, ' ');
+}
+
+string16 NameInfo::MiddleInitial() const {
+ if (middle_.empty())
+ return string16();
+
+ string16 middle_name(middle());
+ string16 initial;
+ initial.push_back(middle_name[0]);
+ return initial;
+}
+
// If each of the 'words' contained in the text are also present in the first
// name then we will consider the text to be of type kFirstName. This means
// that people with multiple first names will be able to enter any one of
// their first names and have it correctly recognized.
-bool ContactInfo::IsFirstName(const string16& text) const {
+bool NameInfo::IsFirstName(const string16& text) const {
return IsNameMatch(text, first_tokens_);
}
// If each of the 'words' contained in the text are also present in the middle
// name then we will consider the text to be of type kMiddleName.
-bool ContactInfo::IsMiddleName(const string16& text) const {
+bool NameInfo::IsMiddleName(const string16& text) const {
return IsNameMatch(text, middle_tokens_);
}
// If each of the 'words' contained in the text are also present in the last
// name then we will consider the text to be of type kLastName.
-bool ContactInfo::IsLastName(const string16& text) const {
+bool NameInfo::IsLastName(const string16& text) const {
return IsNameMatch(text, last_tokens_);
}
-bool ContactInfo::IsSuffix(const string16& text) const {
- string16 lower_suffix = StringToLowerASCII(suffix_);
- return (lower_suffix == text);
-}
-
-bool ContactInfo::IsMiddleInitial(const string16& text) const {
+bool NameInfo::IsMiddleInitial(const string16& text) const {
if (text.length() != 1)
return false;
@@ -280,7 +228,7 @@ bool ContactInfo::IsMiddleInitial(const string16& text) const {
// 2) it contains at least one word from the last name.
// 3) all of the words in the field match a word in either the first,
// middle, or last name.
-bool ContactInfo::IsFullName(const string16& text) const {
+bool NameInfo::IsFullName(const string16& text) const {
size_t first_tokens_size = first_tokens_.size();
if (first_tokens_size == 0)
return false;
@@ -291,7 +239,7 @@ bool ContactInfo::IsFullName(const string16& text) const {
if (last_tokens_size == 0)
return false;
- NameTokens text_tokens;
+ std::vector<string16> text_tokens;
Tokenize(text, kNameSplitChars, &text_tokens);
size_t text_tokens_size = text_tokens.size();
if (text_tokens_size == 0 || text_tokens_size < 2)
@@ -304,8 +252,8 @@ bool ContactInfo::IsFullName(const string16& text) const {
bool first_name_match = false;
bool last_name_match = false;
- NameTokens::iterator iter;
- for (iter = text_tokens.begin(); iter != text_tokens.end(); ++iter) {
+ for (std::vector<string16>::iterator iter = text_tokens.begin();
+ iter != text_tokens.end(); ++iter) {
bool match = false;
if (IsWordInName(*iter, first_tokens_)) {
match = true;
@@ -327,13 +275,13 @@ bool ContactInfo::IsFullName(const string16& text) const {
return (first_name_match && last_name_match);
}
-bool ContactInfo::IsNameMatch(const string16& text,
- const NameTokens& name_tokens) const {
+bool NameInfo::IsNameMatch(const string16& text,
+ const std::vector<string16>& name_tokens) const {
size_t name_tokens_size = name_tokens.size();
if (name_tokens_size == 0)
return false;
- NameTokens text_tokens;
+ std::vector<string16> text_tokens;
Tokenize(text, kNameSplitChars, &text_tokens);
size_t text_tokens_size = text_tokens.size();
if (text_tokens_size == 0)
@@ -344,8 +292,8 @@ bool ContactInfo::IsNameMatch(const string16& text,
// If each of the 'words' contained in the text are also present in the name,
// then we will consider the text to match the name.
- NameTokens::iterator iter;
- for (iter = text_tokens.begin(); iter != text_tokens.end(); ++iter) {
+ for (std::vector<string16>::iterator iter = text_tokens.begin();
+ iter != text_tokens.end(); ++iter) {
if (!IsWordInName(*iter, name_tokens))
return false;
}
@@ -353,10 +301,10 @@ bool ContactInfo::IsNameMatch(const string16& text,
return true;
}
-bool ContactInfo::IsWordInName(const string16& word,
- const NameTokens& name_tokens) const {
- NameTokens::const_iterator iter;
- for (iter = name_tokens.begin(); iter != name_tokens.end(); ++iter) {
+bool NameInfo::IsWordInName(const string16& word,
+ const std::vector<string16>& name_tokens) const {
+ for (std::vector<string16>::const_iterator iter = name_tokens.begin();
+ iter != name_tokens.end(); ++iter) {
// |*iter| is already lower-cased.
if (StringToLowerASCII(word) == *iter)
return true;
@@ -365,35 +313,38 @@ bool ContactInfo::IsWordInName(const string16& word,
return false;
}
-void ContactInfo::SetFirst(const string16& first) {
+void NameInfo::SetFirst(const string16& first) {
first_ = first;
first_tokens_.clear();
Tokenize(first, kNameSplitChars, &first_tokens_);
- NameTokens::iterator iter;
- for (iter = first_tokens_.begin(); iter != first_tokens_.end(); ++iter)
+ for (std::vector<string16>::iterator iter = first_tokens_.begin();
+ iter != first_tokens_.end(); ++iter) {
*iter = StringToLowerASCII(*iter);
+ }
}
-void ContactInfo::SetMiddle(const string16& middle) {
+void NameInfo::SetMiddle(const string16& middle) {
middle_ = middle;
middle_tokens_.clear();
Tokenize(middle, kNameSplitChars, &middle_tokens_);
- NameTokens::iterator iter;
- for (iter = middle_tokens_.begin(); iter != middle_tokens_.end(); ++iter)
+ for (std::vector<string16>::iterator iter = middle_tokens_.begin();
+ iter != middle_tokens_.end(); ++iter) {
*iter = StringToLowerASCII(*iter);
+ }
}
-void ContactInfo::SetLast(const string16& last) {
+void NameInfo::SetLast(const string16& last) {
last_ = last;
last_tokens_.clear();
Tokenize(last, kNameSplitChars, &last_tokens_);
- NameTokens::iterator iter;
- for (iter = last_tokens_.begin(); iter != last_tokens_.end(); ++iter)
+ for (std::vector<string16>::iterator iter = last_tokens_.begin();
+ iter != last_tokens_.end(); ++iter) {
*iter = StringToLowerASCII(*iter);
+ }
}
-void ContactInfo::SetFullName(const string16& full) {
- NameTokens full_name_tokens;
+void NameInfo::SetFullName(const string16& full) {
+ std::vector<string16> full_name_tokens;
Tokenize(full, ASCIIToUTF16(" "), &full_name_tokens);
// Clear the names.
SetFirst(string16());
@@ -415,3 +366,119 @@ void ContactInfo::SetFullName(const string16& full) {
}
}
+EmailInfo::EmailInfo() {}
+
+EmailInfo::EmailInfo(const EmailInfo& info) : FormGroup() {
+ *this = info;
+}
+
+EmailInfo::~EmailInfo() {}
+
+EmailInfo& EmailInfo::operator=(const EmailInfo& info) {
+ if (this == &info)
+ return *this;
+
+ email_ = info.email_;
+ return *this;
+}
+
+void EmailInfo::GetPossibleFieldTypes(const string16& text,
+ FieldTypeSet* possible_types) const {
+ DCHECK(possible_types);
+ // TODO(isherman): Investigate case-insensitive comparison.
+ if (email_ == text)
+ possible_types->insert(EMAIL_ADDRESS);
+}
+
+void EmailInfo::GetAvailableFieldTypes(FieldTypeSet* available_types) const {
+ DCHECK(available_types);
+ if (!email_.empty())
+ available_types->insert(EMAIL_ADDRESS);
+}
+
+void EmailInfo::FindInfoMatches(const AutofillType& type,
+ const string16& info,
+ std::vector<string16>* matched_text) const {
+ DCHECK(matched_text);
+
+ string16 match;
+ if (type.field_type() == UNKNOWN_TYPE && StartsWith(email_, info, false)) {
+ matched_text->push_back(email_);
+ } else if (type.field_type() == EMAIL_ADDRESS &&
+ StartsWith(email_, info, false)) {
+ matched_text->push_back(email_);
+ }
+}
+
+string16 EmailInfo::GetFieldText(const AutofillType& type) const {
+ AutofillFieldType field_type = type.field_type();
+ if (field_type == EMAIL_ADDRESS)
+ return email_;
+
+ return string16();
+}
+
+void EmailInfo::SetInfo(const AutofillType& type, const string16& value) {
+ DCHECK_EQ(AutofillType::EMAIL, type.group());
+ email_ = value;
+}
+
+CompanyInfo::CompanyInfo() {}
+
+CompanyInfo::CompanyInfo(const CompanyInfo& info) : FormGroup() {
+ *this = info;
+}
+
+CompanyInfo::~CompanyInfo() {}
+
+CompanyInfo& CompanyInfo::operator=(const CompanyInfo& info) {
+ if (this == &info)
+ return *this;
+
+ company_name_ = info.company_name_;
+ return *this;
+}
+
+void CompanyInfo::GetPossibleFieldTypes(const string16& text,
+ FieldTypeSet* possible_types) const {
+ DCHECK(possible_types);
+
+ if (company_name_ == text)
+ possible_types->insert(COMPANY_NAME);
+}
+
+void CompanyInfo::GetAvailableFieldTypes(FieldTypeSet* available_types) const {
+ DCHECK(available_types);
+
+ if (!company_name_.empty())
+ available_types->insert(COMPANY_NAME);
+}
+
+void CompanyInfo::FindInfoMatches(const AutofillType& type,
+ const string16& info,
+ std::vector<string16>* matched_text) const {
+ DCHECK(matched_text);
+
+ string16 match;
+ if (type.field_type() == UNKNOWN_TYPE &&
+ StartsWith(company_name_, info, false)) {
+ matched_text->push_back(company_name_);
+ } else if (type.field_type() == COMPANY_NAME &&
+ StartsWith(company_name_, info, false)) {
+ matched_text->push_back(company_name_);
+ }
+}
+
+string16 CompanyInfo::GetFieldText(const AutofillType& type) const {
+ AutofillFieldType field_type = type.field_type();
+
+ if (field_type == COMPANY_NAME)
+ return company_name_;
+
+ return string16();
+}
+
+void CompanyInfo::SetInfo(const AutofillType& type, const string16& value) {
+ DCHECK_EQ(AutofillType::COMPANY, type.group());
+ company_name_ = value;
+}
diff --git a/chrome/browser/autofill/contact_info.h b/chrome/browser/autofill/contact_info.h
index d743630..22c618a 100644
--- a/chrome/browser/autofill/contact_info.h
+++ b/chrome/browser/autofill/contact_info.h
@@ -8,19 +8,20 @@
#include <vector>
+#include "base/gtest_prod_util.h"
#include "base/string16.h"
#include "chrome/browser/autofill/form_group.h"
-typedef std::vector<string16> NameTokens;
-
-// A form group that stores contact information.
-class ContactInfo : public FormGroup {
+// A form group that stores name information.
+class NameInfo : public FormGroup {
public:
- ContactInfo();
- virtual ~ContactInfo();
+ NameInfo();
+ explicit NameInfo(const NameInfo& info);
+ virtual ~NameInfo();
+
+ NameInfo& operator=(const NameInfo& info);
- // FormGroup implementation:
- virtual FormGroup* Clone() const;
+ // FormGroup:
virtual void GetPossibleFieldTypes(const string16& text,
FieldTypeSet* possible_types) const;
virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const;
@@ -31,12 +32,10 @@ class ContactInfo : public FormGroup {
virtual void SetInfo(const AutofillType& type, const string16& value);
private:
- friend class ContactInfoTest;
- explicit ContactInfo(const ContactInfo& contact_info);
- void operator=(const ContactInfo& info);
+ FRIEND_TEST_ALL_PREFIXES(NameInfoTest, TestSetFullName);
- // Returns the full name, which can include up to the first, middle, middle
- // initial, last name, and suffix.
+ // Returns the full name, which can include up to the first, middle, and last
+ // name.
string16 FullName() const;
// Returns the middle initial if |middle_| is non-empty. Returns an empty
@@ -46,9 +45,6 @@ class ContactInfo : public FormGroup {
const string16& first() const { return first_; }
const string16& middle() const { return middle_; }
const string16& last() const { return last_; }
- const string16& suffix() const { return suffix_; }
- const string16& email() const { return email_; }
- const string16& company_name() const { return company_name_; }
// A helper function for FindInfoMatches that only handles matching the info
// with the requested field type.
@@ -65,9 +61,6 @@ class ContactInfo : public FormGroup {
// Returns true if |text| is the last name.
bool IsLastName(const string16& text) const;
- // Returns true if |text| is the suffix.
- bool IsSuffix(const string16& text) const;
-
// Returns true if |text| is the middle initial.
bool IsMiddleInitial(const string16& text) const;
@@ -76,10 +69,12 @@ class ContactInfo : public FormGroup {
// Returns true if all of the tokens in |text| match the tokens in
// |name_tokens|.
- bool IsNameMatch(const string16& text, const NameTokens& name_tokens) const;
+ bool IsNameMatch(const string16& text,
+ const std::vector<string16>& name_tokens) const;
// Returns true if |word| is one of the tokens in |name_tokens|.
- bool IsWordInName(const string16& word, const NameTokens& name_tokens) const;
+ bool IsWordInName(const string16& word,
+ const std::vector<string16>& name_tokens) const;
// Sets |first_| to |first| and |first_tokens_| to the set of tokens in
// |first|, made lowercase.
@@ -97,19 +92,57 @@ class ContactInfo : public FormGroup {
// |full|. It is tokenized on a space only.
void SetFullName(const string16& full);
- void set_suffix(const string16& suffix) { suffix_ = suffix; }
-
// List of tokens in each part of the name.
- NameTokens first_tokens_;
- NameTokens middle_tokens_;
- NameTokens last_tokens_;
+ std::vector<string16> first_tokens_;
+ std::vector<string16> middle_tokens_;
+ std::vector<string16> last_tokens_;
- // Contact information data.
string16 first_;
string16 middle_;
string16 last_;
- string16 suffix_;
+};
+
+class EmailInfo : public FormGroup {
+ public:
+ EmailInfo();
+ explicit EmailInfo(const EmailInfo& info);
+ virtual ~EmailInfo();
+
+ EmailInfo& operator=(const EmailInfo& info);
+
+ // FormGroup:
+ virtual void GetPossibleFieldTypes(const string16& text,
+ FieldTypeSet* possible_types) const;
+ virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const;
+ virtual void FindInfoMatches(const AutofillType& type,
+ const string16& info,
+ std::vector<string16>* matched_text) const;
+ virtual string16 GetFieldText(const AutofillType& type) const;
+ virtual void SetInfo(const AutofillType& type, const string16& value);
+
+ private:
string16 email_;
+};
+
+class CompanyInfo : public FormGroup {
+ public:
+ CompanyInfo();
+ explicit CompanyInfo(const CompanyInfo& info);
+ virtual ~CompanyInfo();
+
+ CompanyInfo& operator=(const CompanyInfo& info);
+
+ // FormGroup:
+ virtual void GetPossibleFieldTypes(const string16& text,
+ FieldTypeSet* possible_types) const;
+ virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const;
+ virtual void FindInfoMatches(const AutofillType& type,
+ const string16& info,
+ std::vector<string16>* matched_text) const;
+ virtual string16 GetFieldText(const AutofillType& type) const;
+ virtual void SetInfo(const AutofillType& type, const string16& value);
+
+ private:
string16 company_name_;
};
diff --git a/chrome/browser/autofill/contact_info_unittest.cc b/chrome/browser/autofill/contact_info_unittest.cc
index 0ce9cec..a99bd79 100644
--- a/chrome/browser/autofill/contact_info_unittest.cc
+++ b/chrome/browser/autofill/contact_info_unittest.cc
@@ -11,57 +11,31 @@
#include "chrome/browser/autofill/field_types.h"
#include "testing/gtest/include/gtest/gtest.h"
-class ContactInfoTest : public testing::Test {
- public:
- ContactInfoTest() {}
-
- string16 first(const ContactInfo& contact) {
- return contact.first();
- }
- string16 middle(const ContactInfo& contact) {
- return contact.middle();
- }
- string16 last(const ContactInfo& contact) {
- return contact.last();
- }
- string16 FullName(const ContactInfo& contact) {
- return contact.FullName();
- }
- void SetFullName(ContactInfo* contact, const string16& full_name) {
- contact->SetFullName(full_name);
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ContactInfoTest);
-};
-
-TEST_F(ContactInfoTest, TestSetFullName) {
- ContactInfo contact_info;
- SetFullName(&contact_info, ASCIIToUTF16("Virgil"));
- EXPECT_EQ(first(contact_info), ASCIIToUTF16("Virgil"));
- EXPECT_EQ(middle(contact_info), ASCIIToUTF16(""));
- EXPECT_EQ(last(contact_info), ASCIIToUTF16(""));
- EXPECT_EQ(FullName(contact_info), ASCIIToUTF16("Virgil"));
-
- SetFullName(&contact_info, ASCIIToUTF16("Murray Gell-Mann"));
- EXPECT_EQ(first(contact_info), ASCIIToUTF16("Murray"));
- EXPECT_EQ(middle(contact_info), ASCIIToUTF16(""));
- EXPECT_EQ(last(contact_info), ASCIIToUTF16("Gell-Mann"));
- EXPECT_EQ(FullName(contact_info), ASCIIToUTF16("Murray Gell-Mann"));
-
- SetFullName(&contact_info,
- ASCIIToUTF16("Mikhail Yevgrafovich Saltykov-Shchedrin"));
- EXPECT_EQ(first(contact_info), ASCIIToUTF16("Mikhail"));
- EXPECT_EQ(middle(contact_info), ASCIIToUTF16("Yevgrafovich"));
- EXPECT_EQ(last(contact_info), ASCIIToUTF16("Saltykov-Shchedrin"));
- EXPECT_EQ(FullName(contact_info),
- ASCIIToUTF16("Mikhail Yevgrafovich Saltykov-Shchedrin"));
-
- SetFullName(&contact_info, ASCIIToUTF16("Arthur Ignatius Conan Doyle"));
- EXPECT_EQ(first(contact_info), ASCIIToUTF16("Arthur"));
- EXPECT_EQ(middle(contact_info), ASCIIToUTF16("Ignatius Conan"));
- EXPECT_EQ(last(contact_info), ASCIIToUTF16("Doyle"));
- EXPECT_EQ(FullName(contact_info),
- ASCIIToUTF16("Arthur Ignatius Conan Doyle"));
+TEST(NameInfoTest, TestSetFullName) {
+ NameInfo name;
+ name.SetFullName(ASCIIToUTF16("Virgil"));
+ EXPECT_EQ(name.first(), ASCIIToUTF16("Virgil"));
+ EXPECT_EQ(name.middle(), ASCIIToUTF16(""));
+ EXPECT_EQ(name.last(), ASCIIToUTF16(""));
+ EXPECT_EQ(name.FullName(), ASCIIToUTF16("Virgil"));
+
+ name.SetFullName(ASCIIToUTF16("Murray Gell-Mann"));
+ EXPECT_EQ(name.first(), ASCIIToUTF16("Murray"));
+ EXPECT_EQ(name.middle(), ASCIIToUTF16(""));
+ EXPECT_EQ(name.last(), ASCIIToUTF16("Gell-Mann"));
+ EXPECT_EQ(name.FullName(), ASCIIToUTF16("Murray Gell-Mann"));
+
+ name.SetFullName(ASCIIToUTF16("Mikhail Yevgrafovich Saltykov-Shchedrin"));
+ EXPECT_EQ(name.first(), ASCIIToUTF16("Mikhail"));
+ EXPECT_EQ(name.middle(), ASCIIToUTF16("Yevgrafovich"));
+ EXPECT_EQ(name.last(), ASCIIToUTF16("Saltykov-Shchedrin"));
+ EXPECT_EQ(name.FullName(),
+ ASCIIToUTF16("Mikhail Yevgrafovich Saltykov-Shchedrin"));
+
+ name.SetFullName(ASCIIToUTF16("Arthur Ignatius Conan Doyle"));
+ EXPECT_EQ(name.first(), ASCIIToUTF16("Arthur"));
+ EXPECT_EQ(name.middle(), ASCIIToUTF16("Ignatius Conan"));
+ EXPECT_EQ(name.last(), ASCIIToUTF16("Doyle"));
+ EXPECT_EQ(name.FullName(), ASCIIToUTF16("Arthur Ignatius Conan Doyle"));
}
diff --git a/chrome/browser/autofill/credit_card.cc b/chrome/browser/autofill/credit_card.cc
index 442c1e6..4360e6a 100644
--- a/chrome/browser/autofill/credit_card.cc
+++ b/chrome/browser/autofill/credit_card.cc
@@ -148,10 +148,6 @@ CreditCard::CreditCard(const CreditCard& credit_card) : FormGroup() {
CreditCard::~CreditCard() {}
-FormGroup* CreditCard::Clone() const {
- return new CreditCard(*this);
-}
-
void CreditCard::GetPossibleFieldTypes(const string16& text,
FieldTypeSet* possible_types) const {
if (IsNameOnCard(text))
diff --git a/chrome/browser/autofill/credit_card.h b/chrome/browser/autofill/credit_card.h
index ab18c5a..84b8d6a 100644
--- a/chrome/browser/autofill/credit_card.h
+++ b/chrome/browser/autofill/credit_card.h
@@ -22,7 +22,6 @@ class CreditCard : public FormGroup {
virtual ~CreditCard();
// FormGroup implementation:
- virtual FormGroup* Clone() const;
virtual void GetPossibleFieldTypes(const string16& text,
FieldTypeSet* possible_types) const;
virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const;
diff --git a/chrome/browser/autofill/fax_number.cc b/chrome/browser/autofill/fax_number.cc
index d1ea3d2..3d1a651 100644
--- a/chrome/browser/autofill/fax_number.cc
+++ b/chrome/browser/autofill/fax_number.cc
@@ -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.
@@ -6,10 +6,13 @@
FaxNumber::FaxNumber() {}
+FaxNumber::FaxNumber(const FaxNumber& fax) : PhoneNumber(fax) {}
+
FaxNumber::~FaxNumber() {}
-FormGroup* FaxNumber::Clone() const {
- return new FaxNumber(*this);
+FaxNumber& FaxNumber::operator=(const FaxNumber& fax) {
+ PhoneNumber::operator=(fax);
+ return *this;
}
AutofillFieldType FaxNumber::GetNumberType() const {
diff --git a/chrome/browser/autofill/fax_number.h b/chrome/browser/autofill/fax_number.h
index 75d6575..3fdc59e 100644
--- a/chrome/browser/autofill/fax_number.h
+++ b/chrome/browser/autofill/fax_number.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.
@@ -13,9 +13,10 @@ class FormGroup;
class FaxNumber : public PhoneNumber {
public:
FaxNumber();
+ explicit FaxNumber(const FaxNumber& fax);
virtual ~FaxNumber();
- virtual FormGroup* Clone() const;
+ FaxNumber& operator=(const FaxNumber& fax);
protected:
virtual AutofillFieldType GetNumberType() const;
@@ -23,10 +24,6 @@ class FaxNumber : public PhoneNumber {
virtual AutofillFieldType GetCountryCodeType() const;
virtual AutofillFieldType GetCityAndNumberType() const;
virtual AutofillFieldType GetWholeNumberType() const;
-
- private:
- explicit FaxNumber(const FaxNumber& phone) : PhoneNumber(phone) {}
- void operator=(const FaxNumber& phone);
};
#endif // CHROME_BROWSER_AUTOFILL_FAX_NUMBER_H_
diff --git a/chrome/browser/autofill/form_group.h b/chrome/browser/autofill/form_group.h
index de1229f..e389ba3 100644
--- a/chrome/browser/autofill/form_group.h
+++ b/chrome/browser/autofill/form_group.h
@@ -20,9 +20,6 @@ class FormGroup {
public:
virtual ~FormGroup() {}
- // Returns a clone of this object.
- virtual FormGroup* Clone() const = 0;
-
// Used to determine the type of a field based on the text that a user enters
// into the field. The field types can then be reported back to the server.
// This method is additive on |possible_types|.
diff --git a/chrome/browser/autofill/home_phone_number.cc b/chrome/browser/autofill/home_phone_number.cc
index fb19c8d..9425df5 100644
--- a/chrome/browser/autofill/home_phone_number.cc
+++ b/chrome/browser/autofill/home_phone_number.cc
@@ -1,11 +1,20 @@
-// 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.
#include "chrome/browser/autofill/home_phone_number.h"
-FormGroup* HomePhoneNumber::Clone() const {
- return new HomePhoneNumber(*this);
+HomePhoneNumber::HomePhoneNumber() {}
+
+HomePhoneNumber::HomePhoneNumber(const HomePhoneNumber& phone)
+ : PhoneNumber(phone) {
+}
+
+HomePhoneNumber::~HomePhoneNumber() {}
+
+HomePhoneNumber& HomePhoneNumber::operator=(const HomePhoneNumber& phone) {
+ PhoneNumber::operator=(phone);
+ return *this;
}
AutofillFieldType HomePhoneNumber::GetNumberType() const {
diff --git a/chrome/browser/autofill/home_phone_number.h b/chrome/browser/autofill/home_phone_number.h
index c24df79..a9e0d145 100644
--- a/chrome/browser/autofill/home_phone_number.h
+++ b/chrome/browser/autofill/home_phone_number.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.
@@ -12,8 +12,11 @@ class FormGroup;
class HomePhoneNumber : public PhoneNumber {
public:
- HomePhoneNumber() {}
- virtual FormGroup* Clone() const;
+ HomePhoneNumber();
+ explicit HomePhoneNumber(const HomePhoneNumber& phone);
+ virtual ~HomePhoneNumber();
+
+ HomePhoneNumber& operator=(const HomePhoneNumber& phone);
protected:
virtual AutofillFieldType GetNumberType() const;
@@ -21,10 +24,6 @@ class HomePhoneNumber : public PhoneNumber {
virtual AutofillFieldType GetCountryCodeType() const;
virtual AutofillFieldType GetCityAndNumberType() const;
virtual AutofillFieldType GetWholeNumberType() const;
-
- private:
- explicit HomePhoneNumber(const HomePhoneNumber& phone) : PhoneNumber(phone) {}
- void operator=(const HomePhoneNumber& phone);
};
#endif // CHROME_BROWSER_AUTOFILL_HOME_PHONE_NUMBER_H_
diff --git a/chrome/browser/autofill/phone_number.cc b/chrome/browser/autofill/phone_number.cc
index 2b8a0cc..110616a 100644
--- a/chrome/browser/autofill/phone_number.cc
+++ b/chrome/browser/autofill/phone_number.cc
@@ -34,8 +34,22 @@ const int kAutoFillPhoneLength = arraysize(kAutoFillPhoneTypes);
PhoneNumber::PhoneNumber() {}
+PhoneNumber::PhoneNumber(const PhoneNumber& number) : FormGroup() {
+ *this = number;
+}
+
PhoneNumber::~PhoneNumber() {}
+PhoneNumber& PhoneNumber::operator=(const PhoneNumber& number) {
+ if (this == &number)
+ return *this;
+ country_code_ = number.country_code_;
+ city_code_ = number.city_code_;
+ number_ = number.number_;
+ extension_ = number.extension_;
+ return *this;
+}
+
void PhoneNumber::GetPossibleFieldTypes(const string16& text,
FieldTypeSet* possible_types) const {
string16 stripped_text(text);
@@ -212,14 +226,6 @@ void PhoneNumber::set_whole_number(const string16& whole_number) {
set_country_code(country_code);
}
-PhoneNumber::PhoneNumber(const PhoneNumber& phone_number)
- : FormGroup(),
- country_code_(phone_number.country_code_),
- city_code_(phone_number.city_code_),
- number_(phone_number.number_),
- extension_(phone_number.extension_) {
-}
-
bool PhoneNumber::FindInfoMatchesHelper(const FieldTypeSubGroup& subgroup,
const string16& info,
string16* match) const {
diff --git a/chrome/browser/autofill/phone_number.h b/chrome/browser/autofill/phone_number.h
index 23fcb69..3c08b9b 100644
--- a/chrome/browser/autofill/phone_number.h
+++ b/chrome/browser/autofill/phone_number.h
@@ -16,10 +16,12 @@
class PhoneNumber : public FormGroup {
public:
PhoneNumber();
+ explicit PhoneNumber(const PhoneNumber& number);
virtual ~PhoneNumber();
+ PhoneNumber& operator=(const PhoneNumber& number);
+
// FormGroup implementation:
- virtual FormGroup* Clone() const = 0;
virtual void GetPossibleFieldTypes(const string16& text,
FieldTypeSet* possible_types) const;
virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const;
@@ -53,14 +55,9 @@ class PhoneNumber : public FormGroup {
virtual AutofillFieldType GetCityAndNumberType() const = 0;
virtual AutofillFieldType GetWholeNumberType() const = 0;
- protected:
- explicit PhoneNumber(const PhoneNumber& phone_number);
-
private:
FRIEND_TEST_ALL_PREFIXES(PhoneNumberTest, Matcher);
- void operator=(const PhoneNumber& phone_number);
-
const string16& country_code() const { return country_code_; }
const string16& city_code() const { return city_code_; }
const string16& number() const { return number_; }