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 5bb36c3aaf7350c1296547158dec10819890cf4d..6580aec90973f8be6298a7d37cab841c7b94d08f 100644 |
| --- a/components/autofill/core/browser/autofill_profile.cc |
| +++ b/components/autofill/core/browser/autofill_profile.cc |
| @@ -518,6 +518,50 @@ bool AutofillProfile::IsSubsetOf(const AutofillProfile& profile, |
| return true; |
| } |
| +void AutofillProfile::SetPreferredNameInfo( |
|
Ilya Sherman
2014/05/29 07:38:03
nit: Please name this something more like "Overwri
Pritam Nikam
2014/05/30 11:12:40
Done.
|
| + const std::vector<NameInfo>& profiles) { |
|
Ilya Sherman
2014/05/29 07:38:03
nit: "profiles" -> "names"
Pritam Nikam
2014/05/30 11:12:40
Done.
|
| + std::vector<NameInfo> append_list; |
|
Ilya Sherman
2014/05/29 07:38:03
nit: Please name this something more like "names_t
Pritam Nikam
2014/05/30 11:12:40
Function restructured, hence not needed.
|
| + std::vector<NameInfo> name_list(name_); |
| + std::vector<NameInfo>::const_iterator itr = profiles.begin(); |
|
Ilya Sherman
2014/05/29 07:38:03
nit: Please declare this within the scope of the f
Ilya Sherman
2014/05/29 07:38:03
nit: Please name this "it", as that is the common
Pritam Nikam
2014/05/30 11:12:40
Function restructured, hence not needed.
Pritam Nikam
2014/05/30 11:12:40
Done.
|
| + |
| + for (; itr != profiles.end(); ++itr) { |
|
Ilya Sherman
2014/05/29 07:38:03
Is it ever possible for the imported profile to co
Pritam Nikam
2014/05/30 11:12:40
Done.
1. HTML Form submission can have maximum 1
|
| + NameInfo imported_profile = *itr; |
| + bool prefer_imported_profile = false; |
| + bool identical_full_names = false; |
| + |
| + for (size_t index = 0; index < name_.size(); index++) { |
|
Ilya Sherman
2014/05/29 07:38:03
nit: "index++" -> "++index"
Pritam Nikam
2014/05/30 11:12:40
Done.
|
| + NameInfo prof = name_[index]; |
|
Ilya Sherman
2014/05/29 07:38:03
nit: Please avoid using abbreviations when naming
Pritam Nikam
2014/05/30 11:12:40
Function restructured, hence not needed.
|
| + base::string16 full_name = prof.GetRawInfo(NAME_FULL); |
| + if (full_name == imported_profile.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; |
| + NameInfo profile_with_paresed_tokens; |
| + profile_with_paresed_tokens.SetRawInfo(NAME_FULL, full_name); |
| + if (prof == profile_with_paresed_tokens) |
| + prefer_imported_profile = true; |
| + |
| + if (prefer_imported_profile) { |
| + name_list[index] = imported_profile; |
| + } else { |
| + if ((imported_profile != prof) && |
| + (imported_profile != profile_with_paresed_tokens)) |
| + append_list.push_back(imported_profile); |
|
Ilya Sherman
2014/05/29 07:38:03
This isn't quite right, as this variant of the nam
Pritam Nikam
2014/05/30 11:12:40
Done.
Added test-cases to cover identical full na
|
| + } |
| + } |
| + } |
| + |
| + if (!identical_full_names) |
| + append_list.push_back(imported_profile); |
| + } |
| + |
| + if (!append_list.empty()) |
| + name_list.insert(name_list.end(), append_list.begin(), append_list.end()); |
| + |
| + name_.swap(name_list); |
| +} |
| + |
| void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, |
| const std::string& app_locale) { |
| // Verified profiles should never be overwritten with unverified data. |
| @@ -567,7 +611,10 @@ void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, |
| existing_values.insert(existing_values.end(), *value_iter); |
| } |
| } |
| - SetRawMultiInfo(*iter, existing_values); |
| + if (group == NAME) |
| + SetPreferredNameInfo(profile.name_); |
| + else |
| + SetRawMultiInfo(*iter, existing_values); |
| } else { |
| base::string16 new_value = profile.GetRawInfo(*iter); |
| if (StringToLowerASCII(GetRawInfo(*iter)) != |