Chromium Code Reviews| 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 8d03d935dbc59df6ff003c6f21fc262c1f603ec5..abb0cf1b9c483859d46f83a53098f9aa74618fa5 100644 |
| --- a/components/autofill/core/browser/webdata/autofill_table.cc |
| +++ b/components/autofill/core/browser/webdata/autofill_table.cc |
| @@ -471,6 +471,9 @@ bool AutofillTable::MigrateToVersion(int version, |
| case 70: |
| *update_compatible_version = false; |
| return MigrateToVersion70AddSyncMetadata(); |
| + case 71: |
| + *update_compatible_version = false; |
| + return MigrateToVersion71AddHasConvertedAndBillingAddressIdMetadata(); |
| } |
| return true; |
| } |
| @@ -1210,17 +1213,17 @@ bool AutofillTable::GetServerCreditCards( |
| sql::Statement s(db_->GetUniqueStatement( |
| "SELECT " |
| - "card_number_encrypted, " // 0 |
| - "last_four," // 1 |
| - "masked.id," // 2 |
| - "metadata.use_count," // 3 |
| - "metadata.use_date," // 4 |
| - "type," // 5 |
| - "status," // 6 |
| - "name_on_card," // 7 |
| - "exp_month," // 8 |
| - "exp_year," // 9 |
| - "billing_address_id " // 10 |
| + "card_number_encrypted, " // 0 |
| + "last_four," // 1 |
| + "masked.id," // 2 |
| + "metadata.use_count," // 3 |
| + "metadata.use_date," // 4 |
| + "type," // 5 |
| + "status," // 6 |
| + "name_on_card," // 7 |
| + "exp_month," // 8 |
| + "exp_year," // 9 |
| + "metadata.billing_address_id " // 10 |
| "FROM masked_credit_cards masked " |
| "LEFT OUTER JOIN unmasked_credit_cards USING (id) " |
| "LEFT OUTER JOIN server_card_metadata metadata USING (id)")); |
| @@ -1308,7 +1311,7 @@ void AutofillTable::SetServerCreditCards( |
| masked_insert.Reset(true); |
| // Save the use count and use date of the card. |
| - UpdateServerCardUsageStats(card); |
| + UpdateServerCardMetadata(card); |
| } |
| // Delete all items in the unmasked table that aren't in the new set. |
| @@ -1349,7 +1352,7 @@ bool AutofillTable::UnmaskServerCreditCard(const CreditCard& masked, |
| unmasked.set_record_type(CreditCard::FULL_SERVER_CARD); |
| unmasked.SetNumber(full_number); |
| unmasked.RecordAndLogUse(); |
| - UpdateServerCardUsageStats(unmasked); |
| + UpdateServerCardMetadata(unmasked); |
| return db_->GetLastChangeCount() > 0; |
| } |
| @@ -1362,8 +1365,7 @@ bool AutofillTable::MaskServerCreditCard(const std::string& id) { |
| return db_->GetLastChangeCount() > 0; |
| } |
| -bool AutofillTable::UpdateServerCardUsageStats( |
| - const CreditCard& credit_card) { |
| +bool AutofillTable::UpdateServerCardMetadata(const CreditCard& credit_card) { |
| DCHECK_NE(CreditCard::LOCAL_CARD, credit_card.record_type()); |
| sql::Transaction transaction(db_); |
| if (!transaction.Begin()) |
| @@ -1374,12 +1376,14 @@ bool AutofillTable::UpdateServerCardUsageStats( |
| remove.BindString(0, credit_card.server_id()); |
| remove.Run(); |
| - sql::Statement s(db_->GetUniqueStatement( |
| - "INSERT INTO server_card_metadata(use_count, use_date, id)" |
| - "VALUES (?,?,?)")); |
| + sql::Statement s( |
| + db_->GetUniqueStatement("INSERT INTO server_card_metadata(use_count, " |
| + "use_date, billing_address_id, id)" |
| + "VALUES (?,?,?,?)")); |
| s.BindInt64(0, credit_card.use_count()); |
| s.BindInt64(1, credit_card.use_date().ToInternalValue()); |
| - s.BindString(2, credit_card.server_id()); |
| + s.BindString(2, credit_card.billing_address_id()); |
| + s.BindString(3, credit_card.server_id()); |
| s.Run(); |
| transaction.Commit(); |
| @@ -1387,7 +1391,9 @@ bool AutofillTable::UpdateServerCardUsageStats( |
| return db_->GetLastChangeCount() > 0; |
| } |
| -bool AutofillTable::UpdateServerAddressUsageStats( |
| +// TODO(crbug.com/680182): Record the address conversion status when a server |
| +// address gets converted. |
| +bool AutofillTable::UpdateServerAddressMetadata( |
| const AutofillProfile& profile) { |
| DCHECK_EQ(AutofillProfile::SERVER_PROFILE, profile.record_type()); |
| @@ -1400,12 +1406,14 @@ bool AutofillTable::UpdateServerAddressUsageStats( |
| remove.BindString(0, profile.server_id()); |
| remove.Run(); |
| - sql::Statement s(db_->GetUniqueStatement( |
| - "INSERT INTO server_address_metadata(use_count, use_date, id)" |
| - "VALUES (?,?,?)")); |
| + sql::Statement s( |
| + db_->GetUniqueStatement("INSERT INTO server_address_metadata(use_count, " |
| + "use_date, has_converted, id)" |
| + "VALUES (?,?,?,?)")); |
| s.BindInt64(0, profile.use_count()); |
| s.BindInt64(1, profile.use_date().ToInternalValue()); |
| - s.BindString(2, profile.server_id()); |
| + s.BindBool(2, false); |
| + s.BindString(3, profile.server_id()); |
| s.Run(); |
| transaction.Commit(); |
| @@ -1413,21 +1421,6 @@ bool AutofillTable::UpdateServerAddressUsageStats( |
| return db_->GetLastChangeCount() > 0; |
| } |
| -bool AutofillTable::UpdateServerCardBillingAddress( |
| - const CreditCard& credit_card) { |
| - DCHECK_NE(CreditCard::LOCAL_CARD, credit_card.record_type()); |
| - |
| - sql::Statement update(db_->GetUniqueStatement( |
| - "UPDATE masked_credit_cards SET billing_address_id = ? " |
| - "WHERE id = ?")); |
| - update.BindString(0, credit_card.billing_address_id()); |
| - update.BindString(1, credit_card.server_id()); |
| - if (!update.Run()) |
| - return false; |
| - |
| - return db_->GetLastChangeCount() > 0; |
| -} |
| - |
| bool AutofillTable::ClearAllServerData() { |
| sql::Transaction transaction(db_); |
| if (!transaction.Begin()) |
| @@ -1957,7 +1950,8 @@ bool AutofillTable::InitServerCardMetadataTable() { |
| if (!db_->Execute("CREATE TABLE server_card_metadata (" |
| "id VARCHAR NOT NULL," |
| "use_count INTEGER NOT NULL DEFAULT 0, " |
| - "use_date INTEGER NOT NULL DEFAULT 0)")) { |
| + "use_date INTEGER NOT NULL DEFAULT 0, " |
| + "billing_address_id VARCHAR)")) { |
| NOTREACHED(); |
| return false; |
| } |
| @@ -1995,7 +1989,8 @@ bool AutofillTable::InitServerAddressMetadataTable() { |
| if (!db_->Execute("CREATE TABLE server_address_metadata (" |
| "id VARCHAR NOT NULL," |
| "use_count INTEGER NOT NULL DEFAULT 0, " |
| - "use_date INTEGER NOT NULL DEFAULT 0)")) { |
| + "use_date INTEGER NOT NULL DEFAULT 0, " |
| + "has_converted BOOL NOT NULL DEFAULT FALSE)")) { |
| NOTREACHED(); |
| return false; |
| } |
| @@ -2473,4 +2468,34 @@ bool AutofillTable::MigrateToVersion70AddSyncMetadata() { |
| "BLOB)"); |
| } |
| +bool AutofillTable::MigrateToVersion71AddHasConvertedAndBillingAddressIdMetadata() { |
|
Peter Kasting
2017/01/12 23:37:48
Nit: 80 columns (git cl format will find this sort
sebsg
2017/01/13 15:23:10
Done.
|
| + sql::Transaction transaction(db_); |
| + if (!transaction.Begin()) |
| + return false; |
| + |
| + if (!db_->DoesColumnExist("server_card_metadata", "billing_address_id") && |
| + !db_->Execute("ALTER TABLE server_card_metadata ADD COLUMN " |
| + "billing_address_id VARCHAR")) { |
| + return false; |
| + } |
| + |
| + if (!db_->DoesColumnExist("server_address_metadata", "has_converted") && |
| + !db_->Execute("ALTER TABLE server_address_metadata ADD COLUMN " |
| + "has_converted BOOL NOT NULL DEFAULT FALSE")) { |
| + return false; |
| + } |
| + |
| + // Copy over the billing_address_id from the masked_server_cards to |
| + // server_card_metadata. |
| + if (!db_->Execute("UPDATE server_card_metadata " |
| + "SET billing_address_id = " |
| + "(SELECT billing_address_id " |
| + "FROM masked_credit_cards " |
| + "WHERE id = server_card_metadata.id)")) { |
| + return false; |
| + } |
| + |
| + return transaction.Commit(); |
| +} |
| + |
| } // namespace autofill |