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

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

Issue 772253003: Create an autofill Suggestion class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review 2 Created 6 years 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 <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 std::string encrypted_data; 130 std::string encrypted_data;
131 OSCrypt::EncryptString16(credit_card.GetRawInfo(CREDIT_CARD_NUMBER), 131 OSCrypt::EncryptString16(credit_card.GetRawInfo(CREDIT_CARD_NUMBER),
132 &encrypted_data); 132 &encrypted_data);
133 s->BindBlob(index++, encrypted_data.data(), 133 s->BindBlob(index++, encrypted_data.data(),
134 static_cast<int>(encrypted_data.length())); 134 static_cast<int>(encrypted_data.length()));
135 135
136 s->BindInt64(index++, Time::Now().ToTimeT()); 136 s->BindInt64(index++, Time::Now().ToTimeT());
137 s->BindString(index++, credit_card.origin()); 137 s->BindString(index++, credit_card.origin());
138 } 138 }
139 139
140 base::string16 UnencryptedCardFromColumn(const sql::Statement& s,
141 int column_index) {
142 base::string16 credit_card_number;
143 int encrypted_number_len = s.ColumnByteLength(column_index);
144 if (encrypted_number_len) {
145 std::string encrypted_number;
146 encrypted_number.resize(encrypted_number_len);
147 memcpy(&encrypted_number[0], s.ColumnBlob(column_index),
148 encrypted_number_len);
149 OSCrypt::DecryptString16(encrypted_number, &credit_card_number);
150 }
151 return credit_card_number;
152 }
153
140 scoped_ptr<CreditCard> CreditCardFromStatement(const sql::Statement& s) { 154 scoped_ptr<CreditCard> CreditCardFromStatement(const sql::Statement& s) {
141 scoped_ptr<CreditCard> credit_card(new CreditCard); 155 scoped_ptr<CreditCard> credit_card(new CreditCard);
142 156
143 int index = 0; 157 int index = 0;
144 credit_card->set_guid(s.ColumnString(index++)); 158 credit_card->set_guid(s.ColumnString(index++));
145 DCHECK(base::IsValidGUID(credit_card->guid())); 159 DCHECK(base::IsValidGUID(credit_card->guid()));
146 160
147 credit_card->SetRawInfo(CREDIT_CARD_NAME, s.ColumnString16(index++)); 161 credit_card->SetRawInfo(CREDIT_CARD_NAME, s.ColumnString16(index++));
148 credit_card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(index++)); 162 credit_card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(index++));
149 credit_card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, 163 credit_card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR,
150 s.ColumnString16(index++)); 164 s.ColumnString16(index++));
151 int encrypted_number_len = s.ColumnByteLength(index); 165 credit_card->SetRawInfo(CREDIT_CARD_NUMBER,
152 base::string16 credit_card_number; 166 UnencryptedCardFromColumn(s, index++));
153 if (encrypted_number_len) {
154 std::string encrypted_number;
155 encrypted_number.resize(encrypted_number_len);
156 memcpy(&encrypted_number[0], s.ColumnBlob(index++), encrypted_number_len);
157 OSCrypt::DecryptString16(encrypted_number, &credit_card_number);
158 } else {
159 index++;
160 }
161 credit_card->SetRawInfo(CREDIT_CARD_NUMBER, credit_card_number);
162 // Intentionally skip column 5, which stores the modification date. 167 // Intentionally skip column 5, which stores the modification date.
163 index++; 168 index++;
164 credit_card->set_origin(s.ColumnString(index++)); 169 credit_card->set_origin(s.ColumnString(index++));
165 170
166 return credit_card.Pass(); 171 return credit_card.Pass();
167 } 172 }
168 173
169 // Obsolete version of AddAutofillProfileNamesToProfile, but still needed 174 // Obsolete version of AddAutofillProfileNamesToProfile, but still needed
170 // for MigrateToVersion37MergeAndCullOlderProfiles(). 175 // for MigrateToVersion37MergeAndCullOlderProfiles().
171 bool AddAutofillProfileNamesToProfileForVersion37(sql::Connection* db, 176 bool AddAutofillProfileNamesToProfileForVersion37(sql::Connection* db,
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 std::string guid = s.ColumnString(0); 1084 std::string guid = s.ColumnString(0);
1080 CreditCard* credit_card = NULL; 1085 CreditCard* credit_card = NULL;
1081 if (!GetCreditCard(guid, &credit_card)) 1086 if (!GetCreditCard(guid, &credit_card))
1082 return false; 1087 return false;
1083 credit_cards->push_back(credit_card); 1088 credit_cards->push_back(credit_card);
1084 } 1089 }
1085 1090
1086 return s.Succeeded(); 1091 return s.Succeeded();
1087 } 1092 }
1088 1093
1094 bool AutofillTable::GetWalletCreditCards(
1095 std::vector<CreditCard*>* credit_cards) {
1096 credit_cards->clear();
1097
1098 sql::Statement s(db_->GetUniqueStatement(
1099 "SELECT "
1100 "card_number_encrypted, " // 0
1101 "last_four," // 1
1102 "masked.id," // 2
1103 "status," // 3
1104 "name_on_card," // 4
1105 "exp_month," // 6
1106 "exp_year " // 7
1107 "FROM masked_credit_cards masked JOIN unmasked_credit_cards unmasked "
1108 "ON masked.id = unmasked.id"));
1109 while (s.Step()) {
1110 int index = 0;
1111
1112 // If the card_number_encrypted field is nonempty, we can assume this card
1113 // is a full card, otherwise it's masked.
1114 base::string16 card_number = UnencryptedCardFromColumn(s, index++);
1115 CreditCard::RecordType type;
1116 if (card_number.empty()) {
1117 // Empty full number field, assume masked card and just use 4 digits.
1118 type = CreditCard::MASKED_WALLET_CARD;
1119 card_number = s.ColumnString16(index++);
Evan Stade 2014/12/10 23:11:14 I think this would be slightly easier to follow if
1120 } else {
1121 type = CreditCard::FULL_WALLET_CARD;
1122 index++; // Skip last_four field since we have a full number.
1123 }
1124 std::string wallet_id = s.ColumnString(index++);
1125
1126 CreditCard* card = new CreditCard(wallet_id, type);
1127 card->SetRawInfo(CREDIT_CARD_NUMBER, card_number);
1128
1129 index++; // TODO(brettw) hook up status. For now, skip over it.
1130 card->SetRawInfo(CREDIT_CARD_NAME, s.ColumnString16(index++));
1131 card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(index++));
1132 card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(index++));
1133 credit_cards->push_back(card);
1134 }
1135 return s.Succeeded();
1136 }
1137
1138 void AutofillTable::UnmaskWalletCreditCard(const std::string& id,
1139 const base::string16& full_number) {
1140 // Make sure there aren't duplicates for this card.
1141 MaskWalletCreditCard(id);
1142 sql::Statement s(db_->GetUniqueStatement(
1143 "INSERT INTO unmasked_credit_cards(id, card_number_encrypted) "
1144 "VALUES (?,?)"));
1145 s.BindString(0, id);
1146
1147 std::string encrypted_data;
1148 OSCrypt::EncryptString16(full_number, &encrypted_data);
1149 s.BindBlob(1, encrypted_data.data(),
1150 static_cast<int>(encrypted_data.length()));
1151
1152 s.Run();
1153 }
1154
1155 void AutofillTable::MaskWalletCreditCard(const std::string& id) {
1156 sql::Statement s(db_->GetUniqueStatement(
1157 "DELETE FROM unmasked_credit_cards WHERE id = ?"));
1158 s.BindString(0, id);
1159 s.Run();
1160 }
1161
1089 bool AutofillTable::UpdateCreditCard(const CreditCard& credit_card) { 1162 bool AutofillTable::UpdateCreditCard(const CreditCard& credit_card) {
1090 DCHECK(base::IsValidGUID(credit_card.guid())); 1163 DCHECK(base::IsValidGUID(credit_card.guid()));
1091 1164
1092 CreditCard* tmp_credit_card = NULL; 1165 CreditCard* tmp_credit_card = NULL;
1093 if (!GetCreditCard(credit_card.guid(), &tmp_credit_card)) 1166 if (!GetCreditCard(credit_card.guid(), &tmp_credit_card))
1094 return false; 1167 return false;
1095 1168
1096 // Preserve appropriate modification dates by not updating unchanged cards. 1169 // Preserve appropriate modification dates by not updating unchanged cards.
1097 scoped_ptr<CreditCard> old_credit_card(tmp_credit_card); 1170 scoped_ptr<CreditCard> old_credit_card(tmp_credit_card);
1098 if (*old_credit_card == credit_card) 1171 if (*old_credit_card == credit_card)
(...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after
2413 "ADD COLUMN full_name VARCHAR"); 2486 "ADD COLUMN full_name VARCHAR");
2414 } 2487 }
2415 2488
2416 bool AutofillTable::MigrateToVersion60AddServerCards() { 2489 bool AutofillTable::MigrateToVersion60AddServerCards() {
2417 return InitMaskedCreditCardsTable() && 2490 return InitMaskedCreditCardsTable() &&
2418 InitUnmaskedCreditCardsTable() && 2491 InitUnmaskedCreditCardsTable() &&
2419 InitServerAddressesTable(); 2492 InitServerAddressesTable();
2420 } 2493 }
2421 2494
2422 } // namespace autofill 2495 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698