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 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1929 | 1936 |
1930 bool AutofillTable::InitMaskedCreditCardsTable() { | 1937 bool AutofillTable::InitMaskedCreditCardsTable() { |
1931 if (!db_->DoesTableExist("masked_credit_cards")) { | 1938 if (!db_->DoesTableExist("masked_credit_cards")) { |
1932 if (!db_->Execute("CREATE TABLE masked_credit_cards (" | 1939 if (!db_->Execute("CREATE TABLE masked_credit_cards (" |
1933 "id VARCHAR," | 1940 "id VARCHAR," |
1934 "status VARCHAR," | 1941 "status VARCHAR," |
1935 "name_on_card VARCHAR," | 1942 "name_on_card VARCHAR," |
1936 "type VARCHAR," | 1943 "type VARCHAR," |
1937 "last_four VARCHAR," | 1944 "last_four VARCHAR," |
1938 "exp_month INTEGER DEFAULT 0," | 1945 "exp_month INTEGER DEFAULT 0," |
1939 "exp_year INTEGER DEFAULT 0)")) { | 1946 "exp_year INTEGER DEFAULT 0," |
1947 " bank_name VARCHAR)")) { | |
Jared Saul
2017/03/03 23:40:09
remove space in front?
Shanfeng
2017/03/04 00:01:08
This is a standard way to make migrating from the
Jared Saul
2017/03/10 19:51:54
(FYI I kind of thought that might be the case, but
Shanfeng
2017/03/10 21:49:57
It is weird. Exp_year is in the table when this ta
Mathieu
2017/03/31 18:25:10
elsewhere they put the space on the previous line
Shanfeng
2017/04/12 01:58:59
Done.
| |
1940 NOTREACHED(); | 1948 NOTREACHED(); |
1941 return false; | 1949 return false; |
1942 } | 1950 } |
1943 } | 1951 } |
1944 return true; | 1952 return true; |
1945 } | 1953 } |
1946 | 1954 |
1947 bool AutofillTable::InitUnmaskedCreditCardsTable() { | 1955 bool AutofillTable::InitUnmaskedCreditCardsTable() { |
1948 if (!db_->DoesTableExist("unmasked_credit_cards")) { | 1956 if (!db_->DoesTableExist("unmasked_credit_cards")) { |
1949 if (!db_->Execute("CREATE TABLE unmasked_credit_cards (" | 1957 if (!db_->Execute("CREATE TABLE unmasked_credit_cards (" |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2537 // temporary table. | 2545 // temporary table. |
2538 if (!db_->Execute("DROP TABLE masked_credit_cards") || | 2546 if (!db_->Execute("DROP TABLE masked_credit_cards") || |
2539 !db_->Execute("ALTER TABLE masked_credit_cards_temp " | 2547 !db_->Execute("ALTER TABLE masked_credit_cards_temp " |
2540 "RENAME TO masked_credit_cards")) { | 2548 "RENAME TO masked_credit_cards")) { |
2541 return false; | 2549 return false; |
2542 } | 2550 } |
2543 | 2551 |
2544 return transaction.Commit(); | 2552 return transaction.Commit(); |
2545 } | 2553 } |
2546 | 2554 |
2555 bool AutofillTable::MigrateToVersion72AddMaskedCardBankName() { | |
2556 sql::Transaction transaction(db_); | |
2557 if (!transaction.Begin()) | |
2558 return false; | |
2559 | |
2560 // Add the new bank_name column to the masked_credit_cards table. | |
2561 if (!db_->DoesColumnExist("masked_credit_cards", "bank_name") && | |
2562 !db_->Execute("ALTER TABLE masked_credit_cards ADD COLUMN " | |
2563 "bank_name VARCHAR")) { | |
2564 return false; | |
2565 } | |
2566 | |
2567 return transaction.Commit(); | |
2568 } | |
2569 | |
2547 } // namespace autofill | 2570 } // namespace autofill |
OLD | NEW |