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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 return MigrateToVersion66AddCardBillingAddress(); | 476 return MigrateToVersion66AddCardBillingAddress(); |
477 case 67: | 477 case 67: |
478 *update_compatible_version = false; | 478 *update_compatible_version = false; |
479 return MigrateToVersion67AddMaskedCardBillingAddress(); | 479 return MigrateToVersion67AddMaskedCardBillingAddress(); |
480 case 70: | 480 case 70: |
481 *update_compatible_version = false; | 481 *update_compatible_version = false; |
482 return MigrateToVersion70AddSyncMetadata(); | 482 return MigrateToVersion70AddSyncMetadata(); |
483 case 71: | 483 case 71: |
484 *update_compatible_version = true; | 484 *update_compatible_version = true; |
485 return MigrateToVersion71AddHasConvertedAndBillingAddressIdMetadata(); | 485 return MigrateToVersion71AddHasConvertedAndBillingAddressIdMetadata(); |
| 486 case 72: |
| 487 *update_compatible_version = true; |
| 488 return MigrateToVersion72AddMaskedCardBankName(); |
486 } | 489 } |
487 return true; | 490 return true; |
488 } | 491 } |
489 | 492 |
490 bool AutofillTable::AddFormFieldValues( | 493 bool AutofillTable::AddFormFieldValues( |
491 const std::vector<FormFieldData>& elements, | 494 const std::vector<FormFieldData>& elements, |
492 std::vector<AutofillChange>* changes) { | 495 std::vector<AutofillChange>* changes) { |
493 return AddFormFieldValuesTime(elements, changes, AutofillClock::Now()); | 496 return AddFormFieldValuesTime(elements, changes, AutofillClock::Now()); |
494 } | 497 } |
495 | 498 |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1232 "card_number_encrypted, " // 0 | 1235 "card_number_encrypted, " // 0 |
1233 "last_four," // 1 | 1236 "last_four," // 1 |
1234 "masked.id," // 2 | 1237 "masked.id," // 2 |
1235 "metadata.use_count," // 3 | 1238 "metadata.use_count," // 3 |
1236 "metadata.use_date," // 4 | 1239 "metadata.use_date," // 4 |
1237 "type," // 5 | 1240 "type," // 5 |
1238 "status," // 6 | 1241 "status," // 6 |
1239 "name_on_card," // 7 | 1242 "name_on_card," // 7 |
1240 "exp_month," // 8 | 1243 "exp_month," // 8 |
1241 "exp_year," // 9 | 1244 "exp_year," // 9 |
1242 "metadata.billing_address_id " // 10 | 1245 "metadata.billing_address_id," // 10 |
| 1246 "bank_name " // 11 |
1243 "FROM masked_credit_cards masked " | 1247 "FROM masked_credit_cards masked " |
1244 "LEFT OUTER JOIN unmasked_credit_cards USING (id) " | 1248 "LEFT OUTER JOIN unmasked_credit_cards USING (id) " |
1245 "LEFT OUTER JOIN server_card_metadata metadata USING (id)")); | 1249 "LEFT OUTER JOIN server_card_metadata metadata USING (id)")); |
1246 while (s.Step()) { | 1250 while (s.Step()) { |
1247 int index = 0; | 1251 int index = 0; |
1248 | 1252 |
1249 // If the card_number_encrypted field is nonempty, we can assume this card | 1253 // If the card_number_encrypted field is nonempty, we can assume this card |
1250 // is a full card, otherwise it's masked. | 1254 // is a full card, otherwise it's masked. |
1251 base::string16 full_card_number = | 1255 base::string16 full_card_number = |
1252 UnencryptedCardFromColumn(s, index++, *autofill_table_encryptor_); | 1256 UnencryptedCardFromColumn(s, index++, *autofill_table_encryptor_); |
(...skipping 22 matching lines...) Expand all Loading... |
1275 card->SetTypeForMaskedCard(card_type.c_str()); | 1279 card->SetTypeForMaskedCard(card_type.c_str()); |
1276 } else { | 1280 } else { |
1277 DCHECK_EQ(CreditCard::GetCreditCardType(full_card_number), card_type); | 1281 DCHECK_EQ(CreditCard::GetCreditCardType(full_card_number), card_type); |
1278 } | 1282 } |
1279 | 1283 |
1280 card->SetServerStatus(ServerStatusStringToEnum(s.ColumnString(index++))); | 1284 card->SetServerStatus(ServerStatusStringToEnum(s.ColumnString(index++))); |
1281 card->SetRawInfo(CREDIT_CARD_NAME_FULL, s.ColumnString16(index++)); | 1285 card->SetRawInfo(CREDIT_CARD_NAME_FULL, s.ColumnString16(index++)); |
1282 card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(index++)); | 1286 card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(index++)); |
1283 card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(index++)); | 1287 card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(index++)); |
1284 card->set_billing_address_id(s.ColumnString(index++)); | 1288 card->set_billing_address_id(s.ColumnString(index++)); |
| 1289 card->SetBankName(s.ColumnString(index++)); |
1285 credit_cards->push_back(std::move(card)); | 1290 credit_cards->push_back(std::move(card)); |
1286 } | 1291 } |
1287 | 1292 |
1288 return s.Succeeded(); | 1293 return s.Succeeded(); |
1289 } | 1294 } |
1290 | 1295 |
1291 void AutofillTable::SetServerCreditCards( | 1296 void AutofillTable::SetServerCreditCards( |
1292 const std::vector<CreditCard>& credit_cards) { | 1297 const std::vector<CreditCard>& credit_cards) { |
1293 sql::Transaction transaction(db_); | 1298 sql::Transaction transaction(db_); |
1294 if (!transaction.Begin()) | 1299 if (!transaction.Begin()) |
1295 return; | 1300 return; |
1296 | 1301 |
1297 // Delete all old values. | 1302 // Delete all old values. |
1298 sql::Statement masked_delete(db_->GetUniqueStatement( | 1303 sql::Statement masked_delete(db_->GetUniqueStatement( |
1299 "DELETE FROM masked_credit_cards")); | 1304 "DELETE FROM masked_credit_cards")); |
1300 masked_delete.Run(); | 1305 masked_delete.Run(); |
1301 | 1306 |
1302 sql::Statement masked_insert( | 1307 sql::Statement masked_insert( |
1303 db_->GetUniqueStatement("INSERT INTO masked_credit_cards(" | 1308 db_->GetUniqueStatement("INSERT INTO masked_credit_cards(" |
1304 "id," // 0 | 1309 "id," // 0 |
1305 "type," // 1 | 1310 "type," // 1 |
1306 "status," // 2 | 1311 "status," // 2 |
1307 "name_on_card," // 3 | 1312 "name_on_card," // 3 |
1308 "last_four," // 4 | 1313 "last_four," // 4 |
1309 "exp_month," // 5 | 1314 "exp_month," // 5 |
1310 "exp_year)" // 6 | 1315 "exp_year," // 6 |
1311 "VALUES (?,?,?,?,?,?,?)")); | 1316 "bank_name)" // 7 |
| 1317 "VALUES (?,?,?,?,?,?,?,?)")); |
1312 for (const CreditCard& card : credit_cards) { | 1318 for (const CreditCard& card : credit_cards) { |
1313 DCHECK_EQ(CreditCard::MASKED_SERVER_CARD, card.record_type()); | 1319 DCHECK_EQ(CreditCard::MASKED_SERVER_CARD, card.record_type()); |
1314 | 1320 |
1315 masked_insert.BindString(0, card.server_id()); | 1321 masked_insert.BindString(0, card.server_id()); |
1316 masked_insert.BindString(1, card.type()); | 1322 masked_insert.BindString(1, card.type()); |
1317 masked_insert.BindString(2, | 1323 masked_insert.BindString(2, |
1318 ServerStatusEnumToString(card.GetServerStatus())); | 1324 ServerStatusEnumToString(card.GetServerStatus())); |
1319 masked_insert.BindString16(3, card.GetRawInfo(CREDIT_CARD_NAME_FULL)); | 1325 masked_insert.BindString16(3, card.GetRawInfo(CREDIT_CARD_NAME_FULL)); |
1320 masked_insert.BindString16(4, card.LastFourDigits()); | 1326 masked_insert.BindString16(4, card.LastFourDigits()); |
1321 masked_insert.BindString16(5, card.GetRawInfo(CREDIT_CARD_EXP_MONTH)); | 1327 masked_insert.BindString16(5, card.GetRawInfo(CREDIT_CARD_EXP_MONTH)); |
1322 masked_insert.BindString16(6, | 1328 masked_insert.BindString16(6, |
1323 card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 1329 card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
| 1330 masked_insert.BindString(7, card.bank_name()); |
1324 | 1331 |
1325 masked_insert.Run(); | 1332 masked_insert.Run(); |
1326 masked_insert.Reset(true); | 1333 masked_insert.Reset(true); |
1327 | 1334 |
1328 // Save the use count and use date of the card. | 1335 // Save the use count and use date of the card. |
1329 UpdateServerCardMetadata(card); | 1336 UpdateServerCardMetadata(card); |
1330 } | 1337 } |
1331 | 1338 |
1332 // Delete all items in the unmasked table that aren't in the new set. | 1339 // Delete all items in the unmasked table that aren't in the new set. |
1333 sql::Statement unmasked_delete(db_->GetUniqueStatement( | 1340 sql::Statement unmasked_delete(db_->GetUniqueStatement( |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1927 | 1934 |
1928 bool AutofillTable::InitMaskedCreditCardsTable() { | 1935 bool AutofillTable::InitMaskedCreditCardsTable() { |
1929 if (!db_->DoesTableExist("masked_credit_cards")) { | 1936 if (!db_->DoesTableExist("masked_credit_cards")) { |
1930 if (!db_->Execute("CREATE TABLE masked_credit_cards (" | 1937 if (!db_->Execute("CREATE TABLE masked_credit_cards (" |
1931 "id VARCHAR," | 1938 "id VARCHAR," |
1932 "status VARCHAR," | 1939 "status VARCHAR," |
1933 "name_on_card VARCHAR," | 1940 "name_on_card VARCHAR," |
1934 "type VARCHAR," | 1941 "type VARCHAR," |
1935 "last_four VARCHAR," | 1942 "last_four VARCHAR," |
1936 "exp_month INTEGER DEFAULT 0," | 1943 "exp_month INTEGER DEFAULT 0," |
1937 "exp_year INTEGER DEFAULT 0)")) { | 1944 "exp_year INTEGER DEFAULT 0, " |
| 1945 "bank_name VARCHAR)")) { |
1938 NOTREACHED(); | 1946 NOTREACHED(); |
1939 return false; | 1947 return false; |
1940 } | 1948 } |
1941 } | 1949 } |
1942 return true; | 1950 return true; |
1943 } | 1951 } |
1944 | 1952 |
1945 bool AutofillTable::InitUnmaskedCreditCardsTable() { | 1953 bool AutofillTable::InitUnmaskedCreditCardsTable() { |
1946 if (!db_->DoesTableExist("unmasked_credit_cards")) { | 1954 if (!db_->DoesTableExist("unmasked_credit_cards")) { |
1947 if (!db_->Execute("CREATE TABLE unmasked_credit_cards (" | 1955 if (!db_->Execute("CREATE TABLE unmasked_credit_cards (" |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2535 // temporary table. | 2543 // temporary table. |
2536 if (!db_->Execute("DROP TABLE masked_credit_cards") || | 2544 if (!db_->Execute("DROP TABLE masked_credit_cards") || |
2537 !db_->Execute("ALTER TABLE masked_credit_cards_temp " | 2545 !db_->Execute("ALTER TABLE masked_credit_cards_temp " |
2538 "RENAME TO masked_credit_cards")) { | 2546 "RENAME TO masked_credit_cards")) { |
2539 return false; | 2547 return false; |
2540 } | 2548 } |
2541 | 2549 |
2542 return transaction.Commit(); | 2550 return transaction.Commit(); |
2543 } | 2551 } |
2544 | 2552 |
| 2553 bool AutofillTable::MigrateToVersion72AddMaskedCardBankName() { |
| 2554 sql::Transaction transaction(db_); |
| 2555 if (!transaction.Begin()) |
| 2556 return false; |
| 2557 |
| 2558 // Add the new bank_name column to the masked_credit_cards table. |
| 2559 if (!db_->DoesColumnExist("masked_credit_cards", "bank_name") && |
| 2560 !db_->Execute("ALTER TABLE masked_credit_cards ADD COLUMN " |
| 2561 "bank_name VARCHAR")) { |
| 2562 return false; |
| 2563 } |
| 2564 |
| 2565 return transaction.Commit(); |
| 2566 } |
| 2567 |
2545 } // namespace autofill | 2568 } // namespace autofill |
OLD | NEW |