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

Unified Diff: components/autofill/core/browser/webdata/autofill_table.cc

Issue 310463005: Fill in more name fields with requestAutocomplete (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: todo Created 6 years, 6 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/webdata/autofill_table.cc
diff --git a/components/autofill/core/browser/webdata/autofill_table.cc b/components/autofill/core/browser/webdata/autofill_table.cc
index e24ceca1d026d3d75eec6904ebaf145ba0bf1ab4..dc01c5e683501ec909842064421ed8c35d4f196b 100644
--- a/components/autofill/core/browser/webdata/autofill_table.cc
+++ b/components/autofill/core/browser/webdata/autofill_table.cc
@@ -167,10 +167,41 @@ scoped_ptr<CreditCard> CreditCardFromStatement(const sql::Statement& s) {
return credit_card.Pass();
}
+// Obsolete version of AddAutofillProfileNamesToProfile, but still needed
+// for MigrateToVersion37MergeAndCullOlderProfiles().
+bool AddAutofillProfileNamesToProfileForVersion37(sql::Connection* db,
+ AutofillProfile* profile) {
+ sql::Statement s(db->GetUniqueStatement(
+ "SELECT guid, first_name, middle_name, last_name "
+ "FROM autofill_profile_names "
+ "WHERE guid=?"));
+ s.BindString(0, profile->guid());
+
+ if (!s.is_valid())
+ return false;
+
+ std::vector<base::string16> first_names;
+ std::vector<base::string16> middle_names;
+ std::vector<base::string16> last_names;
+ while (s.Step()) {
+ DCHECK_EQ(profile->guid(), s.ColumnString(0));
+ first_names.push_back(s.ColumnString16(1));
+ middle_names.push_back(s.ColumnString16(2));
+ last_names.push_back(s.ColumnString16(3));
+ }
+ if (!s.Succeeded())
+ return false;
+
+ profile->SetRawMultiInfo(NAME_FIRST, first_names);
+ profile->SetRawMultiInfo(NAME_MIDDLE, middle_names);
+ profile->SetRawMultiInfo(NAME_LAST, last_names);
+ return true;
+}
Ilya Sherman 2014/06/12 23:25:25 Optional nit: I'd prefer that you inline this code
Scott Hess - ex-Googler 2014/06/13 17:43:27 I support making the minimal changes necessary to
Ilya Sherman 2014/06/13 19:32:59 Fair enough. I'm not worried about inlining for p
Evan Stade 2014/06/14 01:17:23 putting "ForVersionN" at the end is kind of like a
+
bool AddAutofillProfileNamesToProfile(sql::Connection* db,
AutofillProfile* profile) {
sql::Statement s(db->GetUniqueStatement(
- "SELECT guid, first_name, middle_name, last_name "
+ "SELECT guid, first_name, middle_name, last_name, full_name "
"FROM autofill_profile_names "
"WHERE guid=?"));
s.BindString(0, profile->guid());
@@ -181,11 +212,13 @@ bool AddAutofillProfileNamesToProfile(sql::Connection* db,
std::vector<base::string16> first_names;
std::vector<base::string16> middle_names;
std::vector<base::string16> last_names;
+ std::vector<base::string16> full_names;
while (s.Step()) {
DCHECK_EQ(profile->guid(), s.ColumnString(0));
first_names.push_back(s.ColumnString16(1));
middle_names.push_back(s.ColumnString16(2));
last_names.push_back(s.ColumnString16(3));
+ full_names.push_back(s.ColumnString16(4));
}
if (!s.Succeeded())
return false;
@@ -193,6 +226,7 @@ bool AddAutofillProfileNamesToProfile(sql::Connection* db,
profile->SetRawMultiInfo(NAME_FIRST, first_names);
profile->SetRawMultiInfo(NAME_MIDDLE, middle_names);
profile->SetRawMultiInfo(NAME_LAST, last_names);
+ profile->SetRawMultiInfo(NAME_FULL, full_names);
return true;
}
@@ -250,20 +284,38 @@ bool AddAutofillProfileNames(const AutofillProfile& profile,
profile.GetRawMultiInfo(NAME_MIDDLE, &middle_names);
std::vector<base::string16> last_names;
profile.GetRawMultiInfo(NAME_LAST, &last_names);
+ std::vector<base::string16> full_names;
+ profile.GetRawMultiInfo(NAME_FULL, &full_names);
DCHECK_EQ(first_names.size(), middle_names.size());
- DCHECK_EQ(middle_names.size(), last_names.size());
+ DCHECK_EQ(first_names.size(), last_names.size());
+ DCHECK_EQ(first_names.size(), full_names.size());
+ // TODO(estade): remove the conditionally-constructed SQL query.
+ // See http://crbug.com/382562
+ const bool has_full_name =
+ db->DoesColumnExist("autofill_profile_names", "full_name");
Ilya Sherman 2014/06/12 23:25:25 Are we calling this function from the migration co
Scott Hess - ex-Googler 2014/06/13 17:43:27 AFAICT, doing the same thing here would require co
Ilya Sherman 2014/06/13 19:32:59 This is one case where I prefer code duplication.
Scott Hess - ex-Googler 2014/06/13 19:42:47 OK, then, since I think I have a general preferenc
Evan Stade 2014/06/14 01:17:23 Done.
for (size_t i = 0; i < first_names.size(); ++i) {
// Add the new name.
- sql::Statement s(db->GetUniqueStatement(
- "INSERT INTO autofill_profile_names"
- " (guid, first_name, middle_name, last_name) "
- "VALUES (?,?,?,?)"));
+ sql::Statement s;
+ if (has_full_name) {
+ s.Assign(db->GetUniqueStatement(
+ "INSERT INTO autofill_profile_names"
+ " (guid, first_name, middle_name, last_name, full_name) "
+ "VALUES (?,?,?,?,?)"));
+ } else {
+ s.Assign(db->GetUniqueStatement(
+ "INSERT INTO autofill_profile_names"
+ " (guid, first_name, middle_name, last_name) "
+ "VALUES (?,?,?,?)"));
+ }
s.BindString(0, profile.guid());
s.BindString16(1, first_names[i]);
s.BindString16(2, middle_names[i]);
s.BindString16(3, last_names[i]);
+ if (has_full_name)
+ s.BindString16(4, full_names[i]);
+
if (!s.Run())
return false;
}
@@ -447,6 +499,9 @@ bool AutofillTable::MigrateToVersion(int version,
case 56:
*update_compatible_version = true;
return MigrateToVersion56AddProfileLanguageCodeForFormatting();
+ case 57:
+ *update_compatible_version = true;
+ return MigrateToVersion57AddFullNameField();
}
return true;
}
@@ -1292,7 +1347,8 @@ bool AutofillTable::InitProfileNamesTable() {
"guid VARCHAR, "
"first_name VARCHAR, "
"middle_name VARCHAR, "
- "last_name VARCHAR)")) {
+ "last_name VARCHAR, "
+ "full_name VARCHAR)")) {
NOTREACHED();
return false;
}
@@ -2005,7 +2061,7 @@ bool AutofillTable::MigrateToVersion37MergeAndCullOlderProfiles() {
profile->set_origin(s.ColumnString(index++));
// Get associated name info.
- AddAutofillProfileNamesToProfile(db_, profile.get());
+ AddAutofillProfileNamesToProfileForVersion37(db_, profile.get());
// Get associated email info.
AddAutofillProfileEmailsToProfile(db_, profile.get());
@@ -2272,4 +2328,9 @@ bool AutofillTable::MigrateToVersion56AddProfileLanguageCodeForFormatting() {
"ADD COLUMN language_code VARCHAR");
}
+bool AutofillTable::MigrateToVersion57AddFullNameField() {
+ return db_->Execute("ALTER TABLE autofill_profile_names "
+ "ADD COLUMN full_name VARCHAR");
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698