OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/webdata/web_database.h" | 5 #include "chrome/browser/webdata/web_database.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 "VALUES " | 707 "VALUES " |
708 "(?,?,?,?,?,?,?,?,?,?,?,?,?)")); | 708 "(?,?,?,?,?,?,?,?,?,?,?,?,?)")); |
709 if (!s) { | 709 if (!s) { |
710 NOTREACHED() << "Statement prepare failed"; | 710 NOTREACHED() << "Statement prepare failed"; |
711 return false; | 711 return false; |
712 } | 712 } |
713 | 713 |
714 std::string encrypted_password; | 714 std::string encrypted_password; |
715 s.BindString(0, form.origin.spec()); | 715 s.BindString(0, form.origin.spec()); |
716 s.BindString(1, form.action.spec()); | 716 s.BindString(1, form.action.spec()); |
717 s.BindString(2, UTF16ToUTF8(form.username_element)); | 717 s.BindString16(2, form.username_element); |
718 s.BindString(3, UTF16ToUTF8(form.username_value)); | 718 s.BindString16(3, form.username_value); |
719 s.BindString(4, UTF16ToUTF8(form.password_element)); | 719 s.BindString16(4, form.password_element); |
720 Encryptor::EncryptString16(form.password_value, &encrypted_password); | 720 Encryptor::EncryptString16(form.password_value, &encrypted_password); |
721 s.BindBlob(5, encrypted_password.data(), | 721 s.BindBlob(5, encrypted_password.data(), |
722 static_cast<int>(encrypted_password.length())); | 722 static_cast<int>(encrypted_password.length())); |
723 s.BindString(6, UTF16ToUTF8(form.submit_element)); | 723 s.BindString16(6, form.submit_element); |
724 s.BindString(7, form.signon_realm); | 724 s.BindString(7, form.signon_realm); |
725 s.BindInt(8, form.ssl_valid); | 725 s.BindInt(8, form.ssl_valid); |
726 s.BindInt(9, form.preferred); | 726 s.BindInt(9, form.preferred); |
727 s.BindInt64(10, form.date_created.ToTimeT()); | 727 s.BindInt64(10, form.date_created.ToTimeT()); |
728 s.BindInt(11, form.blacklisted_by_user); | 728 s.BindInt(11, form.blacklisted_by_user); |
729 s.BindInt(12, form.scheme); | 729 s.BindInt(12, form.scheme); |
730 if (!s.Run()) { | 730 if (!s.Run()) { |
731 NOTREACHED(); | 731 NOTREACHED(); |
732 return false; | 732 return false; |
733 } | 733 } |
(...skipping 18 matching lines...) Expand all Loading... |
752 } | 752 } |
753 | 753 |
754 s.BindString(0, form.action.spec()); | 754 s.BindString(0, form.action.spec()); |
755 std::string encrypted_password; | 755 std::string encrypted_password; |
756 Encryptor::EncryptString16(form.password_value, &encrypted_password); | 756 Encryptor::EncryptString16(form.password_value, &encrypted_password); |
757 s.BindBlob(1, encrypted_password.data(), | 757 s.BindBlob(1, encrypted_password.data(), |
758 static_cast<int>(encrypted_password.length())); | 758 static_cast<int>(encrypted_password.length())); |
759 s.BindInt(2, form.ssl_valid); | 759 s.BindInt(2, form.ssl_valid); |
760 s.BindInt(3, form.preferred); | 760 s.BindInt(3, form.preferred); |
761 s.BindString(4, form.origin.spec()); | 761 s.BindString(4, form.origin.spec()); |
762 s.BindString(5, UTF16ToUTF8(form.username_element)); | 762 s.BindString16(5, form.username_element); |
763 s.BindString(6, UTF16ToUTF8(form.username_value)); | 763 s.BindString16(6, form.username_value); |
764 s.BindString(7, UTF16ToUTF8(form.password_element)); | 764 s.BindString16(7, form.password_element); |
765 s.BindString(8, form.signon_realm); | 765 s.BindString(8, form.signon_realm); |
766 | 766 |
767 if (!s.Run()) { | 767 if (!s.Run()) { |
768 NOTREACHED(); | 768 NOTREACHED(); |
769 return false; | 769 return false; |
770 } | 770 } |
771 return true; | 771 return true; |
772 } | 772 } |
773 | 773 |
774 bool WebDatabase::RemoveLogin(const PasswordForm& form) { | 774 bool WebDatabase::RemoveLogin(const PasswordForm& form) { |
775 // Remove a login by UNIQUE-constrained fields. | 775 // Remove a login by UNIQUE-constrained fields. |
776 sql::Statement s(db_.GetUniqueStatement( | 776 sql::Statement s(db_.GetUniqueStatement( |
777 "DELETE FROM logins WHERE " | 777 "DELETE FROM logins WHERE " |
778 "origin_url = ? AND " | 778 "origin_url = ? AND " |
779 "username_element = ? AND " | 779 "username_element = ? AND " |
780 "username_value = ? AND " | 780 "username_value = ? AND " |
781 "password_element = ? AND " | 781 "password_element = ? AND " |
782 "submit_element = ? AND " | 782 "submit_element = ? AND " |
783 "signon_realm = ?")); | 783 "signon_realm = ?")); |
784 if (!s) { | 784 if (!s) { |
785 NOTREACHED() << "Statement prepare failed"; | 785 NOTREACHED() << "Statement prepare failed"; |
786 return false; | 786 return false; |
787 } | 787 } |
788 s.BindString(0, form.origin.spec()); | 788 s.BindString(0, form.origin.spec()); |
789 s.BindString(1, UTF16ToUTF8(form.username_element)); | 789 s.BindString16(1, form.username_element); |
790 s.BindString(2, UTF16ToUTF8(form.username_value)); | 790 s.BindString16(2, form.username_value); |
791 s.BindString(3, UTF16ToUTF8(form.password_element)); | 791 s.BindString16(3, form.password_element); |
792 s.BindString(4, UTF16ToUTF8(form.submit_element)); | 792 s.BindString16(4, form.submit_element); |
793 s.BindString(5, form.signon_realm); | 793 s.BindString(5, form.signon_realm); |
794 | 794 |
795 if (!s.Run()) { | 795 if (!s.Run()) { |
796 NOTREACHED(); | 796 NOTREACHED(); |
797 return false; | 797 return false; |
798 } | 798 } |
799 return true; | 799 return true; |
800 } | 800 } |
801 | 801 |
802 bool WebDatabase::RemoveLoginsCreatedBetween(base::Time delete_begin, | 802 bool WebDatabase::RemoveLoginsCreatedBetween(base::Time delete_begin, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 } | 834 } |
835 | 835 |
836 static void InitPasswordFormFromStatement(PasswordForm* form, | 836 static void InitPasswordFormFromStatement(PasswordForm* form, |
837 sql::Statement* s) { | 837 sql::Statement* s) { |
838 std::string tmp; | 838 std::string tmp; |
839 string16 decrypted_password; | 839 string16 decrypted_password; |
840 tmp = s->ColumnString(0); | 840 tmp = s->ColumnString(0); |
841 form->origin = GURL(tmp); | 841 form->origin = GURL(tmp); |
842 tmp = s->ColumnString(1); | 842 tmp = s->ColumnString(1); |
843 form->action = GURL(tmp); | 843 form->action = GURL(tmp); |
844 form->username_element = UTF8ToUTF16(s->ColumnString(2)); | 844 form->username_element = s->ColumnString16(2); |
845 form->username_value = UTF8ToUTF16(s->ColumnString(3)); | 845 form->username_value = s->ColumnString16(3); |
846 form->password_element = UTF8ToUTF16(s->ColumnString(4)); | 846 form->password_element = s->ColumnString16(4); |
847 | 847 |
848 int encrypted_password_len = s->ColumnByteLength(5); | 848 int encrypted_password_len = s->ColumnByteLength(5); |
849 std::string encrypted_password; | 849 std::string encrypted_password; |
850 if (encrypted_password_len) { | 850 if (encrypted_password_len) { |
851 encrypted_password.resize(encrypted_password_len); | 851 encrypted_password.resize(encrypted_password_len); |
852 memcpy(&encrypted_password[0], s->ColumnBlob(5), encrypted_password_len); | 852 memcpy(&encrypted_password[0], s->ColumnBlob(5), encrypted_password_len); |
853 Encryptor::DecryptString16(encrypted_password, &decrypted_password); | 853 Encryptor::DecryptString16(encrypted_password, &decrypted_password); |
854 } | 854 } |
855 | 855 |
856 form->password_value = decrypted_password; | 856 form->password_value = decrypted_password; |
857 form->submit_element = UTF8ToUTF16(s->ColumnString(6)); | 857 form->submit_element = s->ColumnString16(6); |
858 tmp = s->ColumnString(7); | 858 tmp = s->ColumnString(7); |
859 form->signon_realm = tmp; | 859 form->signon_realm = tmp; |
860 form->ssl_valid = (s->ColumnInt(8) > 0); | 860 form->ssl_valid = (s->ColumnInt(8) > 0); |
861 form->preferred = (s->ColumnInt(9) > 0); | 861 form->preferred = (s->ColumnInt(9) > 0); |
862 form->date_created = Time::FromTimeT(s->ColumnInt64(10)); | 862 form->date_created = Time::FromTimeT(s->ColumnInt64(10)); |
863 form->blacklisted_by_user = (s->ColumnInt(11) > 0); | 863 form->blacklisted_by_user = (s->ColumnInt(11) > 0); |
864 int scheme_int = s->ColumnInt(12); | 864 int scheme_int = s->ColumnInt(12); |
865 DCHECK((scheme_int >= 0) && (scheme_int <= PasswordForm::SCHEME_OTHER)); | 865 DCHECK((scheme_int >= 0) && (scheme_int <= PasswordForm::SCHEME_OTHER)); |
866 form->scheme = static_cast<PasswordForm::Scheme>(scheme_int); | 866 form->scheme = static_cast<PasswordForm::Scheme>(scheme_int); |
867 } | 867 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 int64* pair_id, | 965 int64* pair_id, |
966 int* count) { | 966 int* count) { |
967 sql::Statement s(db_.GetUniqueStatement( | 967 sql::Statement s(db_.GetUniqueStatement( |
968 "SELECT pair_id, count FROM autofill " | 968 "SELECT pair_id, count FROM autofill " |
969 "WHERE name = ? AND value = ?")); | 969 "WHERE name = ? AND value = ?")); |
970 if (!s) { | 970 if (!s) { |
971 NOTREACHED() << "Statement prepare failed"; | 971 NOTREACHED() << "Statement prepare failed"; |
972 return false; | 972 return false; |
973 } | 973 } |
974 | 974 |
975 s.BindString(0, UTF16ToUTF8(element.name())); | 975 s.BindString16(0, element.name()); |
976 s.BindString(1, UTF16ToUTF8(element.value())); | 976 s.BindString16(1, element.value()); |
977 | 977 |
978 *count = 0; | 978 *count = 0; |
979 | 979 |
980 if (s.Step()) { | 980 if (s.Step()) { |
981 *pair_id = s.ColumnInt64(0); | 981 *pair_id = s.ColumnInt64(0); |
982 *count = s.ColumnInt(1); | 982 *count = s.ColumnInt(1); |
983 } | 983 } |
984 | 984 |
985 return true; | 985 return true; |
986 } | 986 } |
(...skipping 25 matching lines...) Expand all Loading... |
1012 NOTREACHED() << "Statement prepare failed"; | 1012 NOTREACHED() << "Statement prepare failed"; |
1013 return false; | 1013 return false; |
1014 } | 1014 } |
1015 | 1015 |
1016 bool first_entry = true; | 1016 bool first_entry = true; |
1017 AutofillKey* current_key_ptr = NULL; | 1017 AutofillKey* current_key_ptr = NULL; |
1018 std::vector<base::Time>* timestamps_ptr = NULL; | 1018 std::vector<base::Time>* timestamps_ptr = NULL; |
1019 string16 name, value; | 1019 string16 name, value; |
1020 base::Time time; | 1020 base::Time time; |
1021 while (s.Step()) { | 1021 while (s.Step()) { |
1022 name = UTF8ToUTF16(s.ColumnString(0)); | 1022 name = s.ColumnString16(0); |
1023 value = UTF8ToUTF16(s.ColumnString(1)); | 1023 value = s.ColumnString16(1); |
1024 time = Time::FromTimeT(s.ColumnInt64(2)); | 1024 time = Time::FromTimeT(s.ColumnInt64(2)); |
1025 | 1025 |
1026 if (first_entry) { | 1026 if (first_entry) { |
1027 current_key_ptr = new AutofillKey(name, value); | 1027 current_key_ptr = new AutofillKey(name, value); |
1028 | 1028 |
1029 timestamps_ptr = new std::vector<base::Time>; | 1029 timestamps_ptr = new std::vector<base::Time>; |
1030 timestamps_ptr->push_back(time); | 1030 timestamps_ptr->push_back(time); |
1031 | 1031 |
1032 first_entry = false; | 1032 first_entry = false; |
1033 } else { | 1033 } else { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 sql::Statement s(db_.GetUniqueStatement( | 1065 sql::Statement s(db_.GetUniqueStatement( |
1066 "SELECT date_created FROM autofill a JOIN " | 1066 "SELECT date_created FROM autofill a JOIN " |
1067 "autofill_dates ad ON a.pair_id=ad.pair_id " | 1067 "autofill_dates ad ON a.pair_id=ad.pair_id " |
1068 "WHERE a.name = ? AND a.value = ?")); | 1068 "WHERE a.name = ? AND a.value = ?")); |
1069 | 1069 |
1070 if (!s) { | 1070 if (!s) { |
1071 NOTREACHED() << "Statement prepare failed"; | 1071 NOTREACHED() << "Statement prepare failed"; |
1072 return false; | 1072 return false; |
1073 } | 1073 } |
1074 | 1074 |
1075 s.BindString(0, UTF16ToUTF8(name)); | 1075 s.BindString16(0, name); |
1076 s.BindString(1, UTF16ToUTF8(value)); | 1076 s.BindString16(1, value); |
1077 while (s.Step()) { | 1077 while (s.Step()) { |
1078 timestamps->push_back(Time::FromTimeT(s.ColumnInt64(0))); | 1078 timestamps->push_back(Time::FromTimeT(s.ColumnInt64(0))); |
1079 } | 1079 } |
1080 | 1080 |
1081 return s.Succeeded(); | 1081 return s.Succeeded(); |
1082 } | 1082 } |
1083 | 1083 |
1084 bool WebDatabase::UpdateAutofillEntries( | 1084 bool WebDatabase::UpdateAutofillEntries( |
1085 const std::vector<AutofillEntry>& entries) { | 1085 const std::vector<AutofillEntry>& entries) { |
1086 if (!entries.size()) | 1086 if (!entries.size()) |
1087 return true; | 1087 return true; |
1088 | 1088 |
1089 // Remove all existing entries. | 1089 // Remove all existing entries. |
1090 for (size_t i = 0; i < entries.size(); i++) { | 1090 for (size_t i = 0; i < entries.size(); i++) { |
1091 std::string sql = "SELECT pair_id FROM autofill " | 1091 std::string sql = "SELECT pair_id FROM autofill " |
1092 "WHERE name = ? AND value = ?"; | 1092 "WHERE name = ? AND value = ?"; |
1093 sql::Statement s(db_.GetUniqueStatement(sql.c_str())); | 1093 sql::Statement s(db_.GetUniqueStatement(sql.c_str())); |
1094 if (!s.is_valid()) { | 1094 if (!s.is_valid()) { |
1095 NOTREACHED() << "Statement prepare failed"; | 1095 NOTREACHED() << "Statement prepare failed"; |
1096 return false; | 1096 return false; |
1097 } | 1097 } |
1098 | 1098 |
1099 s.BindString(0, UTF16ToUTF8(entries[i].key().name())); | 1099 s.BindString16(0, entries[i].key().name()); |
1100 s.BindString(1, UTF16ToUTF8(entries[i].key().value())); | 1100 s.BindString16(1, entries[i].key().value()); |
1101 if (s.Step()) { | 1101 if (s.Step()) { |
1102 if (!RemoveFormElementForID(s.ColumnInt64(0))) | 1102 if (!RemoveFormElementForID(s.ColumnInt64(0))) |
1103 return false; | 1103 return false; |
1104 } | 1104 } |
1105 } | 1105 } |
1106 | 1106 |
1107 // Insert all the supplied autofill entries. | 1107 // Insert all the supplied autofill entries. |
1108 for (size_t i = 0; i < entries.size(); i++) { | 1108 for (size_t i = 0; i < entries.size(); i++) { |
1109 if (!InsertAutofillEntry(entries[i])) | 1109 if (!InsertAutofillEntry(entries[i])) |
1110 return false; | 1110 return false; |
1111 } | 1111 } |
1112 | 1112 |
1113 return true; | 1113 return true; |
1114 } | 1114 } |
1115 | 1115 |
1116 bool WebDatabase::InsertAutofillEntry(const AutofillEntry& entry) { | 1116 bool WebDatabase::InsertAutofillEntry(const AutofillEntry& entry) { |
1117 std::string sql = "INSERT INTO autofill (name, value, value_lower, count) " | 1117 std::string sql = "INSERT INTO autofill (name, value, value_lower, count) " |
1118 "VALUES (?, ?, ?, ?)"; | 1118 "VALUES (?, ?, ?, ?)"; |
1119 sql::Statement s(db_.GetUniqueStatement(sql.c_str())); | 1119 sql::Statement s(db_.GetUniqueStatement(sql.c_str())); |
1120 if (!s.is_valid()) { | 1120 if (!s.is_valid()) { |
1121 NOTREACHED() << "Statement prepare failed"; | 1121 NOTREACHED() << "Statement prepare failed"; |
1122 return false; | 1122 return false; |
1123 } | 1123 } |
1124 | 1124 |
1125 s.BindString(0, UTF16ToUTF8(entry.key().name())); | 1125 s.BindString16(0, entry.key().name()); |
1126 s.BindString(1, UTF16ToUTF8(entry.key().value())); | 1126 s.BindString16(1, entry.key().value()); |
1127 s.BindString(2, UTF16ToUTF8(l10n_util::ToLower(entry.key().value()))); | 1127 s.BindString16(2, l10n_util::ToLower(entry.key().value())); |
1128 s.BindInt(3, entry.timestamps().size()); | 1128 s.BindInt(3, entry.timestamps().size()); |
1129 | 1129 |
1130 if (!s.Run()) { | 1130 if (!s.Run()) { |
1131 NOTREACHED(); | 1131 NOTREACHED(); |
1132 return false; | 1132 return false; |
1133 } | 1133 } |
1134 | 1134 |
1135 int64 pair_id = db_.GetLastInsertRowId(); | 1135 int64 pair_id = db_.GetLastInsertRowId(); |
1136 for (size_t i = 0; i < entry.timestamps().size(); i++) { | 1136 for (size_t i = 0; i < entry.timestamps().size(); i++) { |
1137 if (!InsertPairIDAndDate(pair_id, entry.timestamps()[i])) | 1137 if (!InsertPairIDAndDate(pair_id, entry.timestamps()[i])) |
1138 return false; | 1138 return false; |
1139 } | 1139 } |
1140 | 1140 |
1141 return true; | 1141 return true; |
1142 } | 1142 } |
1143 | 1143 |
1144 bool WebDatabase::InsertFormElement(const FormField& element, | 1144 bool WebDatabase::InsertFormElement(const FormField& element, |
1145 int64* pair_id) { | 1145 int64* pair_id) { |
1146 sql::Statement s(db_.GetUniqueStatement( | 1146 sql::Statement s(db_.GetUniqueStatement( |
1147 "INSERT INTO autofill (name, value, value_lower) VALUES (?,?,?)")); | 1147 "INSERT INTO autofill (name, value, value_lower) VALUES (?,?,?)")); |
1148 if (!s) { | 1148 if (!s) { |
1149 NOTREACHED() << "Statement prepare failed"; | 1149 NOTREACHED() << "Statement prepare failed"; |
1150 return false; | 1150 return false; |
1151 } | 1151 } |
1152 | 1152 |
1153 s.BindString(0, UTF16ToUTF8(element.name())); | 1153 s.BindString16(0, element.name()); |
1154 s.BindString(1, UTF16ToUTF8(element.value())); | 1154 s.BindString16(1, element.value()); |
1155 s.BindString(2, UTF16ToUTF8(l10n_util::ToLower(element.value()))); | 1155 s.BindString16(2, l10n_util::ToLower(element.value())); |
1156 | 1156 |
1157 if (!s.Run()) { | 1157 if (!s.Run()) { |
1158 NOTREACHED(); | 1158 NOTREACHED(); |
1159 return false; | 1159 return false; |
1160 } | 1160 } |
1161 | 1161 |
1162 *pair_id = db_.GetLastInsertRowId(); | 1162 *pair_id = db_.GetLastInsertRowId(); |
1163 return true; | 1163 return true; |
1164 } | 1164 } |
1165 | 1165 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 s.Assign(db_.GetUniqueStatement( | 1244 s.Assign(db_.GetUniqueStatement( |
1245 "SELECT value FROM autofill " | 1245 "SELECT value FROM autofill " |
1246 "WHERE name = ? " | 1246 "WHERE name = ? " |
1247 "ORDER BY count DESC " | 1247 "ORDER BY count DESC " |
1248 "LIMIT ?")); | 1248 "LIMIT ?")); |
1249 if (!s) { | 1249 if (!s) { |
1250 NOTREACHED() << "Statement prepare failed"; | 1250 NOTREACHED() << "Statement prepare failed"; |
1251 return false; | 1251 return false; |
1252 } | 1252 } |
1253 | 1253 |
1254 s.BindString(0, UTF16ToUTF8(name)); | 1254 s.BindString16(0, name); |
1255 s.BindInt(1, limit); | 1255 s.BindInt(1, limit); |
1256 } else { | 1256 } else { |
1257 string16 prefix_lower = l10n_util::ToLower(prefix); | 1257 string16 prefix_lower = l10n_util::ToLower(prefix); |
1258 string16 next_prefix = prefix_lower; | 1258 string16 next_prefix = prefix_lower; |
1259 next_prefix[next_prefix.length() - 1]++; | 1259 next_prefix[next_prefix.length() - 1]++; |
1260 | 1260 |
1261 s.Assign(db_.GetUniqueStatement( | 1261 s.Assign(db_.GetUniqueStatement( |
1262 "SELECT value FROM autofill " | 1262 "SELECT value FROM autofill " |
1263 "WHERE name = ? AND " | 1263 "WHERE name = ? AND " |
1264 "value_lower >= ? AND " | 1264 "value_lower >= ? AND " |
1265 "value_lower < ? " | 1265 "value_lower < ? " |
1266 "ORDER BY count DESC " | 1266 "ORDER BY count DESC " |
1267 "LIMIT ?")); | 1267 "LIMIT ?")); |
1268 if (!s) { | 1268 if (!s) { |
1269 NOTREACHED() << "Statement prepare failed"; | 1269 NOTREACHED() << "Statement prepare failed"; |
1270 return false; | 1270 return false; |
1271 } | 1271 } |
1272 | 1272 |
1273 s.BindString(0, UTF16ToUTF8(name)); | 1273 s.BindString16(0, name); |
1274 s.BindString(1, UTF16ToUTF8(prefix_lower)); | 1274 s.BindString16(1, prefix_lower); |
1275 s.BindString(2, UTF16ToUTF8(next_prefix)); | 1275 s.BindString16(2, next_prefix); |
1276 s.BindInt(3, limit); | 1276 s.BindInt(3, limit); |
1277 } | 1277 } |
1278 | 1278 |
1279 values->clear(); | 1279 values->clear(); |
1280 while (s.Step()) | 1280 while (s.Step()) |
1281 values->push_back(UTF8ToUTF16(s.ColumnString(0))); | 1281 values->push_back(s.ColumnString16(0)); |
1282 return s.Succeeded(); | 1282 return s.Succeeded(); |
1283 } | 1283 } |
1284 | 1284 |
1285 bool WebDatabase::RemoveFormElementsAddedBetween( | 1285 bool WebDatabase::RemoveFormElementsAddedBetween( |
1286 base::Time delete_begin, | 1286 base::Time delete_begin, |
1287 base::Time delete_end, | 1287 base::Time delete_end, |
1288 std::vector<AutofillChange>* changes) { | 1288 std::vector<AutofillChange>* changes) { |
1289 DCHECK(changes); | 1289 DCHECK(changes); |
1290 // Query for the pair_id, name, and value of all form elements that | 1290 // Query for the pair_id, name, and value of all form elements that |
1291 // were used between the given times. | 1291 // were used between the given times. |
1292 sql::Statement s(db_.GetUniqueStatement( | 1292 sql::Statement s(db_.GetUniqueStatement( |
1293 "SELECT DISTINCT a.pair_id, a.name, a.value " | 1293 "SELECT DISTINCT a.pair_id, a.name, a.value " |
1294 "FROM autofill_dates ad JOIN autofill a ON ad.pair_id = a.pair_id " | 1294 "FROM autofill_dates ad JOIN autofill a ON ad.pair_id = a.pair_id " |
1295 "WHERE ad.date_created >= ? AND ad.date_created < ?")); | 1295 "WHERE ad.date_created >= ? AND ad.date_created < ?")); |
1296 if (!s) { | 1296 if (!s) { |
1297 NOTREACHED() << "Statement 1 prepare failed"; | 1297 NOTREACHED() << "Statement 1 prepare failed"; |
1298 return false; | 1298 return false; |
1299 } | 1299 } |
1300 s.BindInt64(0, delete_begin.ToTimeT()); | 1300 s.BindInt64(0, delete_begin.ToTimeT()); |
1301 s.BindInt64(1, | 1301 s.BindInt64(1, |
1302 delete_end.is_null() ? | 1302 delete_end.is_null() ? |
1303 std::numeric_limits<int64>::max() : | 1303 std::numeric_limits<int64>::max() : |
1304 delete_end.ToTimeT()); | 1304 delete_end.ToTimeT()); |
1305 | 1305 |
1306 AutofillElementList elements; | 1306 AutofillElementList elements; |
1307 while (s.Step()) | 1307 while (s.Step()) { |
1308 elements.push_back(MakeTuple(s.ColumnInt64(0), | 1308 elements.push_back(MakeTuple(s.ColumnInt64(0), |
1309 UTF8ToUTF16(s.ColumnString(1)), | 1309 s.ColumnString16(1), |
1310 UTF8ToUTF16(s.ColumnString(2)))); | 1310 s.ColumnString16(2))); |
| 1311 } |
1311 | 1312 |
1312 if (!s.Succeeded()) { | 1313 if (!s.Succeeded()) { |
1313 NOTREACHED(); | 1314 NOTREACHED(); |
1314 return false; | 1315 return false; |
1315 } | 1316 } |
1316 | 1317 |
1317 for (AutofillElementList::iterator itr = elements.begin(); | 1318 for (AutofillElementList::iterator itr = elements.begin(); |
1318 itr != elements.end(); | 1319 itr != elements.end(); itr++) { |
1319 itr++) { | |
1320 int how_many = 0; | 1320 int how_many = 0; |
1321 if (!RemoveFormElementForTimeRange(itr->a, delete_begin, delete_end, | 1321 if (!RemoveFormElementForTimeRange(itr->a, delete_begin, delete_end, |
1322 &how_many)) { | 1322 &how_many)) { |
1323 return false; | 1323 return false; |
1324 } | 1324 } |
1325 bool was_removed = false; | 1325 bool was_removed = false; |
1326 if (!AddToCountOfFormElement(itr->a, -how_many, &was_removed)) | 1326 if (!AddToCountOfFormElement(itr->a, -how_many, &was_removed)) |
1327 return false; | 1327 return false; |
1328 AutofillChange::Type change_type = | 1328 AutofillChange::Type change_type = |
1329 was_removed ? AutofillChange::REMOVE : AutofillChange::UPDATE; | 1329 was_removed ? AutofillChange::REMOVE : AutofillChange::UPDATE; |
(...skipping 29 matching lines...) Expand all Loading... |
1359 | 1359 |
1360 bool WebDatabase::RemoveFormElement(const string16& name, | 1360 bool WebDatabase::RemoveFormElement(const string16& name, |
1361 const string16& value) { | 1361 const string16& value) { |
1362 // Find the id for that pair. | 1362 // Find the id for that pair. |
1363 sql::Statement s(db_.GetUniqueStatement( | 1363 sql::Statement s(db_.GetUniqueStatement( |
1364 "SELECT pair_id FROM autofill WHERE name = ? AND value= ?")); | 1364 "SELECT pair_id FROM autofill WHERE name = ? AND value= ?")); |
1365 if (!s) { | 1365 if (!s) { |
1366 NOTREACHED() << "Statement 1 prepare failed"; | 1366 NOTREACHED() << "Statement 1 prepare failed"; |
1367 return false; | 1367 return false; |
1368 } | 1368 } |
1369 s.BindString(0, UTF16ToUTF8(name)); | 1369 s.BindString16(0, name); |
1370 s.BindString(1, UTF16ToUTF8(value)); | 1370 s.BindString16(1, value); |
1371 | 1371 |
1372 if (s.Step()) | 1372 if (s.Step()) |
1373 return RemoveFormElementForID(s.ColumnInt64(0)); | 1373 return RemoveFormElementForID(s.ColumnInt64(0)); |
1374 return false; | 1374 return false; |
1375 } | 1375 } |
1376 | 1376 |
1377 static void BindAutoFillProfileToStatement(const AutoFillProfile& profile, | 1377 static void BindAutoFillProfileToStatement(const AutoFillProfile& profile, |
1378 sql::Statement* s) { | 1378 sql::Statement* s) { |
1379 s->BindString(0, UTF16ToUTF8(profile.Label())); | 1379 s->BindString16(0, profile.Label()); |
1380 s->BindInt(1, profile.unique_id()); | 1380 s->BindInt(1, profile.unique_id()); |
1381 | 1381 |
1382 string16 text = profile.GetFieldText(AutoFillType(NAME_FIRST)); | 1382 string16 text = profile.GetFieldText(AutoFillType(NAME_FIRST)); |
1383 s->BindString(2, UTF16ToUTF8(text)); | 1383 s->BindString16(2, text); |
1384 text = profile.GetFieldText(AutoFillType(NAME_MIDDLE)); | 1384 text = profile.GetFieldText(AutoFillType(NAME_MIDDLE)); |
1385 s->BindString(3, UTF16ToUTF8(text)); | 1385 s->BindString16(3, text); |
1386 text = profile.GetFieldText(AutoFillType(NAME_LAST)); | 1386 text = profile.GetFieldText(AutoFillType(NAME_LAST)); |
1387 s->BindString(4, UTF16ToUTF8(text)); | 1387 s->BindString16(4, text); |
1388 text = profile.GetFieldText(AutoFillType(EMAIL_ADDRESS)); | 1388 text = profile.GetFieldText(AutoFillType(EMAIL_ADDRESS)); |
1389 s->BindString(5, UTF16ToUTF8(text)); | 1389 s->BindString16(5, text); |
1390 text = profile.GetFieldText(AutoFillType(COMPANY_NAME)); | 1390 text = profile.GetFieldText(AutoFillType(COMPANY_NAME)); |
1391 s->BindString(6, UTF16ToUTF8(text)); | 1391 s->BindString16(6, text); |
1392 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE1)); | 1392 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE1)); |
1393 s->BindString(7, UTF16ToUTF8(text)); | 1393 s->BindString16(7, text); |
1394 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE2)); | 1394 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE2)); |
1395 s->BindString(8, UTF16ToUTF8(text)); | 1395 s->BindString16(8, text); |
1396 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_CITY)); | 1396 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_CITY)); |
1397 s->BindString(9, UTF16ToUTF8(text)); | 1397 s->BindString16(9, text); |
1398 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_STATE)); | 1398 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_STATE)); |
1399 s->BindString(10, UTF16ToUTF8(text)); | 1399 s->BindString16(10, text); |
1400 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_ZIP)); | 1400 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_ZIP)); |
1401 s->BindString(11, UTF16ToUTF8(text)); | 1401 s->BindString16(11, text); |
1402 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY)); | 1402 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY)); |
1403 s->BindString(12, UTF16ToUTF8(text)); | 1403 s->BindString16(12, text); |
1404 text = profile.GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER)); | 1404 text = profile.GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER)); |
1405 s->BindString(13, UTF16ToUTF8(text)); | 1405 s->BindString16(13, text); |
1406 text = profile.GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER)); | 1406 text = profile.GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER)); |
1407 s->BindString(14, UTF16ToUTF8(text)); | 1407 s->BindString16(14, text); |
1408 } | 1408 } |
1409 | 1409 |
1410 bool WebDatabase::AddAutoFillProfile(const AutoFillProfile& profile) { | 1410 bool WebDatabase::AddAutoFillProfile(const AutoFillProfile& profile) { |
1411 sql::Statement s(db_.GetUniqueStatement( | 1411 sql::Statement s(db_.GetUniqueStatement( |
1412 "INSERT INTO autofill_profiles" | 1412 "INSERT INTO autofill_profiles" |
1413 "(label, unique_id, first_name, middle_name, last_name, email," | 1413 "(label, unique_id, first_name, middle_name, last_name, email," |
1414 " company_name, address_line_1, address_line_2, city, state, zipcode," | 1414 " company_name, address_line_1, address_line_2, city, state, zipcode," |
1415 " country, phone, fax)" | 1415 " country, phone, fax)" |
1416 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); | 1416 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); |
1417 if (!s) { | 1417 if (!s) { |
1418 NOTREACHED() << "Statement prepare failed"; | 1418 NOTREACHED() << "Statement prepare failed"; |
1419 return false; | 1419 return false; |
1420 } | 1420 } |
1421 | 1421 |
1422 BindAutoFillProfileToStatement(profile, &s); | 1422 BindAutoFillProfileToStatement(profile, &s); |
1423 | 1423 |
1424 if (!s.Run()) { | 1424 if (!s.Run()) { |
1425 NOTREACHED(); | 1425 NOTREACHED(); |
1426 return false; | 1426 return false; |
1427 } | 1427 } |
1428 | 1428 |
1429 return s.Succeeded(); | 1429 return s.Succeeded(); |
1430 } | 1430 } |
1431 | 1431 |
1432 static AutoFillProfile* AutoFillProfileFromStatement(const sql::Statement& s) { | 1432 static AutoFillProfile* AutoFillProfileFromStatement(const sql::Statement& s) { |
1433 AutoFillProfile* profile = new AutoFillProfile( | 1433 AutoFillProfile* profile = new AutoFillProfile( |
1434 UTF8ToUTF16(s.ColumnString(0)), s.ColumnInt(1)); | 1434 s.ColumnString16(0), s.ColumnInt(1)); |
1435 profile->SetInfo(AutoFillType(NAME_FIRST), | 1435 profile->SetInfo(AutoFillType(NAME_FIRST), |
1436 UTF8ToUTF16(s.ColumnString(2))); | 1436 s.ColumnString16(2)); |
1437 profile->SetInfo(AutoFillType(NAME_MIDDLE), | 1437 profile->SetInfo(AutoFillType(NAME_MIDDLE), |
1438 UTF8ToUTF16(s.ColumnString(3))); | 1438 s.ColumnString16(3)); |
1439 profile->SetInfo(AutoFillType(NAME_LAST), | 1439 profile->SetInfo(AutoFillType(NAME_LAST), |
1440 UTF8ToUTF16(s.ColumnString(4))); | 1440 s.ColumnString16(4)); |
1441 profile->SetInfo(AutoFillType(EMAIL_ADDRESS), | 1441 profile->SetInfo(AutoFillType(EMAIL_ADDRESS), |
1442 UTF8ToUTF16(s.ColumnString(5))); | 1442 s.ColumnString16(5)); |
1443 profile->SetInfo(AutoFillType(COMPANY_NAME), | 1443 profile->SetInfo(AutoFillType(COMPANY_NAME), |
1444 UTF8ToUTF16(s.ColumnString(6))); | 1444 s.ColumnString16(6)); |
1445 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), | 1445 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), |
1446 UTF8ToUTF16(s.ColumnString(7))); | 1446 s.ColumnString16(7)); |
1447 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), | 1447 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), |
1448 UTF8ToUTF16(s.ColumnString(8))); | 1448 s.ColumnString16(8)); |
1449 profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), | 1449 profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), |
1450 UTF8ToUTF16(s.ColumnString(9))); | 1450 s.ColumnString16(9)); |
1451 profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), | 1451 profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), |
1452 UTF8ToUTF16(s.ColumnString(10))); | 1452 s.ColumnString16(10)); |
1453 profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP), | 1453 profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP), |
1454 UTF8ToUTF16(s.ColumnString(11))); | 1454 s.ColumnString16(11)); |
1455 profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), | 1455 profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), |
1456 UTF8ToUTF16(s.ColumnString(12))); | 1456 s.ColumnString16(12)); |
1457 profile->SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), | 1457 profile->SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), |
1458 UTF8ToUTF16(s.ColumnString(13))); | 1458 s.ColumnString16(13)); |
1459 profile->SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), | 1459 profile->SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), |
1460 UTF8ToUTF16(s.ColumnString(14))); | 1460 s.ColumnString16(14)); |
1461 | 1461 |
1462 return profile; | 1462 return profile; |
1463 } | 1463 } |
1464 | 1464 |
1465 bool WebDatabase::GetAutoFillProfileForLabel(const string16& label, | 1465 bool WebDatabase::GetAutoFillProfileForLabel(const string16& label, |
1466 AutoFillProfile** profile) { | 1466 AutoFillProfile** profile) { |
1467 DCHECK(profile); | 1467 DCHECK(profile); |
1468 sql::Statement s(db_.GetUniqueStatement( | 1468 sql::Statement s(db_.GetUniqueStatement( |
1469 "SELECT * FROM autofill_profiles " | 1469 "SELECT * FROM autofill_profiles " |
1470 "WHERE label = ?")); | 1470 "WHERE label = ?")); |
1471 if (!s) { | 1471 if (!s) { |
1472 NOTREACHED() << "Statement prepare failed"; | 1472 NOTREACHED() << "Statement prepare failed"; |
1473 return false; | 1473 return false; |
1474 } | 1474 } |
1475 | 1475 |
1476 s.BindString(0, UTF16ToUTF8(label)); | 1476 s.BindString16(0, label); |
1477 if (!s.Step()) | 1477 if (!s.Step()) |
1478 return false; | 1478 return false; |
1479 | 1479 |
1480 *profile = AutoFillProfileFromStatement(s); | 1480 *profile = AutoFillProfileFromStatement(s); |
1481 | 1481 |
1482 return s.Succeeded(); | 1482 return s.Succeeded(); |
1483 } | 1483 } |
1484 | 1484 |
1485 bool WebDatabase::GetAutoFillProfiles( | 1485 bool WebDatabase::GetAutoFillProfiles( |
1486 std::vector<AutoFillProfile*>* profiles) { | 1486 std::vector<AutoFillProfile*>* profiles) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 | 1544 |
1545 s.BindInt(0, profile_id); | 1545 s.BindInt(0, profile_id); |
1546 if (s.Step()) | 1546 if (s.Step()) |
1547 *profile = AutoFillProfileFromStatement(s); | 1547 *profile = AutoFillProfileFromStatement(s); |
1548 | 1548 |
1549 return s.Succeeded(); | 1549 return s.Succeeded(); |
1550 } | 1550 } |
1551 | 1551 |
1552 static void BindCreditCardToStatement(const CreditCard& credit_card, | 1552 static void BindCreditCardToStatement(const CreditCard& credit_card, |
1553 sql::Statement* s) { | 1553 sql::Statement* s) { |
1554 s->BindString(0, UTF16ToUTF8(credit_card.Label())); | 1554 s->BindString16(0, credit_card.Label()); |
1555 s->BindInt(1, credit_card.unique_id()); | 1555 s->BindInt(1, credit_card.unique_id()); |
1556 | 1556 |
1557 string16 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NAME)); | 1557 string16 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NAME)); |
1558 s->BindString(2, UTF16ToUTF8(text)); | 1558 s->BindString16(2, text); |
1559 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_TYPE)); | 1559 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_TYPE)); |
1560 s->BindString(3, UTF16ToUTF8(text)); | 1560 s->BindString16(3, text); |
1561 text.clear(); // No unencrypted cc info. | 1561 text.clear(); // No unencrypted cc info. |
1562 s->BindString(4, UTF16ToUTF8(text)); | 1562 s->BindString16(4, text); |
1563 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH)); | 1563 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH)); |
1564 s->BindString(5, UTF16ToUTF8(text)); | 1564 s->BindString16(5, text); |
1565 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 1565 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
1566 s->BindString(6, UTF16ToUTF8(text)); | 1566 s->BindString16(6, text); |
1567 text.clear(); | 1567 text.clear(); |
1568 s->BindString(7, UTF16ToUTF8(text)); | 1568 s->BindString16(7, text); |
1569 s->BindString(8, UTF16ToUTF8(credit_card.billing_address())); | 1569 s->BindString16(8, credit_card.billing_address()); |
1570 s->BindString(9, UTF16ToUTF8(credit_card.shipping_address())); | 1570 s->BindString16(9, credit_card.shipping_address()); |
1571 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER)); | 1571 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER)); |
1572 std::string encrypted_data; | 1572 std::string encrypted_data; |
1573 Encryptor::EncryptString16(text, &encrypted_data); | 1573 Encryptor::EncryptString16(text, &encrypted_data); |
1574 s->BindBlob(10, encrypted_data.data(), | 1574 s->BindBlob(10, encrypted_data.data(), |
1575 static_cast<int>(encrypted_data.length())); | 1575 static_cast<int>(encrypted_data.length())); |
1576 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_VERIFICATION_CODE)); | 1576 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_VERIFICATION_CODE)); |
1577 Encryptor::EncryptString16(text, &encrypted_data); | 1577 Encryptor::EncryptString16(text, &encrypted_data); |
1578 s->BindBlob(11, encrypted_data.data(), | 1578 s->BindBlob(11, encrypted_data.data(), |
1579 static_cast<int>(encrypted_data.length())); | 1579 static_cast<int>(encrypted_data.length())); |
1580 } | 1580 } |
(...skipping 16 matching lines...) Expand all Loading... |
1597 NOTREACHED(); | 1597 NOTREACHED(); |
1598 return false; | 1598 return false; |
1599 } | 1599 } |
1600 | 1600 |
1601 DCHECK_GT(db_.GetLastChangeCount(), 0); | 1601 DCHECK_GT(db_.GetLastChangeCount(), 0); |
1602 return s.Succeeded(); | 1602 return s.Succeeded(); |
1603 } | 1603 } |
1604 | 1604 |
1605 static CreditCard* CreditCardFromStatement(const sql::Statement& s) { | 1605 static CreditCard* CreditCardFromStatement(const sql::Statement& s) { |
1606 CreditCard* credit_card = new CreditCard( | 1606 CreditCard* credit_card = new CreditCard( |
1607 UTF8ToUTF16(s.ColumnString(0)), s.ColumnInt(1)); | 1607 s.ColumnString16(0), s.ColumnInt(1)); |
1608 credit_card->SetInfo(AutoFillType(CREDIT_CARD_NAME), | 1608 credit_card->SetInfo(AutoFillType(CREDIT_CARD_NAME), |
1609 UTF8ToUTF16(s.ColumnString(2))); | 1609 s.ColumnString16(2)); |
1610 credit_card->SetInfo(AutoFillType(CREDIT_CARD_TYPE), | 1610 credit_card->SetInfo(AutoFillType(CREDIT_CARD_TYPE), |
1611 UTF8ToUTF16(s.ColumnString(3))); | 1611 s.ColumnString16(3)); |
1612 string16 credit_card_number = UTF8ToUTF16(s.ColumnString(4)); | 1612 string16 credit_card_number = s.ColumnString16(4); |
1613 // It could be non-empty prior to version 23. After that it encrypted in | 1613 // It could be non-empty prior to version 23. After that it encrypted in |
1614 // the column 10. | 1614 // the column 10. |
1615 if (credit_card_number.empty()) { | 1615 if (credit_card_number.empty()) { |
1616 int encrypted_cc_len = s.ColumnByteLength(10); | 1616 int encrypted_cc_len = s.ColumnByteLength(10); |
1617 std::string encrypted_cc; | 1617 std::string encrypted_cc; |
1618 if (encrypted_cc_len) { | 1618 if (encrypted_cc_len) { |
1619 encrypted_cc.resize(encrypted_cc_len); | 1619 encrypted_cc.resize(encrypted_cc_len); |
1620 memcpy(&encrypted_cc[0], s.ColumnBlob(10), encrypted_cc_len); | 1620 memcpy(&encrypted_cc[0], s.ColumnBlob(10), encrypted_cc_len); |
1621 Encryptor::DecryptString16(encrypted_cc, &credit_card_number); | 1621 Encryptor::DecryptString16(encrypted_cc, &credit_card_number); |
1622 } | 1622 } |
1623 } | 1623 } |
1624 credit_card->SetInfo(AutoFillType(CREDIT_CARD_NUMBER), credit_card_number); | 1624 credit_card->SetInfo(AutoFillType(CREDIT_CARD_NUMBER), credit_card_number); |
1625 credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), | 1625 credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), |
1626 UTF8ToUTF16(s.ColumnString(5))); | 1626 s.ColumnString16(5)); |
1627 credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), | 1627 credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), |
1628 UTF8ToUTF16(s.ColumnString(6))); | 1628 s.ColumnString16(6)); |
1629 | 1629 |
1630 string16 credit_card_verification_code = UTF8ToUTF16(s.ColumnString(7)); | 1630 string16 credit_card_verification_code = s.ColumnString16(7); |
1631 // It could be non-empty prior to version 23. After that it encrypted in | 1631 // It could be non-empty prior to version 23. After that it encrypted in |
1632 // the column 11. | 1632 // the column 11. |
1633 if (credit_card_verification_code.empty()) { | 1633 if (credit_card_verification_code.empty()) { |
1634 int encrypted_cc_len = s.ColumnByteLength(11); | 1634 int encrypted_cc_len = s.ColumnByteLength(11); |
1635 std::string encrypted_cc; | 1635 std::string encrypted_cc; |
1636 if (encrypted_cc_len) { | 1636 if (encrypted_cc_len) { |
1637 encrypted_cc.resize(encrypted_cc_len); | 1637 encrypted_cc.resize(encrypted_cc_len); |
1638 memcpy(&encrypted_cc[0], s.ColumnBlob(11), encrypted_cc_len); | 1638 memcpy(&encrypted_cc[0], s.ColumnBlob(11), encrypted_cc_len); |
1639 Encryptor::DecryptString16(encrypted_cc, &credit_card_verification_code); | 1639 Encryptor::DecryptString16(encrypted_cc, &credit_card_verification_code); |
1640 } | 1640 } |
1641 } | 1641 } |
1642 credit_card->SetInfo(AutoFillType(CREDIT_CARD_VERIFICATION_CODE), | 1642 credit_card->SetInfo(AutoFillType(CREDIT_CARD_VERIFICATION_CODE), |
1643 credit_card_verification_code); | 1643 credit_card_verification_code); |
1644 credit_card->set_billing_address(UTF8ToUTF16(s.ColumnString(8))); | 1644 credit_card->set_billing_address(s.ColumnString16(8)); |
1645 credit_card->set_shipping_address(UTF8ToUTF16(s.ColumnString(9))); | 1645 credit_card->set_shipping_address(s.ColumnString16(9)); |
1646 // Column 10 is processed above. | 1646 // Column 10 is processed above. |
1647 // Column 11 is processed above. | 1647 // Column 11 is processed above. |
1648 | 1648 |
1649 return credit_card; | 1649 return credit_card; |
1650 } | 1650 } |
1651 | 1651 |
1652 bool WebDatabase::GetCreditCardForLabel(const string16& label, | 1652 bool WebDatabase::GetCreditCardForLabel(const string16& label, |
1653 CreditCard** credit_card) { | 1653 CreditCard** credit_card) { |
1654 DCHECK(credit_card); | 1654 DCHECK(credit_card); |
1655 sql::Statement s(db_.GetUniqueStatement( | 1655 sql::Statement s(db_.GetUniqueStatement( |
1656 "SELECT * FROM credit_cards " | 1656 "SELECT * FROM credit_cards " |
1657 "WHERE label = ?")); | 1657 "WHERE label = ?")); |
1658 if (!s) { | 1658 if (!s) { |
1659 NOTREACHED() << "Statement prepare failed"; | 1659 NOTREACHED() << "Statement prepare failed"; |
1660 return false; | 1660 return false; |
1661 } | 1661 } |
1662 | 1662 |
1663 s.BindString(0, UTF16ToUTF8(label)); | 1663 s.BindString16(0, label); |
1664 if (!s.Step()) | 1664 if (!s.Step()) |
1665 return false; | 1665 return false; |
1666 | 1666 |
1667 *credit_card = CreditCardFromStatement(s); | 1667 *credit_card = CreditCardFromStatement(s); |
1668 | 1668 |
1669 return s.Succeeded(); | 1669 return s.Succeeded(); |
1670 } | 1670 } |
1671 | 1671 |
1672 bool WebDatabase::GetCreditCardForID(int credit_card_id, | 1672 bool WebDatabase::GetCreditCardForID(int credit_card_id, |
1673 CreditCard** credit_card) { | 1673 CreditCard** credit_card) { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1829 | 1829 |
1830 // Add successive versions here. Each should set the version number and | 1830 // Add successive versions here. Each should set the version number and |
1831 // compatible version number as appropriate, then fall through to the next | 1831 // compatible version number as appropriate, then fall through to the next |
1832 // case. | 1832 // case. |
1833 | 1833 |
1834 case kCurrentVersionNumber: | 1834 case kCurrentVersionNumber: |
1835 // No migration needed. | 1835 // No migration needed. |
1836 return; | 1836 return; |
1837 } | 1837 } |
1838 } | 1838 } |
OLD | NEW |