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 b37acd50d1d7235aa1c112567167eba678981daa..db30b721f67561e4d6b140615361fa71e48b190a 100644 |
--- a/components/autofill/core/browser/autofill_profile.cc |
+++ b/components/autofill/core/browser/autofill_profile.cc |
@@ -518,6 +518,44 @@ bool AutofillProfile::IsSubsetOf(const AutofillProfile& profile, |
return true; |
} |
+void AutofillProfile::OverwriteOrAppendNames( |
+ const std::vector<NameInfo>& names) { |
+ // a valid autofill profile can't have more than one nameInfo |
+ DCHECK(names.size() == 1); |
Ilya Sherman
2014/05/31 00:34:41
Thanks for listing the cases from which this metho
Pritam Nikam
2014/05/31 10:30:41
Done.
|
+ |
+ NameInfo imported_profile_name = names[0]; |
+ NameInfo profile_name_with_parsed_tokens; |
+ bool prefer_imported_profile_name = false; |
+ bool identical_full_names = false; |
+ |
+ for (size_t index = 0; index < name_.size(); ++index) { |
+ NameInfo current_name = name_[index]; |
+ base::string16 full_name = current_name.GetRawInfo(NAME_FULL); |
+ if (full_name == imported_profile_name.GetRawInfo(NAME_FULL)) { |
+ // Identical full names, we should always prefer to keep ones with more |
+ // information, i.e. where parsing the full_name_ does not give the same |
+ // results as are stored in first_, middle_, and last_. |
+ identical_full_names = true; |
+ profile_name_with_parsed_tokens.SetRawInfo(NAME_FULL, full_name); |
+ prefer_imported_profile_name = |
+ (current_name == profile_name_with_parsed_tokens) || |
+ (current_name == imported_profile_name); |
+ |
+ if (prefer_imported_profile_name) { |
+ name_[index] = imported_profile_name; |
+ break; |
+ } |
+ } |
+ } |
+ |
+ // Append unique names to the list |
+ if (!identical_full_names || |
+ (!prefer_imported_profile_name && |
+ imported_profile_name != profile_name_with_parsed_tokens)) { |
+ name_.push_back(imported_profile_name); |
+ } |
+} |
+ |
void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, |
const std::string& app_locale) { |
// Verified profiles should never be overwritten with unverified data. |
@@ -567,7 +605,11 @@ 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)) != |