Chromium Code Reviews| Index: components/autofill/core/browser/autofill_profile.cc |
| diff --git a/components/autofill/core/browser/autofill_profile.cc b/components/autofill/core/browser/autofill_profile.cc |
| index 1234c0c7257b331d3c06c7e4f5abfeb183600280..6d66cf7ec0fd138dbc479a47e429c7f7ecd078b9 100644 |
| --- a/components/autofill/core/browser/autofill_profile.cc |
| +++ b/components/autofill/core/browser/autofill_profile.cc |
| @@ -525,16 +525,20 @@ bool AutofillProfile::OverwriteWith(const AutofillProfile& profile, |
| if (profile.use_date() > use_date()) |
| set_use_date(profile.use_date()); |
| - ServerFieldTypeSet field_types; |
| - profile.GetNonEmptyTypes(app_locale, &field_types); |
| + // |types_to_overwrite| is initially populated with all types that have |
| + // non-empty data in the incoming |profile|. After adjustment, all data from |
| + // |profile| corresponding to types in |types_to_overwrite| is overwritten in |
| + // |this| profile. |
| + ServerFieldTypeSet types_to_overwrite; |
| + profile.GetNonEmptyTypes(app_locale, &types_to_overwrite); |
| // Only transfer "full" types (e.g. full name) and not fragments (e.g. |
| // first name, last name). |
| - CollapseCompoundFieldTypes(&field_types); |
| + CollapseCompoundFieldTypes(&types_to_overwrite); |
| // Remove ADDRESS_HOME_STREET_ADDRESS to ensure a merge of the address line by |
| // line. See comment below. |
| - field_types.erase(ADDRESS_HOME_STREET_ADDRESS); |
| + types_to_overwrite.erase(ADDRESS_HOME_STREET_ADDRESS); |
| l10n::CaseInsensitiveCompare compare; |
| @@ -548,24 +552,24 @@ bool AutofillProfile::OverwriteWith(const AutofillProfile& profile, |
| CanonicalizeProfileString(GetRawInfo(ADDRESS_HOME_STREET_ADDRESS))) && |
| !GetRawInfo(ADDRESS_HOME_LINE2).empty() && |
| profile.GetRawInfo(ADDRESS_HOME_LINE2).empty()) { |
| - field_types.erase(ADDRESS_HOME_LINE1); |
| - field_types.erase(ADDRESS_HOME_LINE2); |
| + types_to_overwrite.erase(ADDRESS_HOME_LINE1); |
| + types_to_overwrite.erase(ADDRESS_HOME_LINE2); |
| } |
| bool did_overwrite = false; |
| - for (ServerFieldTypeSet::const_iterator iter = field_types.begin(); |
| - iter != field_types.end(); ++iter) { |
| - FieldTypeGroup group = AutofillType(*iter).group(); |
| - |
| - // Special case names. |
| - if (group == NAME) { |
| - did_overwrite = OverwriteName(profile.name_, app_locale) || did_overwrite; |
| + for (ServerFieldTypeSet::const_iterator iter = types_to_overwrite.begin(); |
|
Mathieu
2016/04/29 15:52:06
nit: can we use a range for loop?
for (const Serv
sebsg
2016/05/03 20:02:17
Done.
|
| + iter != types_to_overwrite.end(); ++iter) { |
| + // Special case for names. |
| + if (AutofillType(*iter).group() == NAME) { |
| + did_overwrite |= OverwriteName(profile.name_, app_locale); |
| continue; |
| } |
| base::string16 new_value = profile.GetRawInfo(*iter); |
| - if (!compare.StringsEqual(GetRawInfo(*iter), new_value)) { |
| + // Overwrite the data in |this| profile for the field type and set |
| + // |did_overwrite| if the previous data was different than the |new_value|. |
| + if (GetRawInfo(*iter) != new_value) { |
| SetRawInfo(*iter, new_value); |
| did_overwrite = true; |
| } |