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 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 return MigrateToVersion63AddServerRecipientName(); | 452 return MigrateToVersion63AddServerRecipientName(); |
453 case 64: | 453 case 64: |
454 *update_compatible_version = false; | 454 *update_compatible_version = false; |
455 return MigrateToVersion64AddUnmaskDate(); | 455 return MigrateToVersion64AddUnmaskDate(); |
456 case 65: | 456 case 65: |
457 *update_compatible_version = false; | 457 *update_compatible_version = false; |
458 return MigrateToVersion65AddServerMetadataTables(); | 458 return MigrateToVersion65AddServerMetadataTables(); |
459 case 66: | 459 case 66: |
460 *update_compatible_version = false; | 460 *update_compatible_version = false; |
461 return MigrateToVersion66AddCardBillingAddress(); | 461 return MigrateToVersion66AddCardBillingAddress(); |
| 462 case 67: |
| 463 *update_compatible_version = false; |
| 464 return MigrateToVersion67AddMaskedCardBillingAddress(); |
462 } | 465 } |
463 return true; | 466 return true; |
464 } | 467 } |
465 | 468 |
466 bool AutofillTable::AddFormFieldValues( | 469 bool AutofillTable::AddFormFieldValues( |
467 const std::vector<FormFieldData>& elements, | 470 const std::vector<FormFieldData>& elements, |
468 std::vector<AutofillChange>* changes) { | 471 std::vector<AutofillChange>* changes) { |
469 return AddFormFieldValuesTime(elements, changes, Time::Now()); | 472 return AddFormFieldValuesTime(elements, changes, Time::Now()); |
470 } | 473 } |
471 | 474 |
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 "SELECT " | 1201 "SELECT " |
1199 "card_number_encrypted, " // 0 | 1202 "card_number_encrypted, " // 0 |
1200 "last_four," // 1 | 1203 "last_four," // 1 |
1201 "masked.id," // 2 | 1204 "masked.id," // 2 |
1202 "metadata.use_count," // 3 | 1205 "metadata.use_count," // 3 |
1203 "metadata.use_date," // 4 | 1206 "metadata.use_date," // 4 |
1204 "type," // 5 | 1207 "type," // 5 |
1205 "status," // 6 | 1208 "status," // 6 |
1206 "name_on_card," // 7 | 1209 "name_on_card," // 7 |
1207 "exp_month," // 8 | 1210 "exp_month," // 8 |
1208 "exp_year " // 9 | 1211 "exp_year," // 9 |
| 1212 "billing_address_id " // 10 |
1209 "FROM masked_credit_cards masked " | 1213 "FROM masked_credit_cards masked " |
1210 "LEFT OUTER JOIN unmasked_credit_cards USING (id) " | 1214 "LEFT OUTER JOIN unmasked_credit_cards USING (id) " |
1211 "LEFT OUTER JOIN server_card_metadata metadata USING (id)")); | 1215 "LEFT OUTER JOIN server_card_metadata metadata USING (id)")); |
1212 while (s.Step()) { | 1216 while (s.Step()) { |
1213 int index = 0; | 1217 int index = 0; |
1214 | 1218 |
1215 // If the card_number_encrypted field is nonempty, we can assume this card | 1219 // If the card_number_encrypted field is nonempty, we can assume this card |
1216 // is a full card, otherwise it's masked. | 1220 // is a full card, otherwise it's masked. |
1217 base::string16 full_card_number = UnencryptedCardFromColumn(s, index++); | 1221 base::string16 full_card_number = UnencryptedCardFromColumn(s, index++); |
1218 base::string16 last_four = s.ColumnString16(index++); | 1222 base::string16 last_four = s.ColumnString16(index++); |
(...skipping 19 matching lines...) Expand all Loading... |
1238 // autodectected type. | 1242 // autodectected type. |
1239 card->SetTypeForMaskedCard(card_type.c_str()); | 1243 card->SetTypeForMaskedCard(card_type.c_str()); |
1240 } else { | 1244 } else { |
1241 DCHECK_EQ(CreditCard::GetCreditCardType(full_card_number), card_type); | 1245 DCHECK_EQ(CreditCard::GetCreditCardType(full_card_number), card_type); |
1242 } | 1246 } |
1243 | 1247 |
1244 card->SetServerStatus(ServerStatusStringToEnum(s.ColumnString(index++))); | 1248 card->SetServerStatus(ServerStatusStringToEnum(s.ColumnString(index++))); |
1245 card->SetRawInfo(CREDIT_CARD_NAME_FULL, s.ColumnString16(index++)); | 1249 card->SetRawInfo(CREDIT_CARD_NAME_FULL, s.ColumnString16(index++)); |
1246 card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(index++)); | 1250 card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(index++)); |
1247 card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(index++)); | 1251 card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(index++)); |
| 1252 card->set_billing_address_id(s.ColumnString(index++)); |
1248 credit_cards->push_back(card); | 1253 credit_cards->push_back(card); |
1249 } | 1254 } |
1250 | 1255 |
1251 return s.Succeeded(); | 1256 return s.Succeeded(); |
1252 } | 1257 } |
1253 | 1258 |
1254 void AutofillTable::SetServerCreditCards( | 1259 void AutofillTable::SetServerCreditCards( |
1255 const std::vector<CreditCard>& credit_cards) { | 1260 const std::vector<CreditCard>& credit_cards) { |
1256 sql::Transaction transaction(db_); | 1261 sql::Transaction transaction(db_); |
1257 if (!transaction.Begin()) | 1262 if (!transaction.Begin()) |
1258 return; | 1263 return; |
1259 | 1264 |
1260 // Delete all old values. | 1265 // Delete all old values. |
1261 sql::Statement masked_delete(db_->GetUniqueStatement( | 1266 sql::Statement masked_delete(db_->GetUniqueStatement( |
1262 "DELETE FROM masked_credit_cards")); | 1267 "DELETE FROM masked_credit_cards")); |
1263 masked_delete.Run(); | 1268 masked_delete.Run(); |
1264 | 1269 |
1265 sql::Statement masked_insert(db_->GetUniqueStatement( | 1270 sql::Statement masked_insert(db_->GetUniqueStatement( |
1266 "INSERT INTO masked_credit_cards(" | 1271 "INSERT INTO masked_credit_cards(" |
1267 "id," // 0 | 1272 "id," // 0 |
1268 "type," // 1 | 1273 "type," // 1 |
1269 "status," // 2 | 1274 "status," // 2 |
1270 "name_on_card," // 3 | 1275 "name_on_card," // 3 |
1271 "last_four," // 4 | 1276 "last_four," // 4 |
1272 "exp_month," // 4 | 1277 "exp_month," // 5 |
1273 "exp_year) " // 5 | 1278 "exp_year," // 6 |
1274 "VALUES (?,?,?,?,?,?,?)")); | 1279 "billing_address_id) " // 7 |
| 1280 "VALUES (?,?,?,?,?,?,?,?)")); |
1275 for (const CreditCard& card : credit_cards) { | 1281 for (const CreditCard& card : credit_cards) { |
1276 DCHECK_EQ(CreditCard::MASKED_SERVER_CARD, card.record_type()); | 1282 DCHECK_EQ(CreditCard::MASKED_SERVER_CARD, card.record_type()); |
1277 | 1283 |
1278 masked_insert.BindString(0, card.server_id()); | 1284 masked_insert.BindString(0, card.server_id()); |
1279 masked_insert.BindString(1, card.type()); | 1285 masked_insert.BindString(1, card.type()); |
1280 masked_insert.BindString(2, | 1286 masked_insert.BindString(2, |
1281 ServerStatusEnumToString(card.GetServerStatus())); | 1287 ServerStatusEnumToString(card.GetServerStatus())); |
1282 masked_insert.BindString16(3, card.GetRawInfo(CREDIT_CARD_NAME_FULL)); | 1288 masked_insert.BindString16(3, card.GetRawInfo(CREDIT_CARD_NAME_FULL)); |
1283 masked_insert.BindString16(4, card.LastFourDigits()); | 1289 masked_insert.BindString16(4, card.LastFourDigits()); |
1284 masked_insert.BindString16(5, card.GetRawInfo(CREDIT_CARD_EXP_MONTH)); | 1290 masked_insert.BindString16(5, card.GetRawInfo(CREDIT_CARD_EXP_MONTH)); |
1285 masked_insert.BindString16(6, | 1291 masked_insert.BindString16(6, |
1286 card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 1292 card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
| 1293 masked_insert.BindString(7, card.billing_address_id()); |
1287 | 1294 |
1288 masked_insert.Run(); | 1295 masked_insert.Run(); |
1289 masked_insert.Reset(true); | 1296 masked_insert.Reset(true); |
1290 | 1297 |
1291 // Save the use count and use date of the card. | 1298 // Save the use count and use date of the card. |
1292 UpdateServerCardUsageStats(card); | 1299 UpdateServerCardUsageStats(card); |
1293 } | 1300 } |
1294 | 1301 |
1295 // Delete all items in the unmasked table that aren't in the new set. | 1302 // Delete all items in the unmasked table that aren't in the new set. |
1296 sql::Statement unmasked_delete(db_->GetUniqueStatement( | 1303 sql::Statement unmasked_delete(db_->GetUniqueStatement( |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 s.BindInt64(0, profile.use_count()); | 1394 s.BindInt64(0, profile.use_count()); |
1388 s.BindInt64(1, profile.use_date().ToInternalValue()); | 1395 s.BindInt64(1, profile.use_date().ToInternalValue()); |
1389 s.BindString(2, profile.server_id()); | 1396 s.BindString(2, profile.server_id()); |
1390 s.Run(); | 1397 s.Run(); |
1391 | 1398 |
1392 transaction.Commit(); | 1399 transaction.Commit(); |
1393 | 1400 |
1394 return db_->GetLastChangeCount() > 0; | 1401 return db_->GetLastChangeCount() > 0; |
1395 } | 1402 } |
1396 | 1403 |
| 1404 bool AutofillTable::UpdateServerCardBillingAddress( |
| 1405 const CreditCard& credit_card) { |
| 1406 DCHECK_NE(CreditCard::LOCAL_CARD, credit_card.record_type()); |
| 1407 |
| 1408 sql::Statement update(db_->GetUniqueStatement( |
| 1409 "UPDATE masked_credit_cards SET billing_address_id = ? " |
| 1410 "WHERE id = ?")); |
| 1411 update.BindString(0, credit_card.billing_address_id()); |
| 1412 update.BindString(1, credit_card.server_id()); |
| 1413 if (!update.Run()) |
| 1414 return false; |
| 1415 |
| 1416 return db_->GetLastChangeCount() > 0; |
| 1417 } |
| 1418 |
1397 bool AutofillTable::ClearAllServerData() { | 1419 bool AutofillTable::ClearAllServerData() { |
1398 sql::Transaction transaction(db_); | 1420 sql::Transaction transaction(db_); |
1399 if (!transaction.Begin()) | 1421 if (!transaction.Begin()) |
1400 return false; // Some error, nothing was changed. | 1422 return false; // Some error, nothing was changed. |
1401 | 1423 |
1402 sql::Statement masked(db_->GetUniqueStatement( | 1424 sql::Statement masked(db_->GetUniqueStatement( |
1403 "DELETE FROM masked_credit_cards")); | 1425 "DELETE FROM masked_credit_cards")); |
1404 masked.Run(); | 1426 masked.Run(); |
1405 bool changed = db_->GetLastChangeCount() > 0; | 1427 bool changed = db_->GetLastChangeCount() > 0; |
1406 | 1428 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1771 | 1793 |
1772 bool AutofillTable::InitMaskedCreditCardsTable() { | 1794 bool AutofillTable::InitMaskedCreditCardsTable() { |
1773 if (!db_->DoesTableExist("masked_credit_cards")) { | 1795 if (!db_->DoesTableExist("masked_credit_cards")) { |
1774 if (!db_->Execute("CREATE TABLE masked_credit_cards (" | 1796 if (!db_->Execute("CREATE TABLE masked_credit_cards (" |
1775 "id VARCHAR," | 1797 "id VARCHAR," |
1776 "status VARCHAR," | 1798 "status VARCHAR," |
1777 "name_on_card VARCHAR," | 1799 "name_on_card VARCHAR," |
1778 "type VARCHAR," | 1800 "type VARCHAR," |
1779 "last_four VARCHAR," | 1801 "last_four VARCHAR," |
1780 "exp_month INTEGER DEFAULT 0," | 1802 "exp_month INTEGER DEFAULT 0," |
1781 "exp_year INTEGER DEFAULT 0)")) { | 1803 "exp_year INTEGER DEFAULT 0, " |
| 1804 "billing_address_id VARCHAR)")) { |
1782 NOTREACHED(); | 1805 NOTREACHED(); |
1783 return false; | 1806 return false; |
1784 } | 1807 } |
1785 } | 1808 } |
1786 return true; | 1809 return true; |
1787 } | 1810 } |
1788 | 1811 |
1789 bool AutofillTable::InitUnmaskedCreditCardsTable() { | 1812 bool AutofillTable::InitUnmaskedCreditCardsTable() { |
1790 if (!db_->DoesTableExist("unmasked_credit_cards")) { | 1813 if (!db_->DoesTableExist("unmasked_credit_cards")) { |
1791 if (!db_->Execute("CREATE TABLE unmasked_credit_cards (" | 1814 if (!db_->Execute("CREATE TABLE unmasked_credit_cards (" |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2274 return transaction.Commit(); | 2297 return transaction.Commit(); |
2275 } | 2298 } |
2276 | 2299 |
2277 bool AutofillTable::MigrateToVersion66AddCardBillingAddress() { | 2300 bool AutofillTable::MigrateToVersion66AddCardBillingAddress() { |
2278 // The default value for this column is null, but Connection::ColumnString() | 2301 // The default value for this column is null, but Connection::ColumnString() |
2279 // returns an empty string for that. | 2302 // returns an empty string for that. |
2280 return db_->Execute( | 2303 return db_->Execute( |
2281 "ALTER TABLE credit_cards ADD COLUMN billing_address_id VARCHAR"); | 2304 "ALTER TABLE credit_cards ADD COLUMN billing_address_id VARCHAR"); |
2282 } | 2305 } |
2283 | 2306 |
| 2307 bool AutofillTable::MigrateToVersion67AddMaskedCardBillingAddress() { |
| 2308 // The default value for this column is null, but Connection::ColumnString() |
| 2309 // returns an empty string for that. |
| 2310 return db_->Execute( |
| 2311 "ALTER TABLE masked_credit_cards ADD COLUMN billing_address_id VARCHAR"); |
| 2312 } |
| 2313 |
2284 } // namespace autofill | 2314 } // namespace autofill |
OLD | NEW |