diff options
author | estade <estade@chromium.org> | 2015-06-05 19:06:10 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-06 02:06:31 +0000 |
commit | 75713f0d6d887890bb4773e522bcdb3cb3e328be (patch) | |
tree | 656c41325ed2dfb69ccc962a314ffe43640a1771 | |
parent | 4e3e57b24a04531bfae6c696426fc781f1631aee (diff) | |
download | chromium_src-75713f0d6d887890bb4773e522bcdb3cb3e328be.zip chromium_src-75713f0d6d887890bb4773e522bcdb3cb3e328be.tar.gz chromium_src-75713f0d6d887890bb4773e522bcdb3cb3e328be.tar.bz2 |
[Autofill] remove *MultiInfo* functions
BUG=493856
Review URL: https://codereview.chromium.org/1151763013
Cr-Commit-Position: refs/heads/master@{#333204}
8 files changed, 101 insertions, 392 deletions
diff --git a/chrome/browser/extensions/api/autofill_private/autofill_private_api.cc b/chrome/browser/extensions/api/autofill_private/autofill_private_api.cc index cf04003..878e4d5 100644 --- a/chrome/browser/extensions/api/autofill_private/autofill_private_api.cc +++ b/chrome/browser/extensions/api/autofill_private/autofill_private_api.cc @@ -28,18 +28,6 @@ namespace { static const char kSettingsOrigin[] = "Chrome settings"; static const char kErrorDataUnavailable[] = "Autofill data unavailable."; -// Converts the UTF-8 strings in |input| to UTF-16 strings and adds them to -// |output|. -void UTF8VectorToUTF16Vector( - const std::vector<std::string>& input, - std::vector<base::string16>* output) { - // Ensure output is clear. - output->clear(); - - for (const std::string& s : input) - output->push_back(base::UTF8ToUTF16(s)); -} - // Fills |components| with the address UI components that should be used to // input an address for |country_code| when UI BCP 47 language code is // |ui_language_code|. @@ -261,14 +249,18 @@ ExtensionFunction::ResponseAction AutofillPrivateSaveAddressFunction::Run() { } if (address->phone_numbers) { - UTF8VectorToUTF16Vector(*address->phone_numbers, &string16Container); - profile.SetRawMultiInfo( - autofill::PHONE_HOME_WHOLE_NUMBER, string16Container); + std::string phone; + if (!address->phone_numbers->empty()) + phone = address->phone_numbers->at(0); + profile.SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER, + base::UTF8ToUTF16(phone)); } if (address->email_addresses) { - UTF8VectorToUTF16Vector(*address->email_addresses, &string16Container); - profile.SetRawMultiInfo(autofill::EMAIL_ADDRESS, string16Container); + std::string email; + if (!address->email_addresses->empty()) + email = address->email_addresses->at(0); + profile.SetRawInfo(autofill::EMAIL_ADDRESS, base::UTF8ToUTF16(email)); } if (address->language_code) diff --git a/components/autofill/core/browser/autofill_merge_unittest.cc b/components/autofill/core/browser/autofill_merge_unittest.cc index 91803e1..a737430 100644 --- a/components/autofill/core/browser/autofill_merge_unittest.cc +++ b/components/autofill/core/browser/autofill_merge_unittest.cc @@ -64,14 +64,11 @@ std::string SerializeProfiles(const std::vector<AutofillProfile*>& profiles) { result += "\n"; for (size_t j = 0; j < arraysize(kProfileFieldTypes); ++j) { ServerFieldType type = kProfileFieldTypes[j]; - std::vector<base::string16> values; - profiles[i]->GetRawMultiInfo(type, &values); - for (size_t k = 0; k < values.size(); ++k) { - result += AutofillType(type).ToString(); - result += kFieldSeparator; - result += base::UTF16ToUTF8(values[k]); - result += "\n"; - } + base::string16 value = profiles[i]->GetRawInfo(type); + result += AutofillType(type).ToString(); + result += kFieldSeparator; + result += base::UTF16ToUTF8(value); + result += "\n"; } } diff --git a/components/autofill/core/browser/autofill_profile.cc b/components/autofill/core/browser/autofill_profile.cc index a568978..7012a9b 100644 --- a/components/autofill/core/browser/autofill_profile.cc +++ b/components/autofill/core/browser/autofill_profile.cc @@ -186,29 +186,6 @@ void GetFieldsForDistinguishingProfiles( } } -// A helper function for string streaming. Concatenates multi-valued entries -// stored for a given |type| into a single string. This string is returned. -const base::string16 MultiString(const AutofillProfile& p, - ServerFieldType type) { - std::vector<base::string16> values; - p.GetRawMultiInfo(type, &values); - base::string16 accumulate; - for (size_t i = 0; i < values.size(); ++i) { - if (i > 0) - accumulate += ASCIIToUTF16(" "); - accumulate += values[i]; - } - return accumulate; -} - -base::string16 GetFormGroupInfo(const FormGroup& form_group, - const AutofillType& type, - const std::string& app_locale) { - return app_locale.empty() ? - form_group.GetRawInfo(type.GetStorableType()) : - form_group.GetInfo(type, app_locale); -} - // Collapse compound field types to their "full" type. I.e. First name // collapses to full name, area code collapses to full phone, etc. void CollapseCompoundFieldTypes(ServerFieldTypeSet* type_set) { @@ -283,8 +260,7 @@ AutofillProfile::AutofillProfile() } AutofillProfile::AutofillProfile(const AutofillProfile& profile) - : AutofillDataModel(std::string(), std::string()), - phone_number_(this) { + : AutofillDataModel(std::string(), std::string()), phone_number_(this) { operator=(profile); } @@ -374,37 +350,6 @@ bool AutofillProfile::SetInfo(const AutofillType& type, return form_group->SetInfo(type, trimmed_value, app_locale); } -// TODO(estade): remove this function. -void AutofillProfile::SetRawMultiInfo( - ServerFieldType type, - const std::vector<base::string16>& values) { - switch (AutofillType(type).group()) { - case NAME: - case NAME_BILLING: - case EMAIL: - case PHONE_HOME: - case PHONE_BILLING: - SetRawInfo(type, values.empty() ? base::string16() : values[0]); - break; - - default: - if (values.size() == 1U) { - SetRawInfo(type, values[0]); - } else if (values.empty()) { - SetRawInfo(type, base::string16()); - } else { - NOTREACHED(); - } - break; - } -} - -void AutofillProfile::GetRawMultiInfo( - ServerFieldType type, - std::vector<base::string16>* values) const { - GetMultiInfoImpl(AutofillType(type), std::string(), values); -} - bool AutofillProfile::IsEmpty(const std::string& app_locale) const { ServerFieldTypeSet types; GetNonEmptyTypes(app_locale, &types); @@ -706,10 +651,10 @@ void AutofillProfile::CreateInferredLabels( void AutofillProfile::GenerateServerProfileIdentifier() { DCHECK_EQ(SERVER_PROFILE, record_type()); - base::string16 contents = MultiString(*this, NAME_FIRST); - contents.append(MultiString(*this, NAME_MIDDLE)); - contents.append(MultiString(*this, NAME_LAST)); - contents.append(MultiString(*this, EMAIL_ADDRESS)); + base::string16 contents = GetRawInfo(NAME_FIRST); + contents.append(GetRawInfo(NAME_MIDDLE)); + contents.append(GetRawInfo(NAME_LAST)); + contents.append(GetRawInfo(EMAIL_ADDRESS)); contents.append(GetRawInfo(COMPANY_NAME)); contents.append(GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)); contents.append(GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY)); @@ -718,7 +663,7 @@ void AutofillProfile::GenerateServerProfileIdentifier() { contents.append(GetRawInfo(ADDRESS_HOME_ZIP)); contents.append(GetRawInfo(ADDRESS_HOME_SORTING_CODE)); contents.append(GetRawInfo(ADDRESS_HOME_COUNTRY)); - contents.append(MultiString(*this, PHONE_HOME_WHOLE_NUMBER)); + contents.append(GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); std::string contents_utf8 = UTF16ToUTF8(contents); contents_utf8.append(language_code()); server_id_ = base::SHA1HashString(contents_utf8); @@ -797,15 +742,6 @@ void AutofillProfile::GetSupportedTypes( (*it)->GetSupportedTypes(supported_types); } -// TODO(estade): remove this function. -void AutofillProfile::GetMultiInfoImpl( - const AutofillType& type, - const std::string& app_locale, - std::vector<base::string16>* values) const { - values->resize(1); - (*values)[0] = GetFormGroupInfo(*this, type, app_locale); -} - base::string16 AutofillProfile::ConstructInferredLabel( const std::vector<ServerFieldType>& included_fields, size_t num_fields_to_use, @@ -1012,40 +948,22 @@ bool AutofillProfile::EqualsSansGuid(const AutofillProfile& profile) const { // So we can compare AutofillProfiles with EXPECT_EQ(). std::ostream& operator<<(std::ostream& os, const AutofillProfile& profile) { - return os - << profile.guid() - << " " - << profile.origin() - << " " - << UTF16ToUTF8(MultiString(profile, NAME_FIRST)) - << " " - << UTF16ToUTF8(MultiString(profile, NAME_MIDDLE)) - << " " - << UTF16ToUTF8(MultiString(profile, NAME_LAST)) - << " " - << UTF16ToUTF8(MultiString(profile, EMAIL_ADDRESS)) - << " " - << UTF16ToUTF8(profile.GetRawInfo(COMPANY_NAME)) - << " " - << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_LINE1)) - << " " - << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_LINE2)) - << " " - << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY)) - << " " - << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) - << " " - << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) - << " " - << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) - << " " - << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) - << " " - << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) - << " " - << profile.language_code() - << " " - << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); + return os << profile.guid() << " " << profile.origin() << " " + << UTF16ToUTF8(profile.GetRawInfo(NAME_FIRST)) << " " + << UTF16ToUTF8(profile.GetRawInfo(NAME_MIDDLE)) << " " + << UTF16ToUTF8(profile.GetRawInfo(NAME_LAST)) << " " + << UTF16ToUTF8(profile.GetRawInfo(EMAIL_ADDRESS)) << " " + << UTF16ToUTF8(profile.GetRawInfo(COMPANY_NAME)) << " " + << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_LINE1)) << " " + << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_LINE2)) << " " + << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY)) + << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " " + << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " " + << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " " + << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " " + << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " " + << profile.language_code() << " " + << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); } } // namespace autofill diff --git a/components/autofill/core/browser/autofill_profile.h b/components/autofill/core/browser/autofill_profile.h index b14d907..433099a 100644 --- a/components/autofill/core/browser/autofill_profile.h +++ b/components/autofill/core/browser/autofill_profile.h @@ -69,12 +69,6 @@ class AutofillProfile : public AutofillDataModel { RecordType record_type() const { return record_type_; } void set_record_type(RecordType type) { record_type_ = type; } - // Multi-value equivalents to |GetInfo| and |SetInfo|. - void SetRawMultiInfo(ServerFieldType type, - const std::vector<base::string16>& values); - void GetRawMultiInfo(ServerFieldType type, - std::vector<base::string16>* values) const; - // Returns true if there are no values (field types) set. bool IsEmpty(const std::string& app_locale) const; @@ -194,13 +188,6 @@ class AutofillProfile : public AutofillDataModel { // FormGroup: void GetSupportedTypes(ServerFieldTypeSet* supported_types) const override; - // Shared implementation for GetRawMultiInfo() and GetMultiInfo(). Pass an - // empty |app_locale| to get the raw info; otherwise, the returned info is - // canonicalized according to the given |app_locale|, if appropriate. - void GetMultiInfoImpl(const AutofillType& type, - const std::string& app_locale, - std::vector<base::string16>* values) const; - // 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 // enough non-empty fields. diff --git a/components/autofill/core/browser/webdata/autofill_profile_syncable_service.cc b/components/autofill/core/browser/webdata/autofill_profile_syncable_service.cc index b438e65..ded701c 100644 --- a/components/autofill/core/browser/webdata/autofill_profile_syncable_service.cc +++ b/components/autofill/core/browser/webdata/autofill_profile_syncable_service.cc @@ -453,19 +453,17 @@ void AutofillProfileSyncableService::WriteAutofillProfile( UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY)))); specifics->set_address_home_language_code(LimitData(profile.language_code())); + // TODO(estade): this should be set_email_address. + specifics->add_email_address( + LimitData(UTF16ToUTF8(profile.GetRawInfo(EMAIL_ADDRESS)))); std::vector<base::string16> values; - profile.GetRawMultiInfo(EMAIL_ADDRESS, &values); - for (size_t i = 0; i < values.size(); ++i) { - specifics->add_email_address(LimitData(UTF16ToUTF8(values[i]))); - } specifics->set_company_name( LimitData(UTF16ToUTF8(profile.GetRawInfo(COMPANY_NAME)))); - profile.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); - for (size_t i = 0; i < values.size(); ++i) { - specifics->add_phone_home_whole_number(LimitData(UTF16ToUTF8(values[i]))); - } + // TODO(estade): this should be set_phone_home_whole_number. + specifics->add_phone_home_whole_number( + LimitData(UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)))); } void AutofillProfileSyncableService::CreateGUIDToProfileMap( @@ -619,29 +617,14 @@ bool AutofillProfileSyncableService::UpdateField( return true; } +// TODO(estade): remove this function. bool AutofillProfileSyncableService::UpdateMultivaluedField( ServerFieldType field_type, const ::google::protobuf::RepeatedPtrField<std::string>& new_values, AutofillProfile* autofill_profile) { - std::vector<base::string16> values; - autofill_profile->GetRawMultiInfo(field_type, &values); - bool changed = false; - if (static_cast<size_t>(new_values.size()) != values.size()) { - values.clear(); - values.resize(static_cast<size_t>(new_values.size())); - changed = true; - } - for (size_t i = 0; i < values.size(); ++i) { - base::string16 synced_value( - UTF8ToUTF16(new_values.Get(static_cast<int>(i)))); - if (values[i] != synced_value) { - values[i] = synced_value; - changed = true; - } - } - if (changed) - autofill_profile->SetRawMultiInfo(field_type, values); - return changed; + return UpdateField(field_type, + new_values.size() < 1 ? std::string() : new_values.Get(0), + autofill_profile); } bool AutofillProfileSyncableService::MergeProfile( diff --git a/components/autofill/core/browser/webdata/autofill_profile_syncable_service_unittest.cc b/components/autofill/core/browser/webdata/autofill_profile_syncable_service_unittest.cc index 15620c4..e4bddcf 100644 --- a/components/autofill/core/browser/webdata/autofill_profile_syncable_service_unittest.cc +++ b/components/autofill/core/browser/webdata/autofill_profile_syncable_service_unittest.cc @@ -141,10 +141,8 @@ scoped_ptr<AutofillProfile> ConstructCompleteProfile() { profile->SetRawInfo(NAME_MIDDLE, ASCIIToUTF16("K.")); profile->SetRawInfo(NAME_LAST, ASCIIToUTF16("Doe")); - profile->SetRawInfo(EMAIL_ADDRESS, - ASCIIToUTF16("user@example.com")); - profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, - ASCIIToUTF16("1.800.555.1234")); + profile->SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("user@example.com")); + profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("1.800.555.1234")); profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, ASCIIToUTF16("123 Fake St.\n" @@ -594,32 +592,19 @@ TEST_F(AutofillProfileSyncableServiceTest, MergeProfile) { AutofillProfile profile1(kGuid1, kHttpOrigin); profile1.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("111 First St.")); - std::vector<base::string16> values; - values.push_back(ASCIIToUTF16("1@1.com")); - profile1.SetRawMultiInfo(EMAIL_ADDRESS, values); - AutofillProfile profile2(kGuid2, kHttpsOrigin); profile2.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("111 First St.")); - // |values| now is [ "1@1.com", "2@1.com", "3@1.com" ]. - values.push_back(ASCIIToUTF16("3@1.com")); - profile2.SetRawMultiInfo(EMAIL_ADDRESS, values); + profile1.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("1@1.com")); + profile2.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("1@1.com")); - values.clear(); - values.push_back(ASCIIToUTF16("John")); - profile1.SetRawMultiInfo(NAME_FIRST, values); - values.push_back(ASCIIToUTF16("Jane")); - profile2.SetRawMultiInfo(NAME_FIRST, values); + profile1.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); + profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); - values.clear(); - values.push_back(ASCIIToUTF16("Doe")); - profile1.SetRawMultiInfo(NAME_LAST, values); - values.push_back(ASCIIToUTF16("Other")); - profile2.SetRawMultiInfo(NAME_LAST, values); + profile1.SetRawInfo(NAME_LAST, ASCIIToUTF16("Doe")); + profile2.SetRawInfo(NAME_LAST, ASCIIToUTF16("Doe")); - values.clear(); - values.push_back(ASCIIToUTF16("650234567")); - profile2.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); + profile2.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("650234567")); profile1.set_language_code("en"); @@ -639,27 +624,16 @@ TEST_F(AutofillProfileSyncableServiceTest, MergeProfile) { EXPECT_EQ(ASCIIToUTF16("John"), profile1.GetRawInfo(NAME_FIRST)); EXPECT_EQ(ASCIIToUTF16("Doe"), profile1.GetRawInfo(NAME_LAST)); - - profile1.GetRawMultiInfo(EMAIL_ADDRESS, &values); - ASSERT_EQ(values.size(), 1U); - EXPECT_EQ(values[0], ASCIIToUTF16("1@1.com")); - - profile1.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); - ASSERT_EQ(values.size(), 1U); - EXPECT_EQ(values[0], ASCIIToUTF16("650234567")); + EXPECT_EQ(ASCIIToUTF16("1@1.com"), profile1.GetRawInfo(EMAIL_ADDRESS)); + EXPECT_EQ(ASCIIToUTF16("650234567"), + profile1.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); EXPECT_EQ(profile2.origin(), profile1.origin()); AutofillProfile profile3(kGuid3, kHttpOrigin); profile3.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("111 First St.")); - - values.clear(); - values.push_back(ASCIIToUTF16("Jane")); - profile3.SetRawMultiInfo(NAME_FIRST, values); - - values.clear(); - values.push_back(ASCIIToUTF16("Doe")); - profile3.SetRawMultiInfo(NAME_LAST, values); + profile3.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane")); + profile3.SetRawInfo(NAME_LAST, ASCIIToUTF16("Doe")); EXPECT_TRUE(AutofillProfileSyncableService::MergeProfile(profile3, &profile1, @@ -667,14 +641,9 @@ TEST_F(AutofillProfileSyncableServiceTest, MergeProfile) { EXPECT_EQ(ASCIIToUTF16("Jane"), profile1.GetRawInfo(NAME_FIRST)); EXPECT_EQ(ASCIIToUTF16("Doe"), profile1.GetRawInfo(NAME_LAST)); - - profile1.GetRawMultiInfo(EMAIL_ADDRESS, &values); - ASSERT_EQ(values.size(), 1U); - EXPECT_EQ(values[0], ASCIIToUTF16("1@1.com")); - - profile1.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); - ASSERT_EQ(values.size(), 1U); - EXPECT_EQ(values[0], ASCIIToUTF16("650234567")); + EXPECT_EQ(ASCIIToUTF16("1@1.com"), profile1.GetRawInfo(EMAIL_ADDRESS)); + EXPECT_EQ(ASCIIToUTF16("650234567"), + profile1.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); } // Ensure that all profile fields are able to be synced up from the client to @@ -1086,8 +1055,7 @@ TEST_F(AutofillProfileSyncableServiceTest, EmptySyncPreservesFullName) { // Local autofill profile has a full name. AutofillProfile profile(kGuid1, kHttpsOrigin); - profile.SetInfo(AutofillType(NAME_FULL), - ASCIIToUTF16("John Jacob Smith, Jr"), "en-US"); + profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("John Jacob Smith, Jr")); profiles_from_web_db.push_back(new AutofillProfile(profile)); // Remote data does not have a full name value. diff --git a/components/autofill/core/browser/webdata/autofill_table.cc b/components/autofill/core/browser/webdata/autofill_table.cc index 3f5a4c2..b9468bb 100644 --- a/components/autofill/core/browser/webdata/autofill_table.cc +++ b/components/autofill/core/browser/webdata/autofill_table.cc @@ -214,10 +214,16 @@ bool AddAutofillProfileNamesToProfile(sql::Connection* db, if (!s.Succeeded()) return false; - profile->SetRawMultiInfo(NAME_FIRST, first_names); - profile->SetRawMultiInfo(NAME_MIDDLE, middle_names); - profile->SetRawMultiInfo(NAME_LAST, last_names); - profile->SetRawMultiInfo(NAME_FULL, full_names); + // TODO(estade): update schema so these aren't vectors. + first_names.resize(1); + middle_names.resize(1); + last_names.resize(1); + full_names.resize(1); + + profile->SetRawInfo(NAME_FIRST, first_names[0]); + profile->SetRawInfo(NAME_MIDDLE, middle_names[0]); + profile->SetRawInfo(NAME_LAST, last_names[0]); + profile->SetRawInfo(NAME_FULL, full_names[0]); return true; } @@ -240,7 +246,9 @@ bool AddAutofillProfileEmailsToProfile(sql::Connection* db, if (!s.Succeeded()) return false; - profile->SetRawMultiInfo(EMAIL_ADDRESS, emails); + // TODO(estade): update schema so this is not a vector. + emails.resize(1); + profile->SetRawInfo(EMAIL_ADDRESS, emails[0]); return true; } @@ -263,82 +271,52 @@ bool AddAutofillProfilePhonesToProfile(sql::Connection* db, if (!s.Succeeded()) return false; - profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, numbers); + // TODO(estade): update schema so this isn't a vector. + numbers.resize(1); + profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, numbers[0]); return true; } bool AddAutofillProfileNames(const AutofillProfile& profile, sql::Connection* db) { - std::vector<base::string16> first_names; - profile.GetRawMultiInfo(NAME_FIRST, &first_names); - std::vector<base::string16> middle_names; - profile.GetRawMultiInfo(NAME_MIDDLE, &middle_names); - std::vector<base::string16> last_names; - profile.GetRawMultiInfo(NAME_LAST, &last_names); - std::vector<base::string16> full_names; - profile.GetRawMultiInfo(NAME_FULL, &full_names); - DCHECK_EQ(first_names.size(), middle_names.size()); - DCHECK_EQ(first_names.size(), last_names.size()); - DCHECK_EQ(first_names.size(), full_names.size()); - - for (size_t i = 0; i < first_names.size(); ++i) { - // Add the new name. - sql::Statement s(db->GetUniqueStatement( - "INSERT INTO autofill_profile_names" - " (guid, first_name, middle_name, last_name, full_name) " - "VALUES (?,?,?,?,?)")); - s.BindString(0, profile.guid()); - s.BindString16(1, first_names[i]); - s.BindString16(2, middle_names[i]); - s.BindString16(3, last_names[i]); - s.BindString16(4, full_names[i]); + // Add the new name. + sql::Statement s(db->GetUniqueStatement( + "INSERT INTO autofill_profile_names" + " (guid, first_name, middle_name, last_name, full_name) " + "VALUES (?,?,?,?,?)")); + s.BindString(0, profile.guid()); + s.BindString16(1, profile.GetRawInfo(NAME_FIRST)); + s.BindString16(2, profile.GetRawInfo(NAME_MIDDLE)); + s.BindString16(3, profile.GetRawInfo(NAME_LAST)); + s.BindString16(4, profile.GetRawInfo(NAME_FULL)); - if (!s.Run()) - return false; - } - return true; + return s.Run(); } bool AddAutofillProfileEmails(const AutofillProfile& profile, sql::Connection* db) { - std::vector<base::string16> emails; - profile.GetRawMultiInfo(EMAIL_ADDRESS, &emails); - - for (size_t i = 0; i < emails.size(); ++i) { - // Add the new email. - sql::Statement s(db->GetUniqueStatement( + // Add the new email. + sql::Statement s(db->GetUniqueStatement( "INSERT INTO autofill_profile_emails" " (guid, email) " "VALUES (?,?)")); - s.BindString(0, profile.guid()); - s.BindString16(1, emails[i]); - - if (!s.Run()) - return false; - } + s.BindString(0, profile.guid()); + s.BindString16(1, profile.GetRawInfo(EMAIL_ADDRESS)); - return true; + return s.Run(); } bool AddAutofillProfilePhones(const AutofillProfile& profile, sql::Connection* db) { - std::vector<base::string16> numbers; - profile.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &numbers); - - for (size_t i = 0; i < numbers.size(); ++i) { - // Add the new number. - sql::Statement s(db->GetUniqueStatement( + // Add the new number. + sql::Statement s(db->GetUniqueStatement( "INSERT INTO autofill_profile_phones" " (guid, number) " "VALUES (?,?)")); - s.BindString(0, profile.guid()); - s.BindString16(1, numbers[i]); + s.BindString(0, profile.guid()); + s.BindString16(1, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); - if (!s.Run()) - return false; - } - - return true; + return s.Run(); } bool AddAutofillProfilePieces(const AutofillProfile& profile, diff --git a/components/autofill/core/browser/webdata/autofill_table_unittest.cc b/components/autofill/core/browser/webdata/autofill_table_unittest.cc index b1b8731..f3cf200 100644 --- a/components/autofill/core/browser/webdata/autofill_table_unittest.cc +++ b/components/autofill/core/browser/webdata/autofill_table_unittest.cc @@ -759,120 +759,6 @@ TEST_F(AutofillTableTest, AutofillProfile) { EXPECT_FALSE(table_->GetAutofillProfile(billing_profile.guid(), &db_profile)); } -TEST_F(AutofillTableTest, AutofillProfileMultiValueNames) { - AutofillProfile p; - const base::string16 kJohnDoe(ASCIIToUTF16("John Doe")); - const base::string16 kJohnPDoe(ASCIIToUTF16("John P. Doe")); - std::vector<base::string16> set_values; - set_values.push_back(kJohnDoe); - set_values.push_back(kJohnPDoe); - p.SetRawMultiInfo(NAME_FULL, set_values); - - EXPECT_TRUE(table_->AddAutofillProfile(p)); - - AutofillProfile* db_profile; - ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); - EXPECT_EQ(p, *db_profile); - EXPECT_EQ(0, p.Compare(*db_profile)); - delete db_profile; - - // Update the values. - const base::string16 kNoOne(ASCIIToUTF16("No One")); - set_values[1] = kNoOne; - p.SetRawMultiInfo(NAME_FULL, set_values); - EXPECT_TRUE(table_->UpdateAutofillProfile(p)); - ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); - EXPECT_EQ(p, *db_profile); - EXPECT_EQ(0, p.Compare(*db_profile)); - delete db_profile; - - // Delete values. - set_values.clear(); - p.SetRawMultiInfo(NAME_FULL, set_values); - EXPECT_TRUE(table_->UpdateAutofillProfile(p)); - ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); - EXPECT_EQ(p, *db_profile); - EXPECT_EQ(0, p.Compare(*db_profile)); - EXPECT_EQ(base::string16(), db_profile->GetRawInfo(NAME_FULL)); - delete db_profile; -} - -TEST_F(AutofillTableTest, AutofillProfileMultiValueEmails) { - AutofillProfile p; - const base::string16 kJohnDoe(ASCIIToUTF16("john@doe.com")); - const base::string16 kJohnPDoe(ASCIIToUTF16("john_p@doe.com")); - std::vector<base::string16> set_values; - set_values.push_back(kJohnDoe); - set_values.push_back(kJohnPDoe); - p.SetRawMultiInfo(EMAIL_ADDRESS, set_values); - - EXPECT_TRUE(table_->AddAutofillProfile(p)); - - AutofillProfile* db_profile; - ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); - EXPECT_EQ(p, *db_profile); - EXPECT_EQ(0, p.Compare(*db_profile)); - delete db_profile; - - // Update the values. - const base::string16 kNoOne(ASCIIToUTF16("no@one.com")); - set_values[1] = kNoOne; - p.SetRawMultiInfo(EMAIL_ADDRESS, set_values); - EXPECT_TRUE(table_->UpdateAutofillProfile(p)); - ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); - EXPECT_EQ(p, *db_profile); - EXPECT_EQ(0, p.Compare(*db_profile)); - delete db_profile; - - // Delete values. - set_values.clear(); - p.SetRawMultiInfo(EMAIL_ADDRESS, set_values); - EXPECT_TRUE(table_->UpdateAutofillProfile(p)); - ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); - EXPECT_EQ(p, *db_profile); - EXPECT_EQ(0, p.Compare(*db_profile)); - EXPECT_EQ(base::string16(), db_profile->GetRawInfo(EMAIL_ADDRESS)); - delete db_profile; -} - -TEST_F(AutofillTableTest, AutofillProfileMultiValuePhone) { - AutofillProfile p; - const base::string16 kJohnDoe(ASCIIToUTF16("4151112222")); - const base::string16 kJohnPDoe(ASCIIToUTF16("4151113333")); - std::vector<base::string16> set_values; - set_values.push_back(kJohnDoe); - set_values.push_back(kJohnPDoe); - p.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values); - - EXPECT_TRUE(table_->AddAutofillProfile(p)); - - AutofillProfile* db_profile; - ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); - EXPECT_EQ(p, *db_profile); - EXPECT_EQ(0, p.Compare(*db_profile)); - delete db_profile; - - // Update the values. - const base::string16 kNoOne(ASCIIToUTF16("4151110000")); - set_values[1] = kNoOne; - p.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values); - EXPECT_TRUE(table_->UpdateAutofillProfile(p)); - ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); - EXPECT_EQ(p, *db_profile); - EXPECT_EQ(0, p.Compare(*db_profile)); - delete db_profile; - - // Delete values. - set_values.clear(); - p.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, set_values); - EXPECT_TRUE(table_->UpdateAutofillProfile(p)); - ASSERT_TRUE(table_->GetAutofillProfile(p.guid(), &db_profile)); - EXPECT_EQ(p, *db_profile); - EXPECT_EQ(0, p.Compare(*db_profile)); - EXPECT_EQ(base::string16(), db_profile->GetRawInfo(EMAIL_ADDRESS)); - delete db_profile; -} - TEST_F(AutofillTableTest, AutofillProfileTrash) { std::vector<std::string> guids; table_->GetAutofillProfilesInTrash(&guids); |