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 02d6197e8176a0128b5d24ea78b932e329d3c1ef..a1309691b02ab0661185996ddb8dad8f0b32f2c1 100644 |
| --- a/components/autofill/core/browser/autofill_profile.cc |
| +++ b/components/autofill/core/browser/autofill_profile.cc |
| @@ -359,6 +359,36 @@ void AutofillProfile::SetRawMultiInfo( |
| } |
| } |
| +void AutofillProfile::SetPreferredNameInfo( |
| + const std::vector<NameInfo>& profiles) { |
| + if (!profiles.size()) |
| + return; |
| + |
| + bool preferImportedProfile = true; |
| + NameInfo importedProfile = profiles[0]; |
|
Ilya Sherman
2014/05/15 22:21:27
Why pass a vector if you're only going to use the
Pritam Nikam
2014/05/19 12:09:15
Done.
|
| + std::vector<NameInfo> namelist(name_); |
| + for (size_t index = 0; index < name_.size(); index++) { |
| + NameInfo prof = name_[index]; |
| + if (prof.GetRawInfo(NAME_FULL) != importedProfile.GetRawInfo(NAME_FULL)) { |
| + namelist.push_back(importedProfile); |
|
Ilya Sherman
2014/05/15 22:21:27
If the existing profile has 10 names, none of whic
Pritam Nikam
2014/05/19 12:09:15
Done.
|
| + continue; |
| + } |
| + |
| + // 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_. Prefer profile |
| + // with smaller middle names. |
| + if (prof.GetRawInfo(NAME_MIDDLE).length() < |
| + importedProfile.GetRawInfo(NAME_MIDDLE).length()) |
|
Ilya Sherman
2014/05/15 22:21:27
I was thinking of something more like:
base::stri
Pritam Nikam
2014/05/19 12:09:15
Done.
|
| + preferImportedProfile = false; |
| + |
| + if (preferImportedProfile) { |
| + namelist[index] = importedProfile; |
| + } |
| + } |
| + name_.swap(namelist); |
| +} |
|
Ilya Sherman
2014/05/15 22:21:27
There are many style guide violations in this code
Pritam Nikam
2014/05/19 12:09:15
Done.
|
| + |
| void AutofillProfile::GetRawMultiInfo( |
| ServerFieldType type, |
| std::vector<base::string16>* values) const { |
| @@ -554,7 +584,11 @@ 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)) != |