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 1209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 return false; | 1220 return false; |
1221 } | 1221 } |
1222 | 1222 |
1223 BindAutoFillProfileToStatement(profile, &s); | 1223 BindAutoFillProfileToStatement(profile, &s); |
1224 | 1224 |
1225 if (!s.Run()) { | 1225 if (!s.Run()) { |
1226 NOTREACHED(); | 1226 NOTREACHED(); |
1227 return false; | 1227 return false; |
1228 } | 1228 } |
1229 | 1229 |
1230 return true; | 1230 return s.Succeeded(); |
| 1231 } |
| 1232 |
| 1233 static AutoFillProfile* AutoFillProfileFromStatement(const sql::Statement& s) { |
| 1234 AutoFillProfile* profile = new AutoFillProfile( |
| 1235 ASCIIToUTF16(s.ColumnString(0)), s.ColumnInt(1)); |
| 1236 profile->SetInfo(AutoFillType(NAME_FIRST), |
| 1237 ASCIIToUTF16(s.ColumnString(2))); |
| 1238 profile->SetInfo(AutoFillType(NAME_MIDDLE), |
| 1239 ASCIIToUTF16(s.ColumnString(3))); |
| 1240 profile->SetInfo(AutoFillType(NAME_LAST), |
| 1241 ASCIIToUTF16(s.ColumnString(4))); |
| 1242 profile->SetInfo(AutoFillType(EMAIL_ADDRESS), |
| 1243 ASCIIToUTF16(s.ColumnString(5))); |
| 1244 profile->SetInfo(AutoFillType(COMPANY_NAME), |
| 1245 ASCIIToUTF16(s.ColumnString(6))); |
| 1246 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), |
| 1247 ASCIIToUTF16(s.ColumnString(7))); |
| 1248 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), |
| 1249 ASCIIToUTF16(s.ColumnString(8))); |
| 1250 profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), |
| 1251 ASCIIToUTF16(s.ColumnString(9))); |
| 1252 profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), |
| 1253 ASCIIToUTF16(s.ColumnString(10))); |
| 1254 profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP), |
| 1255 ASCIIToUTF16(s.ColumnString(11))); |
| 1256 profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), |
| 1257 ASCIIToUTF16(s.ColumnString(12))); |
| 1258 profile->SetInfo(AutoFillType(PHONE_HOME_NUMBER), |
| 1259 ASCIIToUTF16(s.ColumnString(13))); |
| 1260 profile->SetInfo(AutoFillType(PHONE_FAX_NUMBER), |
| 1261 ASCIIToUTF16(s.ColumnString(14))); |
| 1262 |
| 1263 return profile; |
1231 } | 1264 } |
1232 | 1265 |
1233 bool WebDatabase::GetAutoFillProfileForLabel(const string16& label, | 1266 bool WebDatabase::GetAutoFillProfileForLabel(const string16& label, |
1234 AutoFillProfile** profile) { | 1267 AutoFillProfile** profile) { |
| 1268 DCHECK(profile); |
1235 sql::Statement s(db_.GetUniqueStatement( | 1269 sql::Statement s(db_.GetUniqueStatement( |
1236 "SELECT * FROM autofill_profiles " | 1270 "SELECT * FROM autofill_profiles " |
1237 "WHERE label = ?")); | 1271 "WHERE label = ?")); |
1238 if (!s) { | 1272 if (!s) { |
1239 NOTREACHED() << "Statement prepare failed"; | 1273 NOTREACHED() << "Statement prepare failed"; |
1240 return false; | 1274 return false; |
1241 } | 1275 } |
1242 | 1276 |
1243 s.BindString(0, UTF16ToUTF8(label)); | 1277 s.BindString(0, UTF16ToUTF8(label)); |
1244 if (!s.Step()) | 1278 if (!s.Step()) |
1245 return false; | 1279 return false; |
1246 | 1280 |
1247 *profile = new AutoFillProfile(label, s.ColumnInt(1)); | 1281 *profile = AutoFillProfileFromStatement(s); |
1248 AutoFillProfile* profile_ptr = *profile; | |
1249 profile_ptr->SetInfo(AutoFillType(NAME_FIRST), | |
1250 ASCIIToUTF16(s.ColumnString(2))); | |
1251 profile_ptr->SetInfo(AutoFillType(NAME_MIDDLE), | |
1252 ASCIIToUTF16(s.ColumnString(3))); | |
1253 profile_ptr->SetInfo(AutoFillType(NAME_LAST), | |
1254 ASCIIToUTF16(s.ColumnString(4))); | |
1255 profile_ptr->SetInfo(AutoFillType(EMAIL_ADDRESS), | |
1256 ASCIIToUTF16(s.ColumnString(5))); | |
1257 profile_ptr->SetInfo(AutoFillType(COMPANY_NAME), | |
1258 ASCIIToUTF16(s.ColumnString(6))); | |
1259 profile_ptr->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), | |
1260 ASCIIToUTF16(s.ColumnString(7))); | |
1261 profile_ptr->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), | |
1262 ASCIIToUTF16(s.ColumnString(8))); | |
1263 profile_ptr->SetInfo(AutoFillType(ADDRESS_HOME_CITY), | |
1264 ASCIIToUTF16(s.ColumnString(9))); | |
1265 profile_ptr->SetInfo(AutoFillType(ADDRESS_HOME_STATE), | |
1266 ASCIIToUTF16(s.ColumnString(10))); | |
1267 profile_ptr->SetInfo(AutoFillType(ADDRESS_HOME_ZIP), | |
1268 ASCIIToUTF16(s.ColumnString(11))); | |
1269 profile_ptr->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), | |
1270 ASCIIToUTF16(s.ColumnString(12))); | |
1271 profile_ptr->SetInfo(AutoFillType(PHONE_HOME_NUMBER), | |
1272 ASCIIToUTF16(s.ColumnString(13))); | |
1273 profile_ptr->SetInfo(AutoFillType(PHONE_FAX_NUMBER), | |
1274 ASCIIToUTF16(s.ColumnString(14))); | |
1275 | 1282 |
1276 return true; | 1283 return s.Succeeded(); |
| 1284 } |
| 1285 |
| 1286 bool WebDatabase::GetAutoFillProfiles( |
| 1287 std::vector<AutoFillProfile*>* profiles) { |
| 1288 DCHECK(profiles); |
| 1289 profiles->clear(); |
| 1290 |
| 1291 sql::Statement s(db_.GetUniqueStatement("SELECT * FROM autofill_profiles")); |
| 1292 if (!s) { |
| 1293 NOTREACHED() << "Statement prepare failed"; |
| 1294 return false; |
| 1295 } |
| 1296 |
| 1297 while (s.Step()) |
| 1298 profiles->push_back(AutoFillProfileFromStatement(s)); |
| 1299 |
| 1300 return s.Succeeded(); |
1277 } | 1301 } |
1278 | 1302 |
1279 bool WebDatabase::UpdateAutoFillProfile(const AutoFillProfile& profile) { | 1303 bool WebDatabase::UpdateAutoFillProfile(const AutoFillProfile& profile) { |
1280 DCHECK(profile.unique_id()); | 1304 DCHECK(profile.unique_id()); |
1281 sql::Statement s(db_.GetUniqueStatement( | 1305 sql::Statement s(db_.GetUniqueStatement( |
1282 "UPDATE autofill_profiles " | 1306 "UPDATE autofill_profiles " |
1283 "SET label=?, unique_id=?, first_name=?, middle_name=?, last_name=?, " | 1307 "SET label=?, unique_id=?, first_name=?, middle_name=?, last_name=?, " |
1284 " email=?, company_name=?, address_line_1=?, address_line_2=?, " | 1308 " email=?, company_name=?, address_line_1=?, address_line_2=?, " |
1285 " city=?, state=?, zipcode=?, country=?, phone=?, fax=? " | 1309 " city=?, state=?, zipcode=?, country=?, phone=?, fax=? " |
1286 "WHERE unique_id=?")); | 1310 "WHERE unique_id=?")); |
1287 if (!s) { | 1311 if (!s) { |
1288 NOTREACHED() << "Statement prepare failed"; | 1312 NOTREACHED() << "Statement prepare failed"; |
1289 return false; | 1313 return false; |
1290 } | 1314 } |
1291 | 1315 |
1292 BindAutoFillProfileToStatement(profile, &s); | 1316 BindAutoFillProfileToStatement(profile, &s); |
1293 s.BindInt(15, profile.unique_id()); | 1317 s.BindInt(15, profile.unique_id()); |
1294 return s.Run(); | 1318 return s.Run(); |
1295 } | 1319 } |
1296 | 1320 |
1297 bool WebDatabase::RemoveAutoFillProfile(const AutoFillProfile& profile) { | 1321 bool WebDatabase::RemoveAutoFillProfile(int profile_id) { |
1298 DCHECK(profile.unique_id()); | 1322 DCHECK_NE(0, profile_id); |
1299 sql::Statement s(db_.GetUniqueStatement( | 1323 sql::Statement s(db_.GetUniqueStatement( |
1300 "DELETE FROM autofill_profiles WHERE unique_id = ?")); | 1324 "DELETE FROM autofill_profiles WHERE unique_id = ?")); |
1301 if (!s) { | 1325 if (!s) { |
1302 NOTREACHED() << "Statement prepare failed"; | 1326 NOTREACHED() << "Statement prepare failed"; |
1303 return false; | 1327 return false; |
1304 } | 1328 } |
1305 | 1329 |
1306 s.BindInt(0, profile.unique_id()); | 1330 s.BindInt(0, profile_id); |
1307 return s.Run(); | 1331 return s.Run(); |
1308 } | 1332 } |
1309 | 1333 |
1310 bool WebDatabase::AddToCountOfFormElement(int64 pair_id, | 1334 bool WebDatabase::AddToCountOfFormElement(int64 pair_id, |
1311 int delta, | 1335 int delta, |
1312 bool* was_removed) { | 1336 bool* was_removed) { |
1313 DCHECK(was_removed); | 1337 DCHECK(was_removed); |
1314 int count = 0; | 1338 int count = 0; |
1315 *was_removed = false; | 1339 *was_removed = false; |
1316 | 1340 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 | 1405 |
1382 // Add successive versions here. Each should set the version number and | 1406 // Add successive versions here. Each should set the version number and |
1383 // compatible version number as appropriate, then fall through to the next | 1407 // compatible version number as appropriate, then fall through to the next |
1384 // case. | 1408 // case. |
1385 | 1409 |
1386 case kCurrentVersionNumber: | 1410 case kCurrentVersionNumber: |
1387 // No migration needed. | 1411 // No migration needed. |
1388 return; | 1412 return; |
1389 } | 1413 } |
1390 } | 1414 } |
OLD | NEW |