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 fc3f39ef259b0e1c54be6dda1f67e2a2c2851ca5..c58b01dbe893c93bca2f26edc54fae7475f1dcfa 100644 |
| --- a/components/autofill/core/browser/autofill_profile.cc |
| +++ b/components/autofill/core/browser/autofill_profile.cc |
| @@ -518,6 +518,51 @@ bool AutofillProfile::IsSubsetOf(const AutofillProfile& profile, |
| return true; |
| } |
| +void AutofillProfile::OverwriteOrAppendNames( |
| + const std::vector<NameInfo>& names) { |
| + std::vector<NameInfo> results(name_); |
| + for (std::vector<NameInfo>::const_iterator it = names.begin(); |
| + it != names.end(); |
| + ++it) { |
| + NameInfo imported_name = *it; |
| + NameInfo heuristically_parsed_name; |
| + bool should_append_imported_name = true; |
| + |
| + for (size_t index = 0; index < name_.size(); ++index) { |
| + NameInfo current_name = name_[index]; |
| + if (current_name == imported_name) { |
| + should_append_imported_name = false; |
| + break; |
| + } |
| + |
| + base::string16 full_name = current_name.GetRawInfo(NAME_FULL); |
| + if (full_name == imported_name.GetRawInfo(NAME_FULL)) { |
| + // The imported name has the same full name string as one of the |
| + // existing names for this profile. Because full names are |
| + // _heuristically_ parsed into {first, middle, last} name components, |
| + // it's possible that either the existing name or the imported name |
| + // was misparsed. Prefer to keep the name whose {first, middle, |
| + // last} components do not match those computed by the heuristic |
| + // parse, as this more likely represents the correct, user-input parse |
| + // of the name. |
| + heuristically_parsed_name.SetRawInfo(NAME_FULL, full_name); |
| + if (current_name == heuristically_parsed_name) { |
| + results[index] = imported_name; |
| + should_append_imported_name = false; |
| + break; |
| + } |
| + } |
| + } |
| + |
| + // Append unique names to the list. |
| + if (should_append_imported_name && |
| + (imported_name != heuristically_parsed_name)) |
|
Ilya Sherman
2014/06/03 22:09:52
What is the test case that would fail if this line
Pritam Nikam
2014/06/04 06:54:44
If this (imported_name != heuristically_parsed_nam
Ilya Sherman
2014/06/04 22:38:27
Sorry, you are of course correct that this check i
Pritam Nikam
2014/06/07 06:25:12
Done.
|
| + results.push_back(imported_name); |
| + } |
| + |
| + name_.swap(results); |
| +} |
| + |
| void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, |
| const std::string& app_locale) { |
| // Verified profiles should never be overwritten with unverified data. |
| @@ -567,7 +612,10 @@ void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, |
| existing_values.insert(existing_values.end(), *value_iter); |
| } |
| } |
| - SetRawMultiInfo(*iter, existing_values); |
| + if (group == NAME) |
| + OverwriteOrAppendNames(profile.name_); |
| + else |
| + SetRawMultiInfo(*iter, existing_values); |
| } else { |
| base::string16 new_value = profile.GetRawInfo(*iter); |
| if (StringToLowerASCII(GetRawInfo(*iter)) != |