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

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: db migration test 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 bool AddAutofillProfileNamesToProfile(sql::Connection* db, 170 bool AddAutofillProfileNamesToProfile(sql::Connection* db,
171 AutofillProfile* profile) { 171 AutofillProfile* profile) {
172 sql::Statement s(db->GetUniqueStatement( 172 bool has_full_name =
173 "SELECT guid, first_name, middle_name, last_name " 173 db->DoesColumnExist("autofill_profile_names", "full_name");
Scott Hess - ex-Googler 2014/06/04 23:48:17 I may be missing something, here. How does the co
Evan Stade 2014/06/05 18:16:28 MigrateToVersion37MergeAndCullOlderProfiles calls
Scott Hess - ex-Googler 2014/06/06 23:55:36 Wow, you present me with a dilemma. In general, I
Ilya Sherman 2014/06/07 00:02:38 +1. I have found that, despite the ugliness, migr
Evan Stade 2014/06/09 17:48:40 I agree, so I've filed crbug.com/382562 In the me
174 "FROM autofill_profile_names " 174
175 "WHERE guid=?")); 175 sql::Statement s(db->GetUniqueStatement((
176 std::string("SELECT guid, first_name, middle_name, last_name") +
177 (has_full_name ? ", full_name " : " ") +
178 "FROM autofill_profile_names " +
179 "WHERE guid=?").c_str()));
176 s.BindString(0, profile->guid()); 180 s.BindString(0, profile->guid());
177 181
178 if (!s.is_valid()) 182 if (!s.is_valid())
179 return false; 183 return false;
180 184
181 std::vector<base::string16> first_names; 185 std::vector<base::string16> first_names;
182 std::vector<base::string16> middle_names; 186 std::vector<base::string16> middle_names;
183 std::vector<base::string16> last_names; 187 std::vector<base::string16> last_names;
188 std::vector<base::string16> full_names;
184 while (s.Step()) { 189 while (s.Step()) {
185 DCHECK_EQ(profile->guid(), s.ColumnString(0)); 190 DCHECK_EQ(profile->guid(), s.ColumnString(0));
186 first_names.push_back(s.ColumnString16(1)); 191 first_names.push_back(s.ColumnString16(1));
187 middle_names.push_back(s.ColumnString16(2)); 192 middle_names.push_back(s.ColumnString16(2));
188 last_names.push_back(s.ColumnString16(3)); 193 last_names.push_back(s.ColumnString16(3));
194 if (has_full_name)
195 full_names.push_back(s.ColumnString16(4));
189 } 196 }
190 if (!s.Succeeded()) 197 if (!s.Succeeded())
191 return false; 198 return false;
192 199
193 profile->SetRawMultiInfo(NAME_FIRST, first_names); 200 profile->SetRawMultiInfo(NAME_FIRST, first_names);
194 profile->SetRawMultiInfo(NAME_MIDDLE, middle_names); 201 profile->SetRawMultiInfo(NAME_MIDDLE, middle_names);
195 profile->SetRawMultiInfo(NAME_LAST, last_names); 202 profile->SetRawMultiInfo(NAME_LAST, last_names);
203 if (has_full_name)
204 profile->SetRawMultiInfo(NAME_FULL, full_names);
196 return true; 205 return true;
197 } 206 }
198 207
199 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, 208 bool AddAutofillProfileEmailsToProfile(sql::Connection* db,
200 AutofillProfile* profile) { 209 AutofillProfile* profile) {
201 sql::Statement s(db->GetUniqueStatement( 210 sql::Statement s(db->GetUniqueStatement(
202 "SELECT guid, email " 211 "SELECT guid, email "
203 "FROM autofill_profile_emails " 212 "FROM autofill_profile_emails "
204 "WHERE guid=?")); 213 "WHERE guid=?"));
205 s.BindString(0, profile->guid()); 214 s.BindString(0, profile->guid());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 252 }
244 253
245 bool AddAutofillProfileNames(const AutofillProfile& profile, 254 bool AddAutofillProfileNames(const AutofillProfile& profile,
246 sql::Connection* db) { 255 sql::Connection* db) {
247 std::vector<base::string16> first_names; 256 std::vector<base::string16> first_names;
248 profile.GetRawMultiInfo(NAME_FIRST, &first_names); 257 profile.GetRawMultiInfo(NAME_FIRST, &first_names);
249 std::vector<base::string16> middle_names; 258 std::vector<base::string16> middle_names;
250 profile.GetRawMultiInfo(NAME_MIDDLE, &middle_names); 259 profile.GetRawMultiInfo(NAME_MIDDLE, &middle_names);
251 std::vector<base::string16> last_names; 260 std::vector<base::string16> last_names;
252 profile.GetRawMultiInfo(NAME_LAST, &last_names); 261 profile.GetRawMultiInfo(NAME_LAST, &last_names);
262 std::vector<base::string16> full_names;
263 profile.GetRawMultiInfo(NAME_FULL, &full_names);
253 DCHECK_EQ(first_names.size(), middle_names.size()); 264 DCHECK_EQ(first_names.size(), middle_names.size());
254 DCHECK_EQ(middle_names.size(), last_names.size()); 265 DCHECK_EQ(first_names.size(), last_names.size());
266 DCHECK_EQ(first_names.size(), full_names.size());
255 267
256 for (size_t i = 0; i < first_names.size(); ++i) { 268 for (size_t i = 0; i < first_names.size(); ++i) {
269 bool has_full_name =
270 db->DoesColumnExist("autofill_profile_names", "full_name");
271
257 // Add the new name. 272 // Add the new name.
258 sql::Statement s(db->GetUniqueStatement( 273 sql::Statement s;
259 "INSERT INTO autofill_profile_names" 274 if (has_full_name) {
260 " (guid, first_name, middle_name, last_name) " 275 s.Assign(db->GetUniqueStatement(
261 "VALUES (?,?,?,?)")); 276 "INSERT INTO autofill_profile_names"
277 " (guid, first_name, middle_name, last_name, full_name) "
278 "VALUES (?,?,?,?,?)"));
279 } else {
280 s.Assign(db->GetUniqueStatement(
281 "INSERT INTO autofill_profile_names"
282 " (guid, first_name, middle_name, last_name) "
283 "VALUES (?,?,?,?)"));
284 }
262 s.BindString(0, profile.guid()); 285 s.BindString(0, profile.guid());
263 s.BindString16(1, first_names[i]); 286 s.BindString16(1, first_names[i]);
264 s.BindString16(2, middle_names[i]); 287 s.BindString16(2, middle_names[i]);
265 s.BindString16(3, last_names[i]); 288 s.BindString16(3, last_names[i]);
266 289
290 if (has_full_name)
291 s.BindString16(4, full_names[i]);
292
267 if (!s.Run()) 293 if (!s.Run())
268 return false; 294 return false;
269 } 295 }
270 return true; 296 return true;
271 } 297 }
272 298
273 bool AddAutofillProfileEmails(const AutofillProfile& profile, 299 bool AddAutofillProfileEmails(const AutofillProfile& profile,
274 sql::Connection* db) { 300 sql::Connection* db) {
275 std::vector<base::string16> emails; 301 std::vector<base::string16> emails;
276 profile.GetRawMultiInfo(EMAIL_ADDRESS, &emails); 302 profile.GetRawMultiInfo(EMAIL_ADDRESS, &emails);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 return MigrateToVersion51AddOriginColumn(); 466 return MigrateToVersion51AddOriginColumn();
441 case 54: 467 case 54:
442 *update_compatible_version = true; 468 *update_compatible_version = true;
443 return MigrateToVersion54AddI18nFieldsAndRemoveDeprecatedFields(); 469 return MigrateToVersion54AddI18nFieldsAndRemoveDeprecatedFields();
444 case 55: 470 case 55:
445 *update_compatible_version = true; 471 *update_compatible_version = true;
446 return MigrateToVersion55MergeAutofillDatesTable(); 472 return MigrateToVersion55MergeAutofillDatesTable();
447 case 56: 473 case 56:
448 *update_compatible_version = true; 474 *update_compatible_version = true;
449 return MigrateToVersion56AddProfileLanguageCodeForFormatting(); 475 return MigrateToVersion56AddProfileLanguageCodeForFormatting();
476 case 57:
477 *update_compatible_version = true;
478 return MigrateToVersion57AddFullNameField();
450 } 479 }
451 return true; 480 return true;
452 } 481 }
453 482
454 bool AutofillTable::AddFormFieldValues( 483 bool AutofillTable::AddFormFieldValues(
455 const std::vector<FormFieldData>& elements, 484 const std::vector<FormFieldData>& elements,
456 std::vector<AutofillChange>* changes) { 485 std::vector<AutofillChange>* changes) {
457 return AddFormFieldValuesTime(elements, changes, Time::Now()); 486 return AddFormFieldValuesTime(elements, changes, Time::Now());
458 } 487 }
459 488
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 } 1314 }
1286 return true; 1315 return true;
1287 } 1316 }
1288 1317
1289 bool AutofillTable::InitProfileNamesTable() { 1318 bool AutofillTable::InitProfileNamesTable() {
1290 if (!db_->DoesTableExist("autofill_profile_names")) { 1319 if (!db_->DoesTableExist("autofill_profile_names")) {
1291 if (!db_->Execute("CREATE TABLE autofill_profile_names ( " 1320 if (!db_->Execute("CREATE TABLE autofill_profile_names ( "
1292 "guid VARCHAR, " 1321 "guid VARCHAR, "
1293 "first_name VARCHAR, " 1322 "first_name VARCHAR, "
1294 "middle_name VARCHAR, " 1323 "middle_name VARCHAR, "
1295 "last_name VARCHAR)")) { 1324 "last_name VARCHAR, "
1325 "full_name VARCHAR)")) {
1296 NOTREACHED(); 1326 NOTREACHED();
1297 return false; 1327 return false;
1298 } 1328 }
1299 } 1329 }
1300 return true; 1330 return true;
1301 } 1331 }
1302 1332
1303 bool AutofillTable::InitProfileEmailsTable() { 1333 bool AutofillTable::InitProfileEmailsTable() {
1304 if (!db_->DoesTableExist("autofill_profile_emails")) { 1334 if (!db_->DoesTableExist("autofill_profile_emails")) {
1305 if (!db_->Execute("CREATE TABLE autofill_profile_emails ( " 1335 if (!db_->Execute("CREATE TABLE autofill_profile_emails ( "
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after
2265 2295
2266 2296
2267 return transaction.Commit(); 2297 return transaction.Commit();
2268 } 2298 }
2269 2299
2270 bool AutofillTable::MigrateToVersion56AddProfileLanguageCodeForFormatting() { 2300 bool AutofillTable::MigrateToVersion56AddProfileLanguageCodeForFormatting() {
2271 return db_->Execute("ALTER TABLE autofill_profiles " 2301 return db_->Execute("ALTER TABLE autofill_profiles "
2272 "ADD COLUMN language_code VARCHAR"); 2302 "ADD COLUMN language_code VARCHAR");
2273 } 2303 }
2274 2304
2305 bool AutofillTable::MigrateToVersion57AddFullNameField() {
2306 return db_->Execute("ALTER TABLE autofill_profile_names "
2307 "ADD COLUMN full_name VARCHAR");
2308 }
2309
2275 } // namespace autofill 2310 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/webdata/autofill_table.h ('k') | components/test/data/web_database/version_56.sql » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698