Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Unified Diff: components/autofill/core/browser/webdata/autofill_table.cc

Issue 2679803002: Revert "[Payments] Add billing_address_id and has_converted to autofill_table" (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 503eb0fa9e71fa93d8027215685a2a9a1dec91fa..8d03d935dbc59df6ff003c6f21fc262c1f603ec5 100644
--- a/components/autofill/core/browser/webdata/autofill_table.cc
+++ b/components/autofill/core/browser/webdata/autofill_table.cc
@@ -471,9 +471,6 @@ bool AutofillTable::MigrateToVersion(int version,
case 70:
*update_compatible_version = false;
return MigrateToVersion70AddSyncMetadata();
- case 71:
- *update_compatible_version = true;
- return MigrateToVersion71AddHasConvertedAndBillingAddressIdMetadata();
}
return true;
}
@@ -1213,17 +1210,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
- "metadata.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
+ "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)"));
@@ -1282,16 +1279,17 @@ void AutofillTable::SetServerCreditCards(
"DELETE FROM masked_credit_cards"));
masked_delete.Run();
- sql::Statement masked_insert(
- db_->GetUniqueStatement("INSERT INTO masked_credit_cards("
- "id," // 0
- "type," // 1
- "status," // 2
- "name_on_card," // 3
- "last_four," // 4
- "exp_month," // 5
- "exp_year)" // 6
- "VALUES (?,?,?,?,?,?,?)"));
+ sql::Statement masked_insert(db_->GetUniqueStatement(
+ "INSERT INTO masked_credit_cards("
+ "id," // 0
+ "type," // 1
+ "status," // 2
+ "name_on_card," // 3
+ "last_four," // 4
+ "exp_month," // 5
+ "exp_year," // 6
+ "billing_address_id) " // 7
+ "VALUES (?,?,?,?,?,?,?,?)"));
for (const CreditCard& card : credit_cards) {
DCHECK_EQ(CreditCard::MASKED_SERVER_CARD, card.record_type());
@@ -1304,12 +1302,13 @@ void AutofillTable::SetServerCreditCards(
masked_insert.BindString16(5, card.GetRawInfo(CREDIT_CARD_EXP_MONTH));
masked_insert.BindString16(6,
card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR));
+ masked_insert.BindString(7, card.billing_address_id());
masked_insert.Run();
masked_insert.Reset(true);
// Save the use count and use date of the card.
- UpdateServerCardMetadata(card);
+ UpdateServerCardUsageStats(card);
}
// Delete all items in the unmasked table that aren't in the new set.
@@ -1350,7 +1349,7 @@ bool AutofillTable::UnmaskServerCreditCard(const CreditCard& masked,
unmasked.set_record_type(CreditCard::FULL_SERVER_CARD);
unmasked.SetNumber(full_number);
unmasked.RecordAndLogUse();
- UpdateServerCardMetadata(unmasked);
+ UpdateServerCardUsageStats(unmasked);
return db_->GetLastChangeCount() > 0;
}
@@ -1363,7 +1362,8 @@ bool AutofillTable::MaskServerCreditCard(const std::string& id) {
return db_->GetLastChangeCount() > 0;
}
-bool AutofillTable::UpdateServerCardMetadata(const CreditCard& credit_card) {
+bool AutofillTable::UpdateServerCardUsageStats(
+ const CreditCard& credit_card) {
DCHECK_NE(CreditCard::LOCAL_CARD, credit_card.record_type());
sql::Transaction transaction(db_);
if (!transaction.Begin())
@@ -1374,14 +1374,12 @@ bool AutofillTable::UpdateServerCardMetadata(const CreditCard& credit_card) {
remove.BindString(0, credit_card.server_id());
remove.Run();
- sql::Statement s(
- db_->GetUniqueStatement("INSERT INTO server_card_metadata(use_count, "
- "use_date, billing_address_id, id)"
- "VALUES (?,?,?,?)"));
+ sql::Statement s(db_->GetUniqueStatement(
+ "INSERT INTO server_card_metadata(use_count, use_date, id)"
+ "VALUES (?,?,?)"));
s.BindInt64(0, credit_card.use_count());
s.BindInt64(1, credit_card.use_date().ToInternalValue());
- s.BindString(2, credit_card.billing_address_id());
- s.BindString(3, credit_card.server_id());
+ s.BindString(2, credit_card.server_id());
s.Run();
transaction.Commit();
@@ -1389,9 +1387,7 @@ bool AutofillTable::UpdateServerCardMetadata(const CreditCard& credit_card) {
return db_->GetLastChangeCount() > 0;
}
-// TODO(crbug.com/680182): Record the address conversion status when a server
-// address gets converted.
-bool AutofillTable::UpdateServerAddressMetadata(
+bool AutofillTable::UpdateServerAddressUsageStats(
const AutofillProfile& profile) {
DCHECK_EQ(AutofillProfile::SERVER_PROFILE, profile.record_type());
@@ -1404,14 +1400,12 @@ bool AutofillTable::UpdateServerAddressMetadata(
remove.BindString(0, profile.server_id());
remove.Run();
- sql::Statement s(
- db_->GetUniqueStatement("INSERT INTO server_address_metadata(use_count, "
- "use_date, has_converted, id)"
- "VALUES (?,?,?,?)"));
+ sql::Statement s(db_->GetUniqueStatement(
+ "INSERT INTO server_address_metadata(use_count, use_date, id)"
+ "VALUES (?,?,?)"));
s.BindInt64(0, profile.use_count());
s.BindInt64(1, profile.use_date().ToInternalValue());
- s.BindBool(2, false);
- s.BindString(3, profile.server_id());
+ s.BindString(2, profile.server_id());
s.Run();
transaction.Commit();
@@ -1419,6 +1413,21 @@ bool AutofillTable::UpdateServerAddressMetadata(
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())
@@ -1919,7 +1928,8 @@ bool AutofillTable::InitMaskedCreditCardsTable() {
"type VARCHAR,"
"last_four VARCHAR,"
"exp_month INTEGER DEFAULT 0,"
- "exp_year INTEGER DEFAULT 0)")) {
+ "exp_year INTEGER DEFAULT 0, "
+ "billing_address_id VARCHAR)")) {
NOTREACHED();
return false;
}
@@ -1947,8 +1957,7 @@ 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, "
- "billing_address_id VARCHAR)")) {
+ "use_date INTEGER NOT NULL DEFAULT 0)")) {
NOTREACHED();
return false;
}
@@ -1986,8 +1995,7 @@ 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, "
- "has_converted BOOL NOT NULL DEFAULT FALSE)")) {
+ "use_date INTEGER NOT NULL DEFAULT 0)")) {
NOTREACHED();
return false;
}
@@ -2465,66 +2473,4 @@ bool AutofillTable::MigrateToVersion70AddSyncMetadata() {
"BLOB)");
}
-bool AutofillTable::
- MigrateToVersion71AddHasConvertedAndBillingAddressIdMetadata() {
- sql::Transaction transaction(db_);
- if (!transaction.Begin())
- return false;
-
- // Add the new has_converted column to the server_address_metadata table.
- 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;
- }
-
- // Add the new billing_address_id column to the server_card_metadata table.
- if (!db_->DoesColumnExist("server_card_metadata", "billing_address_id") &&
- !db_->Execute("ALTER TABLE server_card_metadata ADD COLUMN "
- "billing_address_id VARCHAR")) {
- 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;
- }
-
- // Remove the billing_address_id column from the masked_credit_cards table.
- // Create a temporary table that is a copy of masked_credit_cards but without
- // the billing_address_id column.
- if (db_->DoesTableExist("masked_credit_cards_temp") ||
- !db_->Execute("CREATE TABLE masked_credit_cards_temp ("
- "id VARCHAR,"
- "status VARCHAR,"
- "name_on_card VARCHAR,"
- "type VARCHAR,"
- "last_four VARCHAR,"
- "exp_month INTEGER DEFAULT 0,"
- "exp_year INTEGER DEFAULT 0)")) {
- return false;
- }
- // Copy over the data from the original masked_credit_cards table.
- if (!db_->Execute("INSERT INTO masked_credit_cards_temp "
- "SELECT id, status, name_on_card, type, last_four, "
- "exp_month, exp_year "
- "FROM masked_credit_cards")) {
- return false;
- }
- // Delete the existing table and replace it with the contents of the
- // temporary table.
- if (!db_->Execute("DROP TABLE masked_credit_cards") ||
- !db_->Execute("ALTER TABLE masked_credit_cards_temp "
- "RENAME TO masked_credit_cards")) {
- return false;
- }
-
- return transaction.Commit();
-}
-
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698