OLD | NEW |
---|---|
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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 index++; | 160 index++; |
161 } | 161 } |
162 credit_card->SetRawInfo(CREDIT_CARD_NUMBER, credit_card_number); | 162 credit_card->SetRawInfo(CREDIT_CARD_NUMBER, credit_card_number); |
163 // Intentionally skip column 5, which stores the modification date. | 163 // Intentionally skip column 5, which stores the modification date. |
164 index++; | 164 index++; |
165 credit_card->set_origin(s.ColumnString(index++)); | 165 credit_card->set_origin(s.ColumnString(index++)); |
166 | 166 |
167 return credit_card.Pass(); | 167 return credit_card.Pass(); |
168 } | 168 } |
169 | 169 |
170 // Obsolete version of AddAutofillProfileNamesToProfile, but still needed | |
171 // for MigrateToVersion37MergeAndCullOlderProfiles(). | |
172 bool AddAutofillProfileNamesToProfileForVersion37(sql::Connection* db, | |
173 AutofillProfile* profile) { | |
174 sql::Statement s(db->GetUniqueStatement( | |
175 "SELECT guid, first_name, middle_name, last_name " | |
176 "FROM autofill_profile_names " | |
177 "WHERE guid=?")); | |
178 s.BindString(0, profile->guid()); | |
179 | |
180 if (!s.is_valid()) | |
181 return false; | |
182 | |
183 std::vector<base::string16> first_names; | |
184 std::vector<base::string16> middle_names; | |
185 std::vector<base::string16> last_names; | |
186 while (s.Step()) { | |
187 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | |
188 first_names.push_back(s.ColumnString16(1)); | |
189 middle_names.push_back(s.ColumnString16(2)); | |
190 last_names.push_back(s.ColumnString16(3)); | |
191 } | |
192 if (!s.Succeeded()) | |
193 return false; | |
194 | |
195 profile->SetRawMultiInfo(NAME_FIRST, first_names); | |
196 profile->SetRawMultiInfo(NAME_MIDDLE, middle_names); | |
197 profile->SetRawMultiInfo(NAME_LAST, last_names); | |
198 return true; | |
199 } | |
200 | |
170 bool AddAutofillProfileNamesToProfile(sql::Connection* db, | 201 bool AddAutofillProfileNamesToProfile(sql::Connection* db, |
171 AutofillProfile* profile) { | 202 AutofillProfile* profile) { |
172 sql::Statement s(db->GetUniqueStatement( | 203 sql::Statement s(db->GetUniqueStatement( |
173 "SELECT guid, first_name, middle_name, last_name " | 204 "SELECT guid, first_name, middle_name, last_name, full_name " |
174 "FROM autofill_profile_names " | 205 "FROM autofill_profile_names " |
175 "WHERE guid=?")); | 206 "WHERE guid=?")); |
176 s.BindString(0, profile->guid()); | 207 s.BindString(0, profile->guid()); |
177 | 208 |
178 if (!s.is_valid()) | 209 if (!s.is_valid()) |
179 return false; | 210 return false; |
180 | 211 |
181 std::vector<base::string16> first_names; | 212 std::vector<base::string16> first_names; |
182 std::vector<base::string16> middle_names; | 213 std::vector<base::string16> middle_names; |
183 std::vector<base::string16> last_names; | 214 std::vector<base::string16> last_names; |
215 std::vector<base::string16> full_names; | |
184 while (s.Step()) { | 216 while (s.Step()) { |
185 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 217 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
186 first_names.push_back(s.ColumnString16(1)); | 218 first_names.push_back(s.ColumnString16(1)); |
187 middle_names.push_back(s.ColumnString16(2)); | 219 middle_names.push_back(s.ColumnString16(2)); |
188 last_names.push_back(s.ColumnString16(3)); | 220 last_names.push_back(s.ColumnString16(3)); |
221 full_names.push_back(s.ColumnString16(4)); | |
189 } | 222 } |
190 if (!s.Succeeded()) | 223 if (!s.Succeeded()) |
191 return false; | 224 return false; |
192 | 225 |
193 profile->SetRawMultiInfo(NAME_FIRST, first_names); | 226 profile->SetRawMultiInfo(NAME_FIRST, first_names); |
194 profile->SetRawMultiInfo(NAME_MIDDLE, middle_names); | 227 profile->SetRawMultiInfo(NAME_MIDDLE, middle_names); |
195 profile->SetRawMultiInfo(NAME_LAST, last_names); | 228 profile->SetRawMultiInfo(NAME_LAST, last_names); |
229 profile->SetRawMultiInfo(NAME_FULL, full_names); | |
196 return true; | 230 return true; |
197 } | 231 } |
198 | 232 |
199 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, | 233 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, |
200 AutofillProfile* profile) { | 234 AutofillProfile* profile) { |
201 sql::Statement s(db->GetUniqueStatement( | 235 sql::Statement s(db->GetUniqueStatement( |
202 "SELECT guid, email " | 236 "SELECT guid, email " |
203 "FROM autofill_profile_emails " | 237 "FROM autofill_profile_emails " |
204 "WHERE guid=?")); | 238 "WHERE guid=?")); |
205 s.BindString(0, profile->guid()); | 239 s.BindString(0, profile->guid()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 } | 277 } |
244 | 278 |
245 bool AddAutofillProfileNames(const AutofillProfile& profile, | 279 bool AddAutofillProfileNames(const AutofillProfile& profile, |
246 sql::Connection* db) { | 280 sql::Connection* db) { |
247 std::vector<base::string16> first_names; | 281 std::vector<base::string16> first_names; |
248 profile.GetRawMultiInfo(NAME_FIRST, &first_names); | 282 profile.GetRawMultiInfo(NAME_FIRST, &first_names); |
249 std::vector<base::string16> middle_names; | 283 std::vector<base::string16> middle_names; |
250 profile.GetRawMultiInfo(NAME_MIDDLE, &middle_names); | 284 profile.GetRawMultiInfo(NAME_MIDDLE, &middle_names); |
251 std::vector<base::string16> last_names; | 285 std::vector<base::string16> last_names; |
252 profile.GetRawMultiInfo(NAME_LAST, &last_names); | 286 profile.GetRawMultiInfo(NAME_LAST, &last_names); |
287 std::vector<base::string16> full_names; | |
288 profile.GetRawMultiInfo(NAME_FULL, &full_names); | |
253 DCHECK_EQ(first_names.size(), middle_names.size()); | 289 DCHECK_EQ(first_names.size(), middle_names.size()); |
254 DCHECK_EQ(middle_names.size(), last_names.size()); | 290 DCHECK_EQ(first_names.size(), last_names.size()); |
291 DCHECK_EQ(first_names.size(), full_names.size()); | |
255 | 292 |
256 for (size_t i = 0; i < first_names.size(); ++i) { | 293 for (size_t i = 0; i < first_names.size(); ++i) { |
294 bool has_full_name = | |
295 db->DoesColumnExist("autofill_profile_names", "full_name"); | |
Scott Hess - ex-Googler
2014/06/09 21:50:50
Sigh - digging around, I don't see a reasonable ch
Evan Stade
2014/06/12 01:55:32
Done.
| |
296 | |
257 // Add the new name. | 297 // Add the new name. |
258 sql::Statement s(db->GetUniqueStatement( | 298 sql::Statement s; |
259 "INSERT INTO autofill_profile_names" | 299 if (has_full_name) { |
260 " (guid, first_name, middle_name, last_name) " | 300 s.Assign(db->GetUniqueStatement( |
261 "VALUES (?,?,?,?)")); | 301 "INSERT INTO autofill_profile_names" |
302 " (guid, first_name, middle_name, last_name, full_name) " | |
303 "VALUES (?,?,?,?,?)")); | |
304 } else { | |
305 s.Assign(db->GetUniqueStatement( | |
306 "INSERT INTO autofill_profile_names" | |
307 " (guid, first_name, middle_name, last_name) " | |
308 "VALUES (?,?,?,?)")); | |
309 } | |
262 s.BindString(0, profile.guid()); | 310 s.BindString(0, profile.guid()); |
263 s.BindString16(1, first_names[i]); | 311 s.BindString16(1, first_names[i]); |
264 s.BindString16(2, middle_names[i]); | 312 s.BindString16(2, middle_names[i]); |
265 s.BindString16(3, last_names[i]); | 313 s.BindString16(3, last_names[i]); |
266 | 314 |
315 if (has_full_name) | |
316 s.BindString16(4, full_names[i]); | |
317 | |
267 if (!s.Run()) | 318 if (!s.Run()) |
268 return false; | 319 return false; |
269 } | 320 } |
270 return true; | 321 return true; |
271 } | 322 } |
272 | 323 |
273 bool AddAutofillProfileEmails(const AutofillProfile& profile, | 324 bool AddAutofillProfileEmails(const AutofillProfile& profile, |
274 sql::Connection* db) { | 325 sql::Connection* db) { |
275 std::vector<base::string16> emails; | 326 std::vector<base::string16> emails; |
276 profile.GetRawMultiInfo(EMAIL_ADDRESS, &emails); | 327 profile.GetRawMultiInfo(EMAIL_ADDRESS, &emails); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 return MigrateToVersion51AddOriginColumn(); | 491 return MigrateToVersion51AddOriginColumn(); |
441 case 54: | 492 case 54: |
442 *update_compatible_version = true; | 493 *update_compatible_version = true; |
443 return MigrateToVersion54AddI18nFieldsAndRemoveDeprecatedFields(); | 494 return MigrateToVersion54AddI18nFieldsAndRemoveDeprecatedFields(); |
444 case 55: | 495 case 55: |
445 *update_compatible_version = true; | 496 *update_compatible_version = true; |
446 return MigrateToVersion55MergeAutofillDatesTable(); | 497 return MigrateToVersion55MergeAutofillDatesTable(); |
447 case 56: | 498 case 56: |
448 *update_compatible_version = true; | 499 *update_compatible_version = true; |
449 return MigrateToVersion56AddProfileLanguageCodeForFormatting(); | 500 return MigrateToVersion56AddProfileLanguageCodeForFormatting(); |
501 case 57: | |
502 *update_compatible_version = true; | |
503 return MigrateToVersion57AddFullNameField(); | |
450 } | 504 } |
451 return true; | 505 return true; |
452 } | 506 } |
453 | 507 |
454 bool AutofillTable::AddFormFieldValues( | 508 bool AutofillTable::AddFormFieldValues( |
455 const std::vector<FormFieldData>& elements, | 509 const std::vector<FormFieldData>& elements, |
456 std::vector<AutofillChange>* changes) { | 510 std::vector<AutofillChange>* changes) { |
457 return AddFormFieldValuesTime(elements, changes, Time::Now()); | 511 return AddFormFieldValuesTime(elements, changes, Time::Now()); |
458 } | 512 } |
459 | 513 |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1285 } | 1339 } |
1286 return true; | 1340 return true; |
1287 } | 1341 } |
1288 | 1342 |
1289 bool AutofillTable::InitProfileNamesTable() { | 1343 bool AutofillTable::InitProfileNamesTable() { |
1290 if (!db_->DoesTableExist("autofill_profile_names")) { | 1344 if (!db_->DoesTableExist("autofill_profile_names")) { |
1291 if (!db_->Execute("CREATE TABLE autofill_profile_names ( " | 1345 if (!db_->Execute("CREATE TABLE autofill_profile_names ( " |
1292 "guid VARCHAR, " | 1346 "guid VARCHAR, " |
1293 "first_name VARCHAR, " | 1347 "first_name VARCHAR, " |
1294 "middle_name VARCHAR, " | 1348 "middle_name VARCHAR, " |
1295 "last_name VARCHAR)")) { | 1349 "last_name VARCHAR, " |
1350 "full_name VARCHAR)")) { | |
1296 NOTREACHED(); | 1351 NOTREACHED(); |
1297 return false; | 1352 return false; |
1298 } | 1353 } |
1299 } | 1354 } |
1300 return true; | 1355 return true; |
1301 } | 1356 } |
1302 | 1357 |
1303 bool AutofillTable::InitProfileEmailsTable() { | 1358 bool AutofillTable::InitProfileEmailsTable() { |
1304 if (!db_->DoesTableExist("autofill_profile_emails")) { | 1359 if (!db_->DoesTableExist("autofill_profile_emails")) { |
1305 if (!db_->Execute("CREATE TABLE autofill_profile_emails ( " | 1360 if (!db_->Execute("CREATE TABLE autofill_profile_emails ( " |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1998 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++)); | 2053 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++)); |
1999 // Intentionally skip column 7, which stores the localized country name. | 2054 // Intentionally skip column 7, which stores the localized country name. |
2000 index++; | 2055 index++; |
2001 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++)); | 2056 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++)); |
2002 // Intentionally skip column 9, which stores the profile's modification | 2057 // Intentionally skip column 9, which stores the profile's modification |
2003 // date. | 2058 // date. |
2004 index++; | 2059 index++; |
2005 profile->set_origin(s.ColumnString(index++)); | 2060 profile->set_origin(s.ColumnString(index++)); |
2006 | 2061 |
2007 // Get associated name info. | 2062 // Get associated name info. |
2008 AddAutofillProfileNamesToProfile(db_, profile.get()); | 2063 AddAutofillProfileNamesToProfileForVersion37(db_, profile.get()); |
2009 | 2064 |
2010 // Get associated email info. | 2065 // Get associated email info. |
2011 AddAutofillProfileEmailsToProfile(db_, profile.get()); | 2066 AddAutofillProfileEmailsToProfile(db_, profile.get()); |
2012 | 2067 |
2013 // Get associated phone info. | 2068 // Get associated phone info. |
2014 AddAutofillProfilePhonesToProfile(db_, profile.get()); | 2069 AddAutofillProfilePhonesToProfile(db_, profile.get()); |
2015 | 2070 |
2016 if (PersonalDataManager::IsValidLearnableProfile(*profile, app_locale_)) { | 2071 if (PersonalDataManager::IsValidLearnableProfile(*profile, app_locale_)) { |
2017 std::vector<AutofillProfile> merged_profiles; | 2072 std::vector<AutofillProfile> merged_profiles; |
2018 std::string merged_guid = PersonalDataManager::MergeProfile( | 2073 std::string merged_guid = PersonalDataManager::MergeProfile( |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2265 | 2320 |
2266 | 2321 |
2267 return transaction.Commit(); | 2322 return transaction.Commit(); |
2268 } | 2323 } |
2269 | 2324 |
2270 bool AutofillTable::MigrateToVersion56AddProfileLanguageCodeForFormatting() { | 2325 bool AutofillTable::MigrateToVersion56AddProfileLanguageCodeForFormatting() { |
2271 return db_->Execute("ALTER TABLE autofill_profiles " | 2326 return db_->Execute("ALTER TABLE autofill_profiles " |
2272 "ADD COLUMN language_code VARCHAR"); | 2327 "ADD COLUMN language_code VARCHAR"); |
2273 } | 2328 } |
2274 | 2329 |
2330 bool AutofillTable::MigrateToVersion57AddFullNameField() { | |
2331 return db_->Execute("ALTER TABLE autofill_profile_names " | |
2332 "ADD COLUMN full_name VARCHAR"); | |
2333 } | |
2334 | |
2275 } // namespace autofill | 2335 } // namespace autofill |
OLD | NEW |