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

Side by Side Diff: components/autofill/core/browser/webdata/autofill_table.cc

Issue 949563003: Add recipient name to server autofill profile database (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 return MigrateToVersion56AddProfileLanguageCodeForFormatting(); 564 return MigrateToVersion56AddProfileLanguageCodeForFormatting();
565 case 57: 565 case 57:
566 *update_compatible_version = true; 566 *update_compatible_version = true;
567 return MigrateToVersion57AddFullNameField(); 567 return MigrateToVersion57AddFullNameField();
568 case 60: 568 case 60:
569 *update_compatible_version = false; 569 *update_compatible_version = false;
570 return MigrateToVersion60AddServerCards(); 570 return MigrateToVersion60AddServerCards();
571 case 61: 571 case 61:
572 *update_compatible_version = false; 572 *update_compatible_version = false;
573 return MigrateToVersion61AddUsageStats(); 573 return MigrateToVersion61AddUsageStats();
574 case 62:
575 *update_compatible_version = false;
576 return MigrateToVersion62AddServerRecipientName();
574 } 577 }
575 return true; 578 return true;
576 } 579 }
577 580
578 bool AutofillTable::AddFormFieldValues( 581 bool AutofillTable::AddFormFieldValues(
579 const std::vector<FormFieldData>& elements, 582 const std::vector<FormFieldData>& elements,
580 std::vector<AutofillChange>* changes) { 583 std::vector<AutofillChange>* changes) {
581 return AddFormFieldValuesTime(elements, changes, Time::Now()); 584 return AddFormFieldValuesTime(elements, changes, Time::Now());
582 } 585 }
583 586
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 return s.Succeeded(); 997 return s.Succeeded();
995 } 998 }
996 999
997 bool AutofillTable::GetAutofillServerProfiles( 1000 bool AutofillTable::GetAutofillServerProfiles(
998 std::vector<AutofillProfile*>* profiles) { 1001 std::vector<AutofillProfile*>* profiles) {
999 profiles->clear(); 1002 profiles->clear();
1000 1003
1001 sql::Statement s(db_->GetUniqueStatement( 1004 sql::Statement s(db_->GetUniqueStatement(
1002 "SELECT " 1005 "SELECT "
1003 "id," 1006 "id,"
1007 "recipient_name,"
1004 "company_name," 1008 "company_name,"
1005 "street_address," 1009 "street_address,"
1006 "address_1," // ADDRESS_HOME_STATE 1010 "address_1," // ADDRESS_HOME_STATE
1007 "address_2," // ADDRESS_HOME_CITY 1011 "address_2," // ADDRESS_HOME_CITY
1008 "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY 1012 "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY
1009 "address_4," // Not supported in AutofillProfile yet. 1013 "address_4," // Not supported in AutofillProfile yet.
1010 "postal_code," // ADDRESS_HOME_ZIP 1014 "postal_code," // ADDRESS_HOME_ZIP
1011 "sorting_code," // ADDRESS_HOME_SORTING_CODE 1015 "sorting_code," // ADDRESS_HOME_SORTING_CODE
1012 "country_code," // ADDRESS_HOME_COUNTRY 1016 "country_code," // ADDRESS_HOME_COUNTRY
1013 "language_code " 1017 "language_code "
1014 "FROM server_addresses")); 1018 "FROM server_addresses"));
1015 1019
1016 while (s.Step()) { 1020 while (s.Step()) {
1017 int index = 0; 1021 int index = 0;
1018 scoped_ptr<AutofillProfile> profile(new AutofillProfile( 1022 scoped_ptr<AutofillProfile> profile(new AutofillProfile(
1019 AutofillProfile::SERVER_PROFILE, s.ColumnString(index++))); 1023 AutofillProfile::SERVER_PROFILE, s.ColumnString(index++)));
1020 1024
1025 profile->SetRawInfo(NAME_FULL, s.ColumnString16(index++));
1021 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(index++)); 1026 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(index++));
1022 profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, s.ColumnString16(index++)); 1027 profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, s.ColumnString16(index++));
1023 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(index++)); 1028 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(index++));
1024 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(index++)); 1029 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(index++));
1025 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, 1030 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY,
1026 s.ColumnString16(index++)); 1031 s.ColumnString16(index++));
1027 index++; // Skip address_4 which we haven't added to AutofillProfile yet. 1032 index++; // Skip address_4 which we haven't added to AutofillProfile yet.
1028 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++)); 1033 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++));
1029 profile->SetRawInfo(ADDRESS_HOME_SORTING_CODE, s.ColumnString16(index++)); 1034 profile->SetRawInfo(ADDRESS_HOME_SORTING_CODE, s.ColumnString16(index++));
1030 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++)); 1035 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++));
1031 profile->set_language_code(s.ColumnString(index++)); 1036 profile->set_language_code(s.ColumnString(index++));
1032 1037
1033 profiles->push_back(profile.release()); 1038 profiles->push_back(profile.release());
1034 } 1039 }
1035 1040
1036 return s.Succeeded(); 1041 return s.Succeeded();
1037 } 1042 }
1038 1043
1039 void AutofillTable::SetAutofillServerProfiles( 1044 void AutofillTable::SetAutofillServerProfiles(
1040 const std::vector<AutofillProfile>& profiles) { 1045 const std::vector<AutofillProfile>& profiles) {
1041 // Delete all old ones first. 1046 // Delete all old ones first.
1042 sql::Statement delete_old(db_->GetUniqueStatement( 1047 sql::Statement delete_old(db_->GetUniqueStatement(
1043 "DELETE FROM server_addresses")); 1048 "DELETE FROM server_addresses"));
1044 delete_old.Run(); 1049 delete_old.Run();
1045 1050
1046 sql::Statement insert(db_->GetUniqueStatement( 1051 sql::Statement insert(db_->GetUniqueStatement(
1047 "INSERT INTO server_addresses(" 1052 "INSERT INTO server_addresses("
1048 "id," 1053 "id,"
1054 "recipient_name,"
1049 "company_name," 1055 "company_name,"
1050 "street_address," 1056 "street_address,"
1051 "address_1," // ADDRESS_HOME_STATE 1057 "address_1," // ADDRESS_HOME_STATE
1052 "address_2," // ADDRESS_HOME_CITY 1058 "address_2," // ADDRESS_HOME_CITY
1053 "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY 1059 "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY
1054 "address_4," // Not supported in AutofillProfile yet. 1060 "address_4," // Not supported in AutofillProfile yet.
1055 "postal_code," // ADDRESS_HOME_ZIP 1061 "postal_code," // ADDRESS_HOME_ZIP
1056 "sorting_code," // ADDRESS_HOME_SORTING_CODE 1062 "sorting_code," // ADDRESS_HOME_SORTING_CODE
1057 "country_code," // ADDRESS_HOME_COUNTRY 1063 "country_code," // ADDRESS_HOME_COUNTRY
1058 "language_code) " 1064 "language_code) "
1059 "VALUES (?,?,?,?,?,?,?,?,?,?,?)")); 1065 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"));
1060 for (const auto& profile : profiles) { 1066 for (const auto& profile : profiles) {
1061 DCHECK(profile.record_type() == AutofillProfile::SERVER_PROFILE); 1067 DCHECK(profile.record_type() == AutofillProfile::SERVER_PROFILE);
1062 1068
1063 int index = 0; 1069 int index = 0;
1064 insert.BindString(index++, profile.server_id()); 1070 insert.BindString(index++, profile.server_id());
1071 insert.BindString16(index++, profile.GetRawInfo(NAME_FULL));
1065 insert.BindString16(index++, profile.GetRawInfo(COMPANY_NAME)); 1072 insert.BindString16(index++, profile.GetRawInfo(COMPANY_NAME));
1066 insert.BindString16(index++, 1073 insert.BindString16(index++,
1067 profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)); 1074 profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS));
1068 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_STATE)); 1075 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_STATE));
1069 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_CITY)); 1076 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_CITY));
1070 insert.BindString16(index++, 1077 insert.BindString16(index++,
1071 profile.GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY)); 1078 profile.GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY));
1072 index++; // SKip address_4 which we haven't added to AutofillProfile yet. 1079 index++; // SKip address_4 which we haven't added to AutofillProfile yet.
1073 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_ZIP)); 1080 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_ZIP));
1074 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)); 1081 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE));
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
1736 "card_number_encrypted VARCHAR)")) { 1743 "card_number_encrypted VARCHAR)")) {
1737 NOTREACHED(); 1744 NOTREACHED();
1738 return false; 1745 return false;
1739 } 1746 }
1740 } 1747 }
1741 return true; 1748 return true;
1742 } 1749 }
1743 1750
1744 bool AutofillTable::InitServerAddressesTable() { 1751 bool AutofillTable::InitServerAddressesTable() {
1745 if (!db_->DoesTableExist("server_addresses")) { 1752 if (!db_->DoesTableExist("server_addresses")) {
1753 // The space after language_code is necessary to make the schemas match
Evan Stade 2015/02/25 23:02:00 I don't think this comment is super necessary. Oth
brettw 2015/02/26 18:54:28 I kept it but pared it down a lot. When I was work
Evan Stade 2015/02/26 19:23:27 right, but it seems unlikely people will see this
1754 // when creating a new table (where sqlite just saves our literal string
1755 // provided here), and when we do the alter table to append the column
1756 // in version 62 (where sqlite appends it to the string itself and adds
1757 // the space). This makes the upgrade tests pass which just does a dumb
1758 // string compare on the schemas.
1746 if (!db_->Execute("CREATE TABLE server_addresses (" 1759 if (!db_->Execute("CREATE TABLE server_addresses ("
1747 "id VARCHAR," 1760 "id VARCHAR,"
1748 "company_name VARCHAR," 1761 "company_name VARCHAR,"
1749 "street_address VARCHAR," 1762 "street_address VARCHAR,"
1750 "address_1 VARCHAR," 1763 "address_1 VARCHAR,"
1751 "address_2 VARCHAR," 1764 "address_2 VARCHAR,"
1752 "address_3 VARCHAR," 1765 "address_3 VARCHAR,"
1753 "address_4 VARCHAR," 1766 "address_4 VARCHAR,"
1754 "postal_code VARCHAR," 1767 "postal_code VARCHAR,"
1755 "sorting_code VARCHAR," 1768 "sorting_code VARCHAR,"
1756 "country_code VARCHAR," 1769 "country_code VARCHAR,"
1757 "language_code VARCHAR)")) { 1770 "language_code VARCHAR, " // See comment above.
1771 "recipient_name VARCHAR)")) {
1758 NOTREACHED(); 1772 NOTREACHED();
1759 return false; 1773 return false;
1760 } 1774 }
1761 } 1775 }
1762 return true; 1776 return true;
1763 } 1777 }
1764 1778
1765 bool AutofillTable::MigrateToVersion22ClearAutofillEmptyValueElements() { 1779 bool AutofillTable::MigrateToVersion22ClearAutofillEmptyValueElements() {
1766 if (!db_->DoesTableExist("autofill") && 1780 if (!db_->DoesTableExist("autofill") &&
1767 (!db_->Execute("CREATE TABLE autofill (" 1781 (!db_->Execute("CREATE TABLE autofill ("
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after
2744 // Add use_date to credit_cards. 2758 // Add use_date to credit_cards.
2745 if (!db_->DoesColumnExist("credit_cards", "use_date") && 2759 if (!db_->DoesColumnExist("credit_cards", "use_date") &&
2746 !db_->Execute("ALTER TABLE credit_cards ADD COLUMN " 2760 !db_->Execute("ALTER TABLE credit_cards ADD COLUMN "
2747 "use_date INTEGER NOT NULL DEFAULT 0")) { 2761 "use_date INTEGER NOT NULL DEFAULT 0")) {
2748 return false; 2762 return false;
2749 } 2763 }
2750 2764
2751 return transaction.Commit(); 2765 return transaction.Commit();
2752 } 2766 }
2753 2767
2768 bool AutofillTable::MigrateToVersion62AddServerRecipientName() {
2769 if (!db_->DoesColumnExist("server_addresses", "recipient_name") &&
2770 !db_->Execute("ALTER TABLE server_addresses ADD COLUMN "
2771 "recipient_name VARCHAR")) {
2772 return false;
2773 }
2774 return true;
2775 }
2776
2754 } // namespace autofill 2777 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698