Commit 8c191a64 authored by estade's avatar estade Committed by Commit bot

[Autofill] More variant-related code deletion

BUG=493856

Review URL: https://codereview.chromium.org/1162203004

Cr-Commit-Position: refs/heads/master@{#333177}
parent a851e897
...@@ -209,44 +209,6 @@ base::string16 GetFormGroupInfo(const FormGroup& form_group, ...@@ -209,44 +209,6 @@ base::string16 GetFormGroupInfo(const FormGroup& form_group,
form_group.GetInfo(type, app_locale); form_group.GetInfo(type, app_locale);
} }
template <class T>
void CopyRawValuesToItems(ServerFieldType type,
const std::vector<base::string16>& values,
const T& prototype,
std::vector<T>* form_group_items) {
form_group_items->resize(values.size(), prototype);
for (size_t i = 0; i < form_group_items->size(); ++i) {
(*form_group_items)[i].SetRawInfo(type, values[i]);
}
// Must have at least one (possibly empty) element.
form_group_items->resize(std::max<size_t>(1UL, values.size()), prototype);
}
template <class T>
void CopyValuesToItems(AutofillType type,
const std::vector<base::string16>& values,
const T& prototype,
const std::string& app_locale,
std::vector<T>* form_group_items) {
form_group_items->resize(values.size(), prototype);
for (size_t i = 0; i < form_group_items->size(); ++i) {
(*form_group_items)[i].SetInfo(type, values[i], app_locale);
}
// Must have at least one (possibly empty) element.
form_group_items->resize(std::max<size_t>(1UL, values.size()), prototype);
}
template <class T>
void CopyItemsToValues(const AutofillType& type,
const std::vector<T>& form_group_items,
const std::string& app_locale,
std::vector<base::string16>* values) {
values->resize(form_group_items.size());
for (size_t i = 0; i < values->size(); ++i) {
(*values)[i] = GetFormGroupInfo(form_group_items[i], type, app_locale);
}
}
// Collapse compound field types to their "full" type. I.e. First name // Collapse compound field types to their "full" type. I.e. First name
// collapses to full name, area code collapses to full phone, etc. // collapses to full name, area code collapses to full phone, etc.
void CollapseCompoundFieldTypes(ServerFieldTypeSet* type_set) { void CollapseCompoundFieldTypes(ServerFieldTypeSet* type_set) {
...@@ -303,15 +265,13 @@ AutofillProfile::AutofillProfile(const std::string& guid, ...@@ -303,15 +265,13 @@ AutofillProfile::AutofillProfile(const std::string& guid,
const std::string& origin) const std::string& origin)
: AutofillDataModel(guid, origin), : AutofillDataModel(guid, origin),
record_type_(LOCAL_PROFILE), record_type_(LOCAL_PROFILE),
email_(1), phone_number_(this) {
phone_number_(1, PhoneNumber(this)) {
} }
AutofillProfile::AutofillProfile(RecordType type, const std::string& server_id) AutofillProfile::AutofillProfile(RecordType type, const std::string& server_id)
: AutofillDataModel(base::GenerateGUID(), std::string()), : AutofillDataModel(base::GenerateGUID(), std::string()),
record_type_(type), record_type_(type),
email_(1), phone_number_(this),
phone_number_(1, PhoneNumber(this)),
server_id_(server_id) { server_id_(server_id) {
DCHECK(type == SERVER_PROFILE); DCHECK(type == SERVER_PROFILE);
} }
...@@ -319,12 +279,12 @@ AutofillProfile::AutofillProfile(RecordType type, const std::string& server_id) ...@@ -319,12 +279,12 @@ AutofillProfile::AutofillProfile(RecordType type, const std::string& server_id)
AutofillProfile::AutofillProfile() AutofillProfile::AutofillProfile()
: AutofillDataModel(base::GenerateGUID(), std::string()), : AutofillDataModel(base::GenerateGUID(), std::string()),
record_type_(LOCAL_PROFILE), record_type_(LOCAL_PROFILE),
email_(1), phone_number_(this) {
phone_number_(1, PhoneNumber(this)) {
} }
AutofillProfile::AutofillProfile(const AutofillProfile& profile) AutofillProfile::AutofillProfile(const AutofillProfile& profile)
: AutofillDataModel(std::string(), std::string()) { : AutofillDataModel(std::string(), std::string()),
phone_number_(this) {
operator=(profile); operator=(profile);
} }
...@@ -348,9 +308,7 @@ AutofillProfile& AutofillProfile::operator=(const AutofillProfile& profile) { ...@@ -348,9 +308,7 @@ AutofillProfile& AutofillProfile::operator=(const AutofillProfile& profile) {
email_ = profile.email_; email_ = profile.email_;
company_ = profile.company_; company_ = profile.company_;
phone_number_ = profile.phone_number_; phone_number_ = profile.phone_number_;
phone_number_.set_profile(this);
for (size_t i = 0; i < phone_number_.size(); ++i)
phone_number_[i].set_profile(this);
address_ = profile.address_; address_ = profile.address_;
set_language_code(profile.language_code()); set_language_code(profile.language_code());
...@@ -423,16 +381,10 @@ void AutofillProfile::SetRawMultiInfo( ...@@ -423,16 +381,10 @@ void AutofillProfile::SetRawMultiInfo(
switch (AutofillType(type).group()) { switch (AutofillType(type).group()) {
case NAME: case NAME:
case NAME_BILLING: case NAME_BILLING:
SetRawInfo(type, values.empty() ? base::string16() : values[0]);
break;
case EMAIL: case EMAIL:
CopyRawValuesToItems(type, values, EmailInfo(), &email_);
break;
case PHONE_HOME: case PHONE_HOME:
case PHONE_BILLING: case PHONE_BILLING:
CopyRawValuesToItems(type, values, PhoneNumber(this), &phone_number_); SetRawInfo(type, values.empty() ? base::string16() : values[0]);
break; break;
default: default:
...@@ -845,22 +797,13 @@ void AutofillProfile::GetSupportedTypes( ...@@ -845,22 +797,13 @@ void AutofillProfile::GetSupportedTypes(
(*it)->GetSupportedTypes(supported_types); (*it)->GetSupportedTypes(supported_types);
} }
// TODO(estade): remove this function.
void AutofillProfile::GetMultiInfoImpl( void AutofillProfile::GetMultiInfoImpl(
const AutofillType& type, const AutofillType& type,
const std::string& app_locale, const std::string& app_locale,
std::vector<base::string16>* values) const { std::vector<base::string16>* values) const {
switch (type.group()) { values->resize(1);
case EMAIL: (*values)[0] = GetFormGroupInfo(*this, type, app_locale);
CopyItemsToValues(type, email_, app_locale, values);
break;
case PHONE_HOME:
case PHONE_BILLING:
CopyItemsToValues(type, phone_number_, app_locale, values);
break;
default:
values->resize(1);
(*values)[0] = GetFormGroupInfo(*this, type, app_locale);
}
} }
base::string16 AutofillProfile::ConstructInferredLabel( base::string16 AutofillProfile::ConstructInferredLabel(
...@@ -1017,9 +960,9 @@ void AutofillProfile::CreateInferredLabelsHelper( ...@@ -1017,9 +960,9 @@ void AutofillProfile::CreateInferredLabelsHelper(
AutofillProfile::FormGroupList AutofillProfile::FormGroups() const { AutofillProfile::FormGroupList AutofillProfile::FormGroups() const {
FormGroupList v(5); FormGroupList v(5);
v[0] = &name_; v[0] = &name_;
v[1] = &email_[0]; v[1] = &email_;
v[2] = &company_; v[2] = &company_;
v[3] = &phone_number_[0]; v[3] = &phone_number_;
v[4] = &address_; v[4] = &address_;
return v; return v;
} }
...@@ -1036,14 +979,14 @@ FormGroup* AutofillProfile::MutableFormGroupForType(const AutofillType& type) { ...@@ -1036,14 +979,14 @@ FormGroup* AutofillProfile::MutableFormGroupForType(const AutofillType& type) {
return &name_; return &name_;
case EMAIL: case EMAIL:
return &email_[0]; return &email_;
case COMPANY: case COMPANY:
return &company_; return &company_;
case PHONE_HOME: case PHONE_HOME:
case PHONE_BILLING: case PHONE_BILLING:
return &phone_number_[0]; return &phone_number_;
case ADDRESS_HOME: case ADDRESS_HOME:
case ADDRESS_BILLING: case ADDRESS_BILLING:
......
...@@ -240,9 +240,9 @@ class AutofillProfile : public AutofillDataModel { ...@@ -240,9 +240,9 @@ class AutofillProfile : public AutofillDataModel {
// Personal information for this profile. // Personal information for this profile.
NameInfo name_; NameInfo name_;
std::vector<EmailInfo> email_; EmailInfo email_;
CompanyInfo company_; CompanyInfo company_;
std::vector<PhoneNumber> phone_number_; PhoneNumber phone_number_;
Address address_; Address address_;
// The BCP 47 language code that can be used to format |address_| for display. // The BCP 47 language code that can be used to format |address_| for display.
......
...@@ -141,15 +141,10 @@ scoped_ptr<AutofillProfile> ConstructCompleteProfile() { ...@@ -141,15 +141,10 @@ scoped_ptr<AutofillProfile> ConstructCompleteProfile() {
profile->SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("K.")); profile->SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("K."));
profile->SetRawInfo(NAME_LAST, ASCIIToUTF16("Doe")); profile->SetRawInfo(NAME_LAST, ASCIIToUTF16("Doe"));
std::vector<base::string16> emails; profile->SetRawInfo(EMAIL_ADDRESS,
emails.push_back(ASCIIToUTF16("user@example.com")); ASCIIToUTF16("user@example.com"));
emails.push_back(ASCIIToUTF16("superuser@example.org")); profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER,
profile->SetRawMultiInfo(EMAIL_ADDRESS, emails); ASCIIToUTF16("1.800.555.1234"));
std::vector<base::string16> phones;
phones.push_back(ASCIIToUTF16("1.800.555.1234"));
phones.push_back(ASCIIToUTF16("1.866.650.0000"));
profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phones);
profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS,
ASCIIToUTF16("123 Fake St.\n" ASCIIToUTF16("123 Fake St.\n"
...@@ -188,10 +183,8 @@ syncer::SyncData ConstructCompleteSyncData() { ...@@ -188,10 +183,8 @@ syncer::SyncData ConstructCompleteSyncData() {
specifics->add_name_full("John K. Doe, Jr."); specifics->add_name_full("John K. Doe, Jr.");
specifics->add_email_address("user@example.com"); specifics->add_email_address("user@example.com");
specifics->add_email_address("superuser@example.org");
specifics->add_phone_home_whole_number("1.800.555.1234"); specifics->add_phone_home_whole_number("1.800.555.1234");
specifics->add_phone_home_whole_number("1.866.650.0000");
specifics->set_address_home_line1("123 Fake St."); specifics->set_address_home_line1("123 Fake St.");
specifics->set_address_home_line2("Apt. 42"); specifics->set_address_home_line2("Apt. 42");
...@@ -597,39 +590,6 @@ TEST_F(AutofillProfileSyncableServiceTest, UpdateField) { ...@@ -597,39 +590,6 @@ TEST_F(AutofillProfileSyncableServiceTest, UpdateField) {
EXPECT_EQ(profile.GetRawInfo(COMPANY_NAME), ASCIIToUTF16(company2)); EXPECT_EQ(profile.GetRawInfo(COMPANY_NAME), ASCIIToUTF16(company2));
} }
TEST_F(AutofillProfileSyncableServiceTest, UpdateMultivaluedField) {
AutofillProfile profile(kGuid1, kHttpsOrigin);
std::vector<base::string16> values;
values.push_back(ASCIIToUTF16("1@1.com"));
values.push_back(ASCIIToUTF16("2@1.com"));
profile.SetRawMultiInfo(EMAIL_ADDRESS, values);
::google::protobuf::RepeatedPtrField<std::string> specifics_fields;
specifics_fields.AddAllocated(new std::string("2@1.com"));
specifics_fields.AddAllocated(new std::string("3@1.com"));
EXPECT_TRUE(AutofillProfileSyncableService::UpdateMultivaluedField(
EMAIL_ADDRESS, specifics_fields, &profile));
profile.GetRawMultiInfo(EMAIL_ADDRESS, &values);
ASSERT_TRUE(values.size() == 2);
EXPECT_EQ(values[0], ASCIIToUTF16("2@1.com"));
EXPECT_EQ(values[1], ASCIIToUTF16("3@1.com"));
EXPECT_FALSE(AutofillProfileSyncableService::UpdateMultivaluedField(
EMAIL_ADDRESS, specifics_fields, &profile));
profile.GetRawMultiInfo(EMAIL_ADDRESS, &values);
ASSERT_EQ(values.size(), 2U);
EXPECT_EQ(values[0], ASCIIToUTF16("2@1.com"));
EXPECT_EQ(values[1], ASCIIToUTF16("3@1.com"));
EXPECT_TRUE(AutofillProfileSyncableService::UpdateMultivaluedField(
EMAIL_ADDRESS, ::google::protobuf::RepeatedPtrField<std::string>(),
&profile));
profile.GetRawMultiInfo(EMAIL_ADDRESS, &values);
ASSERT_EQ(values.size(), 1U); // Always have at least an empty string.
EXPECT_EQ(values[0], ASCIIToUTF16(""));
}
TEST_F(AutofillProfileSyncableServiceTest, MergeProfile) { TEST_F(AutofillProfileSyncableServiceTest, MergeProfile) {
AutofillProfile profile1(kGuid1, kHttpOrigin); AutofillProfile profile1(kGuid1, kHttpOrigin);
profile1.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("111 First St.")); profile1.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("111 First St."));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment