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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 s->BindString16(index++, GetInfo(profile, ADDRESS_HOME_ZIP)); | 92 s->BindString16(index++, GetInfo(profile, ADDRESS_HOME_ZIP)); |
93 s->BindString16(index++, GetInfo(profile, ADDRESS_HOME_SORTING_CODE)); | 93 s->BindString16(index++, GetInfo(profile, ADDRESS_HOME_SORTING_CODE)); |
94 s->BindString16(index++, GetInfo(profile, ADDRESS_HOME_COUNTRY)); | 94 s->BindString16(index++, GetInfo(profile, ADDRESS_HOME_COUNTRY)); |
95 s->BindInt64(index++, profile.use_count()); | 95 s->BindInt64(index++, profile.use_count()); |
96 s->BindInt64(index++, profile.use_date().ToTimeT()); | 96 s->BindInt64(index++, profile.use_date().ToTimeT()); |
97 s->BindInt64(index++, modification_date.ToTimeT()); | 97 s->BindInt64(index++, modification_date.ToTimeT()); |
98 s->BindString(index++, profile.origin()); | 98 s->BindString(index++, profile.origin()); |
99 s->BindString(index++, profile.language_code()); | 99 s->BindString(index++, profile.language_code()); |
100 } | 100 } |
101 | 101 |
102 scoped_ptr<AutofillProfile> AutofillProfileFromStatement( | 102 std::unique_ptr<AutofillProfile> AutofillProfileFromStatement( |
103 const sql::Statement& s) { | 103 const sql::Statement& s) { |
104 scoped_ptr<AutofillProfile> profile(new AutofillProfile); | 104 std::unique_ptr<AutofillProfile> profile(new AutofillProfile); |
105 int index = 0; | 105 int index = 0; |
106 profile->set_guid(s.ColumnString(index++)); | 106 profile->set_guid(s.ColumnString(index++)); |
107 DCHECK(base::IsValidGUID(profile->guid())); | 107 DCHECK(base::IsValidGUID(profile->guid())); |
108 | 108 |
109 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(index++)); | 109 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(index++)); |
110 profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, s.ColumnString16(index++)); | 110 profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, s.ColumnString16(index++)); |
111 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, | 111 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, |
112 s.ColumnString16(index++)); | 112 s.ColumnString16(index++)); |
113 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(index++)); | 113 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(index++)); |
114 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(index++)); | 114 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(index++)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 if (encrypted_number_len) { | 159 if (encrypted_number_len) { |
160 std::string encrypted_number; | 160 std::string encrypted_number; |
161 encrypted_number.resize(encrypted_number_len); | 161 encrypted_number.resize(encrypted_number_len); |
162 memcpy(&encrypted_number[0], s.ColumnBlob(column_index), | 162 memcpy(&encrypted_number[0], s.ColumnBlob(column_index), |
163 encrypted_number_len); | 163 encrypted_number_len); |
164 OSCrypt::DecryptString16(encrypted_number, &credit_card_number); | 164 OSCrypt::DecryptString16(encrypted_number, &credit_card_number); |
165 } | 165 } |
166 return credit_card_number; | 166 return credit_card_number; |
167 } | 167 } |
168 | 168 |
169 scoped_ptr<CreditCard> CreditCardFromStatement(const sql::Statement& s) { | 169 std::unique_ptr<CreditCard> CreditCardFromStatement(const sql::Statement& s) { |
170 scoped_ptr<CreditCard> credit_card(new CreditCard); | 170 std::unique_ptr<CreditCard> credit_card(new CreditCard); |
171 | 171 |
172 int index = 0; | 172 int index = 0; |
173 credit_card->set_guid(s.ColumnString(index++)); | 173 credit_card->set_guid(s.ColumnString(index++)); |
174 DCHECK(base::IsValidGUID(credit_card->guid())); | 174 DCHECK(base::IsValidGUID(credit_card->guid())); |
175 | 175 |
176 credit_card->SetRawInfo(CREDIT_CARD_NAME_FULL, s.ColumnString16(index++)); | 176 credit_card->SetRawInfo(CREDIT_CARD_NAME_FULL, s.ColumnString16(index++)); |
177 credit_card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(index++)); | 177 credit_card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(index++)); |
178 credit_card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, | 178 credit_card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
179 s.ColumnString16(index++)); | 179 s.ColumnString16(index++)); |
180 credit_card->SetRawInfo(CREDIT_CARD_NUMBER, | 180 credit_card->SetRawInfo(CREDIT_CARD_NUMBER, |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 " date_modified, origin, language_code)" | 867 " date_modified, origin, language_code)" |
868 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); | 868 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); |
869 BindAutofillProfileToStatement(profile, Time::Now(), &s); | 869 BindAutofillProfileToStatement(profile, Time::Now(), &s); |
870 | 870 |
871 if (!s.Run()) | 871 if (!s.Run()) |
872 return false; | 872 return false; |
873 | 873 |
874 return AddAutofillProfilePieces(profile, db_); | 874 return AddAutofillProfilePieces(profile, db_); |
875 } | 875 } |
876 | 876 |
877 scoped_ptr<AutofillProfile> AutofillTable::GetAutofillProfile( | 877 std::unique_ptr<AutofillProfile> AutofillTable::GetAutofillProfile( |
878 const std::string& guid) { | 878 const std::string& guid) { |
879 DCHECK(base::IsValidGUID(guid)); | 879 DCHECK(base::IsValidGUID(guid)); |
880 sql::Statement s(db_->GetUniqueStatement( | 880 sql::Statement s(db_->GetUniqueStatement( |
881 "SELECT guid, company_name, street_address, dependent_locality, city," | 881 "SELECT guid, company_name, street_address, dependent_locality, city," |
882 " state, zipcode, sorting_code, country_code, use_count, use_date," | 882 " state, zipcode, sorting_code, country_code, use_count, use_date," |
883 " date_modified, origin, language_code " | 883 " date_modified, origin, language_code " |
884 "FROM autofill_profiles " | 884 "FROM autofill_profiles " |
885 "WHERE guid=?")); | 885 "WHERE guid=?")); |
886 s.BindString(0, guid); | 886 s.BindString(0, guid); |
887 | 887 |
888 scoped_ptr<AutofillProfile> p; | 888 std::unique_ptr<AutofillProfile> p; |
889 if (!s.Step()) | 889 if (!s.Step()) |
890 return p; | 890 return p; |
891 | 891 |
892 p = AutofillProfileFromStatement(s); | 892 p = AutofillProfileFromStatement(s); |
893 | 893 |
894 // Get associated name info. | 894 // Get associated name info. |
895 AddAutofillProfileNamesToProfile(db_, p.get()); | 895 AddAutofillProfileNamesToProfile(db_, p.get()); |
896 | 896 |
897 // Get associated email info. | 897 // Get associated email info. |
898 AddAutofillProfileEmailsToProfile(db_, p.get()); | 898 AddAutofillProfileEmailsToProfile(db_, p.get()); |
899 | 899 |
900 // Get associated phone info. | 900 // Get associated phone info. |
901 AddAutofillProfilePhonesToProfile(db_, p.get()); | 901 AddAutofillProfilePhonesToProfile(db_, p.get()); |
902 | 902 |
903 return p; | 903 return p; |
904 } | 904 } |
905 | 905 |
906 bool AutofillTable::GetAutofillProfiles( | 906 bool AutofillTable::GetAutofillProfiles( |
907 std::vector<AutofillProfile*>* profiles) { | 907 std::vector<AutofillProfile*>* profiles) { |
908 DCHECK(profiles); | 908 DCHECK(profiles); |
909 profiles->clear(); | 909 profiles->clear(); |
910 | 910 |
911 sql::Statement s(db_->GetUniqueStatement( | 911 sql::Statement s(db_->GetUniqueStatement( |
912 "SELECT guid " | 912 "SELECT guid " |
913 "FROM autofill_profiles " | 913 "FROM autofill_profiles " |
914 "ORDER BY date_modified DESC, guid")); | 914 "ORDER BY date_modified DESC, guid")); |
915 | 915 |
916 while (s.Step()) { | 916 while (s.Step()) { |
917 std::string guid = s.ColumnString(0); | 917 std::string guid = s.ColumnString(0); |
918 scoped_ptr<AutofillProfile> profile = GetAutofillProfile(guid); | 918 std::unique_ptr<AutofillProfile> profile = GetAutofillProfile(guid); |
919 if (!profile) | 919 if (!profile) |
920 return false; | 920 return false; |
921 profiles->push_back(profile.release()); | 921 profiles->push_back(profile.release()); |
922 } | 922 } |
923 | 923 |
924 return s.Succeeded(); | 924 return s.Succeeded(); |
925 } | 925 } |
926 | 926 |
927 bool AutofillTable::GetServerProfiles(std::vector<AutofillProfile*>* profiles) { | 927 bool AutofillTable::GetServerProfiles(std::vector<AutofillProfile*>* profiles) { |
928 profiles->clear(); | 928 profiles->clear(); |
(...skipping 13 matching lines...) Expand all Loading... |
942 "postal_code," // ADDRESS_HOME_ZIP | 942 "postal_code," // ADDRESS_HOME_ZIP |
943 "sorting_code," // ADDRESS_HOME_SORTING_CODE | 943 "sorting_code," // ADDRESS_HOME_SORTING_CODE |
944 "country_code," // ADDRESS_HOME_COUNTRY | 944 "country_code," // ADDRESS_HOME_COUNTRY |
945 "phone_number," // PHONE_HOME_WHOLE_NUMBER | 945 "phone_number," // PHONE_HOME_WHOLE_NUMBER |
946 "language_code " | 946 "language_code " |
947 "FROM server_addresses addresses " | 947 "FROM server_addresses addresses " |
948 "LEFT OUTER JOIN server_address_metadata USING (id)")); | 948 "LEFT OUTER JOIN server_address_metadata USING (id)")); |
949 | 949 |
950 while (s.Step()) { | 950 while (s.Step()) { |
951 int index = 0; | 951 int index = 0; |
952 scoped_ptr<AutofillProfile> profile(new AutofillProfile( | 952 std::unique_ptr<AutofillProfile> profile(new AutofillProfile( |
953 AutofillProfile::SERVER_PROFILE, s.ColumnString(index++))); | 953 AutofillProfile::SERVER_PROFILE, s.ColumnString(index++))); |
954 profile->set_use_count(s.ColumnInt64(index++)); | 954 profile->set_use_count(s.ColumnInt64(index++)); |
955 profile->set_use_date(Time::FromInternalValue(s.ColumnInt64(index++))); | 955 profile->set_use_date(Time::FromInternalValue(s.ColumnInt64(index++))); |
956 | 956 |
957 base::string16 recipient_name = s.ColumnString16(index++); | 957 base::string16 recipient_name = s.ColumnString16(index++); |
958 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(index++)); | 958 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(index++)); |
959 profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, s.ColumnString16(index++)); | 959 profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, s.ColumnString16(index++)); |
960 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(index++)); | 960 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(index++)); |
961 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(index++)); | 961 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(index++)); |
962 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, | 962 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 } | 1042 } |
1043 | 1043 |
1044 bool AutofillTable::UpdateAutofillProfile(const AutofillProfile& profile) { | 1044 bool AutofillTable::UpdateAutofillProfile(const AutofillProfile& profile) { |
1045 DCHECK(base::IsValidGUID(profile.guid())); | 1045 DCHECK(base::IsValidGUID(profile.guid())); |
1046 | 1046 |
1047 // Don't update anything until the trash has been emptied. There may be | 1047 // Don't update anything until the trash has been emptied. There may be |
1048 // pending modifications to process. | 1048 // pending modifications to process. |
1049 if (!IsAutofillProfilesTrashEmpty()) | 1049 if (!IsAutofillProfilesTrashEmpty()) |
1050 return true; | 1050 return true; |
1051 | 1051 |
1052 scoped_ptr<AutofillProfile> old_profile = GetAutofillProfile(profile.guid()); | 1052 std::unique_ptr<AutofillProfile> old_profile = |
| 1053 GetAutofillProfile(profile.guid()); |
1053 if (!old_profile) | 1054 if (!old_profile) |
1054 return false; | 1055 return false; |
1055 | 1056 |
1056 bool update_modification_date = *old_profile != profile; | 1057 bool update_modification_date = *old_profile != profile; |
1057 | 1058 |
1058 sql::Statement s(db_->GetUniqueStatement( | 1059 sql::Statement s(db_->GetUniqueStatement( |
1059 "UPDATE autofill_profiles " | 1060 "UPDATE autofill_profiles " |
1060 "SET guid=?, company_name=?, street_address=?, dependent_locality=?, " | 1061 "SET guid=?, company_name=?, street_address=?, dependent_locality=?, " |
1061 " city=?, state=?, zipcode=?, sorting_code=?, country_code=?, " | 1062 " city=?, state=?, zipcode=?, sorting_code=?, country_code=?, " |
1062 " use_count=?, use_date=?, date_modified=?, origin=?, language_code=? " | 1063 " use_count=?, use_date=?, date_modified=?, origin=?, language_code=? " |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 "VALUES (?,?,?,?,?,?,?,?,?)")); | 1136 "VALUES (?,?,?,?,?,?,?,?,?)")); |
1136 BindCreditCardToStatement(credit_card, Time::Now(), &s); | 1137 BindCreditCardToStatement(credit_card, Time::Now(), &s); |
1137 | 1138 |
1138 if (!s.Run()) | 1139 if (!s.Run()) |
1139 return false; | 1140 return false; |
1140 | 1141 |
1141 DCHECK_GT(db_->GetLastChangeCount(), 0); | 1142 DCHECK_GT(db_->GetLastChangeCount(), 0); |
1142 return true; | 1143 return true; |
1143 } | 1144 } |
1144 | 1145 |
1145 scoped_ptr<CreditCard> AutofillTable::GetCreditCard(const std::string& guid) { | 1146 std::unique_ptr<CreditCard> AutofillTable::GetCreditCard( |
| 1147 const std::string& guid) { |
1146 DCHECK(base::IsValidGUID(guid)); | 1148 DCHECK(base::IsValidGUID(guid)); |
1147 sql::Statement s(db_->GetUniqueStatement( | 1149 sql::Statement s(db_->GetUniqueStatement( |
1148 "SELECT guid, name_on_card, expiration_month, expiration_year, " | 1150 "SELECT guid, name_on_card, expiration_month, expiration_year, " |
1149 "card_number_encrypted, use_count, use_date, date_modified, " | 1151 "card_number_encrypted, use_count, use_date, date_modified, " |
1150 "origin " | 1152 "origin " |
1151 "FROM credit_cards " | 1153 "FROM credit_cards " |
1152 "WHERE guid = ?")); | 1154 "WHERE guid = ?")); |
1153 s.BindString(0, guid); | 1155 s.BindString(0, guid); |
1154 | 1156 |
1155 if (!s.Step()) | 1157 if (!s.Step()) |
1156 return scoped_ptr<CreditCard>(); | 1158 return std::unique_ptr<CreditCard>(); |
1157 | 1159 |
1158 return CreditCardFromStatement(s); | 1160 return CreditCardFromStatement(s); |
1159 } | 1161 } |
1160 | 1162 |
1161 bool AutofillTable::GetCreditCards( | 1163 bool AutofillTable::GetCreditCards( |
1162 std::vector<CreditCard*>* credit_cards) { | 1164 std::vector<CreditCard*>* credit_cards) { |
1163 DCHECK(credit_cards); | 1165 DCHECK(credit_cards); |
1164 credit_cards->clear(); | 1166 credit_cards->clear(); |
1165 | 1167 |
1166 sql::Statement s(db_->GetUniqueStatement( | 1168 sql::Statement s(db_->GetUniqueStatement( |
1167 "SELECT guid " | 1169 "SELECT guid " |
1168 "FROM credit_cards " | 1170 "FROM credit_cards " |
1169 "ORDER BY date_modified DESC, guid")); | 1171 "ORDER BY date_modified DESC, guid")); |
1170 | 1172 |
1171 while (s.Step()) { | 1173 while (s.Step()) { |
1172 std::string guid = s.ColumnString(0); | 1174 std::string guid = s.ColumnString(0); |
1173 scoped_ptr<CreditCard> credit_card = GetCreditCard(guid); | 1175 std::unique_ptr<CreditCard> credit_card = GetCreditCard(guid); |
1174 if (!credit_card) | 1176 if (!credit_card) |
1175 return false; | 1177 return false; |
1176 credit_cards->push_back(credit_card.release()); | 1178 credit_cards->push_back(credit_card.release()); |
1177 } | 1179 } |
1178 | 1180 |
1179 return s.Succeeded(); | 1181 return s.Succeeded(); |
1180 } | 1182 } |
1181 | 1183 |
1182 bool AutofillTable::GetServerCreditCards( | 1184 bool AutofillTable::GetServerCreditCards( |
1183 std::vector<CreditCard*>* credit_cards) { | 1185 std::vector<CreditCard*>* credit_cards) { |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 address_metadata.Run(); | 1412 address_metadata.Run(); |
1411 changed |= db_->GetLastChangeCount() > 0; | 1413 changed |= db_->GetLastChangeCount() > 0; |
1412 | 1414 |
1413 transaction.Commit(); | 1415 transaction.Commit(); |
1414 return changed; | 1416 return changed; |
1415 } | 1417 } |
1416 | 1418 |
1417 bool AutofillTable::UpdateCreditCard(const CreditCard& credit_card) { | 1419 bool AutofillTable::UpdateCreditCard(const CreditCard& credit_card) { |
1418 DCHECK(base::IsValidGUID(credit_card.guid())); | 1420 DCHECK(base::IsValidGUID(credit_card.guid())); |
1419 | 1421 |
1420 scoped_ptr<CreditCard> old_credit_card = GetCreditCard(credit_card.guid()); | 1422 std::unique_ptr<CreditCard> old_credit_card = |
| 1423 GetCreditCard(credit_card.guid()); |
1421 if (!old_credit_card) | 1424 if (!old_credit_card) |
1422 return false; | 1425 return false; |
1423 | 1426 |
1424 bool update_modification_date = *old_credit_card != credit_card; | 1427 bool update_modification_date = *old_credit_card != credit_card; |
1425 | 1428 |
1426 sql::Statement s(db_->GetUniqueStatement( | 1429 sql::Statement s(db_->GetUniqueStatement( |
1427 "UPDATE credit_cards " | 1430 "UPDATE credit_cards " |
1428 "SET guid=?, name_on_card=?, expiration_month=?," | 1431 "SET guid=?, name_on_card=?, expiration_month=?," |
1429 "expiration_year=?, card_number_encrypted=?, use_count=?, use_date=?," | 1432 "expiration_year=?, card_number_encrypted=?, use_count=?, use_date=?," |
1430 "date_modified=?, origin=?" | 1433 "date_modified=?, origin=?" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 return false; | 1548 return false; |
1546 | 1549 |
1547 // Clear out the origins for the found Autofill profiles. | 1550 // Clear out the origins for the found Autofill profiles. |
1548 for (const std::string& guid : profile_guids) { | 1551 for (const std::string& guid : profile_guids) { |
1549 sql::Statement s_profile(db_->GetUniqueStatement( | 1552 sql::Statement s_profile(db_->GetUniqueStatement( |
1550 "UPDATE autofill_profiles SET origin='' WHERE guid=?")); | 1553 "UPDATE autofill_profiles SET origin='' WHERE guid=?")); |
1551 s_profile.BindString(0, guid); | 1554 s_profile.BindString(0, guid); |
1552 if (!s_profile.Run()) | 1555 if (!s_profile.Run()) |
1553 return false; | 1556 return false; |
1554 | 1557 |
1555 scoped_ptr<AutofillProfile> profile = GetAutofillProfile(guid); | 1558 std::unique_ptr<AutofillProfile> profile = GetAutofillProfile(guid); |
1556 if (!profile) | 1559 if (!profile) |
1557 return false; | 1560 return false; |
1558 | 1561 |
1559 profiles->push_back(profile.release()); | 1562 profiles->push_back(profile.release()); |
1560 } | 1563 } |
1561 | 1564 |
1562 // Remember Autofill credit cards with URL origins in the time range. | 1565 // Remember Autofill credit cards with URL origins in the time range. |
1563 sql::Statement s_credit_cards_get(db_->GetUniqueStatement( | 1566 sql::Statement s_credit_cards_get(db_->GetUniqueStatement( |
1564 "SELECT guid, origin FROM credit_cards " | 1567 "SELECT guid, origin FROM credit_cards " |
1565 "WHERE date_modified >= ? AND date_modified < ?")); | 1568 "WHERE date_modified >= ? AND date_modified < ?")); |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2253 insert.BindString16(index++, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); | 2256 insert.BindString16(index++, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); |
2254 insert.BindString(index++, profile.language_code()); | 2257 insert.BindString(index++, profile.language_code()); |
2255 insert.Run(); | 2258 insert.Run(); |
2256 insert.Reset(true); | 2259 insert.Reset(true); |
2257 } | 2260 } |
2258 | 2261 |
2259 return transaction.Commit(); | 2262 return transaction.Commit(); |
2260 } | 2263 } |
2261 | 2264 |
2262 } // namespace autofill | 2265 } // namespace autofill |
OLD | NEW |