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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/webdata/autofill_table.h" 5 #include "components/autofill/core/browser/webdata/autofill_table.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 index++; 160 index++;
161 } 161 }
162 credit_card->SetRawInfo(CREDIT_CARD_NUMBER, credit_card_number); 162 credit_card->SetRawInfo(CREDIT_CARD_NUMBER, credit_card_number);
163 // Intentionally skip column 5, which stores the modification date. 163 // Intentionally skip column 5, which stores the modification date.
164 index++; 164 index++;
165 credit_card->set_origin(s.ColumnString(index++)); 165 credit_card->set_origin(s.ColumnString(index++));
166 166
167 return credit_card.Pass(); 167 return credit_card.Pass();
168 } 168 }
169 169
170 // Obsolete version of AddAutofillProfileNamesToProfile, but still needed
171 // for MigrateToVersion37MergeAndCullOlderProfiles().
172 bool AddAutofillProfileNamesToProfileForVersion37(sql::Connection* db,
173 AutofillProfile* profile) {
174 sql::Statement s(db->GetUniqueStatement(
175 "SELECT guid, first_name, middle_name, last_name "
176 "FROM autofill_profile_names "
177 "WHERE guid=?"));
178 s.BindString(0, profile->guid());
179
180 if (!s.is_valid())
181 return false;
182
183 std::vector<base::string16> first_names;
184 std::vector<base::string16> middle_names;
185 std::vector<base::string16> last_names;
186 while (s.Step()) {
187 DCHECK_EQ(profile->guid(), s.ColumnString(0));
188 first_names.push_back(s.ColumnString16(1));
189 middle_names.push_back(s.ColumnString16(2));
190 last_names.push_back(s.ColumnString16(3));
191 }
192 if (!s.Succeeded())
193 return false;
194
195 profile->SetRawMultiInfo(NAME_FIRST, first_names);
196 profile->SetRawMultiInfo(NAME_MIDDLE, middle_names);
197 profile->SetRawMultiInfo(NAME_LAST, last_names);
198 return true;
199 }
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
200
170 bool AddAutofillProfileNamesToProfile(sql::Connection* db, 201 bool AddAutofillProfileNamesToProfile(sql::Connection* db,
171 AutofillProfile* profile) { 202 AutofillProfile* profile) {
172 sql::Statement s(db->GetUniqueStatement( 203 sql::Statement s(db->GetUniqueStatement(
173 "SELECT guid, first_name, middle_name, last_name " 204 "SELECT guid, first_name, middle_name, last_name, full_name "
174 "FROM autofill_profile_names " 205 "FROM autofill_profile_names "
175 "WHERE guid=?")); 206 "WHERE guid=?"));
176 s.BindString(0, profile->guid()); 207 s.BindString(0, profile->guid());
177 208
178 if (!s.is_valid()) 209 if (!s.is_valid())
179 return false; 210 return false;
180 211
181 std::vector<base::string16> first_names; 212 std::vector<base::string16> first_names;
182 std::vector<base::string16> middle_names; 213 std::vector<base::string16> middle_names;
183 std::vector<base::string16> last_names; 214 std::vector<base::string16> last_names;
215 std::vector<base::string16> full_names;
184 while (s.Step()) { 216 while (s.Step()) {
185 DCHECK_EQ(profile->guid(), s.ColumnString(0)); 217 DCHECK_EQ(profile->guid(), s.ColumnString(0));
186 first_names.push_back(s.ColumnString16(1)); 218 first_names.push_back(s.ColumnString16(1));
187 middle_names.push_back(s.ColumnString16(2)); 219 middle_names.push_back(s.ColumnString16(2));
188 last_names.push_back(s.ColumnString16(3)); 220 last_names.push_back(s.ColumnString16(3));
221 full_names.push_back(s.ColumnString16(4));
189 } 222 }
190 if (!s.Succeeded()) 223 if (!s.Succeeded())
191 return false; 224 return false;
192 225
193 profile->SetRawMultiInfo(NAME_FIRST, first_names); 226 profile->SetRawMultiInfo(NAME_FIRST, first_names);
194 profile->SetRawMultiInfo(NAME_MIDDLE, middle_names); 227 profile->SetRawMultiInfo(NAME_MIDDLE, middle_names);
195 profile->SetRawMultiInfo(NAME_LAST, last_names); 228 profile->SetRawMultiInfo(NAME_LAST, last_names);
229 profile->SetRawMultiInfo(NAME_FULL, full_names);
196 return true; 230 return true;
197 } 231 }
198 232
199 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, 233 bool AddAutofillProfileEmailsToProfile(sql::Connection* db,
200 AutofillProfile* profile) { 234 AutofillProfile* profile) {
201 sql::Statement s(db->GetUniqueStatement( 235 sql::Statement s(db->GetUniqueStatement(
202 "SELECT guid, email " 236 "SELECT guid, email "
203 "FROM autofill_profile_emails " 237 "FROM autofill_profile_emails "
204 "WHERE guid=?")); 238 "WHERE guid=?"));
205 s.BindString(0, profile->guid()); 239 s.BindString(0, profile->guid());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 277 }
244 278
245 bool AddAutofillProfileNames(const AutofillProfile& profile, 279 bool AddAutofillProfileNames(const AutofillProfile& profile,
246 sql::Connection* db) { 280 sql::Connection* db) {
247 std::vector<base::string16> first_names; 281 std::vector<base::string16> first_names;
248 profile.GetRawMultiInfo(NAME_FIRST, &first_names); 282 profile.GetRawMultiInfo(NAME_FIRST, &first_names);
249 std::vector<base::string16> middle_names; 283 std::vector<base::string16> middle_names;
250 profile.GetRawMultiInfo(NAME_MIDDLE, &middle_names); 284 profile.GetRawMultiInfo(NAME_MIDDLE, &middle_names);
251 std::vector<base::string16> last_names; 285 std::vector<base::string16> last_names;
252 profile.GetRawMultiInfo(NAME_LAST, &last_names); 286 profile.GetRawMultiInfo(NAME_LAST, &last_names);
287 std::vector<base::string16> full_names;
288 profile.GetRawMultiInfo(NAME_FULL, &full_names);
253 DCHECK_EQ(first_names.size(), middle_names.size()); 289 DCHECK_EQ(first_names.size(), middle_names.size());
254 DCHECK_EQ(middle_names.size(), last_names.size()); 290 DCHECK_EQ(first_names.size(), last_names.size());
291 DCHECK_EQ(first_names.size(), full_names.size());
255 292
293 // TODO(estade): remove the conditionally-constructed SQL query.
294 // See http://crbug.com/382562
295 const bool has_full_name =
296 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.
256 for (size_t i = 0; i < first_names.size(); ++i) { 297 for (size_t i = 0; i < first_names.size(); ++i) {
257 // Add the new name. 298 // Add the new name.
258 sql::Statement s(db->GetUniqueStatement( 299 sql::Statement s;
259 "INSERT INTO autofill_profile_names" 300 if (has_full_name) {
260 " (guid, first_name, middle_name, last_name) " 301 s.Assign(db->GetUniqueStatement(
261 "VALUES (?,?,?,?)")); 302 "INSERT INTO autofill_profile_names"
303 " (guid, first_name, middle_name, last_name, full_name) "
304 "VALUES (?,?,?,?,?)"));
305 } else {
306 s.Assign(db->GetUniqueStatement(
307 "INSERT INTO autofill_profile_names"
308 " (guid, first_name, middle_name, last_name) "
309 "VALUES (?,?,?,?)"));
310 }
262 s.BindString(0, profile.guid()); 311 s.BindString(0, profile.guid());
263 s.BindString16(1, first_names[i]); 312 s.BindString16(1, first_names[i]);
264 s.BindString16(2, middle_names[i]); 313 s.BindString16(2, middle_names[i]);
265 s.BindString16(3, last_names[i]); 314 s.BindString16(3, last_names[i]);
266 315
316 if (has_full_name)
317 s.BindString16(4, full_names[i]);
318
267 if (!s.Run()) 319 if (!s.Run())
268 return false; 320 return false;
269 } 321 }
270 return true; 322 return true;
271 } 323 }
272 324
273 bool AddAutofillProfileEmails(const AutofillProfile& profile, 325 bool AddAutofillProfileEmails(const AutofillProfile& profile,
274 sql::Connection* db) { 326 sql::Connection* db) {
275 std::vector<base::string16> emails; 327 std::vector<base::string16> emails;
276 profile.GetRawMultiInfo(EMAIL_ADDRESS, &emails); 328 profile.GetRawMultiInfo(EMAIL_ADDRESS, &emails);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 return MigrateToVersion51AddOriginColumn(); 492 return MigrateToVersion51AddOriginColumn();
441 case 54: 493 case 54:
442 *update_compatible_version = true; 494 *update_compatible_version = true;
443 return MigrateToVersion54AddI18nFieldsAndRemoveDeprecatedFields(); 495 return MigrateToVersion54AddI18nFieldsAndRemoveDeprecatedFields();
444 case 55: 496 case 55:
445 *update_compatible_version = true; 497 *update_compatible_version = true;
446 return MigrateToVersion55MergeAutofillDatesTable(); 498 return MigrateToVersion55MergeAutofillDatesTable();
447 case 56: 499 case 56:
448 *update_compatible_version = true; 500 *update_compatible_version = true;
449 return MigrateToVersion56AddProfileLanguageCodeForFormatting(); 501 return MigrateToVersion56AddProfileLanguageCodeForFormatting();
502 case 57:
503 *update_compatible_version = true;
504 return MigrateToVersion57AddFullNameField();
450 } 505 }
451 return true; 506 return true;
452 } 507 }
453 508
454 bool AutofillTable::AddFormFieldValues( 509 bool AutofillTable::AddFormFieldValues(
455 const std::vector<FormFieldData>& elements, 510 const std::vector<FormFieldData>& elements,
456 std::vector<AutofillChange>* changes) { 511 std::vector<AutofillChange>* changes) {
457 return AddFormFieldValuesTime(elements, changes, Time::Now()); 512 return AddFormFieldValuesTime(elements, changes, Time::Now());
458 } 513 }
459 514
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 } 1340 }
1286 return true; 1341 return true;
1287 } 1342 }
1288 1343
1289 bool AutofillTable::InitProfileNamesTable() { 1344 bool AutofillTable::InitProfileNamesTable() {
1290 if (!db_->DoesTableExist("autofill_profile_names")) { 1345 if (!db_->DoesTableExist("autofill_profile_names")) {
1291 if (!db_->Execute("CREATE TABLE autofill_profile_names ( " 1346 if (!db_->Execute("CREATE TABLE autofill_profile_names ( "
1292 "guid VARCHAR, " 1347 "guid VARCHAR, "
1293 "first_name VARCHAR, " 1348 "first_name VARCHAR, "
1294 "middle_name VARCHAR, " 1349 "middle_name VARCHAR, "
1295 "last_name VARCHAR)")) { 1350 "last_name VARCHAR, "
1351 "full_name VARCHAR)")) {
1296 NOTREACHED(); 1352 NOTREACHED();
1297 return false; 1353 return false;
1298 } 1354 }
1299 } 1355 }
1300 return true; 1356 return true;
1301 } 1357 }
1302 1358
1303 bool AutofillTable::InitProfileEmailsTable() { 1359 bool AutofillTable::InitProfileEmailsTable() {
1304 if (!db_->DoesTableExist("autofill_profile_emails")) { 1360 if (!db_->DoesTableExist("autofill_profile_emails")) {
1305 if (!db_->Execute("CREATE TABLE autofill_profile_emails ( " 1361 if (!db_->Execute("CREATE TABLE autofill_profile_emails ( "
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1998 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++)); 2054 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++));
1999 // Intentionally skip column 7, which stores the localized country name. 2055 // Intentionally skip column 7, which stores the localized country name.
2000 index++; 2056 index++;
2001 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++)); 2057 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++));
2002 // Intentionally skip column 9, which stores the profile's modification 2058 // Intentionally skip column 9, which stores the profile's modification
2003 // date. 2059 // date.
2004 index++; 2060 index++;
2005 profile->set_origin(s.ColumnString(index++)); 2061 profile->set_origin(s.ColumnString(index++));
2006 2062
2007 // Get associated name info. 2063 // Get associated name info.
2008 AddAutofillProfileNamesToProfile(db_, profile.get()); 2064 AddAutofillProfileNamesToProfileForVersion37(db_, profile.get());
2009 2065
2010 // Get associated email info. 2066 // Get associated email info.
2011 AddAutofillProfileEmailsToProfile(db_, profile.get()); 2067 AddAutofillProfileEmailsToProfile(db_, profile.get());
2012 2068
2013 // Get associated phone info. 2069 // Get associated phone info.
2014 AddAutofillProfilePhonesToProfile(db_, profile.get()); 2070 AddAutofillProfilePhonesToProfile(db_, profile.get());
2015 2071
2016 if (PersonalDataManager::IsValidLearnableProfile(*profile, app_locale_)) { 2072 if (PersonalDataManager::IsValidLearnableProfile(*profile, app_locale_)) {
2017 std::vector<AutofillProfile> merged_profiles; 2073 std::vector<AutofillProfile> merged_profiles;
2018 std::string merged_guid = PersonalDataManager::MergeProfile( 2074 std::string merged_guid = PersonalDataManager::MergeProfile(
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2265 2321
2266 2322
2267 return transaction.Commit(); 2323 return transaction.Commit();
2268 } 2324 }
2269 2325
2270 bool AutofillTable::MigrateToVersion56AddProfileLanguageCodeForFormatting() { 2326 bool AutofillTable::MigrateToVersion56AddProfileLanguageCodeForFormatting() {
2271 return db_->Execute("ALTER TABLE autofill_profiles " 2327 return db_->Execute("ALTER TABLE autofill_profiles "
2272 "ADD COLUMN language_code VARCHAR"); 2328 "ADD COLUMN language_code VARCHAR");
2273 } 2329 }
2274 2330
2331 bool AutofillTable::MigrateToVersion57AddFullNameField() {
2332 return db_->Execute("ALTER TABLE autofill_profile_names "
2333 "ADD COLUMN full_name VARCHAR");
2334 }
2335
2275 } // namespace autofill 2336 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698