Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1454)

Unified Diff: components/autofill/core/browser/autofill_profile.cc

Issue 261993006: Modified to allow to preserve two-word string in first-name and last-name in autofill profile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..11135fd3f25768dffa31a627dbfa7715c989e05a 100644
--- a/components/autofill/core/browser/autofill_profile.cc
+++ b/components/autofill/core/browser/autofill_profile.cc
@@ -518,6 +518,47 @@ bool AutofillProfile::IsSubsetOf(const AutofillProfile& profile,
return true;
}
+void AutofillProfile::OverwriteOrAppendNames(
+ const std::vector<NameInfo>& names) {
+ std::vector<NameInfo> name_list(name_);
Ilya Sherman 2014/06/03 00:25:32 nit: Let's call this "result" or something. Other
Pritam Nikam 2014/06/03 15:37:34 Done. name_list -> result
+ for (std::vector<NameInfo>::const_iterator it = names.begin();
+ it != names.end();
+ ++it) {
+ NameInfo imported_profile_name = *it;
Ilya Sherman 2014/06/03 00:25:32 nit: Let's drop "profile", and call this |imported
Pritam Nikam 2014/06/03 15:37:34 Done.
+ NameInfo profile_name_with_parsed_tokens;
Ilya Sherman 2014/06/03 00:25:32 nit: Let's call this something more like |heuristi
Pritam Nikam 2014/06/03 15:37:34 Done.
+ bool prefer_imported_profile_name = false;
+ bool identical_full_names = false;
Ilya Sherman 2014/06/03 00:25:32 Let's simplify the logic a bit by replacing these
Pritam Nikam 2014/06/03 15:37:34 Done.
+
+ 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_.
Ilya Sherman 2014/06/03 00:25:32 Here's a suggested rewording of this comment. Of
Pritam Nikam 2014/06/03 15:37:34 Done.
+ 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_list[index] = imported_profile_name;
+ break;
+ }
Ilya Sherman 2014/06/03 00:25:32 With the changes above, the body of this loop woul
Pritam Nikam 2014/06/03 15:37:34 Done.
+ }
+ }
+
+ // Append unique names to the list
Ilya Sherman 2014/06/03 00:25:32 nit: Please end the sentence with a period.
Pritam Nikam 2014/06/03 15:37:34 Done.
+ if (!identical_full_names ||
+ (!prefer_imported_profile_name &&
+ imported_profile_name != profile_name_with_parsed_tokens)) {
Ilya Sherman 2014/06/03 00:25:32 With the changes above, this if-stmt's condition w
Pritam Nikam 2014/06/03 15:37:34 Done.
+ name_list.push_back(imported_profile_name);
+ }
+ }
Ilya Sherman 2014/06/03 00:25:32 Optional nit: I'd leave a blank line after this on
Pritam Nikam 2014/06/03 15:37:34 Done. In my opinion,below check is still required
+ 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 +608,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);
+ }
Ilya Sherman 2014/06/03 00:25:32 nit: No need for curly braces.
Pritam Nikam 2014/06/03 15:37:34 Done.
} else {
base::string16 new_value = profile.GetRawInfo(*iter);
if (StringToLowerASCII(GetRawInfo(*iter)) !=

Powered by Google App Engine
This is Rietveld 408576698