| Index: components/autofill/core/browser/webdata/autofill_table.cc
|
| diff --git a/components/autofill/core/browser/webdata/autofill_table.cc b/components/autofill/core/browser/webdata/autofill_table.cc
|
| index f05a739e7c905e15bfed9dc2c66a0fa74ca64604..a34cc9d135fbc10f09340c2a1a9020d683edca9e 100644
|
| --- a/components/autofill/core/browser/webdata/autofill_table.cc
|
| +++ b/components/autofill/core/browser/webdata/autofill_table.cc
|
| @@ -472,6 +472,9 @@ bool AutofillTable::MigrateToVersion(int version,
|
| case 63:
|
| *update_compatible_version = false;
|
| return MigrateToVersion63AddServerRecipientName();
|
| + case 64:
|
| + *update_compatible_version = false;
|
| + return MigrateToVersion64AddUnmaskDate();
|
| }
|
| return true;
|
| }
|
| @@ -1202,6 +1205,7 @@ void AutofillTable::SetServerCreditCards(
|
| // Delete all items in the unmasked table that aren't in the new set.
|
| sql::Statement get_unmasked(db_->GetUniqueStatement(
|
| "SELECT id FROM unmasked_credit_cards"));
|
| + std::set<std::string> kept_unmasked_entries;
|
| while (get_unmasked.Step()) {
|
| // We expect relatively few cards, just do brute-force.
|
| std::string server_id = get_unmasked.ColumnString(0);
|
| @@ -1212,7 +1216,9 @@ void AutofillTable::SetServerCreditCards(
|
| break;
|
| }
|
| }
|
| - if (!found_card) {
|
| + if (found_card) {
|
| + kept_unmasked_entries.insert(server_id);
|
| + } else {
|
| // This unmasked card in the DB isn't present in the input. The statement
|
| // is compiled every time because it's much more likely that this is never
|
| // executed than it runs more than once.
|
| @@ -1236,9 +1242,10 @@ void AutofillTable::SetServerCreditCards(
|
| "VALUES (?,?,?,?,?,?,?)"));
|
| sql::Statement unmasked_insert(db_->GetUniqueStatement(
|
| "INSERT INTO unmasked_credit_cards("
|
| - "id," // 0
|
| - "card_number_encrypted)" // 1
|
| - "VALUES (?,?)"));
|
| + "id," // 0
|
| + "card_number_encrypted, " // 1
|
| + "unmask_date)" // 2
|
| + "VALUES (?,?,?)"));
|
| for (const CreditCard& card : credit_cards) {
|
| DCHECK(card.record_type() != CreditCard::LOCAL_CARD);
|
|
|
| @@ -1255,13 +1262,18 @@ void AutofillTable::SetServerCreditCards(
|
| masked_insert.Run();
|
| masked_insert.Reset(true);
|
|
|
| - if (card.record_type() == CreditCard::FULL_SERVER_CARD) {
|
| - // Unmasked cards also get an entry in the unmasked table. Note that the
|
| - // input card could be MASKED but if we have an UNMASKED entry for that
|
| - // card already, it will be preserved.
|
| + if (kept_unmasked_entries.find(card.server_id()) ==
|
| + kept_unmasked_entries.end() &&
|
| + card.record_type() == CreditCard::FULL_SERVER_CARD) {
|
| + // New unmasked cards also get an entry in the unmasked table. In
|
| + // practice this will only happen for tests since the server cards will
|
| + // all be marked masked (if a server card is manually unmasked, we will
|
| + // have kept the existing entry in the table and won't get here).
|
| unmasked_insert.BindString(0, card.server_id());
|
| BindEncryptedCardToColumn(&unmasked_insert, 1,
|
| card.GetRawInfo(CREDIT_CARD_NUMBER));
|
| + // Unmask time for this card is now.
|
| + unmasked_insert.BindInt64(2, Time::Now().ToInternalValue());
|
| unmasked_insert.Run();
|
| unmasked_insert.Reset(true);
|
| }
|
| @@ -1273,9 +1285,13 @@ bool AutofillTable::UnmaskServerCreditCard(const std::string& id,
|
| // Make sure there aren't duplicates for this card.
|
| MaskServerCreditCard(id);
|
| sql::Statement s(db_->GetUniqueStatement(
|
| - "INSERT INTO unmasked_credit_cards(id, card_number_encrypted,"
|
| - " use_count, use_date) "
|
| - "VALUES (?,?,?,?)"));
|
| + "INSERT INTO unmasked_credit_cards("
|
| + "id,"
|
| + "card_number_encrypted,"
|
| + "use_count,"
|
| + "use_date,"
|
| + "unmask_date)"
|
| + "VALUES (?,?,?,?,?)"));
|
| s.BindString(0, id);
|
|
|
| std::string encrypted_data;
|
| @@ -1284,8 +1300,11 @@ bool AutofillTable::UnmaskServerCreditCard(const std::string& id,
|
| static_cast<int>(encrypted_data.length()));
|
|
|
| // Unmasking counts as a usage, so set the stats accordingly.
|
| - s.BindInt64(2, 1);
|
| - s.BindInt64(3, base::Time::Now().ToInternalValue());
|
| + base::Time now = base::Time::Now();
|
| + s.BindInt64(2, 1); // use_count
|
| + s.BindInt64(3, now.ToInternalValue()); // use_date
|
| +
|
| + s.BindInt64(4, now.ToInternalValue()); // unmask_date
|
|
|
| s.Run();
|
| return db_->GetLastChangeCount() > 0;
|
| @@ -1327,8 +1346,8 @@ bool AutofillTable::UpdateCreditCard(const CreditCard& credit_card) {
|
| sql::Statement s(db_->GetUniqueStatement(
|
| "UPDATE credit_cards "
|
| "SET guid=?, name_on_card=?, expiration_month=?,"
|
| - " expiration_year=?, card_number_encrypted=?, use_count=?, use_date=?,"
|
| - " date_modified=?, origin=?"
|
| + "expiration_year=?, card_number_encrypted=?, use_count=?, use_date=?,"
|
| + "date_modified=?, origin=?"
|
| "WHERE guid=?"));
|
| BindCreditCardToStatement(
|
| credit_card,
|
| @@ -1407,8 +1426,19 @@ bool AutofillTable::RemoveAutofillDataModifiedBetween(
|
| "WHERE date_modified >= ? AND date_modified < ?"));
|
| s_credit_cards.BindInt64(0, delete_begin_t);
|
| s_credit_cards.BindInt64(1, delete_end_t);
|
| + if (!s_credit_cards.Run())
|
| + return false;
|
| +
|
| + // Remove unmasked credit cards in the time range.
|
| + sql::Statement s_unmasked_cards(db_->GetUniqueStatement(
|
| + "DELETE FROM unmasked_credit_cards "
|
| + "WHERE unmask_date >= ? AND unmask_date < ?"));
|
| + s_unmasked_cards.BindInt64(0, delete_begin.ToInternalValue());
|
| + s_unmasked_cards.BindInt64(1, delete_end.ToInternalValue());
|
| + if (!s_unmasked_cards.Run())
|
| + return false;
|
|
|
| - return s_credit_cards.Run();
|
| + return true;
|
| }
|
|
|
| bool AutofillTable::RemoveOriginURLsModifiedBetween(
|
| @@ -1672,7 +1702,8 @@ bool AutofillTable::InitUnmaskedCreditCardsTable() {
|
| "id VARCHAR,"
|
| "card_number_encrypted VARCHAR, "
|
| "use_count INTEGER NOT NULL DEFAULT 0, "
|
| - "use_date INTEGER NOT NULL DEFAULT 0)")) {
|
| + "use_date INTEGER NOT NULL DEFAULT 0, "
|
| + "unmask_date INTEGER NOT NULL DEFAULT 0)")) {
|
| NOTREACHED();
|
| return false;
|
| }
|
| @@ -1989,4 +2020,13 @@ bool AutofillTable::MigrateToVersion63AddServerRecipientName() {
|
| return true;
|
| }
|
|
|
| +bool AutofillTable::MigrateToVersion64AddUnmaskDate() {
|
| + if (!db_->DoesColumnExist("unmasked_credit_cards", "unmask_date") &&
|
| + !db_->Execute("ALTER TABLE unmasked_credit_cards ADD COLUMN "
|
| + "unmask_date INTEGER NOT NULL DEFAULT 0")) {
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| } // namespace autofill
|
|
|