| OLD | NEW |
| 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 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 std::string guid = s.ColumnString(0); | 888 std::string guid = s.ColumnString(0); |
| 889 AutofillProfile* profile = NULL; | 889 AutofillProfile* profile = NULL; |
| 890 if (!GetAutofillProfile(guid, &profile)) | 890 if (!GetAutofillProfile(guid, &profile)) |
| 891 return false; | 891 return false; |
| 892 profiles->push_back(profile); | 892 profiles->push_back(profile); |
| 893 } | 893 } |
| 894 | 894 |
| 895 return s.Succeeded(); | 895 return s.Succeeded(); |
| 896 } | 896 } |
| 897 | 897 |
| 898 bool AutofillTable::GetAutofillServerProfiles( | 898 bool AutofillTable::GetServerProfiles(std::vector<AutofillProfile*>* profiles) { |
| 899 std::vector<AutofillProfile*>* profiles) { | |
| 900 profiles->clear(); | 899 profiles->clear(); |
| 901 | 900 |
| 902 sql::Statement s(db_->GetUniqueStatement( | 901 sql::Statement s(db_->GetUniqueStatement( |
| 903 "SELECT " | 902 "SELECT " |
| 904 "id," | 903 "id," |
| 905 "recipient_name," | 904 "recipient_name," |
| 906 "company_name," | 905 "company_name," |
| 907 "street_address," | 906 "street_address," |
| 908 "address_1," // ADDRESS_HOME_STATE | 907 "address_1," // ADDRESS_HOME_STATE |
| 909 "address_2," // ADDRESS_HOME_CITY | 908 "address_2," // ADDRESS_HOME_CITY |
| 910 "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY | 909 "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY |
| 911 "address_4," // Not supported in AutofillProfile yet. | 910 "address_4," // Not supported in AutofillProfile yet. |
| 912 "postal_code," // ADDRESS_HOME_ZIP | 911 "postal_code," // ADDRESS_HOME_ZIP |
| 913 "sorting_code," // ADDRESS_HOME_SORTING_CODE | 912 "sorting_code," // ADDRESS_HOME_SORTING_CODE |
| 914 "country_code," // ADDRESS_HOME_COUNTRY | 913 "country_code," // ADDRESS_HOME_COUNTRY |
| 915 "language_code " | 914 "language_code " |
| 916 "FROM server_addresses")); | 915 "FROM server_addresses")); |
| 917 | 916 |
| 918 while (s.Step()) { | 917 while (s.Step()) { |
| 919 int index = 0; | 918 int index = 0; |
| 920 scoped_ptr<AutofillProfile> profile(new AutofillProfile( | 919 scoped_ptr<AutofillProfile> profile(new AutofillProfile( |
| 921 AutofillProfile::SERVER_PROFILE, s.ColumnString(index++))); | 920 AutofillProfile::SERVER_PROFILE, s.ColumnString(index++))); |
| 922 | 921 |
| 923 profile->SetRawInfo(NAME_FULL, s.ColumnString16(index++)); | 922 base::string16 recipient_name = s.ColumnString16(index++); |
| 924 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(index++)); | 923 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(index++)); |
| 925 profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, s.ColumnString16(index++)); | 924 profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, s.ColumnString16(index++)); |
| 926 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(index++)); | 925 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(index++)); |
| 927 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(index++)); | 926 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(index++)); |
| 928 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, | 927 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, |
| 929 s.ColumnString16(index++)); | 928 s.ColumnString16(index++)); |
| 930 index++; // Skip address_4 which we haven't added to AutofillProfile yet. | 929 index++; // Skip address_4 which we haven't added to AutofillProfile yet. |
| 931 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++)); | 930 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++)); |
| 932 profile->SetRawInfo(ADDRESS_HOME_SORTING_CODE, s.ColumnString16(index++)); | 931 profile->SetRawInfo(ADDRESS_HOME_SORTING_CODE, s.ColumnString16(index++)); |
| 933 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++)); | 932 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++)); |
| 934 profile->set_language_code(s.ColumnString(index++)); | 933 profile->set_language_code(s.ColumnString(index++)); |
| 935 | 934 |
| 935 // SetInfo instead of SetRawInfo on the name so the constituent pieces will |
| 936 // be parsed. |
| 937 profile->SetInfo(AutofillType(NAME_FULL), recipient_name, |
| 938 profile->language_code()); |
| 939 |
| 936 profiles->push_back(profile.release()); | 940 profiles->push_back(profile.release()); |
| 937 } | 941 } |
| 938 | 942 |
| 939 return s.Succeeded(); | 943 return s.Succeeded(); |
| 940 } | 944 } |
| 941 | 945 |
| 942 void AutofillTable::SetAutofillServerProfiles( | 946 void AutofillTable::SetServerProfiles( |
| 943 const std::vector<AutofillProfile>& profiles) { | 947 const std::vector<AutofillProfile>& profiles) { |
| 944 // Delete all old ones first. | 948 // Delete all old ones first. |
| 945 sql::Statement delete_old(db_->GetUniqueStatement( | 949 sql::Statement delete_old(db_->GetUniqueStatement( |
| 946 "DELETE FROM server_addresses")); | 950 "DELETE FROM server_addresses")); |
| 947 delete_old.Run(); | 951 delete_old.Run(); |
| 948 | 952 |
| 949 sql::Statement insert(db_->GetUniqueStatement( | 953 sql::Statement insert(db_->GetUniqueStatement( |
| 950 "INSERT INTO server_addresses(" | 954 "INSERT INTO server_addresses(" |
| 951 "id," | 955 "id," |
| 952 "recipient_name," | 956 "recipient_name," |
| (...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1979 bool AutofillTable::MigrateToVersion63AddServerRecipientName() { | 1983 bool AutofillTable::MigrateToVersion63AddServerRecipientName() { |
| 1980 if (!db_->DoesColumnExist("server_addresses", "recipient_name") && | 1984 if (!db_->DoesColumnExist("server_addresses", "recipient_name") && |
| 1981 !db_->Execute("ALTER TABLE server_addresses ADD COLUMN " | 1985 !db_->Execute("ALTER TABLE server_addresses ADD COLUMN " |
| 1982 "recipient_name VARCHAR")) { | 1986 "recipient_name VARCHAR")) { |
| 1983 return false; | 1987 return false; |
| 1984 } | 1988 } |
| 1985 return true; | 1989 return true; |
| 1986 } | 1990 } |
| 1987 | 1991 |
| 1988 } // namespace autofill | 1992 } // namespace autofill |
| OLD | NEW |