| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 s->BindString16(index++, GetInfo(credit_card, CREDIT_CARD_NAME_FULL)); | 143 s->BindString16(index++, GetInfo(credit_card, CREDIT_CARD_NAME_FULL)); |
| 144 s->BindString16(index++, GetInfo(credit_card, CREDIT_CARD_EXP_MONTH)); | 144 s->BindString16(index++, GetInfo(credit_card, CREDIT_CARD_EXP_MONTH)); |
| 145 s->BindString16(index++, GetInfo(credit_card, CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 145 s->BindString16(index++, GetInfo(credit_card, CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
| 146 BindEncryptedCardToColumn(s, index++, | 146 BindEncryptedCardToColumn(s, index++, |
| 147 credit_card.GetRawInfo(CREDIT_CARD_NUMBER)); | 147 credit_card.GetRawInfo(CREDIT_CARD_NUMBER)); |
| 148 | 148 |
| 149 s->BindInt64(index++, credit_card.use_count()); | 149 s->BindInt64(index++, credit_card.use_count()); |
| 150 s->BindInt64(index++, credit_card.use_date().ToTimeT()); | 150 s->BindInt64(index++, credit_card.use_date().ToTimeT()); |
| 151 s->BindInt64(index++, modification_date.ToTimeT()); | 151 s->BindInt64(index++, modification_date.ToTimeT()); |
| 152 s->BindString(index++, credit_card.origin()); | 152 s->BindString(index++, credit_card.origin()); |
| 153 s->BindString(index++, credit_card.billing_address_id()); |
| 153 } | 154 } |
| 154 | 155 |
| 155 base::string16 UnencryptedCardFromColumn(const sql::Statement& s, | 156 base::string16 UnencryptedCardFromColumn(const sql::Statement& s, |
| 156 int column_index) { | 157 int column_index) { |
| 157 base::string16 credit_card_number; | 158 base::string16 credit_card_number; |
| 158 int encrypted_number_len = s.ColumnByteLength(column_index); | 159 int encrypted_number_len = s.ColumnByteLength(column_index); |
| 159 if (encrypted_number_len) { | 160 if (encrypted_number_len) { |
| 160 std::string encrypted_number; | 161 std::string encrypted_number; |
| 161 encrypted_number.resize(encrypted_number_len); | 162 encrypted_number.resize(encrypted_number_len); |
| 162 memcpy(&encrypted_number[0], s.ColumnBlob(column_index), | 163 memcpy(&encrypted_number[0], s.ColumnBlob(column_index), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 176 credit_card->SetRawInfo(CREDIT_CARD_NAME_FULL, s.ColumnString16(index++)); | 177 credit_card->SetRawInfo(CREDIT_CARD_NAME_FULL, s.ColumnString16(index++)); |
| 177 credit_card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(index++)); | 178 credit_card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(index++)); |
| 178 credit_card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, | 179 credit_card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 179 s.ColumnString16(index++)); | 180 s.ColumnString16(index++)); |
| 180 credit_card->SetRawInfo(CREDIT_CARD_NUMBER, | 181 credit_card->SetRawInfo(CREDIT_CARD_NUMBER, |
| 181 UnencryptedCardFromColumn(s, index++)); | 182 UnencryptedCardFromColumn(s, index++)); |
| 182 credit_card->set_use_count(s.ColumnInt64(index++)); | 183 credit_card->set_use_count(s.ColumnInt64(index++)); |
| 183 credit_card->set_use_date(Time::FromTimeT(s.ColumnInt64(index++))); | 184 credit_card->set_use_date(Time::FromTimeT(s.ColumnInt64(index++))); |
| 184 credit_card->set_modification_date(Time::FromTimeT(s.ColumnInt64(index++))); | 185 credit_card->set_modification_date(Time::FromTimeT(s.ColumnInt64(index++))); |
| 185 credit_card->set_origin(s.ColumnString(index++)); | 186 credit_card->set_origin(s.ColumnString(index++)); |
| 187 credit_card->set_billing_address_id(s.ColumnString(index++)); |
| 186 | 188 |
| 187 return credit_card; | 189 return credit_card; |
| 188 } | 190 } |
| 189 | 191 |
| 190 bool AddAutofillProfileNamesToProfile(sql::Connection* db, | 192 bool AddAutofillProfileNamesToProfile(sql::Connection* db, |
| 191 AutofillProfile* profile) { | 193 AutofillProfile* profile) { |
| 192 // TODO(estade): update schema so that multiple names are not associated per | 194 // TODO(estade): update schema so that multiple names are not associated per |
| 193 // unique profile guid. Please refer https://crbug.com/497934. | 195 // unique profile guid. Please refer https://crbug.com/497934. |
| 194 sql::Statement s(db->GetUniqueStatement( | 196 sql::Statement s(db->GetUniqueStatement( |
| 195 "SELECT guid, first_name, middle_name, last_name, full_name " | 197 "SELECT guid, first_name, middle_name, last_name, full_name " |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 return MigrateToVersion62AddUsageStatsForUnmaskedCards(); | 449 return MigrateToVersion62AddUsageStatsForUnmaskedCards(); |
| 448 case 63: | 450 case 63: |
| 449 *update_compatible_version = false; | 451 *update_compatible_version = false; |
| 450 return MigrateToVersion63AddServerRecipientName(); | 452 return MigrateToVersion63AddServerRecipientName(); |
| 451 case 64: | 453 case 64: |
| 452 *update_compatible_version = false; | 454 *update_compatible_version = false; |
| 453 return MigrateToVersion64AddUnmaskDate(); | 455 return MigrateToVersion64AddUnmaskDate(); |
| 454 case 65: | 456 case 65: |
| 455 *update_compatible_version = false; | 457 *update_compatible_version = false; |
| 456 return MigrateToVersion65AddServerMetadataTables(); | 458 return MigrateToVersion65AddServerMetadataTables(); |
| 459 case 66: |
| 460 *update_compatible_version = false; |
| 461 return MigrateToVersion66AddCardBillingAddress(); |
| 457 } | 462 } |
| 458 return true; | 463 return true; |
| 459 } | 464 } |
| 460 | 465 |
| 461 bool AutofillTable::AddFormFieldValues( | 466 bool AutofillTable::AddFormFieldValues( |
| 462 const std::vector<FormFieldData>& elements, | 467 const std::vector<FormFieldData>& elements, |
| 463 std::vector<AutofillChange>* changes) { | 468 std::vector<AutofillChange>* changes) { |
| 464 return AddFormFieldValuesTime(elements, changes, Time::Now()); | 469 return AddFormFieldValuesTime(elements, changes, Time::Now()); |
| 465 } | 470 } |
| 466 | 471 |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 sql::Statement s4(db_->GetUniqueStatement( | 1133 sql::Statement s4(db_->GetUniqueStatement( |
| 1129 "DELETE FROM autofill_profile_phones")); | 1134 "DELETE FROM autofill_profile_phones")); |
| 1130 | 1135 |
| 1131 return s4.Run(); | 1136 return s4.Run(); |
| 1132 } | 1137 } |
| 1133 | 1138 |
| 1134 bool AutofillTable::AddCreditCard(const CreditCard& credit_card) { | 1139 bool AutofillTable::AddCreditCard(const CreditCard& credit_card) { |
| 1135 sql::Statement s(db_->GetUniqueStatement( | 1140 sql::Statement s(db_->GetUniqueStatement( |
| 1136 "INSERT INTO credit_cards" | 1141 "INSERT INTO credit_cards" |
| 1137 "(guid, name_on_card, expiration_month, expiration_year, " | 1142 "(guid, name_on_card, expiration_month, expiration_year, " |
| 1138 " card_number_encrypted, use_count, use_date, date_modified, origin)" | 1143 " card_number_encrypted, use_count, use_date, date_modified, origin," |
| 1139 "VALUES (?,?,?,?,?,?,?,?,?)")); | 1144 " billing_address_id)" |
| 1145 "VALUES (?,?,?,?,?,?,?,?,?,?)")); |
| 1140 BindCreditCardToStatement(credit_card, Time::Now(), &s); | 1146 BindCreditCardToStatement(credit_card, Time::Now(), &s); |
| 1141 | 1147 |
| 1142 if (!s.Run()) | 1148 if (!s.Run()) |
| 1143 return false; | 1149 return false; |
| 1144 | 1150 |
| 1145 DCHECK_GT(db_->GetLastChangeCount(), 0); | 1151 DCHECK_GT(db_->GetLastChangeCount(), 0); |
| 1146 return true; | 1152 return true; |
| 1147 } | 1153 } |
| 1148 | 1154 |
| 1149 std::unique_ptr<CreditCard> AutofillTable::GetCreditCard( | 1155 std::unique_ptr<CreditCard> AutofillTable::GetCreditCard( |
| 1150 const std::string& guid) { | 1156 const std::string& guid) { |
| 1151 DCHECK(base::IsValidGUID(guid)); | 1157 DCHECK(base::IsValidGUID(guid)); |
| 1152 sql::Statement s(db_->GetUniqueStatement( | 1158 sql::Statement s(db_->GetUniqueStatement( |
| 1153 "SELECT guid, name_on_card, expiration_month, expiration_year, " | 1159 "SELECT guid, name_on_card, expiration_month, expiration_year, " |
| 1154 "card_number_encrypted, use_count, use_date, date_modified, " | 1160 "card_number_encrypted, use_count, use_date, date_modified, " |
| 1155 "origin " | 1161 "origin, billing_address_id " |
| 1156 "FROM credit_cards " | 1162 "FROM credit_cards " |
| 1157 "WHERE guid = ?")); | 1163 "WHERE guid = ?")); |
| 1158 s.BindString(0, guid); | 1164 s.BindString(0, guid); |
| 1159 | 1165 |
| 1160 if (!s.Step()) | 1166 if (!s.Step()) |
| 1161 return std::unique_ptr<CreditCard>(); | 1167 return std::unique_ptr<CreditCard>(); |
| 1162 | 1168 |
| 1163 return CreditCardFromStatement(s); | 1169 return CreditCardFromStatement(s); |
| 1164 } | 1170 } |
| 1165 | 1171 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1429 GetCreditCard(credit_card.guid()); | 1435 GetCreditCard(credit_card.guid()); |
| 1430 if (!old_credit_card) | 1436 if (!old_credit_card) |
| 1431 return false; | 1437 return false; |
| 1432 | 1438 |
| 1433 bool update_modification_date = *old_credit_card != credit_card; | 1439 bool update_modification_date = *old_credit_card != credit_card; |
| 1434 | 1440 |
| 1435 sql::Statement s(db_->GetUniqueStatement( | 1441 sql::Statement s(db_->GetUniqueStatement( |
| 1436 "UPDATE credit_cards " | 1442 "UPDATE credit_cards " |
| 1437 "SET guid=?, name_on_card=?, expiration_month=?," | 1443 "SET guid=?, name_on_card=?, expiration_month=?," |
| 1438 "expiration_year=?, card_number_encrypted=?, use_count=?, use_date=?," | 1444 "expiration_year=?, card_number_encrypted=?, use_count=?, use_date=?," |
| 1439 "date_modified=?, origin=?" | 1445 "date_modified=?, origin=?, billing_address_id=?" |
| 1440 "WHERE guid=?")); | 1446 "WHERE guid=?1")); |
| 1441 BindCreditCardToStatement( | 1447 BindCreditCardToStatement( |
| 1442 credit_card, | 1448 credit_card, |
| 1443 update_modification_date ? Time::Now() : | 1449 update_modification_date ? Time::Now() : |
| 1444 old_credit_card->modification_date(), | 1450 old_credit_card->modification_date(), |
| 1445 &s); | 1451 &s); |
| 1446 s.BindString(9, credit_card.guid()); | |
| 1447 | 1452 |
| 1448 bool result = s.Run(); | 1453 bool result = s.Run(); |
| 1449 DCHECK_GT(db_->GetLastChangeCount(), 0); | 1454 DCHECK_GT(db_->GetLastChangeCount(), 0); |
| 1450 return result; | 1455 return result; |
| 1451 } | 1456 } |
| 1452 | 1457 |
| 1453 bool AutofillTable::RemoveCreditCard(const std::string& guid) { | 1458 bool AutofillTable::RemoveCreditCard(const std::string& guid) { |
| 1454 DCHECK(base::IsValidGUID(guid)); | 1459 DCHECK(base::IsValidGUID(guid)); |
| 1455 sql::Statement s(db_->GetUniqueStatement( | 1460 sql::Statement s(db_->GetUniqueStatement( |
| 1456 "DELETE FROM credit_cards WHERE guid = ?")); | 1461 "DELETE FROM credit_cards WHERE guid = ?")); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1673 if (!db_->DoesTableExist("credit_cards")) { | 1678 if (!db_->DoesTableExist("credit_cards")) { |
| 1674 if (!db_->Execute("CREATE TABLE credit_cards ( " | 1679 if (!db_->Execute("CREATE TABLE credit_cards ( " |
| 1675 "guid VARCHAR PRIMARY KEY, " | 1680 "guid VARCHAR PRIMARY KEY, " |
| 1676 "name_on_card VARCHAR, " | 1681 "name_on_card VARCHAR, " |
| 1677 "expiration_month INTEGER, " | 1682 "expiration_month INTEGER, " |
| 1678 "expiration_year INTEGER, " | 1683 "expiration_year INTEGER, " |
| 1679 "card_number_encrypted BLOB, " | 1684 "card_number_encrypted BLOB, " |
| 1680 "date_modified INTEGER NOT NULL DEFAULT 0, " | 1685 "date_modified INTEGER NOT NULL DEFAULT 0, " |
| 1681 "origin VARCHAR DEFAULT '', " | 1686 "origin VARCHAR DEFAULT '', " |
| 1682 "use_count INTEGER NOT NULL DEFAULT 0, " | 1687 "use_count INTEGER NOT NULL DEFAULT 0, " |
| 1683 "use_date INTEGER NOT NULL DEFAULT 0) ")) { | 1688 "use_date INTEGER NOT NULL DEFAULT 0, " |
| 1689 "billing_address_id VARCHAR) ")) { |
| 1684 NOTREACHED(); | 1690 NOTREACHED(); |
| 1685 return false; | 1691 return false; |
| 1686 } | 1692 } |
| 1687 } | 1693 } |
| 1688 | 1694 |
| 1689 return true; | 1695 return true; |
| 1690 } | 1696 } |
| 1691 | 1697 |
| 1692 bool AutofillTable::InitProfilesTable() { | 1698 bool AutofillTable::InitProfilesTable() { |
| 1693 if (!db_->DoesTableExist("autofill_profiles")) { | 1699 if (!db_->DoesTableExist("autofill_profiles")) { |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2261 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_COUNTRY)); | 2267 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_COUNTRY)); |
| 2262 insert.BindString16(index++, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); | 2268 insert.BindString16(index++, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); |
| 2263 insert.BindString(index++, profile.language_code()); | 2269 insert.BindString(index++, profile.language_code()); |
| 2264 insert.Run(); | 2270 insert.Run(); |
| 2265 insert.Reset(true); | 2271 insert.Reset(true); |
| 2266 } | 2272 } |
| 2267 | 2273 |
| 2268 return transaction.Commit(); | 2274 return transaction.Commit(); |
| 2269 } | 2275 } |
| 2270 | 2276 |
| 2277 bool AutofillTable::MigrateToVersion66AddCardBillingAddress() { |
| 2278 // The default value for this column is null, but Connection::ColumnString() |
| 2279 // returns an empty string for that. |
| 2280 return db_->Execute( |
| 2281 "ALTER TABLE credit_cards ADD COLUMN billing_address_id VARCHAR"); |
| 2282 } |
| 2283 |
| 2271 } // namespace autofill | 2284 } // namespace autofill |
| OLD | NEW |