OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/webdata/web_database.h" | 5 #include "chrome/browser/webdata/web_database.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 return data.substr(0, kMaxDataLength); | 278 return data.substr(0, kMaxDataLength); |
279 | 279 |
280 return data; | 280 return data; |
281 } | 281 } |
282 | 282 |
283 void BindAutofillProfileToStatement(const AutofillProfile& profile, | 283 void BindAutofillProfileToStatement(const AutofillProfile& profile, |
284 sql::Statement* s) { | 284 sql::Statement* s) { |
285 DCHECK(guid::IsValidGUID(profile.guid())); | 285 DCHECK(guid::IsValidGUID(profile.guid())); |
286 s->BindString(0, profile.guid()); | 286 s->BindString(0, profile.guid()); |
287 | 287 |
288 string16 text = profile.GetFieldText(AutofillType(COMPANY_NAME)); | 288 string16 text = profile.GetFieldText(COMPANY_NAME); |
289 s->BindString16(1, LimitDataSize(text)); | 289 s->BindString16(1, LimitDataSize(text)); |
290 text = profile.GetFieldText(AutofillType(ADDRESS_HOME_LINE1)); | 290 text = profile.GetFieldText(ADDRESS_HOME_LINE1); |
291 s->BindString16(2, LimitDataSize(text)); | 291 s->BindString16(2, LimitDataSize(text)); |
292 text = profile.GetFieldText(AutofillType(ADDRESS_HOME_LINE2)); | 292 text = profile.GetFieldText(ADDRESS_HOME_LINE2); |
293 s->BindString16(3, LimitDataSize(text)); | 293 s->BindString16(3, LimitDataSize(text)); |
294 text = profile.GetFieldText(AutofillType(ADDRESS_HOME_CITY)); | 294 text = profile.GetFieldText(ADDRESS_HOME_CITY); |
295 s->BindString16(4, LimitDataSize(text)); | 295 s->BindString16(4, LimitDataSize(text)); |
296 text = profile.GetFieldText(AutofillType(ADDRESS_HOME_STATE)); | 296 text = profile.GetFieldText(ADDRESS_HOME_STATE); |
297 s->BindString16(5, LimitDataSize(text)); | 297 s->BindString16(5, LimitDataSize(text)); |
298 text = profile.GetFieldText(AutofillType(ADDRESS_HOME_ZIP)); | 298 text = profile.GetFieldText(ADDRESS_HOME_ZIP); |
299 s->BindString16(6, LimitDataSize(text)); | 299 s->BindString16(6, LimitDataSize(text)); |
300 text = profile.GetFieldText(AutofillType(ADDRESS_HOME_COUNTRY)); | 300 text = profile.GetFieldText(ADDRESS_HOME_COUNTRY); |
301 s->BindString16(7, LimitDataSize(text)); | 301 s->BindString16(7, LimitDataSize(text)); |
302 std::string country_code = profile.CountryCode(); | 302 std::string country_code = profile.CountryCode(); |
303 s->BindString(8, country_code); | 303 s->BindString(8, country_code); |
304 s->BindInt64(9, Time::Now().ToTimeT()); | 304 s->BindInt64(9, Time::Now().ToTimeT()); |
305 } | 305 } |
306 | 306 |
307 AutofillProfile* AutofillProfileFromStatement(const sql::Statement& s) { | 307 AutofillProfile* AutofillProfileFromStatement(const sql::Statement& s) { |
308 AutofillProfile* profile = new AutofillProfile; | 308 AutofillProfile* profile = new AutofillProfile; |
309 profile->set_guid(s.ColumnString(0)); | 309 profile->set_guid(s.ColumnString(0)); |
310 DCHECK(guid::IsValidGUID(profile->guid())); | 310 DCHECK(guid::IsValidGUID(profile->guid())); |
311 | 311 |
312 profile->SetInfo(AutofillType(COMPANY_NAME), s.ColumnString16(1)); | 312 profile->SetInfo(COMPANY_NAME, s.ColumnString16(1)); |
313 profile->SetInfo(AutofillType(ADDRESS_HOME_LINE1), s.ColumnString16(2)); | 313 profile->SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(2)); |
314 profile->SetInfo(AutofillType(ADDRESS_HOME_LINE2), s.ColumnString16(3)); | 314 profile->SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(3)); |
315 profile->SetInfo(AutofillType(ADDRESS_HOME_CITY), s.ColumnString16(4)); | 315 profile->SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(4)); |
316 profile->SetInfo(AutofillType(ADDRESS_HOME_STATE), s.ColumnString16(5)); | 316 profile->SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(5)); |
317 profile->SetInfo(AutofillType(ADDRESS_HOME_ZIP), s.ColumnString16(6)); | 317 profile->SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(6)); |
318 // Intentionally skip column 7, which stores the localized country name. | 318 // Intentionally skip column 7, which stores the localized country name. |
319 profile->SetCountryCode(s.ColumnString(8)); | 319 profile->SetCountryCode(s.ColumnString(8)); |
320 // Intentionally skip column 9, which stores the profile's modification date. | 320 // Intentionally skip column 9, which stores the profile's modification date. |
321 | 321 |
322 return profile; | 322 return profile; |
323 } | 323 } |
324 | 324 |
325 void AddAutofillProfileNameFromStatement(const sql::Statement& s, | 325 void AddAutofillProfileNameFromStatement(const sql::Statement& s, |
326 AutofillProfile* profile) { | 326 AutofillProfile* profile) { |
327 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 327 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
328 DCHECK(guid::IsValidGUID(profile->guid())); | 328 DCHECK(guid::IsValidGUID(profile->guid())); |
329 | 329 |
330 profile->SetInfo(AutofillType(NAME_FIRST), s.ColumnString16(1)); | 330 profile->SetInfo(NAME_FIRST, s.ColumnString16(1)); |
331 profile->SetInfo(AutofillType(NAME_MIDDLE), s.ColumnString16(2)); | 331 profile->SetInfo(NAME_MIDDLE, s.ColumnString16(2)); |
332 profile->SetInfo(AutofillType(NAME_LAST), s.ColumnString16(3)); | 332 profile->SetInfo(NAME_LAST, s.ColumnString16(3)); |
333 } | 333 } |
334 | 334 |
335 void AddAutofillProfileEmailFromStatement(const sql::Statement& s, | 335 void AddAutofillProfileEmailFromStatement(const sql::Statement& s, |
336 AutofillProfile* profile) { | 336 AutofillProfile* profile) { |
337 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 337 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
338 DCHECK(guid::IsValidGUID(profile->guid())); | 338 DCHECK(guid::IsValidGUID(profile->guid())); |
339 | 339 |
340 profile->SetInfo(AutofillType(EMAIL_ADDRESS), s.ColumnString16(1)); | 340 profile->SetInfo(EMAIL_ADDRESS, s.ColumnString16(1)); |
341 } | 341 } |
342 | 342 |
343 void AddAutofillProfilePhoneFromStatement(const sql::Statement& s, | 343 void AddAutofillProfilePhoneFromStatement(const sql::Statement& s, |
344 AutofillProfile* profile) { | 344 AutofillProfile* profile) { |
345 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 345 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
346 DCHECK(guid::IsValidGUID(profile->guid())); | 346 DCHECK(guid::IsValidGUID(profile->guid())); |
347 DCHECK_EQ(kAutoFillPhoneNumber, s.ColumnInt(1)); | 347 DCHECK_EQ(kAutoFillPhoneNumber, s.ColumnInt(1)); |
348 profile->SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), s.ColumnString16(2)); | 348 profile->SetInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(2)); |
349 } | 349 } |
350 | 350 |
351 void AddAutofillProfileFaxFromStatement(const sql::Statement& s, | 351 void AddAutofillProfileFaxFromStatement(const sql::Statement& s, |
352 AutofillProfile* profile) { | 352 AutofillProfile* profile) { |
353 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 353 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
354 DCHECK(guid::IsValidGUID(profile->guid())); | 354 DCHECK(guid::IsValidGUID(profile->guid())); |
355 DCHECK_EQ(kAutoFillFaxNumber, s.ColumnInt(1)); | 355 DCHECK_EQ(kAutoFillFaxNumber, s.ColumnInt(1)); |
356 profile->SetInfo(AutofillType(PHONE_FAX_WHOLE_NUMBER), s.ColumnString16(2)); | 356 profile->SetInfo(PHONE_FAX_WHOLE_NUMBER, s.ColumnString16(2)); |
357 } | 357 } |
358 | 358 |
359 void BindCreditCardToStatement(const CreditCard& credit_card, | 359 void BindCreditCardToStatement(const CreditCard& credit_card, |
360 sql::Statement* s) { | 360 sql::Statement* s) { |
361 DCHECK(guid::IsValidGUID(credit_card.guid())); | 361 DCHECK(guid::IsValidGUID(credit_card.guid())); |
362 s->BindString(0, credit_card.guid()); | 362 s->BindString(0, credit_card.guid()); |
363 | 363 |
364 string16 text = credit_card.GetFieldText(AutofillType(CREDIT_CARD_NAME)); | 364 string16 text = credit_card.GetFieldText(CREDIT_CARD_NAME); |
365 s->BindString16(1, LimitDataSize(text)); | 365 s->BindString16(1, LimitDataSize(text)); |
366 text = credit_card.GetFieldText(AutofillType(CREDIT_CARD_EXP_MONTH)); | 366 text = credit_card.GetFieldText(CREDIT_CARD_EXP_MONTH); |
367 s->BindString16(2, LimitDataSize(text)); | 367 s->BindString16(2, LimitDataSize(text)); |
368 text = credit_card.GetFieldText(AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 368 text = credit_card.GetFieldText(CREDIT_CARD_EXP_4_DIGIT_YEAR); |
369 s->BindString16(3, LimitDataSize(text)); | 369 s->BindString16(3, LimitDataSize(text)); |
370 text = credit_card.GetFieldText(AutofillType(CREDIT_CARD_NUMBER)); | 370 text = credit_card.GetFieldText(CREDIT_CARD_NUMBER); |
371 std::string encrypted_data; | 371 std::string encrypted_data; |
372 Encryptor::EncryptString16(text, &encrypted_data); | 372 Encryptor::EncryptString16(text, &encrypted_data); |
373 s->BindBlob(4, encrypted_data.data(), | 373 s->BindBlob(4, encrypted_data.data(), |
374 static_cast<int>(encrypted_data.length())); | 374 static_cast<int>(encrypted_data.length())); |
375 s->BindInt64(5, Time::Now().ToTimeT()); | 375 s->BindInt64(5, Time::Now().ToTimeT()); |
376 } | 376 } |
377 | 377 |
378 CreditCard* CreditCardFromStatement(const sql::Statement& s) { | 378 CreditCard* CreditCardFromStatement(const sql::Statement& s) { |
379 CreditCard* credit_card = new CreditCard; | 379 CreditCard* credit_card = new CreditCard; |
380 | 380 |
381 credit_card->set_guid(s.ColumnString(0)); | 381 credit_card->set_guid(s.ColumnString(0)); |
382 DCHECK(guid::IsValidGUID(credit_card->guid())); | 382 DCHECK(guid::IsValidGUID(credit_card->guid())); |
383 | 383 |
384 credit_card->SetInfo(AutofillType(CREDIT_CARD_NAME), s.ColumnString16(1)); | 384 credit_card->SetInfo(CREDIT_CARD_NAME, s.ColumnString16(1)); |
385 credit_card->SetInfo(AutofillType(CREDIT_CARD_EXP_MONTH), | 385 credit_card->SetInfo(CREDIT_CARD_EXP_MONTH, |
386 s.ColumnString16(2)); | 386 s.ColumnString16(2)); |
387 credit_card->SetInfo(AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), | 387 credit_card->SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
388 s.ColumnString16(3)); | 388 s.ColumnString16(3)); |
389 int encrypted_number_len = s.ColumnByteLength(4); | 389 int encrypted_number_len = s.ColumnByteLength(4); |
390 string16 credit_card_number; | 390 string16 credit_card_number; |
391 if (encrypted_number_len) { | 391 if (encrypted_number_len) { |
392 std::string encrypted_number; | 392 std::string encrypted_number; |
393 encrypted_number.resize(encrypted_number_len); | 393 encrypted_number.resize(encrypted_number_len); |
394 memcpy(&encrypted_number[0], s.ColumnBlob(4), encrypted_number_len); | 394 memcpy(&encrypted_number[0], s.ColumnBlob(4), encrypted_number_len); |
395 Encryptor::DecryptString16(encrypted_number, &credit_card_number); | 395 Encryptor::DecryptString16(encrypted_number, &credit_card_number); |
396 } | 396 } |
397 credit_card->SetInfo(AutofillType(CREDIT_CARD_NUMBER), credit_card_number); | 397 credit_card->SetInfo(CREDIT_CARD_NUMBER, credit_card_number); |
398 // Intentionally skip column 5, which stores the modification date. | 398 // Intentionally skip column 5, which stores the modification date. |
399 | 399 |
400 return credit_card; | 400 return credit_card; |
401 } | 401 } |
402 | 402 |
403 bool AutofillProfileHasName(const AutofillProfile& profile) { | 403 bool AutofillProfileHasName(const AutofillProfile& profile) { |
404 return !profile.GetFieldText(AutofillType(NAME_FIRST)).empty() || | 404 return !profile.GetFieldText(NAME_FIRST).empty() || |
405 !profile.GetFieldText(AutofillType(NAME_MIDDLE)).empty() || | 405 !profile.GetFieldText(NAME_MIDDLE).empty() || |
406 !profile.GetFieldText(AutofillType(NAME_MIDDLE)).empty(); | 406 !profile.GetFieldText(NAME_MIDDLE).empty(); |
407 } | 407 } |
408 | 408 |
409 bool AddAutofillProfileName(const std::string& guid, | 409 bool AddAutofillProfileName(const std::string& guid, |
410 const AutofillProfile& profile, | 410 const AutofillProfile& profile, |
411 sql::Connection* db) { | 411 sql::Connection* db) { |
412 if (!AutofillProfileHasName(profile)) | 412 if (!AutofillProfileHasName(profile)) |
413 return true; | 413 return true; |
414 | 414 |
415 // Check for duplicate. | 415 // Check for duplicate. |
416 sql::Statement s_find(db->GetUniqueStatement( | 416 sql::Statement s_find(db->GetUniqueStatement( |
417 "SELECT guid, first_name, middle_name, last_name " | 417 "SELECT guid, first_name, middle_name, last_name " |
418 "FROM autofill_profile_names " | 418 "FROM autofill_profile_names " |
419 "WHERE guid=? AND first_name=? AND middle_name=? AND last_name=?")); | 419 "WHERE guid=? AND first_name=? AND middle_name=? AND last_name=?")); |
420 if (!s_find) { | 420 if (!s_find) { |
421 NOTREACHED(); | 421 NOTREACHED(); |
422 return false; | 422 return false; |
423 } | 423 } |
424 s_find.BindString(0, guid); | 424 s_find.BindString(0, guid); |
425 s_find.BindString16(1, profile.GetFieldText(AutofillType(NAME_FIRST))); | 425 s_find.BindString16(1, profile.GetFieldText(NAME_FIRST)); |
426 s_find.BindString16(2, profile.GetFieldText(AutofillType(NAME_MIDDLE))); | 426 s_find.BindString16(2, profile.GetFieldText(NAME_MIDDLE)); |
427 s_find.BindString16(3, profile.GetFieldText(AutofillType(NAME_LAST))); | 427 s_find.BindString16(3, profile.GetFieldText(NAME_LAST)); |
428 | 428 |
429 if (!s_find.Step()) { | 429 if (!s_find.Step()) { |
430 // Add the new name. | 430 // Add the new name. |
431 sql::Statement s(db->GetUniqueStatement( | 431 sql::Statement s(db->GetUniqueStatement( |
432 "INSERT INTO autofill_profile_names" | 432 "INSERT INTO autofill_profile_names" |
433 " (guid, first_name, middle_name, last_name) " | 433 " (guid, first_name, middle_name, last_name) " |
434 "VALUES (?,?,?,?)")); | 434 "VALUES (?,?,?,?)")); |
435 if (!s) { | 435 if (!s) { |
436 NOTREACHED(); | 436 NOTREACHED(); |
437 return false; | 437 return false; |
438 } | 438 } |
439 s.BindString(0, guid); | 439 s.BindString(0, guid); |
440 s.BindString16(1, profile.GetFieldText(AutofillType(NAME_FIRST))); | 440 s.BindString16(1, profile.GetFieldText(NAME_FIRST)); |
441 s.BindString16(2, profile.GetFieldText(AutofillType(NAME_MIDDLE))); | 441 s.BindString16(2, profile.GetFieldText(NAME_MIDDLE)); |
442 s.BindString16(3, profile.GetFieldText(AutofillType(NAME_LAST))); | 442 s.BindString16(3, profile.GetFieldText(NAME_LAST)); |
443 | 443 |
444 if (!s.Run()) { | 444 if (!s.Run()) { |
445 NOTREACHED(); | 445 NOTREACHED(); |
446 return false; | 446 return false; |
447 } | 447 } |
448 } | 448 } |
449 return true; | 449 return true; |
450 } | 450 } |
451 | 451 |
452 bool AddAutofillProfileEmail(const std::string& guid, | 452 bool AddAutofillProfileEmail(const std::string& guid, |
453 const AutofillProfile& profile, | 453 const AutofillProfile& profile, |
454 sql::Connection* db) { | 454 sql::Connection* db) { |
455 if (profile.GetFieldText(AutofillType(EMAIL_ADDRESS)).empty()) | 455 if (profile.GetFieldText(EMAIL_ADDRESS).empty()) |
456 return true; | 456 return true; |
457 | 457 |
458 // Check for duplicate. | 458 // Check for duplicate. |
459 sql::Statement s_find(db->GetUniqueStatement( | 459 sql::Statement s_find(db->GetUniqueStatement( |
460 "SELECT guid, email " | 460 "SELECT guid, email " |
461 "FROM autofill_profile_emails " | 461 "FROM autofill_profile_emails " |
462 "WHERE guid=? AND email=?")); | 462 "WHERE guid=? AND email=?")); |
463 if (!s_find) { | 463 if (!s_find) { |
464 NOTREACHED(); | 464 NOTREACHED(); |
465 return false; | 465 return false; |
466 } | 466 } |
467 s_find.BindString(0, guid); | 467 s_find.BindString(0, guid); |
468 s_find.BindString16(1, profile.GetFieldText(AutofillType(EMAIL_ADDRESS))); | 468 s_find.BindString16(1, profile.GetFieldText(EMAIL_ADDRESS)); |
469 | 469 |
470 if (!s_find.Step()) { | 470 if (!s_find.Step()) { |
471 sql::Statement s(db->GetUniqueStatement( | 471 sql::Statement s(db->GetUniqueStatement( |
472 "INSERT INTO autofill_profile_emails" | 472 "INSERT INTO autofill_profile_emails" |
473 " (guid, email) " | 473 " (guid, email) " |
474 "VALUES (?,?)")); | 474 "VALUES (?,?)")); |
475 if (!s) { | 475 if (!s) { |
476 NOTREACHED(); | 476 NOTREACHED(); |
477 return false; | 477 return false; |
478 } | 478 } |
479 s.BindString(0, guid); | 479 s.BindString(0, guid); |
480 s.BindString16(1, profile.GetFieldText(AutofillType(EMAIL_ADDRESS))); | 480 s.BindString16(1, profile.GetFieldText(EMAIL_ADDRESS)); |
481 | 481 |
482 if (!s.Run()) { | 482 if (!s.Run()) { |
483 NOTREACHED(); | 483 NOTREACHED(); |
484 return false; | 484 return false; |
485 } | 485 } |
486 } | 486 } |
487 return true; | 487 return true; |
488 } | 488 } |
489 | 489 |
490 bool AddAutofillProfilePhone(const std::string& guid, | 490 bool AddAutofillProfilePhone(const std::string& guid, |
491 const AutofillProfile& profile, | 491 const AutofillProfile& profile, |
492 AutoFillPhoneType phone_type, | 492 AutoFillPhoneType phone_type, |
493 sql::Connection* db) { | 493 sql::Connection* db) { |
494 AutofillFieldType field_type; | 494 AutofillFieldType field_type; |
495 if (phone_type == kAutoFillPhoneNumber) { | 495 if (phone_type == kAutoFillPhoneNumber) { |
496 field_type = PHONE_HOME_WHOLE_NUMBER; | 496 field_type = PHONE_HOME_WHOLE_NUMBER; |
497 } else if (phone_type == kAutoFillFaxNumber) { | 497 } else if (phone_type == kAutoFillFaxNumber) { |
498 field_type = PHONE_FAX_WHOLE_NUMBER; | 498 field_type = PHONE_FAX_WHOLE_NUMBER; |
499 } else { | 499 } else { |
500 NOTREACHED(); | 500 NOTREACHED(); |
501 return false; | 501 return false; |
502 } | 502 } |
503 | 503 |
504 if (profile.GetFieldText(AutofillType(field_type)).empty()) | 504 if (profile.GetFieldText(field_type).empty()) |
505 return true; | 505 return true; |
506 | 506 |
507 // Check for duplicate. | 507 // Check for duplicate. |
508 sql::Statement s_find(db->GetUniqueStatement( | 508 sql::Statement s_find(db->GetUniqueStatement( |
509 "SELECT guid, type, number " | 509 "SELECT guid, type, number " |
510 "FROM autofill_profile_phones " | 510 "FROM autofill_profile_phones " |
511 "WHERE guid=? AND type=? AND number=?")); | 511 "WHERE guid=? AND type=? AND number=?")); |
512 if (!s_find) { | 512 if (!s_find) { |
513 NOTREACHED(); | 513 NOTREACHED(); |
514 return false; | 514 return false; |
515 } | 515 } |
516 s_find.BindString(0, guid); | 516 s_find.BindString(0, guid); |
517 s_find.BindInt(1, phone_type); | 517 s_find.BindInt(1, phone_type); |
518 s_find.BindString16( | 518 s_find.BindString16( |
519 2, profile.GetFieldText(AutofillType(field_type))); | 519 2, profile.GetFieldText(field_type)); |
520 | 520 |
521 if (!s_find.Step()) { | 521 if (!s_find.Step()) { |
522 sql::Statement s(db->GetUniqueStatement( | 522 sql::Statement s(db->GetUniqueStatement( |
523 "INSERT INTO autofill_profile_phones" | 523 "INSERT INTO autofill_profile_phones" |
524 " (guid, type, number) " | 524 " (guid, type, number) " |
525 "VALUES (?,?,?)")); | 525 "VALUES (?,?,?)")); |
526 if (!s) { | 526 if (!s) { |
527 NOTREACHED(); | 527 NOTREACHED(); |
528 return sql::INIT_FAILURE; | 528 return sql::INIT_FAILURE; |
529 } | 529 } |
530 s.BindString(0, guid); | 530 s.BindString(0, guid); |
531 s.BindInt(1, phone_type); | 531 s.BindInt(1, phone_type); |
532 s.BindString16( | 532 s.BindString16( |
533 2, profile.GetFieldText(AutofillType(field_type))); | 533 2, profile.GetFieldText(field_type)); |
534 | 534 |
535 if (!s.Run()) { | 535 if (!s.Run()) { |
536 NOTREACHED(); | 536 NOTREACHED(); |
537 return false; | 537 return false; |
538 } | 538 } |
539 } | 539 } |
540 return true; | 540 return true; |
541 } | 541 } |
542 | 542 |
543 bool AddAutofillProfilePieces(const std::string& guid, | 543 bool AddAutofillProfilePieces(const std::string& guid, |
(...skipping 2344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2888 sql::Statement s(db_.GetUniqueStatement( | 2888 sql::Statement s(db_.GetUniqueStatement( |
2889 "SELECT guid, first_name, middle_name, last_name, email, " | 2889 "SELECT guid, first_name, middle_name, last_name, email, " |
2890 "company_name, address_line_1, address_line_2, city, state, " | 2890 "company_name, address_line_1, address_line_2, city, state, " |
2891 "zipcode, country, phone, fax, date_modified " | 2891 "zipcode, country, phone, fax, date_modified " |
2892 "FROM autofill_profiles")); | 2892 "FROM autofill_profiles")); |
2893 while (s.Step()) { | 2893 while (s.Step()) { |
2894 AutofillProfile profile; | 2894 AutofillProfile profile; |
2895 profile.set_guid(s.ColumnString(0)); | 2895 profile.set_guid(s.ColumnString(0)); |
2896 DCHECK(guid::IsValidGUID(profile.guid())); | 2896 DCHECK(guid::IsValidGUID(profile.guid())); |
2897 | 2897 |
2898 profile.SetInfo(AutofillType(NAME_FIRST), s.ColumnString16(1)); | 2898 profile.SetInfo(NAME_FIRST, s.ColumnString16(1)); |
2899 profile.SetInfo(AutofillType(NAME_MIDDLE), s.ColumnString16(2)); | 2899 profile.SetInfo(NAME_MIDDLE, s.ColumnString16(2)); |
2900 profile.SetInfo(AutofillType(NAME_LAST), s.ColumnString16(3)); | 2900 profile.SetInfo(NAME_LAST, s.ColumnString16(3)); |
2901 profile.SetInfo(AutofillType(EMAIL_ADDRESS), s.ColumnString16(4)); | 2901 profile.SetInfo(EMAIL_ADDRESS, s.ColumnString16(4)); |
2902 profile.SetInfo(AutofillType(COMPANY_NAME), s.ColumnString16(5)); | 2902 profile.SetInfo(COMPANY_NAME, s.ColumnString16(5)); |
2903 profile.SetInfo(AutofillType(ADDRESS_HOME_LINE1), | 2903 profile.SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6)); |
2904 s.ColumnString16(6)); | 2904 profile.SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7)); |
2905 profile.SetInfo(AutofillType(ADDRESS_HOME_LINE2), | 2905 profile.SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(8)); |
2906 s.ColumnString16(7)); | 2906 profile.SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(9)); |
2907 profile.SetInfo(AutofillType(ADDRESS_HOME_CITY), | 2907 profile.SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(10)); |
2908 s.ColumnString16(8)); | 2908 profile.SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(11)); |
2909 profile.SetInfo(AutofillType(ADDRESS_HOME_STATE), | 2909 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(12)); |
2910 s.ColumnString16(9)); | 2910 profile.SetInfo(PHONE_FAX_WHOLE_NUMBER, s.ColumnString16(13)); |
2911 profile.SetInfo(AutofillType(ADDRESS_HOME_ZIP), | |
2912 s.ColumnString16(10)); | |
2913 profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), | |
2914 s.ColumnString16(11)); | |
2915 profile.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), | |
2916 s.ColumnString16(12)); | |
2917 profile.SetInfo(AutofillType(PHONE_FAX_WHOLE_NUMBER), | |
2918 s.ColumnString16(13)); | |
2919 int64 date_modified = s.ColumnInt64(14); | 2911 int64 date_modified = s.ColumnInt64(14); |
2920 | 2912 |
2921 sql::Statement s_insert(db_.GetUniqueStatement( | 2913 sql::Statement s_insert(db_.GetUniqueStatement( |
2922 "INSERT INTO autofill_profiles_temp" | 2914 "INSERT INTO autofill_profiles_temp" |
2923 "(guid, company_name, address_line_1, address_line_2, city," | 2915 "(guid, company_name, address_line_1, address_line_2, city," |
2924 " state, zipcode, country, date_modified)" | 2916 " state, zipcode, country, date_modified)" |
2925 "VALUES (?,?,?,?,?,?,?,?,?)")); | 2917 "VALUES (?,?,?,?,?,?,?,?,?)")); |
2926 if (!s) { | 2918 if (!s) { |
2927 LOG(WARNING) << "Unable to update web database to version 33."; | 2919 LOG(WARNING) << "Unable to update web database to version 33."; |
2928 NOTREACHED(); | 2920 NOTREACHED(); |
2929 return sql::INIT_FAILURE; | 2921 return sql::INIT_FAILURE; |
2930 } | 2922 } |
2931 s_insert.BindString(0, profile.guid()); | 2923 s_insert.BindString(0, profile.guid()); |
2932 s_insert.BindString16( | 2924 s_insert.BindString16(1, profile.GetFieldText(COMPANY_NAME)); |
2933 1, profile.GetFieldText(AutofillType(COMPANY_NAME))); | 2925 s_insert.BindString16(2, profile.GetFieldText(ADDRESS_HOME_LINE1)); |
2934 s_insert.BindString16( | 2926 s_insert.BindString16(3, profile.GetFieldText(ADDRESS_HOME_LINE2)); |
2935 2, profile.GetFieldText(AutofillType(ADDRESS_HOME_LINE1))); | 2927 s_insert.BindString16(4, profile.GetFieldText(ADDRESS_HOME_CITY)); |
2936 s_insert.BindString16( | 2928 s_insert.BindString16(5, profile.GetFieldText(ADDRESS_HOME_STATE)); |
2937 3, profile.GetFieldText(AutofillType(ADDRESS_HOME_LINE2))); | 2929 s_insert.BindString16(6, profile.GetFieldText(ADDRESS_HOME_ZIP)); |
2938 s_insert.BindString16( | 2930 s_insert.BindString16(7, |
2939 4, profile.GetFieldText(AutofillType(ADDRESS_HOME_CITY))); | 2931 profile.GetFieldText(ADDRESS_HOME_COUNTRY)); |
2940 s_insert.BindString16( | |
2941 5, profile.GetFieldText(AutofillType(ADDRESS_HOME_STATE))); | |
2942 s_insert.BindString16( | |
2943 6, profile.GetFieldText(AutofillType(ADDRESS_HOME_ZIP))); | |
2944 s_insert.BindString16( | |
2945 7, profile.GetFieldText(AutofillType(ADDRESS_HOME_COUNTRY))); | |
2946 s_insert.BindInt64(8, date_modified); | 2932 s_insert.BindInt64(8, date_modified); |
2947 | 2933 |
2948 if (!s_insert.Run()) { | 2934 if (!s_insert.Run()) { |
2949 NOTREACHED(); | 2935 NOTREACHED(); |
2950 return sql::INIT_FAILURE; | 2936 return sql::INIT_FAILURE; |
2951 } | 2937 } |
2952 | 2938 |
2953 // Add the other bits: names, emails, and phone/fax. | 2939 // Add the other bits: names, emails, and phone/fax. |
2954 if (!AddAutofillProfilePieces(profile.guid(), profile, &db_)) { | 2940 if (!AddAutofillProfilePieces(profile.guid(), profile, &db_)) { |
2955 NOTREACHED(); | 2941 NOTREACHED(); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3094 | 3080 |
3095 // Add successive versions here. Each should set the version number and | 3081 // Add successive versions here. Each should set the version number and |
3096 // compatible version number as appropriate, then fall through to the next | 3082 // compatible version number as appropriate, then fall through to the next |
3097 // case. | 3083 // case. |
3098 | 3084 |
3099 case kCurrentVersionNumber: | 3085 case kCurrentVersionNumber: |
3100 // No migration needed. | 3086 // No migration needed. |
3101 return sql::INIT_OK; | 3087 return sql::INIT_OK; |
3102 } | 3088 } |
3103 } | 3089 } |
OLD | NEW |