| Index: chrome/browser/autofill/personal_data_manager.cc
|
| diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc
|
| index 73af53e14ed7597bfb7a43ed828c1bbfdf202af3..edef1d92848c0f8c7d13c4bbd2f56ab87b7b6b1e 100644
|
| --- a/chrome/browser/autofill/personal_data_manager.cc
|
| +++ b/chrome/browser/autofill/personal_data_manager.cc
|
| @@ -421,53 +421,8 @@ void PersonalDataManager::AddProfile(const AutoFillProfile& profile) {
|
| return;
|
| }
|
|
|
| - // Set to true if |profile| is merged into the profile list.
|
| - bool merged = false;
|
| -
|
| - // First preference is to add missing values to an existing profile.
|
| - // Only merge with the first match.
|
| std::vector<AutoFillProfile> profiles;
|
| - for (std::vector<AutoFillProfile*>::const_iterator iter =
|
| - web_profiles_.begin();
|
| - iter != web_profiles_.end(); ++iter) {
|
| - if (!merged) {
|
| - if (profile.IsSubsetOf(**iter)) {
|
| - // In this case, the existing profile already contains all of the data
|
| - // in |profile|, so consider the profiles already merged.
|
| - merged = true;
|
| - } else if ((*iter)->IntersectionOfTypesHasEqualValues(profile)) {
|
| - // |profile| contains all of the data in this profile, plus more.
|
| - merged = true;
|
| - (*iter)->MergeWith(profile);
|
| - }
|
| - }
|
| - profiles.push_back(**iter);
|
| - }
|
| -
|
| - // The second preference, if not merged above, is to alter non-primary values
|
| - // where the primary values match.
|
| - // Again, only merge with the first match.
|
| - if (!merged) {
|
| - profiles.clear();
|
| - for (std::vector<AutoFillProfile*>::const_iterator iter =
|
| - web_profiles_.begin();
|
| - iter != web_profiles_.end(); ++iter) {
|
| - if (!merged) {
|
| - if (!profile.PrimaryValue().empty() &&
|
| - (*iter)->PrimaryValue() == profile.PrimaryValue()) {
|
| - merged = true;
|
| - (*iter)->OverwriteWith(profile);
|
| - }
|
| - }
|
| - profiles.push_back(**iter);
|
| - }
|
| - }
|
| -
|
| - // Finally, if the new profile was not merged with an existing profile then
|
| - // add the new profile to the list.
|
| - if (!merged)
|
| - profiles.push_back(profile);
|
| -
|
| + MergeProfile(profile, web_profiles_.get(), &profiles);
|
| SetProfiles(&profiles);
|
| }
|
|
|
| @@ -784,6 +739,63 @@ void PersonalDataManager::SaveImportedProfile(
|
| AddProfile(imported_profile);
|
| }
|
|
|
| +bool PersonalDataManager::MergeProfile(
|
| + const AutoFillProfile& profile,
|
| + const std::vector<AutoFillProfile*>& existing_profiles,
|
| + std::vector<AutoFillProfile>* merged_profiles) {
|
| + DCHECK(merged_profiles);
|
| + merged_profiles->clear();
|
| +
|
| + // Set to true if |profile| is merged into |existing_profiles|.
|
| + bool merged = false;
|
| +
|
| + // First preference is to add missing values to an existing profile.
|
| + // Only merge with the first match.
|
| + for (std::vector<AutoFillProfile*>::const_iterator iter =
|
| + existing_profiles.begin();
|
| + iter != existing_profiles.end(); ++iter) {
|
| + if (!merged) {
|
| + if (profile.IsSubsetOf(**iter)) {
|
| + // In this case, the existing profile already contains all of the data
|
| + // in |profile|, so consider the profiles already merged.
|
| + merged = true;
|
| + } else if ((*iter)->IntersectionOfTypesHasEqualValues(profile)) {
|
| + // |profile| contains all of the data in this profile, plus more.
|
| + merged = true;
|
| + (*iter)->MergeWith(profile);
|
| + }
|
| + }
|
| + merged_profiles->push_back(**iter);
|
| + }
|
| +
|
| + // The second preference, if not merged above, is to alter non-primary values
|
| + // where the primary values match.
|
| + // Again, only merge with the first match.
|
| + if (!merged) {
|
| + merged_profiles->clear();
|
| + for (std::vector<AutoFillProfile*>::const_iterator iter =
|
| + existing_profiles.begin();
|
| + iter != existing_profiles.end(); ++iter) {
|
| + if (!merged) {
|
| + if (!profile.PrimaryValue().empty() &&
|
| + (*iter)->PrimaryValue() == profile.PrimaryValue()) {
|
| + merged = true;
|
| + (*iter)->OverwriteWith(profile);
|
| + }
|
| + }
|
| + merged_profiles->push_back(**iter);
|
| + }
|
| + }
|
| +
|
| + // Finally, if the new profile was not merged with an existing profile then
|
| + // add the new profile to the list.
|
| + if (!merged)
|
| + merged_profiles->push_back(profile);
|
| +
|
| + return merged;
|
| +}
|
| +
|
| +
|
| void PersonalDataManager::SaveImportedCreditCard(
|
| const CreditCard& imported_credit_card) {
|
| if (profile_->IsOffTheRecord())
|
|
|