OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/autofill_table.h" | 5 #include "chrome/browser/webdata/autofill_table.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 | 132 |
133 return credit_card; | 133 return credit_card; |
134 } | 134 } |
135 | 135 |
136 bool AddAutofillProfileNamesToProfile(sql::Connection* db, | 136 bool AddAutofillProfileNamesToProfile(sql::Connection* db, |
137 AutofillProfile* profile) { | 137 AutofillProfile* profile) { |
138 sql::Statement s(db->GetUniqueStatement( | 138 sql::Statement s(db->GetUniqueStatement( |
139 "SELECT guid, first_name, middle_name, last_name " | 139 "SELECT guid, first_name, middle_name, last_name " |
140 "FROM autofill_profile_names " | 140 "FROM autofill_profile_names " |
141 "WHERE guid=?")); | 141 "WHERE guid=?")); |
142 if (!s) { | 142 s.BindString(0, profile->guid()); |
143 NOTREACHED() << "Statement prepare failed"; | 143 |
144 if (!s.is_valid()) | |
144 return false; | 145 return false; |
145 } | |
146 s.BindString(0, profile->guid()); | |
147 | 146 |
148 std::vector<string16> first_names; | 147 std::vector<string16> first_names; |
149 std::vector<string16> middle_names; | 148 std::vector<string16> middle_names; |
150 std::vector<string16> last_names; | 149 std::vector<string16> last_names; |
151 while (s.Step()) { | 150 while (s.Step()) { |
152 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 151 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
153 first_names.push_back(s.ColumnString16(1)); | 152 first_names.push_back(s.ColumnString16(1)); |
154 middle_names.push_back(s.ColumnString16(2)); | 153 middle_names.push_back(s.ColumnString16(2)); |
155 last_names.push_back(s.ColumnString16(3)); | 154 last_names.push_back(s.ColumnString16(3)); |
156 } | 155 } |
156 if (!s.Succeeded()) | |
157 return false; | |
Scott Hess - ex-Googler
2011/12/16 22:37:09
Yeah, I think this is a reasonable pattern for the
| |
158 | |
157 profile->SetMultiInfo(NAME_FIRST, first_names); | 159 profile->SetMultiInfo(NAME_FIRST, first_names); |
158 profile->SetMultiInfo(NAME_MIDDLE, middle_names); | 160 profile->SetMultiInfo(NAME_MIDDLE, middle_names); |
159 profile->SetMultiInfo(NAME_LAST, last_names); | 161 profile->SetMultiInfo(NAME_LAST, last_names); |
160 return true; | 162 return true; |
161 } | 163 } |
162 | 164 |
163 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, | 165 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, |
164 AutofillProfile* profile) { | 166 AutofillProfile* profile) { |
165 sql::Statement s(db->GetUniqueStatement( | 167 sql::Statement s(db->GetUniqueStatement( |
166 "SELECT guid, email " | 168 "SELECT guid, email " |
167 "FROM autofill_profile_emails " | 169 "FROM autofill_profile_emails " |
168 "WHERE guid=?")); | 170 "WHERE guid=?")); |
169 if (!s) { | 171 s.BindString(0, profile->guid()); |
170 NOTREACHED() << "Statement prepare failed"; | 172 |
173 if (!s.is_valid()) | |
171 return false; | 174 return false; |
172 } | |
173 s.BindString(0, profile->guid()); | |
174 | 175 |
175 std::vector<string16> emails; | 176 std::vector<string16> emails; |
176 while (s.Step()) { | 177 while (s.Step()) { |
177 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 178 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
178 emails.push_back(s.ColumnString16(1)); | 179 emails.push_back(s.ColumnString16(1)); |
179 } | 180 } |
181 if (!s.Succeeded()) | |
182 return false; | |
183 | |
180 profile->SetMultiInfo(EMAIL_ADDRESS, emails); | 184 profile->SetMultiInfo(EMAIL_ADDRESS, emails); |
181 return true; | 185 return true; |
182 } | 186 } |
183 | 187 |
184 bool AddAutofillProfilePhonesToProfile(sql::Connection* db, | 188 bool AddAutofillProfilePhonesToProfile(sql::Connection* db, |
185 AutofillProfile* profile) { | 189 AutofillProfile* profile) { |
186 sql::Statement s(db->GetUniqueStatement( | 190 sql::Statement s(db->GetUniqueStatement( |
187 "SELECT guid, type, number " | 191 "SELECT guid, type, number " |
188 "FROM autofill_profile_phones " | 192 "FROM autofill_profile_phones " |
189 "WHERE guid=? AND type=?")); | 193 "WHERE guid=? AND type=?")); |
190 if (!s) { | 194 |
191 NOTREACHED() << "Statement prepare failed"; | 195 // Value used to be either [(0, phone), (1, fax)] but fax has been removed. |
196 s.BindString(0, profile->guid()); | |
197 s.BindInt(1, 0); | |
198 | |
199 if (!s.is_valid()) | |
192 return false; | 200 return false; |
193 } | |
194 s.BindString(0, profile->guid()); | |
195 // Value used to be either [(0, phone), (1, fax)] but fax has been removed. | |
196 s.BindInt(1, 0); | |
197 | 201 |
198 std::vector<string16> numbers; | 202 std::vector<string16> numbers; |
199 while (s.Step()) { | 203 while (s.Step()) { |
200 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 204 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
201 numbers.push_back(s.ColumnString16(2)); | 205 numbers.push_back(s.ColumnString16(2)); |
202 } | 206 } |
207 if (!s.Succeeded()) | |
208 return false; | |
209 | |
203 profile->SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, numbers); | 210 profile->SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, numbers); |
204 return true; | 211 return true; |
205 } | 212 } |
206 | 213 |
207 bool AddAutofillProfileNames(const AutofillProfile& profile, | 214 bool AddAutofillProfileNames(const AutofillProfile& profile, |
208 sql::Connection* db) { | 215 sql::Connection* db) { |
209 std::vector<string16> first_names; | 216 std::vector<string16> first_names; |
210 profile.GetMultiInfo(NAME_FIRST, &first_names); | 217 profile.GetMultiInfo(NAME_FIRST, &first_names); |
211 std::vector<string16> middle_names; | 218 std::vector<string16> middle_names; |
212 profile.GetMultiInfo(NAME_MIDDLE, &middle_names); | 219 profile.GetMultiInfo(NAME_MIDDLE, &middle_names); |
213 std::vector<string16> last_names; | 220 std::vector<string16> last_names; |
214 profile.GetMultiInfo(NAME_LAST, &last_names); | 221 profile.GetMultiInfo(NAME_LAST, &last_names); |
215 DCHECK_EQ(first_names.size(), middle_names.size()); | 222 DCHECK_EQ(first_names.size(), middle_names.size()); |
216 DCHECK_EQ(middle_names.size(), last_names.size()); | 223 DCHECK_EQ(middle_names.size(), last_names.size()); |
217 | 224 |
218 for (size_t i = 0; i < first_names.size(); ++i) { | 225 for (size_t i = 0; i < first_names.size(); ++i) { |
219 // Add the new name. | 226 // Add the new name. |
220 sql::Statement s(db->GetUniqueStatement( | 227 sql::Statement s(db->GetUniqueStatement( |
221 "INSERT INTO autofill_profile_names" | 228 "INSERT INTO autofill_profile_names" |
222 " (guid, first_name, middle_name, last_name) " | 229 " (guid, first_name, middle_name, last_name) " |
223 "VALUES (?,?,?,?)")); | 230 "VALUES (?,?,?,?)")); |
224 if (!s) { | |
225 NOTREACHED(); | |
226 return false; | |
227 } | |
228 s.BindString(0, profile.guid()); | 231 s.BindString(0, profile.guid()); |
229 s.BindString16(1, first_names[i]); | 232 s.BindString16(1, first_names[i]); |
230 s.BindString16(2, middle_names[i]); | 233 s.BindString16(2, middle_names[i]); |
231 s.BindString16(3, last_names[i]); | 234 s.BindString16(3, last_names[i]); |
232 | 235 |
233 if (!s.Run()) { | 236 if (!s.Run()) |
234 NOTREACHED(); | |
235 return false; | 237 return false; |
236 } | |
237 } | 238 } |
238 return true; | 239 return true; |
239 } | 240 } |
240 | 241 |
241 bool AddAutofillProfileEmails(const AutofillProfile& profile, | 242 bool AddAutofillProfileEmails(const AutofillProfile& profile, |
242 sql::Connection* db) { | 243 sql::Connection* db) { |
243 std::vector<string16> emails; | 244 std::vector<string16> emails; |
244 profile.GetMultiInfo(EMAIL_ADDRESS, &emails); | 245 profile.GetMultiInfo(EMAIL_ADDRESS, &emails); |
245 | 246 |
246 for (size_t i = 0; i < emails.size(); ++i) { | 247 for (size_t i = 0; i < emails.size(); ++i) { |
247 // Add the new email. | 248 // Add the new email. |
248 sql::Statement s(db->GetUniqueStatement( | 249 sql::Statement s(db->GetUniqueStatement( |
249 "INSERT INTO autofill_profile_emails" | 250 "INSERT INTO autofill_profile_emails" |
250 " (guid, email) " | 251 " (guid, email) " |
251 "VALUES (?,?)")); | 252 "VALUES (?,?)")); |
252 if (!s) { | |
253 NOTREACHED(); | |
254 return false; | |
255 } | |
256 s.BindString(0, profile.guid()); | 253 s.BindString(0, profile.guid()); |
257 s.BindString16(1, emails[i]); | 254 s.BindString16(1, emails[i]); |
258 | 255 |
259 if (!s.Run()) { | 256 if (!s.Run()) |
260 NOTREACHED(); | |
261 return false; | 257 return false; |
262 } | |
263 } | 258 } |
259 | |
264 return true; | 260 return true; |
265 } | 261 } |
266 | 262 |
267 bool AddAutofillProfilePhones(const AutofillProfile& profile, | 263 bool AddAutofillProfilePhones(const AutofillProfile& profile, |
268 sql::Connection* db) { | 264 sql::Connection* db) { |
269 std::vector<string16> numbers; | 265 std::vector<string16> numbers; |
270 profile.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &numbers); | 266 profile.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &numbers); |
271 | 267 |
272 for (size_t i = 0; i < numbers.size(); ++i) { | 268 for (size_t i = 0; i < numbers.size(); ++i) { |
273 // Add the new number. | 269 // Add the new number. |
274 sql::Statement s(db->GetUniqueStatement( | 270 sql::Statement s(db->GetUniqueStatement( |
275 "INSERT INTO autofill_profile_phones" | 271 "INSERT INTO autofill_profile_phones" |
276 " (guid, type, number) " | 272 " (guid, type, number) " |
277 "VALUES (?,?,?)")); | 273 "VALUES (?,?,?)")); |
278 if (!s) { | |
279 NOTREACHED(); | |
280 return false; | |
281 } | |
282 s.BindString(0, profile.guid()); | 274 s.BindString(0, profile.guid()); |
283 // Value used to be either [(0, phone), (1, fax)] but fax has been removed. | 275 // Value used to be either [(0, phone), (1, fax)] but fax has been removed. |
284 s.BindInt(1, 0); | 276 s.BindInt(1, 0); |
285 s.BindString16(2, numbers[i]); | 277 s.BindString16(2, numbers[i]); |
286 | 278 |
287 if (!s.Run()) { | 279 if (!s.Run()) |
288 NOTREACHED(); | |
289 return false; | 280 return false; |
290 } | |
291 } | 281 } |
292 | 282 |
293 return true; | 283 return true; |
294 } | 284 } |
295 | 285 |
296 bool AddAutofillProfilePieces(const AutofillProfile& profile, | 286 bool AddAutofillProfilePieces(const AutofillProfile& profile, |
297 sql::Connection* db) { | 287 sql::Connection* db) { |
298 if (!AddAutofillProfileNames(profile, db)) | 288 if (!AddAutofillProfileNames(profile, db)) |
299 return false; | 289 return false; |
300 | 290 |
301 if (!AddAutofillProfileEmails(profile, db)) | 291 if (!AddAutofillProfileEmails(profile, db)) |
302 return false; | 292 return false; |
303 | 293 |
304 if (!AddAutofillProfilePhones(profile, db)) | 294 if (!AddAutofillProfilePhones(profile, db)) |
305 return false; | 295 return false; |
306 | 296 |
307 return true; | 297 return true; |
308 } | 298 } |
309 | 299 |
310 bool RemoveAutofillProfilePieces(const std::string& guid, sql::Connection* db) { | 300 bool RemoveAutofillProfilePieces(const std::string& guid, sql::Connection* db) { |
311 sql::Statement s1(db->GetUniqueStatement( | 301 sql::Statement s1(db->GetUniqueStatement( |
312 "DELETE FROM autofill_profile_names WHERE guid = ?")); | 302 "DELETE FROM autofill_profile_names WHERE guid = ?")); |
313 if (!s1) { | 303 s1.BindString(0, guid); |
314 NOTREACHED() << "Statement prepare failed"; | |
315 return false; | |
316 } | |
317 | 304 |
318 s1.BindString(0, guid); | |
319 if (!s1.Run()) | 305 if (!s1.Run()) |
320 return false; | 306 return false; |
321 | 307 |
322 sql::Statement s2(db->GetUniqueStatement( | 308 sql::Statement s2(db->GetUniqueStatement( |
323 "DELETE FROM autofill_profile_emails WHERE guid = ?")); | 309 "DELETE FROM autofill_profile_emails WHERE guid = ?")); |
324 if (!s2) { | 310 s2.BindString(0, guid); |
325 NOTREACHED() << "Statement prepare failed"; | |
326 return false; | |
327 } | |
328 | 311 |
329 s2.BindString(0, guid); | |
330 if (!s2.Run()) | 312 if (!s2.Run()) |
331 return false; | 313 return false; |
332 | 314 |
333 sql::Statement s3(db->GetUniqueStatement( | 315 sql::Statement s3(db->GetUniqueStatement( |
334 "DELETE FROM autofill_profile_phones WHERE guid = ?")); | 316 "DELETE FROM autofill_profile_phones WHERE guid = ?")); |
335 if (!s3) { | 317 s3.BindString(0, guid); |
336 NOTREACHED() << "Statement prepare failed"; | |
337 return false; | |
338 } | |
339 | 318 |
340 s3.BindString(0, guid); | |
341 return s3.Run(); | 319 return s3.Run(); |
342 } | 320 } |
343 | 321 |
344 } // namespace | 322 } // namespace |
345 | 323 |
346 // The maximum length allowed for form data. | 324 // The maximum length allowed for form data. |
347 const size_t AutofillTable::kMaxDataLength = 1024; | 325 const size_t AutofillTable::kMaxDataLength = 1024; |
348 | 326 |
349 AutofillTable::AutofillTable(sql::Connection* db, sql::MetaTable* meta_table) | 327 AutofillTable::AutofillTable(sql::Connection* db, sql::MetaTable* meta_table) |
350 : WebDatabaseTable(db, meta_table) { | 328 : WebDatabaseTable(db, meta_table) { |
(...skipping 29 matching lines...) Expand all Loading... | |
380 int limit) { | 358 int limit) { |
381 DCHECK(values); | 359 DCHECK(values); |
382 sql::Statement s; | 360 sql::Statement s; |
383 | 361 |
384 if (prefix.empty()) { | 362 if (prefix.empty()) { |
385 s.Assign(db_->GetUniqueStatement( | 363 s.Assign(db_->GetUniqueStatement( |
386 "SELECT value FROM autofill " | 364 "SELECT value FROM autofill " |
387 "WHERE name = ? " | 365 "WHERE name = ? " |
388 "ORDER BY count DESC " | 366 "ORDER BY count DESC " |
389 "LIMIT ?")); | 367 "LIMIT ?")); |
390 if (!s) { | |
391 NOTREACHED() << "Statement prepare failed"; | |
392 return false; | |
393 } | |
394 | |
395 s.BindString16(0, name); | 368 s.BindString16(0, name); |
396 s.BindInt(1, limit); | 369 s.BindInt(1, limit); |
397 } else { | 370 } else { |
398 string16 prefix_lower = base::i18n::ToLower(prefix); | 371 string16 prefix_lower = base::i18n::ToLower(prefix); |
399 string16 next_prefix = prefix_lower; | 372 string16 next_prefix = prefix_lower; |
400 next_prefix[next_prefix.length() - 1]++; | 373 next_prefix[next_prefix.length() - 1]++; |
401 | 374 |
402 s.Assign(db_->GetUniqueStatement( | 375 s.Assign(db_->GetUniqueStatement( |
403 "SELECT value FROM autofill " | 376 "SELECT value FROM autofill " |
404 "WHERE name = ? AND " | 377 "WHERE name = ? AND " |
405 "value_lower >= ? AND " | 378 "value_lower >= ? AND " |
406 "value_lower < ? " | 379 "value_lower < ? " |
407 "ORDER BY count DESC " | 380 "ORDER BY count DESC " |
408 "LIMIT ?")); | 381 "LIMIT ?")); |
409 if (!s) { | |
410 NOTREACHED() << "Statement prepare failed"; | |
411 return false; | |
412 } | |
413 | |
414 s.BindString16(0, name); | 382 s.BindString16(0, name); |
415 s.BindString16(1, prefix_lower); | 383 s.BindString16(1, prefix_lower); |
416 s.BindString16(2, next_prefix); | 384 s.BindString16(2, next_prefix); |
417 s.BindInt(3, limit); | 385 s.BindInt(3, limit); |
418 } | 386 } |
419 | 387 |
420 values->clear(); | 388 values->clear(); |
421 while (s.Step()) | 389 while (s.Step()) |
422 values->push_back(s.ColumnString16(0)); | 390 values->push_back(s.ColumnString16(0)); |
423 return s.Succeeded(); | 391 return s.Succeeded(); |
424 } | 392 } |
425 | 393 |
426 bool AutofillTable::RemoveFormElementsAddedBetween( | 394 bool AutofillTable::RemoveFormElementsAddedBetween( |
427 const Time& delete_begin, | 395 const Time& delete_begin, |
428 const Time& delete_end, | 396 const Time& delete_end, |
429 std::vector<AutofillChange>* changes) { | 397 std::vector<AutofillChange>* changes) { |
430 DCHECK(changes); | 398 DCHECK(changes); |
431 // Query for the pair_id, name, and value of all form elements that | 399 // Query for the pair_id, name, and value of all form elements that |
432 // were used between the given times. | 400 // were used between the given times. |
433 sql::Statement s(db_->GetUniqueStatement( | 401 sql::Statement s(db_->GetUniqueStatement( |
434 "SELECT DISTINCT a.pair_id, a.name, a.value " | 402 "SELECT DISTINCT a.pair_id, a.name, a.value " |
435 "FROM autofill_dates ad JOIN autofill a ON ad.pair_id = a.pair_id " | 403 "FROM autofill_dates ad JOIN autofill a ON ad.pair_id = a.pair_id " |
436 "WHERE ad.date_created >= ? AND ad.date_created < ?")); | 404 "WHERE ad.date_created >= ? AND ad.date_created < ?")); |
437 if (!s) { | |
438 NOTREACHED() << "Statement 1 prepare failed"; | |
439 return false; | |
440 } | |
441 s.BindInt64(0, delete_begin.ToTimeT()); | 405 s.BindInt64(0, delete_begin.ToTimeT()); |
442 s.BindInt64(1, | 406 s.BindInt64(1, |
443 delete_end.is_null() ? | 407 delete_end.is_null() ? |
444 std::numeric_limits<int64>::max() : | 408 std::numeric_limits<int64>::max() : |
445 delete_end.ToTimeT()); | 409 delete_end.ToTimeT()); |
446 | 410 |
447 AutofillElementList elements; | 411 AutofillElementList elements; |
448 while (s.Step()) { | 412 while (s.Step()) { |
449 elements.push_back(MakeTuple(s.ColumnInt64(0), | 413 elements.push_back(MakeTuple(s.ColumnInt64(0), |
450 s.ColumnString16(1), | 414 s.ColumnString16(1), |
451 s.ColumnString16(2))); | 415 s.ColumnString16(2))); |
452 } | 416 } |
453 | 417 if (!s.Succeeded()) |
454 if (!s.Succeeded()) { | |
455 NOTREACHED(); | |
456 return false; | 418 return false; |
457 } | |
458 | 419 |
459 for (AutofillElementList::iterator itr = elements.begin(); | 420 for (AutofillElementList::iterator itr = elements.begin(); |
460 itr != elements.end(); itr++) { | 421 itr != elements.end(); itr++) { |
461 int how_many = 0; | 422 int how_many = 0; |
462 if (!RemoveFormElementForTimeRange(itr->a, delete_begin, delete_end, | 423 if (!RemoveFormElementForTimeRange(itr->a, delete_begin, delete_end, |
463 &how_many)) { | 424 &how_many)) { |
464 return false; | 425 return false; |
465 } | 426 } |
466 bool was_removed = false; | 427 bool was_removed = false; |
467 if (!AddToCountOfFormElement(itr->a, -how_many, &was_removed)) | 428 if (!AddToCountOfFormElement(itr->a, -how_many, &was_removed)) |
468 return false; | 429 return false; |
469 AutofillChange::Type change_type = | 430 AutofillChange::Type change_type = |
470 was_removed ? AutofillChange::REMOVE : AutofillChange::UPDATE; | 431 was_removed ? AutofillChange::REMOVE : AutofillChange::UPDATE; |
471 changes->push_back(AutofillChange(change_type, | 432 changes->push_back(AutofillChange(change_type, |
472 AutofillKey(itr->b, itr->c))); | 433 AutofillKey(itr->b, itr->c))); |
473 } | 434 } |
474 | 435 |
475 return true; | 436 return true; |
476 } | 437 } |
477 | 438 |
478 bool AutofillTable::RemoveFormElementForTimeRange(int64 pair_id, | 439 bool AutofillTable::RemoveFormElementForTimeRange(int64 pair_id, |
479 const Time& delete_begin, | 440 const Time& delete_begin, |
480 const Time& delete_end, | 441 const Time& delete_end, |
481 int* how_many) { | 442 int* how_many) { |
482 sql::Statement s(db_->GetUniqueStatement( | 443 sql::Statement s(db_->GetUniqueStatement( |
483 "DELETE FROM autofill_dates WHERE pair_id = ? AND " | 444 "DELETE FROM autofill_dates WHERE pair_id = ? AND " |
484 "date_created >= ? AND date_created < ?")); | 445 "date_created >= ? AND date_created < ?")); |
485 if (!s) { | |
486 NOTREACHED() << "Statement 1 prepare failed"; | |
487 return false; | |
488 } | |
489 s.BindInt64(0, pair_id); | 446 s.BindInt64(0, pair_id); |
490 s.BindInt64(1, delete_begin.is_null() ? 0 : delete_begin.ToTimeT()); | 447 s.BindInt64(1, delete_begin.is_null() ? 0 : delete_begin.ToTimeT()); |
491 s.BindInt64(2, delete_end.is_null() ? std::numeric_limits<int64>::max() : | 448 s.BindInt64(2, delete_end.is_null() ? std::numeric_limits<int64>::max() : |
492 delete_end.ToTimeT()); | 449 delete_end.ToTimeT()); |
493 | 450 |
494 bool result = s.Run(); | 451 bool result = s.Run(); |
495 if (how_many) | 452 if (how_many) |
496 *how_many = db_->GetLastChangeCount(); | 453 *how_many = db_->GetLastChangeCount(); |
497 | 454 |
498 return result; | 455 return result; |
(...skipping 17 matching lines...) Expand all Loading... | |
516 if (!SetCountOfFormElement(pair_id, count + delta)) | 473 if (!SetCountOfFormElement(pair_id, count + delta)) |
517 return false; | 474 return false; |
518 } | 475 } |
519 return true; | 476 return true; |
520 } | 477 } |
521 | 478 |
522 bool AutofillTable::GetIDAndCountOfFormElement( | 479 bool AutofillTable::GetIDAndCountOfFormElement( |
523 const FormField& element, | 480 const FormField& element, |
524 int64* pair_id, | 481 int64* pair_id, |
525 int* count) { | 482 int* count) { |
483 DCHECK(pair_id); | |
484 DCHECK(count); | |
485 | |
526 sql::Statement s(db_->GetUniqueStatement( | 486 sql::Statement s(db_->GetUniqueStatement( |
527 "SELECT pair_id, count FROM autofill " | 487 "SELECT pair_id, count FROM autofill " |
528 "WHERE name = ? AND value = ?")); | 488 "WHERE name = ? AND value = ?")); |
529 if (!s) { | |
530 NOTREACHED() << "Statement prepare failed"; | |
531 return false; | |
532 } | |
533 | |
534 s.BindString16(0, element.name); | 489 s.BindString16(0, element.name); |
535 s.BindString16(1, element.value); | 490 s.BindString16(1, element.value); |
536 | 491 |
492 if (!s.is_valid()) | |
493 return false; | |
494 | |
537 *pair_id = 0; | 495 *pair_id = 0; |
538 *count = 0; | 496 *count = 0; |
539 | 497 |
540 if (s.Step()) { | 498 if (s.Step()) { |
541 *pair_id = s.ColumnInt64(0); | 499 *pair_id = s.ColumnInt64(0); |
542 *count = s.ColumnInt(1); | 500 *count = s.ColumnInt(1); |
543 } | 501 } |
544 | 502 |
545 return true; | 503 return true; |
546 } | 504 } |
547 | 505 |
548 bool AutofillTable::GetCountOfFormElement(int64 pair_id, int* count) { | 506 bool AutofillTable::GetCountOfFormElement(int64 pair_id, int* count) { |
507 DCHECK(count); | |
549 sql::Statement s(db_->GetUniqueStatement( | 508 sql::Statement s(db_->GetUniqueStatement( |
550 "SELECT count FROM autofill WHERE pair_id = ?")); | 509 "SELECT count FROM autofill WHERE pair_id = ?")); |
551 if (!s) { | |
552 NOTREACHED() << "Statement prepare failed"; | |
553 return false; | |
554 } | |
555 | |
556 s.BindInt64(0, pair_id); | 510 s.BindInt64(0, pair_id); |
557 | 511 |
558 if (s.Step()) { | 512 if (s.Step()) { |
559 *count = s.ColumnInt(0); | 513 *count = s.ColumnInt(0); |
560 return true; | 514 return true; |
561 } | 515 } |
562 return false; | 516 return false; |
563 } | 517 } |
564 | 518 |
565 bool AutofillTable::SetCountOfFormElement(int64 pair_id, int count) { | 519 bool AutofillTable::SetCountOfFormElement(int64 pair_id, int count) { |
566 sql::Statement s(db_->GetUniqueStatement( | 520 sql::Statement s(db_->GetUniqueStatement( |
567 "UPDATE autofill SET count = ? WHERE pair_id = ?")); | 521 "UPDATE autofill SET count = ? WHERE pair_id = ?")); |
568 if (!s) { | |
569 NOTREACHED() << "Statement prepare failed"; | |
570 return false; | |
571 } | |
572 | |
573 s.BindInt(0, count); | 522 s.BindInt(0, count); |
574 s.BindInt64(1, pair_id); | 523 s.BindInt64(1, pair_id); |
575 if (!s.Run()) { | |
576 NOTREACHED(); | |
577 return false; | |
578 } | |
579 | 524 |
580 return true; | 525 return s.Run(); |
581 } | 526 } |
582 | 527 |
583 bool AutofillTable::InsertFormElement(const FormField& element, | 528 bool AutofillTable::InsertFormElement(const FormField& element, |
584 int64* pair_id) { | 529 int64* pair_id) { |
530 DCHECK(pair_id); | |
585 sql::Statement s(db_->GetUniqueStatement( | 531 sql::Statement s(db_->GetUniqueStatement( |
586 "INSERT INTO autofill (name, value, value_lower) VALUES (?,?,?)")); | 532 "INSERT INTO autofill (name, value, value_lower) VALUES (?,?,?)")); |
587 if (!s) { | |
588 NOTREACHED() << "Statement prepare failed"; | |
589 return false; | |
590 } | |
591 | |
592 s.BindString16(0, element.name); | 533 s.BindString16(0, element.name); |
593 s.BindString16(1, element.value); | 534 s.BindString16(1, element.value); |
594 s.BindString16(2, base::i18n::ToLower(element.value)); | 535 s.BindString16(2, base::i18n::ToLower(element.value)); |
595 | 536 |
596 if (!s.Run()) { | 537 if (!s.Run()) |
597 NOTREACHED(); | |
598 return false; | 538 return false; |
599 } | |
600 | 539 |
601 *pair_id = db_->GetLastInsertRowId(); | 540 *pair_id = db_->GetLastInsertRowId(); |
602 return true; | 541 return true; |
603 } | 542 } |
604 | 543 |
605 bool AutofillTable::InsertPairIDAndDate(int64 pair_id, | 544 bool AutofillTable::InsertPairIDAndDate(int64 pair_id, |
606 const Time& date_created) { | 545 const Time& date_created) { |
607 sql::Statement s(db_->GetUniqueStatement( | 546 sql::Statement s(db_->GetUniqueStatement( |
608 "INSERT INTO autofill_dates " | 547 "INSERT INTO autofill_dates " |
609 "(pair_id, date_created) VALUES (?, ?)")); | 548 "(pair_id, date_created) VALUES (?, ?)")); |
610 if (!s) { | |
611 NOTREACHED() << "Statement prepare failed"; | |
612 return false; | |
613 } | |
614 | |
615 s.BindInt64(0, pair_id); | 549 s.BindInt64(0, pair_id); |
616 s.BindInt64(1, date_created.ToTimeT()); | 550 s.BindInt64(1, date_created.ToTimeT()); |
617 | 551 |
618 if (!s.Run()) { | 552 return s.Run(); |
619 NOTREACHED(); | |
620 return false; | |
621 } | |
622 | |
623 return true; | |
624 } | 553 } |
625 | 554 |
626 bool AutofillTable::AddFormFieldValuesTime( | 555 bool AutofillTable::AddFormFieldValuesTime( |
627 const std::vector<FormField>& elements, | 556 const std::vector<FormField>& elements, |
628 std::vector<AutofillChange>* changes, | 557 std::vector<AutofillChange>* changes, |
629 Time time) { | 558 Time time) { |
630 // Only add one new entry for each unique element name. Use |seen_names| to | 559 // Only add one new entry for each unique element name. Use |seen_names| to |
631 // track this. Add up to |kMaximumUniqueNames| unique entries per form. | 560 // track this. Add up to |kMaximumUniqueNames| unique entries per form. |
632 const size_t kMaximumUniqueNames = 256; | 561 const size_t kMaximumUniqueNames = 256; |
633 std::set<string16> seen_names; | 562 std::set<string16> seen_names; |
634 bool result = true; | 563 bool result = true; |
635 for (std::vector<FormField>::const_iterator | 564 for (std::vector<FormField>::const_iterator |
636 itr = elements.begin(); | 565 itr = elements.begin(); |
637 itr != elements.end(); | 566 itr != elements.end(); |
638 itr++) { | 567 itr++) { |
639 if (seen_names.size() >= kMaximumUniqueNames) | 568 if (seen_names.size() >= kMaximumUniqueNames) |
640 break; | 569 break; |
641 if (seen_names.find(itr->name) != seen_names.end()) | 570 if (seen_names.find(itr->name) != seen_names.end()) |
642 continue; | 571 continue; |
643 result = result && AddFormFieldValueTime(*itr, changes, time); | 572 result = result && AddFormFieldValueTime(*itr, changes, time); |
644 seen_names.insert(itr->name); | 573 seen_names.insert(itr->name); |
645 } | 574 } |
646 return result; | 575 return result; |
647 } | 576 } |
648 | 577 |
649 bool AutofillTable::ClearAutofillEmptyValueElements() { | 578 bool AutofillTable::ClearAutofillEmptyValueElements() { |
650 sql::Statement s(db_->GetUniqueStatement( | 579 sql::Statement s(db_->GetUniqueStatement( |
651 "SELECT pair_id FROM autofill WHERE TRIM(value)= \"\"")); | 580 "SELECT pair_id FROM autofill WHERE TRIM(value)= \"\"")); |
652 if (!s) { | 581 if (!s.is_valid()) |
653 NOTREACHED() << "Statement prepare failed"; | |
654 return false; | 582 return false; |
655 } | |
656 | 583 |
657 std::set<int64> ids; | 584 std::set<int64> ids; |
658 while (s.Step()) | 585 while (s.Step()) |
659 ids.insert(s.ColumnInt64(0)); | 586 ids.insert(s.ColumnInt64(0)); |
587 if (!s.Succeeded()) | |
588 return false; | |
660 | 589 |
661 bool success = true; | 590 bool success = true; |
662 for (std::set<int64>::const_iterator iter = ids.begin(); iter != ids.end(); | 591 for (std::set<int64>::const_iterator iter = ids.begin(); iter != ids.end(); |
663 ++iter) { | 592 ++iter) { |
664 if (!RemoveFormElementForID(*iter)) | 593 if (!RemoveFormElementForID(*iter)) |
665 success = false; | 594 success = false; |
666 } | 595 } |
667 | 596 |
668 return success; | 597 return success; |
669 } | 598 } |
670 | 599 |
671 bool AutofillTable::GetAllAutofillEntries(std::vector<AutofillEntry>* entries) { | 600 bool AutofillTable::GetAllAutofillEntries(std::vector<AutofillEntry>* entries) { |
672 DCHECK(entries); | 601 DCHECK(entries); |
673 sql::Statement s(db_->GetUniqueStatement( | 602 sql::Statement s(db_->GetUniqueStatement( |
674 "SELECT name, value, date_created FROM autofill a JOIN " | 603 "SELECT name, value, date_created FROM autofill a JOIN " |
675 "autofill_dates ad ON a.pair_id=ad.pair_id")); | 604 "autofill_dates ad ON a.pair_id=ad.pair_id")); |
676 | 605 |
677 if (!s) { | |
678 NOTREACHED() << "Statement prepare failed"; | |
679 return false; | |
680 } | |
681 | |
682 bool first_entry = true; | 606 bool first_entry = true; |
683 AutofillKey* current_key_ptr = NULL; | 607 AutofillKey* current_key_ptr = NULL; |
684 std::vector<Time>* timestamps_ptr = NULL; | 608 std::vector<Time>* timestamps_ptr = NULL; |
685 string16 name, value; | 609 string16 name, value; |
686 Time time; | 610 Time time; |
687 while (s.Step()) { | 611 while (s.Step()) { |
688 name = s.ColumnString16(0); | 612 name = s.ColumnString16(0); |
689 value = s.ColumnString16(1); | 613 value = s.ColumnString16(1); |
690 time = Time::FromTimeT(s.ColumnInt64(2)); | 614 time = Time::FromTimeT(s.ColumnInt64(2)); |
691 | 615 |
(...skipping 13 matching lines...) Expand all Loading... | |
705 | 629 |
706 delete current_key_ptr; | 630 delete current_key_ptr; |
707 delete timestamps_ptr; | 631 delete timestamps_ptr; |
708 | 632 |
709 current_key_ptr = new AutofillKey(name, value); | 633 current_key_ptr = new AutofillKey(name, value); |
710 timestamps_ptr = new std::vector<Time>; | 634 timestamps_ptr = new std::vector<Time>; |
711 } | 635 } |
712 timestamps_ptr->push_back(time); | 636 timestamps_ptr->push_back(time); |
713 } | 637 } |
714 } | 638 } |
639 | |
640 if (!s.Succeeded()) | |
641 return false; | |
642 | |
715 // If there is at least one result returned, first_entry will be false. | 643 // If there is at least one result returned, first_entry will be false. |
716 // For this case we need to do a final cleanup step. | 644 // For this case we need to do a final cleanup step. |
717 if (!first_entry) { | 645 if (!first_entry) { |
718 AutofillEntry entry(*current_key_ptr, *timestamps_ptr); | 646 AutofillEntry entry(*current_key_ptr, *timestamps_ptr); |
719 entries->push_back(entry); | 647 entries->push_back(entry); |
720 delete current_key_ptr; | 648 delete current_key_ptr; |
721 delete timestamps_ptr; | 649 delete timestamps_ptr; |
722 } | 650 } |
723 | 651 |
724 return s.Succeeded(); | 652 return s.Succeeded(); |
725 } | 653 } |
726 | 654 |
727 bool AutofillTable::GetAutofillTimestamps(const string16& name, | 655 bool AutofillTable::GetAutofillTimestamps(const string16& name, |
728 const string16& value, | 656 const string16& value, |
729 std::vector<Time>* timestamps) { | 657 std::vector<Time>* timestamps) { |
730 DCHECK(timestamps); | 658 DCHECK(timestamps); |
731 sql::Statement s(db_->GetUniqueStatement( | 659 sql::Statement s(db_->GetUniqueStatement( |
732 "SELECT date_created FROM autofill a JOIN " | 660 "SELECT date_created FROM autofill a JOIN " |
733 "autofill_dates ad ON a.pair_id=ad.pair_id " | 661 "autofill_dates ad ON a.pair_id=ad.pair_id " |
734 "WHERE a.name = ? AND a.value = ?")); | 662 "WHERE a.name = ? AND a.value = ?")); |
735 | |
736 if (!s) { | |
737 NOTREACHED() << "Statement prepare failed"; | |
738 return false; | |
739 } | |
740 | |
741 s.BindString16(0, name); | 663 s.BindString16(0, name); |
742 s.BindString16(1, value); | 664 s.BindString16(1, value); |
665 | |
743 while (s.Step()) | 666 while (s.Step()) |
744 timestamps->push_back(Time::FromTimeT(s.ColumnInt64(0))); | 667 timestamps->push_back(Time::FromTimeT(s.ColumnInt64(0))); |
745 | 668 |
746 return s.Succeeded(); | 669 return s.Succeeded(); |
747 } | 670 } |
748 | 671 |
749 bool AutofillTable::UpdateAutofillEntries( | 672 bool AutofillTable::UpdateAutofillEntries( |
750 const std::vector<AutofillEntry>& entries) { | 673 const std::vector<AutofillEntry>& entries) { |
751 if (!entries.size()) | 674 if (!entries.size()) |
752 return true; | 675 return true; |
753 | 676 |
754 // Remove all existing entries. | 677 // Remove all existing entries. |
755 for (size_t i = 0; i < entries.size(); i++) { | 678 for (size_t i = 0; i < entries.size(); i++) { |
756 std::string sql = "SELECT pair_id FROM autofill " | 679 std::string sql = "SELECT pair_id FROM autofill " |
757 "WHERE name = ? AND value = ?"; | 680 "WHERE name = ? AND value = ?"; |
758 sql::Statement s(db_->GetUniqueStatement(sql.c_str())); | 681 sql::Statement s(db_->GetUniqueStatement(sql.c_str())); |
759 if (!s.is_valid()) { | |
760 NOTREACHED() << "Statement prepare failed"; | |
761 return false; | |
762 } | |
763 | |
764 s.BindString16(0, entries[i].key().name()); | 682 s.BindString16(0, entries[i].key().name()); |
765 s.BindString16(1, entries[i].key().value()); | 683 s.BindString16(1, entries[i].key().value()); |
684 | |
685 if (!s.is_valid()) | |
686 return false; | |
687 | |
766 if (s.Step()) { | 688 if (s.Step()) { |
767 if (!RemoveFormElementForID(s.ColumnInt64(0))) | 689 if (!RemoveFormElementForID(s.ColumnInt64(0))) |
768 return false; | 690 return false; |
769 } | 691 } |
770 } | 692 } |
771 | 693 |
772 // Insert all the supplied autofill entries. | 694 // Insert all the supplied autofill entries. |
773 for (size_t i = 0; i < entries.size(); i++) { | 695 for (size_t i = 0; i < entries.size(); i++) { |
774 if (!InsertAutofillEntry(entries[i])) | 696 if (!InsertAutofillEntry(entries[i])) |
775 return false; | 697 return false; |
776 } | 698 } |
777 | 699 |
778 return true; | 700 return true; |
779 } | 701 } |
780 | 702 |
781 bool AutofillTable::InsertAutofillEntry(const AutofillEntry& entry) { | 703 bool AutofillTable::InsertAutofillEntry(const AutofillEntry& entry) { |
782 std::string sql = "INSERT INTO autofill (name, value, value_lower, count) " | 704 std::string sql = "INSERT INTO autofill (name, value, value_lower, count) " |
783 "VALUES (?, ?, ?, ?)"; | 705 "VALUES (?, ?, ?, ?)"; |
784 sql::Statement s(db_->GetUniqueStatement(sql.c_str())); | 706 sql::Statement s(db_->GetUniqueStatement(sql.c_str())); |
785 if (!s.is_valid()) { | |
786 NOTREACHED() << "Statement prepare failed"; | |
787 return false; | |
788 } | |
789 | |
790 s.BindString16(0, entry.key().name()); | 707 s.BindString16(0, entry.key().name()); |
791 s.BindString16(1, entry.key().value()); | 708 s.BindString16(1, entry.key().value()); |
792 s.BindString16(2, base::i18n::ToLower(entry.key().value())); | 709 s.BindString16(2, base::i18n::ToLower(entry.key().value())); |
793 s.BindInt(3, entry.timestamps().size()); | 710 s.BindInt(3, entry.timestamps().size()); |
794 | 711 |
795 if (!s.Run()) { | 712 if (!s.Run()) |
796 NOTREACHED(); | |
797 return false; | 713 return false; |
798 } | |
799 | 714 |
800 int64 pair_id = db_->GetLastInsertRowId(); | 715 int64 pair_id = db_->GetLastInsertRowId(); |
801 for (size_t i = 0; i < entry.timestamps().size(); i++) { | 716 for (size_t i = 0; i < entry.timestamps().size(); i++) { |
802 if (!InsertPairIDAndDate(pair_id, entry.timestamps()[i])) | 717 if (!InsertPairIDAndDate(pair_id, entry.timestamps()[i])) |
803 return false; | 718 return false; |
804 } | 719 } |
805 | 720 |
806 return true; | 721 return true; |
807 } | 722 } |
808 | 723 |
(...skipping 22 matching lines...) Expand all Loading... | |
831 AutofillKey(element.name, element.value))); | 746 AutofillKey(element.name, element.value))); |
832 return true; | 747 return true; |
833 } | 748 } |
834 | 749 |
835 | 750 |
836 bool AutofillTable::RemoveFormElement(const string16& name, | 751 bool AutofillTable::RemoveFormElement(const string16& name, |
837 const string16& value) { | 752 const string16& value) { |
838 // Find the id for that pair. | 753 // Find the id for that pair. |
839 sql::Statement s(db_->GetUniqueStatement( | 754 sql::Statement s(db_->GetUniqueStatement( |
840 "SELECT pair_id FROM autofill WHERE name = ? AND value= ?")); | 755 "SELECT pair_id FROM autofill WHERE name = ? AND value= ?")); |
841 if (!s) { | |
842 NOTREACHED() << "Statement 1 prepare failed"; | |
843 return false; | |
844 } | |
845 s.BindString16(0, name); | 756 s.BindString16(0, name); |
846 s.BindString16(1, value); | 757 s.BindString16(1, value); |
847 | 758 |
848 if (s.Step()) | 759 if (s.Step()) |
849 return RemoveFormElementForID(s.ColumnInt64(0)); | 760 return RemoveFormElementForID(s.ColumnInt64(0)); |
850 return false; | 761 return false; |
851 } | 762 } |
852 | 763 |
853 bool AutofillTable::AddAutofillProfile(const AutofillProfile& profile) { | 764 bool AutofillTable::AddAutofillProfile(const AutofillProfile& profile) { |
854 if (IsAutofillGUIDInTrash(profile.guid())) | 765 if (IsAutofillGUIDInTrash(profile.guid())) |
855 return true; | 766 return true; |
856 | 767 |
857 sql::Statement s(db_->GetUniqueStatement( | 768 sql::Statement s(db_->GetUniqueStatement( |
858 "INSERT INTO autofill_profiles" | 769 "INSERT INTO autofill_profiles" |
859 "(guid, company_name, address_line_1, address_line_2, city, state," | 770 "(guid, company_name, address_line_1, address_line_2, city, state," |
860 " zipcode, country, country_code, date_modified)" | 771 " zipcode, country, country_code, date_modified)" |
861 "VALUES (?,?,?,?,?,?,?,?,?,?)")); | 772 "VALUES (?,?,?,?,?,?,?,?,?,?)")); |
862 if (!s) { | |
863 NOTREACHED() << "Statement prepare failed"; | |
864 return false; | |
865 } | |
866 | |
867 BindAutofillProfileToStatement(profile, &s); | 773 BindAutofillProfileToStatement(profile, &s); |
868 | 774 |
869 if (!s.Run()) { | 775 if (!s.Run()) |
870 NOTREACHED(); | |
871 return false; | |
872 } | |
873 | |
874 if (!s.Succeeded()) | |
875 return false; | 776 return false; |
876 | 777 |
877 return AddAutofillProfilePieces(profile, db_); | 778 return AddAutofillProfilePieces(profile, db_); |
878 } | 779 } |
879 | 780 |
880 bool AutofillTable::GetAutofillProfile(const std::string& guid, | 781 bool AutofillTable::GetAutofillProfile(const std::string& guid, |
881 AutofillProfile** profile) { | 782 AutofillProfile** profile) { |
882 DCHECK(guid::IsValidGUID(guid)); | 783 DCHECK(guid::IsValidGUID(guid)); |
883 DCHECK(profile); | 784 DCHECK(profile); |
884 sql::Statement s(db_->GetUniqueStatement( | 785 sql::Statement s(db_->GetUniqueStatement( |
885 "SELECT guid, company_name, address_line_1, address_line_2, city, state," | 786 "SELECT guid, company_name, address_line_1, address_line_2, city, state," |
886 " zipcode, country, country_code, date_modified " | 787 " zipcode, country, country_code, date_modified " |
887 "FROM autofill_profiles " | 788 "FROM autofill_profiles " |
888 "WHERE guid=?")); | 789 "WHERE guid=?")); |
889 if (!s) { | 790 s.BindString(0, guid); |
890 NOTREACHED() << "Statement prepare failed"; | |
891 return false; | |
892 } | |
893 | 791 |
894 s.BindString(0, guid); | |
895 if (!s.Step()) | 792 if (!s.Step()) |
896 return false; | 793 return false; |
897 | 794 |
898 if (!s.Succeeded()) | |
899 return false; | |
900 | |
901 scoped_ptr<AutofillProfile> p(AutofillProfileFromStatement(s)); | 795 scoped_ptr<AutofillProfile> p(AutofillProfileFromStatement(s)); |
902 | 796 |
903 // Get associated name info. | 797 // Get associated name info. |
904 AddAutofillProfileNamesToProfile(db_, p.get()); | 798 AddAutofillProfileNamesToProfile(db_, p.get()); |
905 | 799 |
906 // Get associated email info. | 800 // Get associated email info. |
907 AddAutofillProfileEmailsToProfile(db_, p.get()); | 801 AddAutofillProfileEmailsToProfile(db_, p.get()); |
908 | 802 |
909 // Get associated phone info. | 803 // Get associated phone info. |
910 AddAutofillProfilePhonesToProfile(db_, p.get()); | 804 AddAutofillProfilePhonesToProfile(db_, p.get()); |
911 | 805 |
912 *profile = p.release(); | 806 *profile = p.release(); |
913 return true; | 807 return true; |
914 } | 808 } |
915 | 809 |
916 bool AutofillTable::GetAutofillProfiles( | 810 bool AutofillTable::GetAutofillProfiles( |
917 std::vector<AutofillProfile*>* profiles) { | 811 std::vector<AutofillProfile*>* profiles) { |
918 DCHECK(profiles); | 812 DCHECK(profiles); |
919 profiles->clear(); | 813 profiles->clear(); |
920 | 814 |
921 sql::Statement s(db_->GetUniqueStatement( | 815 sql::Statement s(db_->GetUniqueStatement( |
922 "SELECT guid " | 816 "SELECT guid " |
923 "FROM autofill_profiles")); | 817 "FROM autofill_profiles")); |
924 if (!s) { | |
925 NOTREACHED() << "Statement prepare failed"; | |
926 return false; | |
927 } | |
928 | 818 |
929 while (s.Step()) { | 819 while (s.Step()) { |
930 std::string guid = s.ColumnString(0); | 820 std::string guid = s.ColumnString(0); |
931 AutofillProfile* profile = NULL; | 821 AutofillProfile* profile = NULL; |
932 if (!GetAutofillProfile(guid, &profile)) | 822 if (!GetAutofillProfile(guid, &profile)) |
933 return false; | 823 return false; |
934 profiles->push_back(profile); | 824 profiles->push_back(profile); |
935 } | 825 } |
936 | 826 |
937 return s.Succeeded(); | 827 return s.Succeeded(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
988 scoped_ptr<AutofillProfile> old_profile(tmp_profile); | 878 scoped_ptr<AutofillProfile> old_profile(tmp_profile); |
989 if (old_profile->CompareMulti(profile) == 0) | 879 if (old_profile->CompareMulti(profile) == 0) |
990 return true; | 880 return true; |
991 | 881 |
992 sql::Statement s(db_->GetUniqueStatement( | 882 sql::Statement s(db_->GetUniqueStatement( |
993 "UPDATE autofill_profiles " | 883 "UPDATE autofill_profiles " |
994 "SET guid=?, company_name=?, address_line_1=?, address_line_2=?, " | 884 "SET guid=?, company_name=?, address_line_1=?, address_line_2=?, " |
995 " city=?, state=?, zipcode=?, country=?, country_code=?, " | 885 " city=?, state=?, zipcode=?, country=?, country_code=?, " |
996 " date_modified=? " | 886 " date_modified=? " |
997 "WHERE guid=?")); | 887 "WHERE guid=?")); |
998 if (!s) { | |
999 NOTREACHED() << "Statement prepare failed"; | |
1000 return false; | |
1001 } | |
1002 | |
1003 BindAutofillProfileToStatement(profile, &s); | 888 BindAutofillProfileToStatement(profile, &s); |
1004 s.BindString(10, profile.guid()); | 889 s.BindString(10, profile.guid()); |
890 | |
1005 bool result = s.Run(); | 891 bool result = s.Run(); |
1006 DCHECK_GT(db_->GetLastChangeCount(), 0); | 892 DCHECK_GT(db_->GetLastChangeCount(), 0); |
1007 if (!result) | 893 if (!result) |
1008 return result; | 894 return result; |
1009 | 895 |
1010 // Remove the old names, emails, and phone numbers. | 896 // Remove the old names, emails, and phone numbers. |
1011 if (!RemoveAutofillProfilePieces(profile.guid(), db_)) | 897 if (!RemoveAutofillProfilePieces(profile.guid(), db_)) |
1012 return false; | 898 return false; |
1013 | 899 |
1014 return AddAutofillProfilePieces(profile, db_); | 900 return AddAutofillProfilePieces(profile, db_); |
1015 } | 901 } |
1016 | 902 |
1017 bool AutofillTable::RemoveAutofillProfile(const std::string& guid) { | 903 bool AutofillTable::RemoveAutofillProfile(const std::string& guid) { |
1018 DCHECK(guid::IsValidGUID(guid)); | 904 DCHECK(guid::IsValidGUID(guid)); |
1019 | 905 |
1020 if (IsAutofillGUIDInTrash(guid)) { | 906 if (IsAutofillGUIDInTrash(guid)) { |
1021 sql::Statement s_trash(db_->GetUniqueStatement( | 907 sql::Statement s_trash(db_->GetUniqueStatement( |
1022 "DELETE FROM autofill_profiles_trash WHERE guid = ?")); | 908 "DELETE FROM autofill_profiles_trash WHERE guid = ?")); |
1023 if (!s_trash) { | |
1024 NOTREACHED() << "Statement prepare failed"; | |
1025 return false; | |
1026 } | |
1027 s_trash.BindString(0, guid); | 909 s_trash.BindString(0, guid); |
1028 if (!s_trash.Run()) { | |
1029 NOTREACHED() << "Expected item in trash."; | |
1030 return false; | |
1031 } | |
1032 | 910 |
1033 return true; | 911 bool success = s_trash.Run(); |
912 DCHECK_GT(db_->GetLastChangeCount(), 0) << "Expected item in trash"; | |
913 return success; | |
1034 } | 914 } |
1035 | 915 |
1036 sql::Statement s(db_->GetUniqueStatement( | 916 sql::Statement s(db_->GetUniqueStatement( |
1037 "DELETE FROM autofill_profiles WHERE guid = ?")); | 917 "DELETE FROM autofill_profiles WHERE guid = ?")); |
1038 if (!s) { | 918 s.BindString(0, guid); |
1039 NOTREACHED() << "Statement prepare failed"; | |
1040 return false; | |
1041 } | |
1042 | 919 |
1043 s.BindString(0, guid); | |
1044 if (!s.Run()) | 920 if (!s.Run()) |
1045 return false; | 921 return false; |
1046 | 922 |
1047 return RemoveAutofillProfilePieces(guid, db_); | 923 return RemoveAutofillProfilePieces(guid, db_); |
1048 } | 924 } |
1049 | 925 |
1050 bool AutofillTable::ClearAutofillProfiles() { | 926 bool AutofillTable::ClearAutofillProfiles() { |
1051 sql::Statement s1(db_->GetUniqueStatement( | 927 sql::Statement s1(db_->GetUniqueStatement( |
1052 "DELETE FROM autofill_profiles")); | 928 "DELETE FROM autofill_profiles")); |
1053 if (!s1) { | |
1054 NOTREACHED() << "Statement prepare failed"; | |
1055 return false; | |
1056 } | |
1057 | 929 |
1058 if (!s1.Run()) | 930 if (!s1.Run()) |
1059 return false; | 931 return false; |
1060 | 932 |
1061 sql::Statement s2(db_->GetUniqueStatement( | 933 sql::Statement s2(db_->GetUniqueStatement( |
1062 "DELETE FROM autofill_profile_names")); | 934 "DELETE FROM autofill_profile_names")); |
1063 if (!s2) { | |
1064 NOTREACHED() << "Statement prepare failed"; | |
1065 return false; | |
1066 } | |
1067 | 935 |
1068 if (!s2.Run()) | 936 if (!s2.Run()) |
1069 return false; | 937 return false; |
1070 | 938 |
1071 sql::Statement s3(db_->GetUniqueStatement( | 939 sql::Statement s3(db_->GetUniqueStatement( |
1072 "DELETE FROM autofill_profile_emails")); | 940 "DELETE FROM autofill_profile_emails")); |
1073 if (!s3) { | |
1074 NOTREACHED() << "Statement prepare failed"; | |
1075 return false; | |
1076 } | |
1077 | 941 |
1078 if (!s3.Run()) | 942 if (!s3.Run()) |
1079 return false; | 943 return false; |
1080 | 944 |
1081 sql::Statement s4(db_->GetUniqueStatement( | 945 sql::Statement s4(db_->GetUniqueStatement( |
1082 "DELETE FROM autofill_profile_phones")); | 946 "DELETE FROM autofill_profile_phones")); |
1083 if (!s4) { | |
1084 NOTREACHED() << "Statement prepare failed"; | |
1085 return false; | |
1086 } | |
1087 | 947 |
1088 if (!s4.Run()) | 948 return s4.Run(); |
1089 return false; | |
1090 | |
1091 return true; | |
1092 } | 949 } |
1093 | 950 |
1094 bool AutofillTable::AddCreditCard(const CreditCard& credit_card) { | 951 bool AutofillTable::AddCreditCard(const CreditCard& credit_card) { |
1095 sql::Statement s(db_->GetUniqueStatement( | 952 sql::Statement s(db_->GetUniqueStatement( |
1096 "INSERT INTO credit_cards" | 953 "INSERT INTO credit_cards" |
1097 "(guid, name_on_card, expiration_month, expiration_year, " | 954 "(guid, name_on_card, expiration_month, expiration_year, " |
1098 "card_number_encrypted, date_modified)" | 955 "card_number_encrypted, date_modified)" |
1099 "VALUES (?,?,?,?,?,?)")); | 956 "VALUES (?,?,?,?,?,?)")); |
1100 if (!s) { | |
1101 NOTREACHED() << "Statement prepare failed"; | |
1102 return false; | |
1103 } | |
1104 | |
1105 BindCreditCardToStatement(credit_card, &s); | 957 BindCreditCardToStatement(credit_card, &s); |
1106 | 958 |
1107 if (!s.Run()) { | 959 if (!s.Run()) |
1108 NOTREACHED(); | |
1109 return false; | 960 return false; |
1110 } | |
1111 | 961 |
1112 DCHECK_GT(db_->GetLastChangeCount(), 0); | 962 DCHECK_GT(db_->GetLastChangeCount(), 0); |
1113 return s.Succeeded(); | 963 return true; |
1114 } | 964 } |
1115 | 965 |
1116 bool AutofillTable::GetCreditCard(const std::string& guid, | 966 bool AutofillTable::GetCreditCard(const std::string& guid, |
1117 CreditCard** credit_card) { | 967 CreditCard** credit_card) { |
1118 DCHECK(guid::IsValidGUID(guid)); | 968 DCHECK(guid::IsValidGUID(guid)); |
1119 sql::Statement s(db_->GetUniqueStatement( | 969 sql::Statement s(db_->GetUniqueStatement( |
1120 "SELECT guid, name_on_card, expiration_month, expiration_year, " | 970 "SELECT guid, name_on_card, expiration_month, expiration_year, " |
1121 "card_number_encrypted, date_modified " | 971 "card_number_encrypted, date_modified " |
1122 "FROM credit_cards " | 972 "FROM credit_cards " |
1123 "WHERE guid = ?")); | 973 "WHERE guid = ?")); |
1124 if (!s) { | 974 s.BindString(0, guid); |
1125 NOTREACHED() << "Statement prepare failed"; | |
1126 return false; | |
1127 } | |
1128 | 975 |
1129 s.BindString(0, guid); | |
1130 if (!s.Step()) | 976 if (!s.Step()) |
1131 return false; | 977 return false; |
1132 | 978 |
1133 *credit_card = CreditCardFromStatement(s); | 979 *credit_card = CreditCardFromStatement(s); |
1134 | 980 return true; |
1135 return s.Succeeded(); | |
1136 } | 981 } |
1137 | 982 |
1138 bool AutofillTable::GetCreditCards( | 983 bool AutofillTable::GetCreditCards( |
1139 std::vector<CreditCard*>* credit_cards) { | 984 std::vector<CreditCard*>* credit_cards) { |
1140 DCHECK(credit_cards); | 985 DCHECK(credit_cards); |
1141 credit_cards->clear(); | 986 credit_cards->clear(); |
1142 | 987 |
1143 sql::Statement s(db_->GetUniqueStatement( | 988 sql::Statement s(db_->GetUniqueStatement( |
1144 "SELECT guid " | 989 "SELECT guid " |
1145 "FROM credit_cards")); | 990 "FROM credit_cards")); |
1146 if (!s) { | |
1147 NOTREACHED() << "Statement prepare failed"; | |
1148 return false; | |
1149 } | |
1150 | 991 |
1151 while (s.Step()) { | 992 while (s.Step()) { |
1152 std::string guid = s.ColumnString(0); | 993 std::string guid = s.ColumnString(0); |
1153 CreditCard* credit_card = NULL; | 994 CreditCard* credit_card = NULL; |
1154 if (!GetCreditCard(guid, &credit_card)) | 995 if (!GetCreditCard(guid, &credit_card)) |
1155 return false; | 996 return false; |
1156 credit_cards->push_back(credit_card); | 997 credit_cards->push_back(credit_card); |
1157 } | 998 } |
1158 | 999 |
1159 return s.Succeeded(); | 1000 return s.Succeeded(); |
1160 } | 1001 } |
1161 | 1002 |
1162 bool AutofillTable::UpdateCreditCard(const CreditCard& credit_card) { | 1003 bool AutofillTable::UpdateCreditCard(const CreditCard& credit_card) { |
1163 DCHECK(guid::IsValidGUID(credit_card.guid())); | 1004 DCHECK(guid::IsValidGUID(credit_card.guid())); |
1164 | 1005 |
1165 CreditCard* tmp_credit_card = NULL; | 1006 CreditCard* tmp_credit_card = NULL; |
1166 if (!GetCreditCard(credit_card.guid(), &tmp_credit_card)) | 1007 if (!GetCreditCard(credit_card.guid(), &tmp_credit_card)) |
1167 return false; | 1008 return false; |
1168 | 1009 |
1169 // Preserve appropriate modification dates by not updating unchanged cards. | 1010 // Preserve appropriate modification dates by not updating unchanged cards. |
1170 scoped_ptr<CreditCard> old_credit_card(tmp_credit_card); | 1011 scoped_ptr<CreditCard> old_credit_card(tmp_credit_card); |
1171 if (*old_credit_card == credit_card) | 1012 if (*old_credit_card == credit_card) |
1172 return true; | 1013 return true; |
1173 | 1014 |
1174 sql::Statement s(db_->GetUniqueStatement( | 1015 sql::Statement s(db_->GetUniqueStatement( |
1175 "UPDATE credit_cards " | 1016 "UPDATE credit_cards " |
1176 "SET guid=?, name_on_card=?, expiration_month=?, " | 1017 "SET guid=?, name_on_card=?, expiration_month=?, " |
1177 " expiration_year=?, card_number_encrypted=?, date_modified=? " | 1018 " expiration_year=?, card_number_encrypted=?, date_modified=? " |
1178 "WHERE guid=?")); | 1019 "WHERE guid=?")); |
1179 if (!s) { | |
1180 NOTREACHED() << "Statement prepare failed"; | |
1181 return false; | |
1182 } | |
1183 | |
1184 BindCreditCardToStatement(credit_card, &s); | 1020 BindCreditCardToStatement(credit_card, &s); |
1185 s.BindString(6, credit_card.guid()); | 1021 s.BindString(6, credit_card.guid()); |
1022 | |
1186 bool result = s.Run(); | 1023 bool result = s.Run(); |
1187 DCHECK_GT(db_->GetLastChangeCount(), 0); | 1024 DCHECK_GT(db_->GetLastChangeCount(), 0); |
1188 return result; | 1025 return result; |
1189 } | 1026 } |
1190 | 1027 |
1191 bool AutofillTable::RemoveCreditCard(const std::string& guid) { | 1028 bool AutofillTable::RemoveCreditCard(const std::string& guid) { |
1192 DCHECK(guid::IsValidGUID(guid)); | 1029 DCHECK(guid::IsValidGUID(guid)); |
1193 sql::Statement s(db_->GetUniqueStatement( | 1030 sql::Statement s(db_->GetUniqueStatement( |
1194 "DELETE FROM credit_cards WHERE guid = ?")); | 1031 "DELETE FROM credit_cards WHERE guid = ?")); |
1195 if (!s) { | 1032 s.BindString(0, guid); |
1196 NOTREACHED() << "Statement prepare failed"; | |
1197 return false; | |
1198 } | |
1199 | 1033 |
1200 s.BindString(0, guid); | |
1201 return s.Run(); | 1034 return s.Run(); |
1202 } | 1035 } |
1203 | 1036 |
1204 bool AutofillTable::RemoveAutofillProfilesAndCreditCardsModifiedBetween( | 1037 bool AutofillTable::RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
1205 const Time& delete_begin, | 1038 const Time& delete_begin, |
1206 const Time& delete_end, | 1039 const Time& delete_end, |
1207 std::vector<std::string>* profile_guids, | 1040 std::vector<std::string>* profile_guids, |
1208 std::vector<std::string>* credit_card_guids) { | 1041 std::vector<std::string>* credit_card_guids) { |
1209 DCHECK(delete_end.is_null() || delete_begin < delete_end); | 1042 DCHECK(delete_end.is_null() || delete_begin < delete_end); |
1210 | 1043 |
1211 time_t delete_begin_t = delete_begin.ToTimeT(); | 1044 time_t delete_begin_t = delete_begin.ToTimeT(); |
1212 time_t delete_end_t = delete_end.is_null() ? | 1045 time_t delete_end_t = delete_end.is_null() ? |
1213 std::numeric_limits<time_t>::max() : | 1046 std::numeric_limits<time_t>::max() : |
1214 delete_end.ToTimeT(); | 1047 delete_end.ToTimeT(); |
1215 | 1048 |
1216 // Remember Autofill profiles in the time range. | 1049 // Remember Autofill profiles in the time range. |
1217 sql::Statement s_profiles_get(db_->GetUniqueStatement( | 1050 sql::Statement s_profiles_get(db_->GetUniqueStatement( |
1218 "SELECT guid FROM autofill_profiles " | 1051 "SELECT guid FROM autofill_profiles " |
1219 "WHERE date_modified >= ? AND date_modified < ?")); | 1052 "WHERE date_modified >= ? AND date_modified < ?")); |
1220 if (!s_profiles_get) { | |
1221 NOTREACHED() << "Autofill profiles statement prepare failed"; | |
1222 return false; | |
1223 } | |
1224 | |
1225 s_profiles_get.BindInt64(0, delete_begin_t); | 1053 s_profiles_get.BindInt64(0, delete_begin_t); |
1226 s_profiles_get.BindInt64(1, delete_end_t); | 1054 s_profiles_get.BindInt64(1, delete_end_t); |
1055 | |
1227 profile_guids->clear(); | 1056 profile_guids->clear(); |
1228 while (s_profiles_get.Step()) { | 1057 while (s_profiles_get.Step()) { |
1229 std::string guid = s_profiles_get.ColumnString(0); | 1058 std::string guid = s_profiles_get.ColumnString(0); |
1230 profile_guids->push_back(guid); | 1059 profile_guids->push_back(guid); |
1231 } | 1060 } |
1061 if (!s_profiles_get.Succeeded()) | |
1062 return false; | |
Scott Hess - ex-Googler
2011/12/16 22:37:09
I think that, given that the caller already is com
Greg Billock
2011/12/21 21:43:03
Added documentation for this. Checked caller; it i
| |
1232 | 1063 |
1233 // Remove Autofill profiles in the time range. | 1064 // Remove Autofill profiles in the time range. |
1234 sql::Statement s_profiles(db_->GetUniqueStatement( | 1065 sql::Statement s_profiles(db_->GetUniqueStatement( |
1235 "DELETE FROM autofill_profiles " | 1066 "DELETE FROM autofill_profiles " |
1236 "WHERE date_modified >= ? AND date_modified < ?")); | 1067 "WHERE date_modified >= ? AND date_modified < ?")); |
1237 if (!s_profiles) { | |
1238 NOTREACHED() << "Autofill profiles statement prepare failed"; | |
1239 return false; | |
1240 } | |
1241 | |
1242 s_profiles.BindInt64(0, delete_begin_t); | 1068 s_profiles.BindInt64(0, delete_begin_t); |
1243 s_profiles.BindInt64(1, delete_end_t); | 1069 s_profiles.BindInt64(1, delete_end_t); |
1244 s_profiles.Run(); | |
1245 | 1070 |
1246 if (!s_profiles.Succeeded()) { | 1071 if (!s_profiles.Run()) |
1247 NOTREACHED(); | |
1248 return false; | 1072 return false; |
1249 } | |
1250 | 1073 |
1251 // Remember Autofill credit cards in the time range. | 1074 // Remember Autofill credit cards in the time range. |
1252 sql::Statement s_credit_cards_get(db_->GetUniqueStatement( | 1075 sql::Statement s_credit_cards_get(db_->GetUniqueStatement( |
1253 "SELECT guid FROM credit_cards " | 1076 "SELECT guid FROM credit_cards " |
1254 "WHERE date_modified >= ? AND date_modified < ?")); | 1077 "WHERE date_modified >= ? AND date_modified < ?")); |
1255 if (!s_credit_cards_get) { | |
1256 NOTREACHED() << "Autofill profiles statement prepare failed"; | |
1257 return false; | |
1258 } | |
1259 | |
1260 s_credit_cards_get.BindInt64(0, delete_begin_t); | 1078 s_credit_cards_get.BindInt64(0, delete_begin_t); |
1261 s_credit_cards_get.BindInt64(1, delete_end_t); | 1079 s_credit_cards_get.BindInt64(1, delete_end_t); |
1080 | |
1262 credit_card_guids->clear(); | 1081 credit_card_guids->clear(); |
1263 while (s_credit_cards_get.Step()) { | 1082 while (s_credit_cards_get.Step()) { |
1264 std::string guid = s_credit_cards_get.ColumnString(0); | 1083 std::string guid = s_credit_cards_get.ColumnString(0); |
1265 credit_card_guids->push_back(guid); | 1084 credit_card_guids->push_back(guid); |
1266 } | 1085 } |
1086 if (!s_credit_cards_get.Succeeded()) | |
1087 return false; | |
1267 | 1088 |
1268 // Remove Autofill credit cards in the time range. | 1089 // Remove Autofill credit cards in the time range. |
1269 sql::Statement s_credit_cards(db_->GetUniqueStatement( | 1090 sql::Statement s_credit_cards(db_->GetUniqueStatement( |
1270 "DELETE FROM credit_cards " | 1091 "DELETE FROM credit_cards " |
1271 "WHERE date_modified >= ? AND date_modified < ?")); | 1092 "WHERE date_modified >= ? AND date_modified < ?")); |
1272 if (!s_credit_cards) { | |
1273 NOTREACHED() << "Autofill credit cards statement prepare failed"; | |
1274 return false; | |
1275 } | |
1276 | |
1277 s_credit_cards.BindInt64(0, delete_begin_t); | 1093 s_credit_cards.BindInt64(0, delete_begin_t); |
1278 s_credit_cards.BindInt64(1, delete_end_t); | 1094 s_credit_cards.BindInt64(1, delete_end_t); |
1279 s_credit_cards.Run(); | |
1280 | 1095 |
1281 if (!s_credit_cards.Succeeded()) { | 1096 return s_credit_cards.Run(); |
1282 NOTREACHED(); | |
1283 return false; | |
1284 } | |
1285 | |
1286 return true; | |
1287 } | 1097 } |
1288 | 1098 |
1289 bool AutofillTable::GetAutofillProfilesInTrash( | 1099 bool AutofillTable::GetAutofillProfilesInTrash( |
1290 std::vector<std::string>* guids) { | 1100 std::vector<std::string>* guids) { |
1291 guids->clear(); | 1101 guids->clear(); |
1292 | 1102 |
1293 sql::Statement s(db_->GetUniqueStatement( | 1103 sql::Statement s(db_->GetUniqueStatement( |
1294 "SELECT guid " | 1104 "SELECT guid " |
1295 "FROM autofill_profiles_trash")); | 1105 "FROM autofill_profiles_trash")); |
1296 if (!s) { | |
1297 NOTREACHED() << "Statement prepare failed"; | |
1298 return false; | |
1299 } | |
1300 | 1106 |
1301 while (s.Step()) { | 1107 while (s.Step()) { |
1302 std::string guid = s.ColumnString(0); | 1108 std::string guid = s.ColumnString(0); |
1303 guids->push_back(guid); | 1109 guids->push_back(guid); |
1304 } | 1110 } |
1305 | 1111 |
1306 return s.Succeeded(); | 1112 return s.Succeeded(); |
1307 } | 1113 } |
1308 | 1114 |
1309 bool AutofillTable::EmptyAutofillProfilesTrash() { | 1115 bool AutofillTable::EmptyAutofillProfilesTrash() { |
1310 sql::Statement s(db_->GetUniqueStatement( | 1116 sql::Statement s(db_->GetUniqueStatement( |
1311 "DELETE FROM autofill_profiles_trash")); | 1117 "DELETE FROM autofill_profiles_trash")); |
1312 if (!s) { | |
1313 NOTREACHED() << "Statement prepare failed"; | |
1314 return false; | |
1315 } | |
1316 | 1118 |
1317 return s.Run(); | 1119 return s.Run(); |
1318 } | 1120 } |
1319 | 1121 |
1320 | 1122 |
1321 bool AutofillTable::RemoveFormElementForID(int64 pair_id) { | 1123 bool AutofillTable::RemoveFormElementForID(int64 pair_id) { |
1322 sql::Statement s(db_->GetUniqueStatement( | 1124 sql::Statement s(db_->GetUniqueStatement( |
1323 "DELETE FROM autofill WHERE pair_id = ?")); | 1125 "DELETE FROM autofill WHERE pair_id = ?")); |
1324 if (!s) { | |
1325 NOTREACHED() << "Statement prepare failed"; | |
1326 return false; | |
1327 } | |
1328 s.BindInt64(0, pair_id); | 1126 s.BindInt64(0, pair_id); |
1127 | |
1329 if (s.Run()) | 1128 if (s.Run()) |
1330 return RemoveFormElementForTimeRange(pair_id, Time(), Time(), NULL); | 1129 return RemoveFormElementForTimeRange(pair_id, Time(), Time(), NULL); |
1331 | 1130 |
1332 return false; | 1131 return false; |
1333 } | 1132 } |
1334 | 1133 |
1335 bool AutofillTable::AddAutofillGUIDToTrash(const std::string& guid) { | 1134 bool AutofillTable::AddAutofillGUIDToTrash(const std::string& guid) { |
1336 sql::Statement s(db_->GetUniqueStatement( | 1135 sql::Statement s(db_->GetUniqueStatement( |
1337 "INSERT INTO autofill_profiles_trash" | 1136 "INSERT INTO autofill_profiles_trash" |
1338 " (guid) " | 1137 " (guid) " |
1339 "VALUES (?)")); | 1138 "VALUES (?)")); |
1340 if (!s) { | 1139 s.BindString(0, guid); |
1341 NOTREACHED(); | |
1342 return sql::INIT_FAILURE; | |
1343 } | |
1344 | 1140 |
1345 s.BindString(0, guid); | 1141 return s.Run(); |
1346 if (!s.Run()) { | |
1347 NOTREACHED(); | |
1348 return false; | |
1349 } | |
1350 return true; | |
1351 } | 1142 } |
1352 | 1143 |
1353 bool AutofillTable::IsAutofillProfilesTrashEmpty() { | 1144 bool AutofillTable::IsAutofillProfilesTrashEmpty() { |
1354 sql::Statement s(db_->GetUniqueStatement( | 1145 sql::Statement s(db_->GetUniqueStatement( |
1355 "SELECT guid " | 1146 "SELECT guid " |
1356 "FROM autofill_profiles_trash")); | 1147 "FROM autofill_profiles_trash")); |
1357 if (!s) { | |
1358 NOTREACHED() << "Statement prepare failed"; | |
1359 return false; | |
1360 } | |
1361 | 1148 |
1362 return !s.Step(); | 1149 return !s.Step(); |
1363 } | 1150 } |
1364 | 1151 |
1365 bool AutofillTable::IsAutofillGUIDInTrash(const std::string& guid) { | 1152 bool AutofillTable::IsAutofillGUIDInTrash(const std::string& guid) { |
1366 sql::Statement s(db_->GetUniqueStatement( | 1153 sql::Statement s(db_->GetUniqueStatement( |
1367 "SELECT guid " | 1154 "SELECT guid " |
1368 "FROM autofill_profiles_trash " | 1155 "FROM autofill_profiles_trash " |
1369 "WHERE guid = ?")); | 1156 "WHERE guid = ?")); |
1370 if (!s) { | 1157 s.BindString(0, guid); |
1371 NOTREACHED() << "Statement prepare failed"; | |
1372 return false; | |
1373 } | |
1374 | 1158 |
1375 s.BindString(0, guid); | |
1376 return s.Step(); | 1159 return s.Step(); |
1377 } | 1160 } |
1378 | 1161 |
1379 bool AutofillTable::InitMainTable() { | 1162 bool AutofillTable::InitMainTable() { |
1380 if (!db_->DoesTableExist("autofill")) { | 1163 if (!db_->DoesTableExist("autofill")) { |
1381 if (!db_->Execute("CREATE TABLE autofill (" | 1164 if (!db_->Execute("CREATE TABLE autofill (" |
1382 "name VARCHAR, " | 1165 "name VARCHAR, " |
1383 "value VARCHAR, " | 1166 "value VARCHAR, " |
1384 "value_lower VARCHAR, " | 1167 "value_lower VARCHAR, " |
1385 "pair_id INTEGER PRIMARY KEY, " | 1168 "pair_id INTEGER PRIMARY KEY, " |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1628 db_->DoesColumnExist("credit_cards", "billing_address") && | 1411 db_->DoesColumnExist("credit_cards", "billing_address") && |
1629 db_->DoesColumnExist("autofill_profiles", "unique_id"))) { | 1412 db_->DoesColumnExist("autofill_profiles", "unique_id"))) { |
1630 return true; | 1413 return true; |
1631 } | 1414 } |
1632 | 1415 |
1633 std::string stmt = | 1416 std::string stmt = |
1634 "SELECT credit_cards.unique_id, autofill_profiles.unique_id " | 1417 "SELECT credit_cards.unique_id, autofill_profiles.unique_id " |
1635 "FROM autofill_profiles, credit_cards " | 1418 "FROM autofill_profiles, credit_cards " |
1636 "WHERE credit_cards.billing_address = autofill_profiles.label"; | 1419 "WHERE credit_cards.billing_address = autofill_profiles.label"; |
1637 sql::Statement s(db_->GetUniqueStatement(stmt.c_str())); | 1420 sql::Statement s(db_->GetUniqueStatement(stmt.c_str())); |
1638 if (!s) | |
1639 return false; | |
1640 | 1421 |
1641 std::map<int, int> cc_billing_map; | 1422 std::map<int, int> cc_billing_map; |
1642 while (s.Step()) | 1423 while (s.Step()) |
1643 cc_billing_map[s.ColumnInt(0)] = s.ColumnInt(1); | 1424 cc_billing_map[s.ColumnInt(0)] = s.ColumnInt(1); |
1425 if (!s.Succeeded()) | |
1426 return false; | |
1644 | 1427 |
1645 // Windows already stores the IDs as strings in |billing_address|. Try | 1428 // Windows already stores the IDs as strings in |billing_address|. Try |
1646 // to convert those. | 1429 // to convert those. |
1647 if (cc_billing_map.empty()) { | 1430 if (cc_billing_map.empty()) { |
1648 std::string stmt = "SELECT unique_id,billing_address FROM credit_cards"; | 1431 std::string stmt = "SELECT unique_id,billing_address FROM credit_cards"; |
1649 sql::Statement s(db_->GetUniqueStatement(stmt.c_str())); | 1432 sql::Statement s(db_->GetUniqueStatement(stmt.c_str())); |
1650 if (!s) | |
1651 return false; | |
1652 | 1433 |
1653 while (s.Step()) { | 1434 while (s.Step()) { |
1654 int id = 0; | 1435 int id = 0; |
1655 if (base::StringToInt(s.ColumnString(1), &id)) | 1436 if (base::StringToInt(s.ColumnString(1), &id)) |
1656 cc_billing_map[s.ColumnInt(0)] = id; | 1437 cc_billing_map[s.ColumnInt(0)] = id; |
1657 } | 1438 } |
1439 if (!s.Succeeded()) | |
1440 return false; | |
1658 } | 1441 } |
1659 | 1442 |
1660 if (!db_->Execute("CREATE TABLE credit_cards_temp ( " | 1443 if (!db_->Execute("CREATE TABLE credit_cards_temp ( " |
1661 "label VARCHAR, " | 1444 "label VARCHAR, " |
1662 "unique_id INTEGER PRIMARY KEY, " | 1445 "unique_id INTEGER PRIMARY KEY, " |
1663 "name_on_card VARCHAR, " | 1446 "name_on_card VARCHAR, " |
1664 "type VARCHAR, " | 1447 "type VARCHAR, " |
1665 "card_number VARCHAR, " | 1448 "card_number VARCHAR, " |
1666 "expiration_month INTEGER, " | 1449 "expiration_month INTEGER, " |
1667 "expiration_year INTEGER, " | 1450 "expiration_year INTEGER, " |
(...skipping 18 matching lines...) Expand all Loading... | |
1686 return false; | 1469 return false; |
1687 | 1470 |
1688 if (!db_->Execute("ALTER TABLE credit_cards_temp RENAME TO credit_cards")) | 1471 if (!db_->Execute("ALTER TABLE credit_cards_temp RENAME TO credit_cards")) |
1689 return false; | 1472 return false; |
1690 | 1473 |
1691 for (std::map<int, int>::const_iterator iter = cc_billing_map.begin(); | 1474 for (std::map<int, int>::const_iterator iter = cc_billing_map.begin(); |
1692 iter != cc_billing_map.end(); ++iter) { | 1475 iter != cc_billing_map.end(); ++iter) { |
1693 sql::Statement s(db_->GetCachedStatement( | 1476 sql::Statement s(db_->GetCachedStatement( |
1694 SQL_FROM_HERE, | 1477 SQL_FROM_HERE, |
1695 "UPDATE credit_cards SET billing_address=? WHERE unique_id=?")); | 1478 "UPDATE credit_cards SET billing_address=? WHERE unique_id=?")); |
1696 if (!s) | |
1697 return false; | |
1698 | |
1699 s.BindInt(0, (*iter).second); | 1479 s.BindInt(0, (*iter).second); |
1700 s.BindInt(1, (*iter).first); | 1480 s.BindInt(1, (*iter).first); |
1701 | 1481 |
1702 if (!s.Run()) | 1482 if (!s.Run()) |
1703 return false; | 1483 return false; |
1704 } | 1484 } |
1705 | 1485 |
1706 return true; | 1486 return true; |
1707 } | 1487 } |
1708 | 1488 |
1709 bool AutofillTable::MigrateToVersion30AddDateModifed() { | 1489 bool AutofillTable::MigrateToVersion30AddDateModifed() { |
1710 // Add date_modified to autofill_profiles. | 1490 // Add date_modified to autofill_profiles. |
1711 if (!db_->DoesColumnExist("autofill_profiles", "date_modified")) { | 1491 if (!db_->DoesColumnExist("autofill_profiles", "date_modified")) { |
1712 if (!db_->Execute("ALTER TABLE autofill_profiles ADD COLUMN " | 1492 if (!db_->Execute("ALTER TABLE autofill_profiles ADD COLUMN " |
1713 "date_modified INTEGER NON NULL DEFAULT 0")) { | 1493 "date_modified INTEGER NON NULL DEFAULT 0")) { |
1714 return false; | 1494 return false; |
1715 } | 1495 } |
1716 | 1496 |
1717 sql::Statement s(db_->GetUniqueStatement( | 1497 sql::Statement s(db_->GetUniqueStatement( |
1718 "UPDATE autofill_profiles SET date_modified=?")); | 1498 "UPDATE autofill_profiles SET date_modified=?")); |
1719 if (!s) | |
1720 return false; | |
1721 | |
1722 s.BindInt64(0, Time::Now().ToTimeT()); | 1499 s.BindInt64(0, Time::Now().ToTimeT()); |
1723 | 1500 |
1724 if (!s.Run()) | 1501 if (!s.Run()) |
1725 return false; | 1502 return false; |
1726 } | 1503 } |
1727 | 1504 |
1728 // Add date_modified to credit_cards. | 1505 // Add date_modified to credit_cards. |
1729 if (!db_->DoesColumnExist("credit_cards", "date_modified")) { | 1506 if (!db_->DoesColumnExist("credit_cards", "date_modified")) { |
1730 if (!db_->Execute("ALTER TABLE credit_cards ADD COLUMN " | 1507 if (!db_->Execute("ALTER TABLE credit_cards ADD COLUMN " |
1731 "date_modified INTEGER NON NULL DEFAULT 0")) { | 1508 "date_modified INTEGER NON NULL DEFAULT 0")) { |
1732 return false; | 1509 return false; |
1733 } | 1510 } |
1734 | 1511 |
1735 sql::Statement s(db_->GetUniqueStatement( | 1512 sql::Statement s(db_->GetUniqueStatement( |
1736 "UPDATE credit_cards SET date_modified=?")); | 1513 "UPDATE credit_cards SET date_modified=?")); |
1737 if (!s) | |
1738 return false; | |
1739 | |
1740 s.BindInt64(0, Time::Now().ToTimeT()); | 1514 s.BindInt64(0, Time::Now().ToTimeT()); |
1741 | 1515 |
1742 if (!s.Run()) | 1516 if (!s.Run()) |
1743 return false; | 1517 return false; |
1744 } | 1518 } |
1745 | 1519 |
1746 return true; | 1520 return true; |
1747 } | 1521 } |
1748 | 1522 |
1749 bool AutofillTable::MigrateToVersion31AddGUIDToCreditCardsAndProfiles() { | 1523 bool AutofillTable::MigrateToVersion31AddGUIDToCreditCardsAndProfiles() { |
1750 // Note that we need to check for the guid column's existence due to the | 1524 // Note that we need to check for the guid column's existence due to the |
1751 // fact that for a version 22 database the |autofill_profiles| table | 1525 // fact that for a version 22 database the |autofill_profiles| table |
1752 // gets created fresh with |InitAutofillProfilesTable|. | 1526 // gets created fresh with |InitAutofillProfilesTable|. |
1753 if (!db_->DoesColumnExist("autofill_profiles", "guid")) { | 1527 if (!db_->DoesColumnExist("autofill_profiles", "guid")) { |
1754 if (!db_->Execute("ALTER TABLE autofill_profiles ADD COLUMN " | 1528 if (!db_->Execute("ALTER TABLE autofill_profiles ADD COLUMN " |
1755 "guid VARCHAR NOT NULL DEFAULT \"\"")) { | 1529 "guid VARCHAR NOT NULL DEFAULT \"\"")) { |
1756 return false; | 1530 return false; |
1757 } | 1531 } |
1758 | 1532 |
1759 // Set all the |guid| fields to valid values. | 1533 // Set all the |guid| fields to valid values. |
1760 | 1534 |
1761 sql::Statement s(db_->GetUniqueStatement("SELECT unique_id " | 1535 sql::Statement s(db_->GetUniqueStatement("SELECT unique_id " |
1762 "FROM autofill_profiles")); | 1536 "FROM autofill_profiles")); |
1763 if (!s) | |
1764 return false; | |
1765 | 1537 |
1766 while (s.Step()) { | 1538 while (s.Step()) { |
1767 sql::Statement update_s( | 1539 sql::Statement update_s( |
1768 db_->GetUniqueStatement("UPDATE autofill_profiles " | 1540 db_->GetUniqueStatement("UPDATE autofill_profiles " |
1769 "SET guid=? WHERE unique_id=?")); | 1541 "SET guid=? WHERE unique_id=?")); |
1770 if (!update_s) | |
1771 return false; | |
1772 update_s.BindString(0, guid::GenerateGUID()); | 1542 update_s.BindString(0, guid::GenerateGUID()); |
1773 update_s.BindInt(1, s.ColumnInt(0)); | 1543 update_s.BindInt(1, s.ColumnInt(0)); |
1774 | 1544 |
1775 if (!update_s.Run()) | 1545 if (!update_s.Run()) |
1776 return false; | 1546 return false; |
1777 } | 1547 } |
1548 if (!s.Succeeded()) | |
1549 return false; | |
1778 } | 1550 } |
1779 | 1551 |
1780 // Note that we need to check for the guid column's existence due to the | 1552 // Note that we need to check for the guid column's existence due to the |
1781 // fact that for a version 22 database the |autofill_profiles| table | 1553 // fact that for a version 22 database the |autofill_profiles| table |
1782 // gets created fresh with |InitAutofillProfilesTable|. | 1554 // gets created fresh with |InitAutofillProfilesTable|. |
1783 if (!db_->DoesColumnExist("credit_cards", "guid")) { | 1555 if (!db_->DoesColumnExist("credit_cards", "guid")) { |
1784 if (!db_->Execute("ALTER TABLE credit_cards ADD COLUMN " | 1556 if (!db_->Execute("ALTER TABLE credit_cards ADD COLUMN " |
1785 "guid VARCHAR NOT NULL DEFAULT \"\"")) { | 1557 "guid VARCHAR NOT NULL DEFAULT \"\"")) { |
1786 return false; | 1558 return false; |
1787 } | 1559 } |
1788 | 1560 |
1789 // Set all the |guid| fields to valid values. | 1561 // Set all the |guid| fields to valid values. |
1790 | 1562 |
1791 sql::Statement s(db_->GetUniqueStatement("SELECT unique_id " | 1563 sql::Statement s(db_->GetUniqueStatement("SELECT unique_id " |
1792 "FROM credit_cards")); | 1564 "FROM credit_cards")); |
1793 if (!s) | |
1794 return false; | |
1795 | 1565 |
1796 while (s.Step()) { | 1566 while (s.Step()) { |
1797 sql::Statement update_s( | 1567 sql::Statement update_s( |
1798 db_->GetUniqueStatement("UPDATE credit_cards " | 1568 db_->GetUniqueStatement("UPDATE credit_cards " |
1799 "set guid=? WHERE unique_id=?")); | 1569 "set guid=? WHERE unique_id=?")); |
1800 if (!update_s) | |
1801 return false; | |
1802 update_s.BindString(0, guid::GenerateGUID()); | 1570 update_s.BindString(0, guid::GenerateGUID()); |
1803 update_s.BindInt(1, s.ColumnInt(0)); | 1571 update_s.BindInt(1, s.ColumnInt(0)); |
1804 | 1572 |
1805 if (!update_s.Run()) | 1573 if (!update_s.Run()) |
1806 return false; | 1574 return false; |
1807 } | 1575 } |
1576 if (!s.Succeeded()) | |
1577 return false; | |
1808 } | 1578 } |
1809 | 1579 |
1810 return true; | 1580 return true; |
1811 } | 1581 } |
1812 | 1582 |
1813 bool AutofillTable::MigrateToVersion32UpdateProfilesAndCreditCards() { | 1583 bool AutofillTable::MigrateToVersion32UpdateProfilesAndCreditCards() { |
1814 if (db_->DoesColumnExist("autofill_profiles", "unique_id")) { | 1584 if (db_->DoesColumnExist("autofill_profiles", "unique_id")) { |
1815 if (!db_->Execute("CREATE TABLE autofill_profiles_temp ( " | 1585 if (!db_->Execute("CREATE TABLE autofill_profiles_temp ( " |
1816 "guid VARCHAR PRIMARY KEY, " | 1586 "guid VARCHAR PRIMARY KEY, " |
1817 "label VARCHAR, " | 1587 "label VARCHAR, " |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1899 "date_modified INTEGER NOT NULL DEFAULT 0)")) { | 1669 "date_modified INTEGER NOT NULL DEFAULT 0)")) { |
1900 return false; | 1670 return false; |
1901 } | 1671 } |
1902 } | 1672 } |
1903 | 1673 |
1904 sql::Statement s(db_->GetUniqueStatement( | 1674 sql::Statement s(db_->GetUniqueStatement( |
1905 "SELECT guid, first_name, middle_name, last_name, email, " | 1675 "SELECT guid, first_name, middle_name, last_name, email, " |
1906 "company_name, address_line_1, address_line_2, city, state, " | 1676 "company_name, address_line_1, address_line_2, city, state, " |
1907 "zipcode, country, phone, date_modified " | 1677 "zipcode, country, phone, date_modified " |
1908 "FROM autofill_profiles")); | 1678 "FROM autofill_profiles")); |
1679 | |
1909 while (s.Step()) { | 1680 while (s.Step()) { |
1910 AutofillProfile profile; | 1681 AutofillProfile profile; |
1911 profile.set_guid(s.ColumnString(0)); | 1682 profile.set_guid(s.ColumnString(0)); |
1912 DCHECK(guid::IsValidGUID(profile.guid())); | 1683 DCHECK(guid::IsValidGUID(profile.guid())); |
1913 | 1684 |
1914 profile.SetInfo(NAME_FIRST, s.ColumnString16(1)); | 1685 profile.SetInfo(NAME_FIRST, s.ColumnString16(1)); |
1915 profile.SetInfo(NAME_MIDDLE, s.ColumnString16(2)); | 1686 profile.SetInfo(NAME_MIDDLE, s.ColumnString16(2)); |
1916 profile.SetInfo(NAME_LAST, s.ColumnString16(3)); | 1687 profile.SetInfo(NAME_LAST, s.ColumnString16(3)); |
1917 profile.SetInfo(EMAIL_ADDRESS, s.ColumnString16(4)); | 1688 profile.SetInfo(EMAIL_ADDRESS, s.ColumnString16(4)); |
1918 profile.SetInfo(COMPANY_NAME, s.ColumnString16(5)); | 1689 profile.SetInfo(COMPANY_NAME, s.ColumnString16(5)); |
1919 profile.SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6)); | 1690 profile.SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6)); |
1920 profile.SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7)); | 1691 profile.SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7)); |
1921 profile.SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(8)); | 1692 profile.SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(8)); |
1922 profile.SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(9)); | 1693 profile.SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(9)); |
1923 profile.SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(10)); | 1694 profile.SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(10)); |
1924 profile.SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(11)); | 1695 profile.SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(11)); |
1925 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(12)); | 1696 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(12)); |
1926 int64 date_modified = s.ColumnInt64(13); | 1697 int64 date_modified = s.ColumnInt64(13); |
1927 | 1698 |
1928 sql::Statement s_insert(db_->GetUniqueStatement( | 1699 sql::Statement s_insert(db_->GetUniqueStatement( |
1929 "INSERT INTO autofill_profiles_temp" | 1700 "INSERT INTO autofill_profiles_temp" |
1930 "(guid, company_name, address_line_1, address_line_2, city," | 1701 "(guid, company_name, address_line_1, address_line_2, city," |
1931 " state, zipcode, country, date_modified)" | 1702 " state, zipcode, country, date_modified)" |
1932 "VALUES (?,?,?,?,?,?,?,?,?)")); | 1703 "VALUES (?,?,?,?,?,?,?,?,?)")); |
1933 if (!s) | |
1934 return false; | |
1935 | |
1936 s_insert.BindString(0, profile.guid()); | 1704 s_insert.BindString(0, profile.guid()); |
1937 s_insert.BindString16(1, profile.GetInfo(COMPANY_NAME)); | 1705 s_insert.BindString16(1, profile.GetInfo(COMPANY_NAME)); |
1938 s_insert.BindString16(2, profile.GetInfo(ADDRESS_HOME_LINE1)); | 1706 s_insert.BindString16(2, profile.GetInfo(ADDRESS_HOME_LINE1)); |
1939 s_insert.BindString16(3, profile.GetInfo(ADDRESS_HOME_LINE2)); | 1707 s_insert.BindString16(3, profile.GetInfo(ADDRESS_HOME_LINE2)); |
1940 s_insert.BindString16(4, profile.GetInfo(ADDRESS_HOME_CITY)); | 1708 s_insert.BindString16(4, profile.GetInfo(ADDRESS_HOME_CITY)); |
1941 s_insert.BindString16(5, profile.GetInfo(ADDRESS_HOME_STATE)); | 1709 s_insert.BindString16(5, profile.GetInfo(ADDRESS_HOME_STATE)); |
1942 s_insert.BindString16(6, profile.GetInfo(ADDRESS_HOME_ZIP)); | 1710 s_insert.BindString16(6, profile.GetInfo(ADDRESS_HOME_ZIP)); |
1943 s_insert.BindString16(7, profile.GetInfo(ADDRESS_HOME_COUNTRY)); | 1711 s_insert.BindString16(7, profile.GetInfo(ADDRESS_HOME_COUNTRY)); |
1944 s_insert.BindInt64(8, date_modified); | 1712 s_insert.BindInt64(8, date_modified); |
1945 | 1713 |
1946 if (!s_insert.Run()) | 1714 if (!s_insert.Run()) |
1947 return false; | 1715 return false; |
1948 | 1716 |
1949 // Add the other bits: names, emails, and phone numbers. | 1717 // Add the other bits: names, emails, and phone numbers. |
1950 if (!AddAutofillProfilePieces(profile, db_)) | 1718 if (!AddAutofillProfilePieces(profile, db_)) |
1951 return false; | 1719 return false; |
1952 } | 1720 } // endwhile |
1721 if (!s.Succeeded()) | |
1722 return false; | |
1953 | 1723 |
1954 if (!db_->Execute("DROP TABLE autofill_profiles")) | 1724 if (!db_->Execute("DROP TABLE autofill_profiles")) |
1955 return false; | 1725 return false; |
1956 | 1726 |
1957 if (!db_->Execute( | 1727 if (!db_->Execute( |
1958 "ALTER TABLE autofill_profiles_temp RENAME TO autofill_profiles")) { | 1728 "ALTER TABLE autofill_profiles_temp RENAME TO autofill_profiles")) { |
1959 return false; | 1729 return false; |
1960 } | 1730 } |
1961 } | 1731 } |
1962 | 1732 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1998 if (!db_->DoesColumnExist("autofill_profiles", "country_code")) { | 1768 if (!db_->DoesColumnExist("autofill_profiles", "country_code")) { |
1999 if (!db_->Execute("ALTER TABLE autofill_profiles ADD COLUMN " | 1769 if (!db_->Execute("ALTER TABLE autofill_profiles ADD COLUMN " |
2000 "country_code VARCHAR")) { | 1770 "country_code VARCHAR")) { |
2001 return false; | 1771 return false; |
2002 } | 1772 } |
2003 | 1773 |
2004 // Set all the |country_code| fields to match existing |country| values. | 1774 // Set all the |country_code| fields to match existing |country| values. |
2005 sql::Statement s(db_->GetUniqueStatement("SELECT guid, country " | 1775 sql::Statement s(db_->GetUniqueStatement("SELECT guid, country " |
2006 "FROM autofill_profiles")); | 1776 "FROM autofill_profiles")); |
2007 | 1777 |
2008 if (!s) | |
2009 return false; | |
2010 | |
2011 while (s.Step()) { | 1778 while (s.Step()) { |
2012 sql::Statement update_s( | 1779 sql::Statement update_s( |
2013 db_->GetUniqueStatement("UPDATE autofill_profiles " | 1780 db_->GetUniqueStatement("UPDATE autofill_profiles " |
2014 "SET country_code=? WHERE guid=?")); | 1781 "SET country_code=? WHERE guid=?")); |
2015 if (!update_s) | |
2016 return false; | |
2017 | 1782 |
2018 string16 country = s.ColumnString16(1); | 1783 string16 country = s.ColumnString16(1); |
2019 std::string app_locale = AutofillCountry::ApplicationLocale(); | 1784 std::string app_locale = AutofillCountry::ApplicationLocale(); |
2020 update_s.BindString(0, AutofillCountry::GetCountryCode(country, | 1785 update_s.BindString(0, AutofillCountry::GetCountryCode(country, |
2021 app_locale)); | 1786 app_locale)); |
2022 update_s.BindString(1, s.ColumnString(0)); | 1787 update_s.BindString(1, s.ColumnString(0)); |
2023 | 1788 |
2024 if (!update_s.Run()) | 1789 if (!update_s.Run()) |
2025 return false; | 1790 return false; |
2026 } | 1791 } |
1792 if (!s.Succeeded()) | |
1793 return false; | |
2027 } | 1794 } |
2028 | 1795 |
2029 return true; | 1796 return true; |
2030 } | 1797 } |
2031 | 1798 |
2032 // Correct all country codes with value "UK" to be "GB". This data | 1799 // Correct all country codes with value "UK" to be "GB". This data |
2033 // was mistakenly introduced in build 686.0. This migration is to clean | 1800 // was mistakenly introduced in build 686.0. This migration is to clean |
2034 // it up. See http://crbug.com/74511 for details. | 1801 // it up. See http://crbug.com/74511 for details. |
2035 bool AutofillTable::MigrateToVersion35GreatBritainCountryCodes() { | 1802 bool AutofillTable::MigrateToVersion35GreatBritainCountryCodes() { |
2036 sql::Statement s(db_->GetUniqueStatement( | 1803 sql::Statement s(db_->GetUniqueStatement( |
2037 "UPDATE autofill_profiles SET country_code=\"GB\" " | 1804 "UPDATE autofill_profiles SET country_code=\"GB\" " |
2038 "WHERE country_code=\"UK\"")); | 1805 "WHERE country_code=\"UK\"")); |
2039 | 1806 |
2040 return s.Run(); | 1807 return s.Run(); |
2041 } | 1808 } |
2042 | 1809 |
2043 // Merge and cull older profiles where possible. | 1810 // Merge and cull older profiles where possible. |
2044 bool AutofillTable::MigrateToVersion37MergeAndCullOlderProfiles() { | 1811 bool AutofillTable::MigrateToVersion37MergeAndCullOlderProfiles() { |
2045 sql::Statement s(db_->GetUniqueStatement( | 1812 sql::Statement s(db_->GetUniqueStatement( |
2046 "SELECT guid, date_modified FROM autofill_profiles")); | 1813 "SELECT guid, date_modified FROM autofill_profiles")); |
2047 if (!s) | |
2048 return false; | |
2049 | 1814 |
2050 // Accumulate the good profiles. | 1815 // Accumulate the good profiles. |
2051 std::vector<AutofillProfile> accumulated_profiles; | 1816 std::vector<AutofillProfile> accumulated_profiles; |
2052 std::vector<AutofillProfile*> accumulated_profiles_p; | 1817 std::vector<AutofillProfile*> accumulated_profiles_p; |
2053 std::map<std::string, int64> modification_map; | 1818 std::map<std::string, int64> modification_map; |
2054 while (s.Step()) { | 1819 while (s.Step()) { |
2055 std::string guid = s.ColumnString(0); | 1820 std::string guid = s.ColumnString(0); |
2056 int64 date_modified = s.ColumnInt64(1); | 1821 int64 date_modified = s.ColumnInt64(1); |
2057 modification_map.insert( | 1822 modification_map.insert( |
2058 std::pair<std::string, int64>(guid, date_modified)); | 1823 std::pair<std::string, int64>(guid, date_modified)); |
(...skipping 18 matching lines...) Expand all Loading... | |
2077 address_of<AutofillProfile>); | 1842 address_of<AutofillProfile>); |
2078 | 1843 |
2079 // If the profile got merged trash the original. | 1844 // If the profile got merged trash the original. |
2080 if (merged) | 1845 if (merged) |
2081 AddAutofillGUIDToTrash(p->guid()); | 1846 AddAutofillGUIDToTrash(p->guid()); |
2082 | 1847 |
2083 } else { | 1848 } else { |
2084 // An invalid profile, so trash it. | 1849 // An invalid profile, so trash it. |
2085 AddAutofillGUIDToTrash(p->guid()); | 1850 AddAutofillGUIDToTrash(p->guid()); |
2086 } | 1851 } |
2087 } | 1852 } // endwhile |
1853 if (!s.Succeeded()) | |
1854 return false; | |
2088 | 1855 |
2089 // Drop the current profiles. | 1856 // Drop the current profiles. |
2090 if (!ClearAutofillProfiles()) | 1857 if (!ClearAutofillProfiles()) |
2091 return false; | 1858 return false; |
2092 | 1859 |
2093 // Add the newly merged profiles back in. | 1860 // Add the newly merged profiles back in. |
2094 for (std::vector<AutofillProfile>::const_iterator | 1861 for (std::vector<AutofillProfile>::const_iterator |
2095 iter = accumulated_profiles.begin(); | 1862 iter = accumulated_profiles.begin(); |
2096 iter != accumulated_profiles.end(); | 1863 iter != accumulated_profiles.end(); |
2097 ++iter) { | 1864 ++iter) { |
2098 if (!AddAutofillProfile(*iter)) | 1865 if (!AddAutofillProfile(*iter)) |
2099 return false; | 1866 return false; |
2100 | 1867 |
2101 // Fix up the original modification date. | 1868 // Fix up the original modification date. |
2102 std::map<std::string, int64>::const_iterator date_item = | 1869 std::map<std::string, int64>::const_iterator date_item = |
2103 modification_map.find(iter->guid()); | 1870 modification_map.find(iter->guid()); |
2104 if (date_item == modification_map.end()) | 1871 if (date_item == modification_map.end()) |
2105 return false; | 1872 return false; |
2106 | 1873 |
2107 sql::Statement s_date(db_->GetUniqueStatement( | 1874 sql::Statement s_date(db_->GetUniqueStatement( |
2108 "UPDATE autofill_profiles SET date_modified=? " | 1875 "UPDATE autofill_profiles SET date_modified=? " |
2109 "WHERE guid=?")); | 1876 "WHERE guid=?")); |
2110 s_date.BindInt64(0, date_item->second); | 1877 s_date.BindInt64(0, date_item->second); |
2111 s_date.BindString(1, iter->guid()); | 1878 s_date.BindString(1, iter->guid()); |
1879 | |
2112 if (!s_date.Run()) | 1880 if (!s_date.Run()) |
2113 return false; | 1881 return false; |
2114 } | 1882 } |
2115 | 1883 |
2116 return true; | 1884 return true; |
2117 } | 1885 } |
OLD | NEW |