| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 26 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 27 #include "components/autofill/core/browser/autofill_country.h" | 27 #include "components/autofill/core/browser/autofill_country.h" |
| 28 #include "components/autofill/core/browser/autofill_profile.h" | 28 #include "components/autofill/core/browser/autofill_profile.h" |
| 29 #include "components/autofill/core/browser/autofill_type.h" | 29 #include "components/autofill/core/browser/autofill_type.h" |
| 30 #include "components/autofill/core/browser/credit_card.h" | 30 #include "components/autofill/core/browser/credit_card.h" |
| 31 #include "components/autofill/core/browser/personal_data_manager.h" | 31 #include "components/autofill/core/browser/personal_data_manager.h" |
| 32 #include "components/autofill/core/browser/webdata/autofill_change.h" | 32 #include "components/autofill/core/browser/webdata/autofill_change.h" |
| 33 #include "components/autofill/core/browser/webdata/autofill_entry.h" | 33 #include "components/autofill/core/browser/webdata/autofill_entry.h" |
| 34 #include "components/autofill/core/common/autofill_clock.h" |
| 34 #include "components/autofill/core/common/autofill_switches.h" | 35 #include "components/autofill/core/common/autofill_switches.h" |
| 35 #include "components/autofill/core/common/autofill_util.h" | 36 #include "components/autofill/core/common/autofill_util.h" |
| 36 #include "components/autofill/core/common/form_field_data.h" | 37 #include "components/autofill/core/common/form_field_data.h" |
| 37 #include "components/os_crypt/os_crypt.h" | 38 #include "components/os_crypt/os_crypt.h" |
| 38 #include "components/sync/base/model_type.h" | 39 #include "components/sync/base/model_type.h" |
| 39 #include "components/sync/model/metadata_batch.h" | 40 #include "components/sync/model/metadata_batch.h" |
| 40 #include "components/sync/protocol/entity_metadata.pb.h" | 41 #include "components/sync/protocol/entity_metadata.pb.h" |
| 41 #include "components/sync/protocol/model_type_state.pb.h" | 42 #include "components/sync/protocol/model_type_state.pb.h" |
| 42 #include "components/webdata/common/web_database.h" | 43 #include "components/webdata/common/web_database.h" |
| 43 #include "sql/statement.h" | 44 #include "sql/statement.h" |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 case 71: | 475 case 71: |
| 475 *update_compatible_version = true; | 476 *update_compatible_version = true; |
| 476 return MigrateToVersion71AddHasConvertedAndBillingAddressIdMetadata(); | 477 return MigrateToVersion71AddHasConvertedAndBillingAddressIdMetadata(); |
| 477 } | 478 } |
| 478 return true; | 479 return true; |
| 479 } | 480 } |
| 480 | 481 |
| 481 bool AutofillTable::AddFormFieldValues( | 482 bool AutofillTable::AddFormFieldValues( |
| 482 const std::vector<FormFieldData>& elements, | 483 const std::vector<FormFieldData>& elements, |
| 483 std::vector<AutofillChange>* changes) { | 484 std::vector<AutofillChange>* changes) { |
| 484 return AddFormFieldValuesTime(elements, changes, Time::Now()); | 485 return AddFormFieldValuesTime(elements, changes, AutofillClock::Now()); |
| 485 } | 486 } |
| 486 | 487 |
| 487 bool AutofillTable::AddFormFieldValue(const FormFieldData& element, | 488 bool AutofillTable::AddFormFieldValue(const FormFieldData& element, |
| 488 std::vector<AutofillChange>* changes) { | 489 std::vector<AutofillChange>* changes) { |
| 489 return AddFormFieldValueTime(element, changes, Time::Now()); | 490 return AddFormFieldValueTime(element, changes, AutofillClock::Now()); |
| 490 } | 491 } |
| 491 | 492 |
| 492 bool AutofillTable::GetFormValuesForElementName( | 493 bool AutofillTable::GetFormValuesForElementName( |
| 493 const base::string16& name, | 494 const base::string16& name, |
| 494 const base::string16& prefix, | 495 const base::string16& prefix, |
| 495 std::vector<base::string16>* values, | 496 std::vector<base::string16>* values, |
| 496 int limit) { | 497 int limit) { |
| 497 DCHECK(values); | 498 DCHECK(values); |
| 498 bool succeeded = false; | 499 bool succeeded = false; |
| 499 | 500 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 if (!transaction.Commit()) | 668 if (!transaction.Commit()) |
| 668 return false; | 669 return false; |
| 669 | 670 |
| 670 *changes = tentative_changes; | 671 *changes = tentative_changes; |
| 671 return true; | 672 return true; |
| 672 } | 673 } |
| 673 | 674 |
| 674 bool AutofillTable::RemoveExpiredFormElements( | 675 bool AutofillTable::RemoveExpiredFormElements( |
| 675 std::vector<AutofillChange>* changes) { | 676 std::vector<AutofillChange>* changes) { |
| 676 Time expiration_time = | 677 Time expiration_time = |
| 677 Time::Now() - TimeDelta::FromDays(kExpirationPeriodInDays); | 678 AutofillClock::Now() - TimeDelta::FromDays(kExpirationPeriodInDays); |
| 678 | 679 |
| 679 // Query for the name and value of all form elements that were last used | 680 // Query for the name and value of all form elements that were last used |
| 680 // before the |expiration_time|. | 681 // before the |expiration_time|. |
| 681 sql::Statement select_for_delete(db_->GetUniqueStatement( | 682 sql::Statement select_for_delete(db_->GetUniqueStatement( |
| 682 "SELECT name, value FROM autofill WHERE date_last_used < ?")); | 683 "SELECT name, value FROM autofill WHERE date_last_used < ?")); |
| 683 select_for_delete.BindInt64(0, expiration_time.ToTimeT()); | 684 select_for_delete.BindInt64(0, expiration_time.ToTimeT()); |
| 684 std::vector<AutofillChange> tentative_changes; | 685 std::vector<AutofillChange> tentative_changes; |
| 685 while (select_for_delete.Step()) { | 686 while (select_for_delete.Step()) { |
| 686 base::string16 name = select_for_delete.ColumnString16(0); | 687 base::string16 name = select_for_delete.ColumnString16(0); |
| 687 base::string16 value = select_for_delete.ColumnString16(1); | 688 base::string16 value = select_for_delete.ColumnString16(1); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 bool AutofillTable::AddAutofillProfile(const AutofillProfile& profile) { | 880 bool AutofillTable::AddAutofillProfile(const AutofillProfile& profile) { |
| 880 if (IsAutofillGUIDInTrash(profile.guid())) | 881 if (IsAutofillGUIDInTrash(profile.guid())) |
| 881 return true; | 882 return true; |
| 882 | 883 |
| 883 sql::Statement s(db_->GetUniqueStatement( | 884 sql::Statement s(db_->GetUniqueStatement( |
| 884 "INSERT INTO autofill_profiles" | 885 "INSERT INTO autofill_profiles" |
| 885 "(guid, company_name, street_address, dependent_locality, city, state," | 886 "(guid, company_name, street_address, dependent_locality, city, state," |
| 886 " zipcode, sorting_code, country_code, use_count, use_date, " | 887 " zipcode, sorting_code, country_code, use_count, use_date, " |
| 887 " date_modified, origin, language_code)" | 888 " date_modified, origin, language_code)" |
| 888 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); | 889 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); |
| 889 BindAutofillProfileToStatement(profile, Time::Now(), &s); | 890 BindAutofillProfileToStatement(profile, AutofillClock::Now(), &s); |
| 890 | 891 |
| 891 if (!s.Run()) | 892 if (!s.Run()) |
| 892 return false; | 893 return false; |
| 893 | 894 |
| 894 return AddAutofillProfilePieces(profile, db_); | 895 return AddAutofillProfilePieces(profile, db_); |
| 895 } | 896 } |
| 896 | 897 |
| 897 std::unique_ptr<AutofillProfile> AutofillTable::GetAutofillProfile( | 898 std::unique_ptr<AutofillProfile> AutofillTable::GetAutofillProfile( |
| 898 const std::string& guid) { | 899 const std::string& guid) { |
| 899 DCHECK(base::IsValidGUID(guid)); | 900 DCHECK(base::IsValidGUID(guid)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 "LEFT OUTER JOIN server_address_metadata USING (id)")); | 970 "LEFT OUTER JOIN server_address_metadata USING (id)")); |
| 970 | 971 |
| 971 while (s.Step()) { | 972 while (s.Step()) { |
| 972 int index = 0; | 973 int index = 0; |
| 973 std::unique_ptr<AutofillProfile> profile = | 974 std::unique_ptr<AutofillProfile> profile = |
| 974 base::MakeUnique<AutofillProfile>(AutofillProfile::SERVER_PROFILE, | 975 base::MakeUnique<AutofillProfile>(AutofillProfile::SERVER_PROFILE, |
| 975 s.ColumnString(index++)); | 976 s.ColumnString(index++)); |
| 976 profile->set_use_count(s.ColumnInt64(index++)); | 977 profile->set_use_count(s.ColumnInt64(index++)); |
| 977 profile->set_use_date(Time::FromInternalValue(s.ColumnInt64(index++))); | 978 profile->set_use_date(Time::FromInternalValue(s.ColumnInt64(index++))); |
| 978 // Modification date is not tracked for server profiles. Explicitly set it | 979 // Modification date is not tracked for server profiles. Explicitly set it |
| 979 // here to override the default value of Time::Now(). | 980 // here to override the default value of AutofillClock::Now(). |
| 980 profile->set_modification_date(Time()); | 981 profile->set_modification_date(Time()); |
| 981 | 982 |
| 982 base::string16 recipient_name = s.ColumnString16(index++); | 983 base::string16 recipient_name = s.ColumnString16(index++); |
| 983 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(index++)); | 984 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(index++)); |
| 984 profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, s.ColumnString16(index++)); | 985 profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, s.ColumnString16(index++)); |
| 985 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(index++)); | 986 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(index++)); |
| 986 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(index++)); | 987 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(index++)); |
| 987 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, | 988 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, |
| 988 s.ColumnString16(index++)); | 989 s.ColumnString16(index++)); |
| 989 index++; // Skip address_4 which we haven't added to AutofillProfile yet. | 990 index++; // Skip address_4 which we haven't added to AutofillProfile yet. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 return false; | 1081 return false; |
| 1081 | 1082 |
| 1082 bool update_modification_date = *old_profile != profile; | 1083 bool update_modification_date = *old_profile != profile; |
| 1083 | 1084 |
| 1084 sql::Statement s(db_->GetUniqueStatement( | 1085 sql::Statement s(db_->GetUniqueStatement( |
| 1085 "UPDATE autofill_profiles " | 1086 "UPDATE autofill_profiles " |
| 1086 "SET guid=?, company_name=?, street_address=?, dependent_locality=?, " | 1087 "SET guid=?, company_name=?, street_address=?, dependent_locality=?, " |
| 1087 " city=?, state=?, zipcode=?, sorting_code=?, country_code=?, " | 1088 " city=?, state=?, zipcode=?, sorting_code=?, country_code=?, " |
| 1088 " use_count=?, use_date=?, date_modified=?, origin=?, language_code=? " | 1089 " use_count=?, use_date=?, date_modified=?, origin=?, language_code=? " |
| 1089 "WHERE guid=?")); | 1090 "WHERE guid=?")); |
| 1090 BindAutofillProfileToStatement( | 1091 BindAutofillProfileToStatement(profile, |
| 1091 profile, | 1092 update_modification_date |
| 1092 update_modification_date ? Time::Now() : old_profile->modification_date(), | 1093 ? AutofillClock::Now() |
| 1093 &s); | 1094 : old_profile->modification_date(), |
| 1095 &s); |
| 1094 s.BindString(14, profile.guid()); | 1096 s.BindString(14, profile.guid()); |
| 1095 | 1097 |
| 1096 bool result = s.Run(); | 1098 bool result = s.Run(); |
| 1097 DCHECK_GT(db_->GetLastChangeCount(), 0); | 1099 DCHECK_GT(db_->GetLastChangeCount(), 0); |
| 1098 if (!result) | 1100 if (!result) |
| 1099 return result; | 1101 return result; |
| 1100 | 1102 |
| 1101 // Remove the old names, emails, and phone numbers. | 1103 // Remove the old names, emails, and phone numbers. |
| 1102 if (!RemoveAutofillProfilePieces(profile.guid(), db_)) | 1104 if (!RemoveAutofillProfilePieces(profile.guid(), db_)) |
| 1103 return false; | 1105 return false; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1153 return s4.Run(); | 1155 return s4.Run(); |
| 1154 } | 1156 } |
| 1155 | 1157 |
| 1156 bool AutofillTable::AddCreditCard(const CreditCard& credit_card) { | 1158 bool AutofillTable::AddCreditCard(const CreditCard& credit_card) { |
| 1157 sql::Statement s(db_->GetUniqueStatement( | 1159 sql::Statement s(db_->GetUniqueStatement( |
| 1158 "INSERT INTO credit_cards" | 1160 "INSERT INTO credit_cards" |
| 1159 "(guid, name_on_card, expiration_month, expiration_year, " | 1161 "(guid, name_on_card, expiration_month, expiration_year, " |
| 1160 " card_number_encrypted, use_count, use_date, date_modified, origin," | 1162 " card_number_encrypted, use_count, use_date, date_modified, origin," |
| 1161 " billing_address_id)" | 1163 " billing_address_id)" |
| 1162 "VALUES (?,?,?,?,?,?,?,?,?,?)")); | 1164 "VALUES (?,?,?,?,?,?,?,?,?,?)")); |
| 1163 BindCreditCardToStatement(credit_card, Time::Now(), &s); | 1165 BindCreditCardToStatement(credit_card, AutofillClock::Now(), &s); |
| 1164 | 1166 |
| 1165 if (!s.Run()) | 1167 if (!s.Run()) |
| 1166 return false; | 1168 return false; |
| 1167 | 1169 |
| 1168 DCHECK_GT(db_->GetLastChangeCount(), 0); | 1170 DCHECK_GT(db_->GetLastChangeCount(), 0); |
| 1169 return true; | 1171 return true; |
| 1170 } | 1172 } |
| 1171 | 1173 |
| 1172 std::unique_ptr<CreditCard> AutofillTable::GetCreditCard( | 1174 std::unique_ptr<CreditCard> AutofillTable::GetCreditCard( |
| 1173 const std::string& guid) { | 1175 const std::string& guid) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 | 1243 |
| 1242 std::unique_ptr<CreditCard> card = | 1244 std::unique_ptr<CreditCard> card = |
| 1243 base::MakeUnique<CreditCard>(record_type, server_id); | 1245 base::MakeUnique<CreditCard>(record_type, server_id); |
| 1244 card->SetRawInfo( | 1246 card->SetRawInfo( |
| 1245 CREDIT_CARD_NUMBER, | 1247 CREDIT_CARD_NUMBER, |
| 1246 record_type == CreditCard::MASKED_SERVER_CARD ? last_four | 1248 record_type == CreditCard::MASKED_SERVER_CARD ? last_four |
| 1247 : full_card_number); | 1249 : full_card_number); |
| 1248 card->set_use_count(s.ColumnInt64(index++)); | 1250 card->set_use_count(s.ColumnInt64(index++)); |
| 1249 card->set_use_date(Time::FromInternalValue(s.ColumnInt64(index++))); | 1251 card->set_use_date(Time::FromInternalValue(s.ColumnInt64(index++))); |
| 1250 // Modification date is not tracked for server cards. Explicitly set it here | 1252 // Modification date is not tracked for server cards. Explicitly set it here |
| 1251 // to override the default value of Time::Now(). | 1253 // to override the default value of AutofillClock::Now(). |
| 1252 card->set_modification_date(Time()); | 1254 card->set_modification_date(Time()); |
| 1253 | 1255 |
| 1254 std::string card_type = s.ColumnString(index++); | 1256 std::string card_type = s.ColumnString(index++); |
| 1255 if (record_type == CreditCard::MASKED_SERVER_CARD) { | 1257 if (record_type == CreditCard::MASKED_SERVER_CARD) { |
| 1256 // The type must be set after setting the number to override the | 1258 // The type must be set after setting the number to override the |
| 1257 // autodetected type. | 1259 // autodetected type. |
| 1258 card->SetTypeForMaskedCard(card_type.c_str()); | 1260 card->SetTypeForMaskedCard(card_type.c_str()); |
| 1259 } else { | 1261 } else { |
| 1260 DCHECK_EQ(CreditCard::GetCreditCardType(full_card_number), card_type); | 1262 DCHECK_EQ(CreditCard::GetCreditCardType(full_card_number), card_type); |
| 1261 } | 1263 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1335 "id," | 1337 "id," |
| 1336 "card_number_encrypted," | 1338 "card_number_encrypted," |
| 1337 "unmask_date)" | 1339 "unmask_date)" |
| 1338 "VALUES (?,?,?)")); | 1340 "VALUES (?,?,?)")); |
| 1339 s.BindString(0, masked.server_id()); | 1341 s.BindString(0, masked.server_id()); |
| 1340 | 1342 |
| 1341 std::string encrypted_data; | 1343 std::string encrypted_data; |
| 1342 OSCrypt::EncryptString16(full_number, &encrypted_data); | 1344 OSCrypt::EncryptString16(full_number, &encrypted_data); |
| 1343 s.BindBlob(1, encrypted_data.data(), | 1345 s.BindBlob(1, encrypted_data.data(), |
| 1344 static_cast<int>(encrypted_data.length())); | 1346 static_cast<int>(encrypted_data.length())); |
| 1345 s.BindInt64(2, Time::Now().ToInternalValue()); // unmask_date | 1347 s.BindInt64(2, AutofillClock::Now().ToInternalValue()); // unmask_date |
| 1346 | 1348 |
| 1347 s.Run(); | 1349 s.Run(); |
| 1348 | 1350 |
| 1349 CreditCard unmasked = masked; | 1351 CreditCard unmasked = masked; |
| 1350 unmasked.set_record_type(CreditCard::FULL_SERVER_CARD); | 1352 unmasked.set_record_type(CreditCard::FULL_SERVER_CARD); |
| 1351 unmasked.SetNumber(full_number); | 1353 unmasked.SetNumber(full_number); |
| 1352 unmasked.RecordAndLogUse(); | 1354 unmasked.RecordAndLogUse(); |
| 1353 UpdateServerCardMetadata(unmasked); | 1355 UpdateServerCardMetadata(unmasked); |
| 1354 | 1356 |
| 1355 return db_->GetLastChangeCount() > 0; | 1357 return db_->GetLastChangeCount() > 0; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1462 return false; | 1464 return false; |
| 1463 | 1465 |
| 1464 bool update_modification_date = *old_credit_card != credit_card; | 1466 bool update_modification_date = *old_credit_card != credit_card; |
| 1465 | 1467 |
| 1466 sql::Statement s(db_->GetUniqueStatement( | 1468 sql::Statement s(db_->GetUniqueStatement( |
| 1467 "UPDATE credit_cards " | 1469 "UPDATE credit_cards " |
| 1468 "SET guid=?, name_on_card=?, expiration_month=?," | 1470 "SET guid=?, name_on_card=?, expiration_month=?," |
| 1469 "expiration_year=?, card_number_encrypted=?, use_count=?, use_date=?," | 1471 "expiration_year=?, card_number_encrypted=?, use_count=?, use_date=?," |
| 1470 "date_modified=?, origin=?, billing_address_id=?" | 1472 "date_modified=?, origin=?, billing_address_id=?" |
| 1471 "WHERE guid=?1")); | 1473 "WHERE guid=?1")); |
| 1472 BindCreditCardToStatement( | 1474 BindCreditCardToStatement(credit_card, |
| 1473 credit_card, | 1475 update_modification_date |
| 1474 update_modification_date ? Time::Now() : | 1476 ? AutofillClock::Now() |
| 1475 old_credit_card->modification_date(), | 1477 : old_credit_card->modification_date(), |
| 1476 &s); | 1478 &s); |
| 1477 | 1479 |
| 1478 bool result = s.Run(); | 1480 bool result = s.Run(); |
| 1479 DCHECK_GT(db_->GetLastChangeCount(), 0); | 1481 DCHECK_GT(db_->GetLastChangeCount(), 0); |
| 1480 return result; | 1482 return result; |
| 1481 } | 1483 } |
| 1482 | 1484 |
| 1483 bool AutofillTable::RemoveCreditCard(const std::string& guid) { | 1485 bool AutofillTable::RemoveCreditCard(const std::string& guid) { |
| 1484 DCHECK(base::IsValidGUID(guid)); | 1486 DCHECK(base::IsValidGUID(guid)); |
| 1485 sql::Statement s(db_->GetUniqueStatement( | 1487 sql::Statement s(db_->GetUniqueStatement( |
| 1486 "DELETE FROM credit_cards WHERE guid = ?")); | 1488 "DELETE FROM credit_cards WHERE guid = ?")); |
| (...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2521 if (!db_->Execute("DROP TABLE masked_credit_cards") || | 2523 if (!db_->Execute("DROP TABLE masked_credit_cards") || |
| 2522 !db_->Execute("ALTER TABLE masked_credit_cards_temp " | 2524 !db_->Execute("ALTER TABLE masked_credit_cards_temp " |
| 2523 "RENAME TO masked_credit_cards")) { | 2525 "RENAME TO masked_credit_cards")) { |
| 2524 return false; | 2526 return false; |
| 2525 } | 2527 } |
| 2526 | 2528 |
| 2527 return transaction.Commit(); | 2529 return transaction.Commit(); |
| 2528 } | 2530 } |
| 2529 | 2531 |
| 2530 } // namespace autofill | 2532 } // namespace autofill |
| OLD | NEW |