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

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, 9 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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 return MigrateToVersion57AddFullNameField(); 462 return MigrateToVersion57AddFullNameField();
463 case 60: 463 case 60:
464 *update_compatible_version = false; 464 *update_compatible_version = false;
465 return MigrateToVersion60AddServerCards(); 465 return MigrateToVersion60AddServerCards();
466 case 61: 466 case 61:
467 *update_compatible_version = false; 467 *update_compatible_version = false;
468 return MigrateToVersion61AddUsageStats(); 468 return MigrateToVersion61AddUsageStats();
469 case 62: 469 case 62:
470 *update_compatible_version = false; 470 *update_compatible_version = false;
471 return MigrateToVersion62AddUsageStatsForUnmaskedCards(); 471 return MigrateToVersion62AddUsageStatsForUnmaskedCards();
472 case 63:
473 *update_compatible_version = false;
474 return MigrateToVersion63AddServerRecipientName();
472 } 475 }
473 return true; 476 return true;
474 } 477 }
475 478
476 bool AutofillTable::AddFormFieldValues( 479 bool AutofillTable::AddFormFieldValues(
477 const std::vector<FormFieldData>& elements, 480 const std::vector<FormFieldData>& elements,
478 std::vector<AutofillChange>* changes) { 481 std::vector<AutofillChange>* changes) {
479 return AddFormFieldValuesTime(elements, changes, Time::Now()); 482 return AddFormFieldValuesTime(elements, changes, Time::Now());
480 } 483 }
481 484
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 return s.Succeeded(); 895 return s.Succeeded();
893 } 896 }
894 897
895 bool AutofillTable::GetAutofillServerProfiles( 898 bool AutofillTable::GetAutofillServerProfiles(
896 std::vector<AutofillProfile*>* profiles) { 899 std::vector<AutofillProfile*>* profiles) {
897 profiles->clear(); 900 profiles->clear();
898 901
899 sql::Statement s(db_->GetUniqueStatement( 902 sql::Statement s(db_->GetUniqueStatement(
900 "SELECT " 903 "SELECT "
901 "id," 904 "id,"
905 "recipient_name,"
902 "company_name," 906 "company_name,"
903 "street_address," 907 "street_address,"
904 "address_1," // ADDRESS_HOME_STATE 908 "address_1," // ADDRESS_HOME_STATE
905 "address_2," // ADDRESS_HOME_CITY 909 "address_2," // ADDRESS_HOME_CITY
906 "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY 910 "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY
907 "address_4," // Not supported in AutofillProfile yet. 911 "address_4," // Not supported in AutofillProfile yet.
908 "postal_code," // ADDRESS_HOME_ZIP 912 "postal_code," // ADDRESS_HOME_ZIP
909 "sorting_code," // ADDRESS_HOME_SORTING_CODE 913 "sorting_code," // ADDRESS_HOME_SORTING_CODE
910 "country_code," // ADDRESS_HOME_COUNTRY 914 "country_code," // ADDRESS_HOME_COUNTRY
911 "language_code " 915 "language_code "
912 "FROM server_addresses")); 916 "FROM server_addresses"));
913 917
914 while (s.Step()) { 918 while (s.Step()) {
915 int index = 0; 919 int index = 0;
916 scoped_ptr<AutofillProfile> profile(new AutofillProfile( 920 scoped_ptr<AutofillProfile> profile(new AutofillProfile(
917 AutofillProfile::SERVER_PROFILE, s.ColumnString(index++))); 921 AutofillProfile::SERVER_PROFILE, s.ColumnString(index++)));
918 922
923 profile->SetRawInfo(NAME_FULL, s.ColumnString16(index++));
919 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(index++)); 924 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(index++));
920 profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, s.ColumnString16(index++)); 925 profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, s.ColumnString16(index++));
921 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(index++)); 926 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(index++));
922 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(index++)); 927 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(index++));
923 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, 928 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY,
924 s.ColumnString16(index++)); 929 s.ColumnString16(index++));
925 index++; // Skip address_4 which we haven't added to AutofillProfile yet. 930 index++; // Skip address_4 which we haven't added to AutofillProfile yet.
926 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++)); 931 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++));
927 profile->SetRawInfo(ADDRESS_HOME_SORTING_CODE, s.ColumnString16(index++)); 932 profile->SetRawInfo(ADDRESS_HOME_SORTING_CODE, s.ColumnString16(index++));
928 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++)); 933 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++));
929 profile->set_language_code(s.ColumnString(index++)); 934 profile->set_language_code(s.ColumnString(index++));
930 935
931 profiles->push_back(profile.release()); 936 profiles->push_back(profile.release());
932 } 937 }
933 938
934 return s.Succeeded(); 939 return s.Succeeded();
935 } 940 }
936 941
937 void AutofillTable::SetAutofillServerProfiles( 942 void AutofillTable::SetAutofillServerProfiles(
938 const std::vector<AutofillProfile>& profiles) { 943 const std::vector<AutofillProfile>& profiles) {
939 // Delete all old ones first. 944 // Delete all old ones first.
940 sql::Statement delete_old(db_->GetUniqueStatement( 945 sql::Statement delete_old(db_->GetUniqueStatement(
941 "DELETE FROM server_addresses")); 946 "DELETE FROM server_addresses"));
942 delete_old.Run(); 947 delete_old.Run();
943 948
944 sql::Statement insert(db_->GetUniqueStatement( 949 sql::Statement insert(db_->GetUniqueStatement(
945 "INSERT INTO server_addresses(" 950 "INSERT INTO server_addresses("
946 "id," 951 "id,"
952 "recipient_name,"
947 "company_name," 953 "company_name,"
948 "street_address," 954 "street_address,"
949 "address_1," // ADDRESS_HOME_STATE 955 "address_1," // ADDRESS_HOME_STATE
950 "address_2," // ADDRESS_HOME_CITY 956 "address_2," // ADDRESS_HOME_CITY
951 "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY 957 "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY
952 "address_4," // Not supported in AutofillProfile yet. 958 "address_4," // Not supported in AutofillProfile yet.
953 "postal_code," // ADDRESS_HOME_ZIP 959 "postal_code," // ADDRESS_HOME_ZIP
954 "sorting_code," // ADDRESS_HOME_SORTING_CODE 960 "sorting_code," // ADDRESS_HOME_SORTING_CODE
955 "country_code," // ADDRESS_HOME_COUNTRY 961 "country_code," // ADDRESS_HOME_COUNTRY
956 "language_code) " 962 "language_code) "
957 "VALUES (?,?,?,?,?,?,?,?,?,?,?)")); 963 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"));
958 for (const auto& profile : profiles) { 964 for (const auto& profile : profiles) {
959 DCHECK(profile.record_type() == AutofillProfile::SERVER_PROFILE); 965 DCHECK(profile.record_type() == AutofillProfile::SERVER_PROFILE);
960 966
961 int index = 0; 967 int index = 0;
962 insert.BindString(index++, profile.server_id()); 968 insert.BindString(index++, profile.server_id());
969 insert.BindString16(index++, profile.GetRawInfo(NAME_FULL));
963 insert.BindString16(index++, profile.GetRawInfo(COMPANY_NAME)); 970 insert.BindString16(index++, profile.GetRawInfo(COMPANY_NAME));
964 insert.BindString16(index++, 971 insert.BindString16(index++,
965 profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)); 972 profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS));
966 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_STATE)); 973 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_STATE));
967 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_CITY)); 974 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_CITY));
968 insert.BindString16(index++, 975 insert.BindString16(index++,
969 profile.GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY)); 976 profile.GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY));
970 index++; // SKip address_4 which we haven't added to AutofillProfile yet. 977 index++; // SKip address_4 which we haven't added to AutofillProfile yet.
971 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_ZIP)); 978 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_ZIP));
972 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)); 979 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE));
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 "use_date INTEGER NOT NULL DEFAULT 0)")) { 1671 "use_date INTEGER NOT NULL DEFAULT 0)")) {
1665 NOTREACHED(); 1672 NOTREACHED();
1666 return false; 1673 return false;
1667 } 1674 }
1668 } 1675 }
1669 return true; 1676 return true;
1670 } 1677 }
1671 1678
1672 bool AutofillTable::InitServerAddressesTable() { 1679 bool AutofillTable::InitServerAddressesTable() {
1673 if (!db_->DoesTableExist("server_addresses")) { 1680 if (!db_->DoesTableExist("server_addresses")) {
1681 // The space after language_code is necessary to match what sqlite does
1682 // when it appends the column in migration.
1674 if (!db_->Execute("CREATE TABLE server_addresses (" 1683 if (!db_->Execute("CREATE TABLE server_addresses ("
1675 "id VARCHAR," 1684 "id VARCHAR,"
1676 "company_name VARCHAR," 1685 "company_name VARCHAR,"
1677 "street_address VARCHAR," 1686 "street_address VARCHAR,"
1678 "address_1 VARCHAR," 1687 "address_1 VARCHAR,"
1679 "address_2 VARCHAR," 1688 "address_2 VARCHAR,"
1680 "address_3 VARCHAR," 1689 "address_3 VARCHAR,"
1681 "address_4 VARCHAR," 1690 "address_4 VARCHAR,"
1682 "postal_code VARCHAR," 1691 "postal_code VARCHAR,"
1683 "sorting_code VARCHAR," 1692 "sorting_code VARCHAR,"
1684 "country_code VARCHAR," 1693 "country_code VARCHAR,"
1685 "language_code VARCHAR)")) { 1694 "language_code VARCHAR, " // Space required.
1695 "recipient_name VARCHAR)")) {
1686 NOTREACHED(); 1696 NOTREACHED();
1687 return false; 1697 return false;
1688 } 1698 }
1689 } 1699 }
1690 return true; 1700 return true;
1691 } 1701 }
1692 1702
1693 bool AutofillTable::MigrateToVersion54AddI18nFieldsAndRemoveDeprecatedFields() { 1703 bool AutofillTable::MigrateToVersion54AddI18nFieldsAndRemoveDeprecatedFields() {
1694 sql::Transaction transaction(db_); 1704 sql::Transaction transaction(db_);
1695 if (!transaction.Begin()) 1705 if (!transaction.Begin())
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1959 // Add use_date to unmasked_credit_cards. 1969 // Add use_date to unmasked_credit_cards.
1960 if (!db_->DoesColumnExist("unmasked_credit_cards", "use_date") && 1970 if (!db_->DoesColumnExist("unmasked_credit_cards", "use_date") &&
1961 !db_->Execute("ALTER TABLE unmasked_credit_cards ADD COLUMN " 1971 !db_->Execute("ALTER TABLE unmasked_credit_cards ADD COLUMN "
1962 "use_date INTEGER NOT NULL DEFAULT 0")) { 1972 "use_date INTEGER NOT NULL DEFAULT 0")) {
1963 return false; 1973 return false;
1964 } 1974 }
1965 1975
1966 return transaction.Commit(); 1976 return transaction.Commit();
1967 } 1977 }
1968 1978
1979 bool AutofillTable::MigrateToVersion63AddServerRecipientName() {
1980 if (!db_->DoesColumnExist("server_addresses", "recipient_name") &&
1981 !db_->Execute("ALTER TABLE server_addresses ADD COLUMN "
1982 "recipient_name VARCHAR")) {
1983 return false;
1984 }
1985 return true;
1986 }
1987
1969 } // namespace autofill 1988 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698