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

Side by Side Diff: components/autofill/core/browser/webdata/autofill_table.cc

Issue 2711543002: Experiment to add bank name in autofill ui. (Closed)
Patch Set: Experiment to add bank name in autofill ui. Created 3 years, 5 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 unified diff | Download patch
OLDNEW
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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 credit_card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, 186 credit_card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR,
187 s.ColumnString16(index++)); 187 s.ColumnString16(index++));
188 credit_card->SetRawInfo(CREDIT_CARD_NUMBER, 188 credit_card->SetRawInfo(CREDIT_CARD_NUMBER,
189 UnencryptedCardFromColumn(s, index++, encryptor)); 189 UnencryptedCardFromColumn(s, index++, encryptor));
190 credit_card->set_use_count(s.ColumnInt64(index++)); 190 credit_card->set_use_count(s.ColumnInt64(index++));
191 credit_card->set_use_date(base::Time::FromTimeT(s.ColumnInt64(index++))); 191 credit_card->set_use_date(base::Time::FromTimeT(s.ColumnInt64(index++)));
192 credit_card->set_modification_date( 192 credit_card->set_modification_date(
193 base::Time::FromTimeT(s.ColumnInt64(index++))); 193 base::Time::FromTimeT(s.ColumnInt64(index++)));
194 credit_card->set_origin(s.ColumnString(index++)); 194 credit_card->set_origin(s.ColumnString(index++));
195 credit_card->set_billing_address_id(s.ColumnString(index++)); 195 credit_card->set_billing_address_id(s.ColumnString(index++));
196 credit_card->set_bank_name(s.ColumnString(index++));
196 197
197 return credit_card; 198 return credit_card;
198 } 199 }
199 200
200 bool AddAutofillProfileNamesToProfile(sql::Connection* db, 201 bool AddAutofillProfileNamesToProfile(sql::Connection* db,
201 AutofillProfile* profile) { 202 AutofillProfile* profile) {
202 // TODO(estade): update schema so that multiple names are not associated per 203 // TODO(estade): update schema so that multiple names are not associated per
203 // unique profile guid. Please refer https://crbug.com/497934. 204 // unique profile guid. Please refer https://crbug.com/497934.
204 sql::Statement s(db->GetUniqueStatement( 205 sql::Statement s(db->GetUniqueStatement(
205 "SELECT guid, first_name, middle_name, last_name, full_name " 206 "SELECT guid, first_name, middle_name, last_name, full_name "
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 return MigrateToVersion67AddMaskedCardBillingAddress(); 466 return MigrateToVersion67AddMaskedCardBillingAddress();
466 case 70: 467 case 70:
467 *update_compatible_version = false; 468 *update_compatible_version = false;
468 return MigrateToVersion70AddSyncMetadata(); 469 return MigrateToVersion70AddSyncMetadata();
469 case 71: 470 case 71:
470 *update_compatible_version = true; 471 *update_compatible_version = true;
471 return MigrateToVersion71AddHasConvertedAndBillingAddressIdMetadata(); 472 return MigrateToVersion71AddHasConvertedAndBillingAddressIdMetadata();
472 case 72: 473 case 72:
473 *update_compatible_version = true; 474 *update_compatible_version = true;
474 return MigrateToVersion72RenameCardTypeToIssuerNetwork(); 475 return MigrateToVersion72RenameCardTypeToIssuerNetwork();
476 case 73:
477 *update_compatible_version = false;
478 return MigrateToVersion73AddMaskedCardBankName();
475 } 479 }
476 return true; 480 return true;
477 } 481 }
478 482
479 bool AutofillTable::AddFormFieldValues( 483 bool AutofillTable::AddFormFieldValues(
480 const std::vector<FormFieldData>& elements, 484 const std::vector<FormFieldData>& elements,
481 std::vector<AutofillChange>* changes) { 485 std::vector<AutofillChange>* changes) {
482 return AddFormFieldValuesTime(elements, changes, AutofillClock::Now()); 486 return AddFormFieldValuesTime(elements, changes, AutofillClock::Now());
483 } 487 }
484 488
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 "card_number_encrypted, " // 0 1216 "card_number_encrypted, " // 0
1213 "last_four," // 1 1217 "last_four," // 1
1214 "masked.id," // 2 1218 "masked.id," // 2
1215 "metadata.use_count," // 3 1219 "metadata.use_count," // 3
1216 "metadata.use_date," // 4 1220 "metadata.use_date," // 4
1217 "network," // 5 1221 "network," // 5
1218 "status," // 6 1222 "status," // 6
1219 "name_on_card," // 7 1223 "name_on_card," // 7
1220 "exp_month," // 8 1224 "exp_month," // 8
1221 "exp_year," // 9 1225 "exp_year," // 9
1222 "metadata.billing_address_id " // 10 1226 "metadata.billing_address_id," // 10
1227 "bank_name " // 11
1223 "FROM masked_credit_cards masked " 1228 "FROM masked_credit_cards masked "
1224 "LEFT OUTER JOIN unmasked_credit_cards USING (id) " 1229 "LEFT OUTER JOIN unmasked_credit_cards USING (id) "
1225 "LEFT OUTER JOIN server_card_metadata metadata USING (id)")); 1230 "LEFT OUTER JOIN server_card_metadata metadata USING (id)"));
1226 while (s.Step()) { 1231 while (s.Step()) {
1227 int index = 0; 1232 int index = 0;
1228 1233
1229 // If the card_number_encrypted field is nonempty, we can assume this card 1234 // If the card_number_encrypted field is nonempty, we can assume this card
1230 // is a full card, otherwise it's masked. 1235 // is a full card, otherwise it's masked.
1231 base::string16 full_card_number = 1236 base::string16 full_card_number =
1232 UnencryptedCardFromColumn(s, index++, *autofill_table_encryptor_); 1237 UnencryptedCardFromColumn(s, index++, *autofill_table_encryptor_);
(...skipping 21 matching lines...) Expand all
1254 card->SetNetworkForMaskedCard(card_network.c_str()); 1259 card->SetNetworkForMaskedCard(card_network.c_str());
1255 } else { 1260 } else {
1256 DCHECK_EQ(CreditCard::GetCardNetwork(full_card_number), card_network); 1261 DCHECK_EQ(CreditCard::GetCardNetwork(full_card_number), card_network);
1257 } 1262 }
1258 1263
1259 card->SetServerStatus(ServerStatusStringToEnum(s.ColumnString(index++))); 1264 card->SetServerStatus(ServerStatusStringToEnum(s.ColumnString(index++)));
1260 card->SetRawInfo(CREDIT_CARD_NAME_FULL, s.ColumnString16(index++)); 1265 card->SetRawInfo(CREDIT_CARD_NAME_FULL, s.ColumnString16(index++));
1261 card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(index++)); 1266 card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(index++));
1262 card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(index++)); 1267 card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(index++));
1263 card->set_billing_address_id(s.ColumnString(index++)); 1268 card->set_billing_address_id(s.ColumnString(index++));
1269 card->set_bank_name(s.ColumnString(index++));
1264 credit_cards->push_back(std::move(card)); 1270 credit_cards->push_back(std::move(card));
1265 } 1271 }
1266 return s.Succeeded(); 1272 return s.Succeeded();
1267 } 1273 }
1268 1274
1269 void AutofillTable::AddMaskedCreditCards( 1275 void AutofillTable::AddMaskedCreditCards(
1270 const std::vector<CreditCard>& credit_cards) { 1276 const std::vector<CreditCard>& credit_cards) {
1271 DCHECK_GT(db_->transaction_nesting(), 0); 1277 DCHECK_GT(db_->transaction_nesting(), 0);
1272 sql::Statement masked_insert( 1278 sql::Statement masked_insert(
1273 db_->GetUniqueStatement("INSERT INTO masked_credit_cards(" 1279 db_->GetUniqueStatement("INSERT INTO masked_credit_cards("
1274 "id," // 0 1280 "id," // 0
1275 "network," // 1 1281 "network," // 1
1276 "status," // 2 1282 "status," // 2
1277 "name_on_card," // 3 1283 "name_on_card," // 3
1278 "last_four," // 4 1284 "last_four," // 4
1279 "exp_month," // 5 1285 "exp_month," // 5
1280 "exp_year)" // 6 1286 "exp_year," // 6
1281 "VALUES (?,?,?,?,?,?,?)")); 1287 "bank_name)" // 7
1288 "VALUES (?,?,?,?,?,?,?,?)"));
1282 for (const CreditCard& card : credit_cards) { 1289 for (const CreditCard& card : credit_cards) {
1283 DCHECK_EQ(CreditCard::MASKED_SERVER_CARD, card.record_type()); 1290 DCHECK_EQ(CreditCard::MASKED_SERVER_CARD, card.record_type());
1284 masked_insert.BindString(0, card.server_id()); 1291 masked_insert.BindString(0, card.server_id());
1285 masked_insert.BindString(1, card.network()); 1292 masked_insert.BindString(1, card.network());
1286 masked_insert.BindString(2, 1293 masked_insert.BindString(2,
1287 ServerStatusEnumToString(card.GetServerStatus())); 1294 ServerStatusEnumToString(card.GetServerStatus()));
1288 masked_insert.BindString16(3, card.GetRawInfo(CREDIT_CARD_NAME_FULL)); 1295 masked_insert.BindString16(3, card.GetRawInfo(CREDIT_CARD_NAME_FULL));
1289 masked_insert.BindString16(4, card.LastFourDigits()); 1296 masked_insert.BindString16(4, card.LastFourDigits());
1290 masked_insert.BindString16(5, card.GetRawInfo(CREDIT_CARD_EXP_MONTH)); 1297 masked_insert.BindString16(5, card.GetRawInfo(CREDIT_CARD_EXP_MONTH));
1291 masked_insert.BindString16(6, 1298 masked_insert.BindString16(6,
1292 card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); 1299 card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR));
1293 1300 masked_insert.BindString(7, card.bank_name());
1294 masked_insert.Run(); 1301 masked_insert.Run();
1295 masked_insert.Reset(true); 1302 masked_insert.Reset(true);
1296 1303
1297 // Save the use count and use date of the card. 1304 // Save the use count and use date of the card.
1298 UpdateServerCardMetadata(card); 1305 UpdateServerCardMetadata(card);
1299 } 1306 }
1300 } 1307 }
1301 1308
1302 void AutofillTable::SetServerCreditCards( 1309 void AutofillTable::SetServerCreditCards(
1303 const std::vector<CreditCard>& credit_cards) { 1310 const std::vector<CreditCard>& credit_cards) {
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 1956
1950 bool AutofillTable::InitMaskedCreditCardsTable() { 1957 bool AutofillTable::InitMaskedCreditCardsTable() {
1951 if (!db_->DoesTableExist("masked_credit_cards")) { 1958 if (!db_->DoesTableExist("masked_credit_cards")) {
1952 if (!db_->Execute("CREATE TABLE masked_credit_cards (" 1959 if (!db_->Execute("CREATE TABLE masked_credit_cards ("
1953 "id VARCHAR," 1960 "id VARCHAR,"
1954 "status VARCHAR," 1961 "status VARCHAR,"
1955 "name_on_card VARCHAR," 1962 "name_on_card VARCHAR,"
1956 "network VARCHAR," 1963 "network VARCHAR,"
1957 "last_four VARCHAR," 1964 "last_four VARCHAR,"
1958 "exp_month INTEGER DEFAULT 0," 1965 "exp_month INTEGER DEFAULT 0,"
1959 "exp_year INTEGER DEFAULT 0)")) { 1966 "exp_year INTEGER DEFAULT 0, "
1967 "bank_name VARCHAR)")) {
1960 NOTREACHED(); 1968 NOTREACHED();
1961 return false; 1969 return false;
1962 } 1970 }
1963 } 1971 }
1964 return true; 1972 return true;
1965 } 1973 }
1966 1974
1967 bool AutofillTable::InitUnmaskedCreditCardsTable() { 1975 bool AutofillTable::InitUnmaskedCreditCardsTable() {
1968 if (!db_->DoesTableExist("unmasked_credit_cards")) { 1976 if (!db_->DoesTableExist("unmasked_credit_cards")) {
1969 if (!db_->Execute("CREATE TABLE unmasked_credit_cards (" 1977 if (!db_->Execute("CREATE TABLE unmasked_credit_cards ("
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
2592 ") SELECT " 2600 ") SELECT "
2593 "id, status, name_on_card, type, last_four, exp_month, exp_year" 2601 "id, status, name_on_card, type, last_four, exp_month, exp_year"
2594 " FROM masked_credit_cards") && 2602 " FROM masked_credit_cards") &&
2595 db_->Execute("DROP TABLE masked_credit_cards") && 2603 db_->Execute("DROP TABLE masked_credit_cards") &&
2596 db_->Execute( 2604 db_->Execute(
2597 "ALTER TABLE masked_credit_cards_temp " 2605 "ALTER TABLE masked_credit_cards_temp "
2598 "RENAME TO masked_credit_cards") && 2606 "RENAME TO masked_credit_cards") &&
2599 transaction.Commit(); 2607 transaction.Commit();
2600 } 2608 }
2601 2609
2610 bool AutofillTable::MigrateToVersion73AddMaskedCardBankName() {
2611 sql::Transaction transaction(db_);
2612 if (!transaction.Begin())
2613 return false;
2614
2615 // Add the new bank_name column to the masked_credit_cards table.
2616 if (!db_->DoesColumnExist("masked_credit_cards", "bank_name") &&
2617 !db_->Execute("ALTER TABLE masked_credit_cards ADD COLUMN "
2618 "bank_name VARCHAR")) {
2619 return false;
2620 }
2621
2622 return transaction.Commit();
2623 }
2624
2602 } // namespace autofill 2625 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698