Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: chrome/browser/webdata/autofill_table.cc

Issue 7601013: Web Intents: Hook up the register intent InfoBar with the WebIntentsRegistry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test fix. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 return true; 397 return true;
398 } 398 }
399 399
400 bool AutofillTable::AddFormFieldValues(const std::vector<FormField>& elements, 400 bool AutofillTable::AddFormFieldValues(const std::vector<FormField>& elements,
401 std::vector<AutofillChange>* changes) { 401 std::vector<AutofillChange>* changes) {
402 return AddFormFieldValuesTime(elements, changes, Time::Now()); 402 return AddFormFieldValuesTime(elements, changes, Time::Now());
403 } 403 }
404 404
405 bool AutofillTable::AddFormFieldValue(const FormField& element, 405 bool AutofillTable::AddFormFieldValue(const FormField& element,
406 std::vector<AutofillChange>* changes) { 406 std::vector<AutofillChange>* changes) {
407 return AddFormFieldValueTime(element, changes, base::Time::Now()); 407 return AddFormFieldValueTime(element, changes, Time::Now());
408 } 408 }
409 409
410 bool AutofillTable::GetFormValuesForElementName(const string16& name, 410 bool AutofillTable::GetFormValuesForElementName(const string16& name,
411 const string16& prefix, 411 const string16& prefix,
412 std::vector<string16>* values, 412 std::vector<string16>* values,
413 int limit) { 413 int limit) {
414 DCHECK(values); 414 DCHECK(values);
415 sql::Statement s; 415 sql::Statement s;
416 416
417 if (prefix.empty()) { 417 if (prefix.empty()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 s.BindInt(3, limit); 450 s.BindInt(3, limit);
451 } 451 }
452 452
453 values->clear(); 453 values->clear();
454 while (s.Step()) 454 while (s.Step())
455 values->push_back(s.ColumnString16(0)); 455 values->push_back(s.ColumnString16(0));
456 return s.Succeeded(); 456 return s.Succeeded();
457 } 457 }
458 458
459 bool AutofillTable::RemoveFormElementsAddedBetween( 459 bool AutofillTable::RemoveFormElementsAddedBetween(
460 base::Time delete_begin, 460 const Time& delete_begin,
461 base::Time delete_end, 461 const Time& delete_end,
462 std::vector<AutofillChange>* changes) { 462 std::vector<AutofillChange>* changes) {
463 DCHECK(changes); 463 DCHECK(changes);
464 // Query for the pair_id, name, and value of all form elements that 464 // Query for the pair_id, name, and value of all form elements that
465 // were used between the given times. 465 // were used between the given times.
466 sql::Statement s(db_->GetUniqueStatement( 466 sql::Statement s(db_->GetUniqueStatement(
467 "SELECT DISTINCT a.pair_id, a.name, a.value " 467 "SELECT DISTINCT a.pair_id, a.name, a.value "
468 "FROM autofill_dates ad JOIN autofill a ON ad.pair_id = a.pair_id " 468 "FROM autofill_dates ad JOIN autofill a ON ad.pair_id = a.pair_id "
469 "WHERE ad.date_created >= ? AND ad.date_created < ?")); 469 "WHERE ad.date_created >= ? AND ad.date_created < ?"));
470 if (!s) { 470 if (!s) {
471 NOTREACHED() << "Statement 1 prepare failed"; 471 NOTREACHED() << "Statement 1 prepare failed";
(...skipping 30 matching lines...) Expand all
502 AutofillChange::Type change_type = 502 AutofillChange::Type change_type =
503 was_removed ? AutofillChange::REMOVE : AutofillChange::UPDATE; 503 was_removed ? AutofillChange::REMOVE : AutofillChange::UPDATE;
504 changes->push_back(AutofillChange(change_type, 504 changes->push_back(AutofillChange(change_type,
505 AutofillKey(itr->b, itr->c))); 505 AutofillKey(itr->b, itr->c)));
506 } 506 }
507 507
508 return true; 508 return true;
509 } 509 }
510 510
511 bool AutofillTable::RemoveFormElementForTimeRange(int64 pair_id, 511 bool AutofillTable::RemoveFormElementForTimeRange(int64 pair_id,
512 const Time delete_begin, 512 const Time& delete_begin,
513 const Time delete_end, 513 const Time& delete_end,
514 int* how_many) { 514 int* how_many) {
515 sql::Statement s(db_->GetUniqueStatement( 515 sql::Statement s(db_->GetUniqueStatement(
516 "DELETE FROM autofill_dates WHERE pair_id = ? AND " 516 "DELETE FROM autofill_dates WHERE pair_id = ? AND "
517 "date_created >= ? AND date_created < ?")); 517 "date_created >= ? AND date_created < ?"));
518 if (!s) { 518 if (!s) {
519 NOTREACHED() << "Statement 1 prepare failed"; 519 NOTREACHED() << "Statement 1 prepare failed";
520 return false; 520 return false;
521 } 521 }
522 s.BindInt64(0, pair_id); 522 s.BindInt64(0, pair_id);
523 s.BindInt64(1, delete_begin.is_null() ? 0 : delete_begin.ToTimeT()); 523 s.BindInt64(1, delete_begin.is_null() ? 0 : delete_begin.ToTimeT());
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 if (!s.Run()) { 629 if (!s.Run()) {
630 NOTREACHED(); 630 NOTREACHED();
631 return false; 631 return false;
632 } 632 }
633 633
634 *pair_id = db_->GetLastInsertRowId(); 634 *pair_id = db_->GetLastInsertRowId();
635 return true; 635 return true;
636 } 636 }
637 637
638 bool AutofillTable::InsertPairIDAndDate(int64 pair_id, 638 bool AutofillTable::InsertPairIDAndDate(int64 pair_id,
639 base::Time date_created) { 639 const Time& date_created) {
640 sql::Statement s(db_->GetUniqueStatement( 640 sql::Statement s(db_->GetUniqueStatement(
641 "INSERT INTO autofill_dates " 641 "INSERT INTO autofill_dates "
642 "(pair_id, date_created) VALUES (?, ?)")); 642 "(pair_id, date_created) VALUES (?, ?)"));
643 if (!s) { 643 if (!s) {
644 NOTREACHED() << "Statement prepare failed"; 644 NOTREACHED() << "Statement prepare failed";
645 return false; 645 return false;
646 } 646 }
647 647
648 s.BindInt64(0, pair_id); 648 s.BindInt64(0, pair_id);
649 s.BindInt64(1, date_created.ToTimeT()); 649 s.BindInt64(1, date_created.ToTimeT());
650 650
651 if (!s.Run()) { 651 if (!s.Run()) {
652 NOTREACHED(); 652 NOTREACHED();
653 return false; 653 return false;
654 } 654 }
655 655
656 return true; 656 return true;
657 } 657 }
658 658
659 bool AutofillTable::AddFormFieldValuesTime( 659 bool AutofillTable::AddFormFieldValuesTime(
660 const std::vector<FormField>& elements, 660 const std::vector<FormField>& elements,
661 std::vector<AutofillChange>* changes, 661 std::vector<AutofillChange>* changes,
662 base::Time time) { 662 Time time) {
663 // Only add one new entry for each unique element name. Use |seen_names| to 663 // Only add one new entry for each unique element name. Use |seen_names| to
664 // track this. Add up to |kMaximumUniqueNames| unique entries per form. 664 // track this. Add up to |kMaximumUniqueNames| unique entries per form.
665 const size_t kMaximumUniqueNames = 256; 665 const size_t kMaximumUniqueNames = 256;
666 std::set<string16> seen_names; 666 std::set<string16> seen_names;
667 bool result = true; 667 bool result = true;
668 for (std::vector<FormField>::const_iterator 668 for (std::vector<FormField>::const_iterator
669 itr = elements.begin(); 669 itr = elements.begin();
670 itr != elements.end(); 670 itr != elements.end();
671 itr++) { 671 itr++) {
672 if (seen_names.size() >= kMaximumUniqueNames) 672 if (seen_names.size() >= kMaximumUniqueNames)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 "SELECT name, value, date_created FROM autofill a JOIN " 707 "SELECT name, value, date_created FROM autofill a JOIN "
708 "autofill_dates ad ON a.pair_id=ad.pair_id")); 708 "autofill_dates ad ON a.pair_id=ad.pair_id"));
709 709
710 if (!s) { 710 if (!s) {
711 NOTREACHED() << "Statement prepare failed"; 711 NOTREACHED() << "Statement prepare failed";
712 return false; 712 return false;
713 } 713 }
714 714
715 bool first_entry = true; 715 bool first_entry = true;
716 AutofillKey* current_key_ptr = NULL; 716 AutofillKey* current_key_ptr = NULL;
717 std::vector<base::Time>* timestamps_ptr = NULL; 717 std::vector<Time>* timestamps_ptr = NULL;
718 string16 name, value; 718 string16 name, value;
719 base::Time time; 719 Time time;
720 while (s.Step()) { 720 while (s.Step()) {
721 name = s.ColumnString16(0); 721 name = s.ColumnString16(0);
722 value = s.ColumnString16(1); 722 value = s.ColumnString16(1);
723 time = Time::FromTimeT(s.ColumnInt64(2)); 723 time = Time::FromTimeT(s.ColumnInt64(2));
724 724
725 if (first_entry) { 725 if (first_entry) {
726 current_key_ptr = new AutofillKey(name, value); 726 current_key_ptr = new AutofillKey(name, value);
727 727
728 timestamps_ptr = new std::vector<base::Time>; 728 timestamps_ptr = new std::vector<Time>;
729 timestamps_ptr->push_back(time); 729 timestamps_ptr->push_back(time);
730 730
731 first_entry = false; 731 first_entry = false;
732 } else { 732 } else {
733 // we've encountered the next entry 733 // we've encountered the next entry
734 if (current_key_ptr->name().compare(name) != 0 || 734 if (current_key_ptr->name().compare(name) != 0 ||
735 current_key_ptr->value().compare(value) != 0) { 735 current_key_ptr->value().compare(value) != 0) {
736 AutofillEntry entry(*current_key_ptr, *timestamps_ptr); 736 AutofillEntry entry(*current_key_ptr, *timestamps_ptr);
737 entries->push_back(entry); 737 entries->push_back(entry);
738 738
739 delete current_key_ptr; 739 delete current_key_ptr;
740 delete timestamps_ptr; 740 delete timestamps_ptr;
741 741
742 current_key_ptr = new AutofillKey(name, value); 742 current_key_ptr = new AutofillKey(name, value);
743 timestamps_ptr = new std::vector<base::Time>; 743 timestamps_ptr = new std::vector<Time>;
744 } 744 }
745 timestamps_ptr->push_back(time); 745 timestamps_ptr->push_back(time);
746 } 746 }
747 } 747 }
748 // If there is at least one result returned, first_entry will be false. 748 // If there is at least one result returned, first_entry will be false.
749 // For this case we need to do a final cleanup step. 749 // For this case we need to do a final cleanup step.
750 if (!first_entry) { 750 if (!first_entry) {
751 AutofillEntry entry(*current_key_ptr, *timestamps_ptr); 751 AutofillEntry entry(*current_key_ptr, *timestamps_ptr);
752 entries->push_back(entry); 752 entries->push_back(entry);
753 delete current_key_ptr; 753 delete current_key_ptr;
754 delete timestamps_ptr; 754 delete timestamps_ptr;
755 } 755 }
756 756
757 return s.Succeeded(); 757 return s.Succeeded();
758 } 758 }
759 759
760 bool AutofillTable::GetAutofillTimestamps(const string16& name, 760 bool AutofillTable::GetAutofillTimestamps(const string16& name,
761 const string16& value, 761 const string16& value,
762 std::vector<base::Time>* timestamps) { 762 std::vector<Time>* timestamps) {
763 DCHECK(timestamps); 763 DCHECK(timestamps);
764 sql::Statement s(db_->GetUniqueStatement( 764 sql::Statement s(db_->GetUniqueStatement(
765 "SELECT date_created FROM autofill a JOIN " 765 "SELECT date_created FROM autofill a JOIN "
766 "autofill_dates ad ON a.pair_id=ad.pair_id " 766 "autofill_dates ad ON a.pair_id=ad.pair_id "
767 "WHERE a.name = ? AND a.value = ?")); 767 "WHERE a.name = ? AND a.value = ?"));
768 768
769 if (!s) { 769 if (!s) {
770 NOTREACHED() << "Statement prepare failed"; 770 NOTREACHED() << "Statement prepare failed";
771 return false; 771 return false;
772 } 772 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 for (size_t i = 0; i < entry.timestamps().size(); i++) { 835 for (size_t i = 0; i < entry.timestamps().size(); i++) {
836 if (!InsertPairIDAndDate(pair_id, entry.timestamps()[i])) 836 if (!InsertPairIDAndDate(pair_id, entry.timestamps()[i]))
837 return false; 837 return false;
838 } 838 }
839 839
840 return true; 840 return true;
841 } 841 }
842 842
843 bool AutofillTable::AddFormFieldValueTime(const FormField& element, 843 bool AutofillTable::AddFormFieldValueTime(const FormField& element,
844 std::vector<AutofillChange>* changes, 844 std::vector<AutofillChange>* changes,
845 base::Time time) { 845 Time time) {
846 int count = 0; 846 int count = 0;
847 int64 pair_id; 847 int64 pair_id;
848 848
849 if (!GetIDAndCountOfFormElement(element, &pair_id, &count)) 849 if (!GetIDAndCountOfFormElement(element, &pair_id, &count))
850 return false; 850 return false;
851 851
852 if (count == 0 && !InsertFormElement(element, &pair_id)) 852 if (count == 0 && !InsertFormElement(element, &pair_id))
853 return false; 853 return false;
854 854
855 if (!SetCountOfFormElement(pair_id, count + 1)) 855 if (!SetCountOfFormElement(pair_id, count + 1))
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 if (!s) { 1236 if (!s) {
1237 NOTREACHED() << "Statement prepare failed"; 1237 NOTREACHED() << "Statement prepare failed";
1238 return false; 1238 return false;
1239 } 1239 }
1240 1240
1241 s.BindString(0, guid); 1241 s.BindString(0, guid);
1242 return s.Run(); 1242 return s.Run();
1243 } 1243 }
1244 1244
1245 bool AutofillTable::RemoveAutofillProfilesAndCreditCardsModifiedBetween( 1245 bool AutofillTable::RemoveAutofillProfilesAndCreditCardsModifiedBetween(
1246 base::Time delete_begin, 1246 const Time& delete_begin,
1247 base::Time delete_end, 1247 const Time& delete_end,
1248 std::vector<std::string>* profile_guids, 1248 std::vector<std::string>* profile_guids,
1249 std::vector<std::string>* credit_card_guids) { 1249 std::vector<std::string>* credit_card_guids) {
1250 DCHECK(delete_end.is_null() || delete_begin < delete_end); 1250 DCHECK(delete_end.is_null() || delete_begin < delete_end);
1251 1251
1252 time_t delete_begin_t = delete_begin.ToTimeT(); 1252 time_t delete_begin_t = delete_begin.ToTimeT();
1253 time_t delete_end_t = delete_end.is_null() ? 1253 time_t delete_end_t = delete_end.is_null() ?
1254 std::numeric_limits<time_t>::max() : 1254 std::numeric_limits<time_t>::max() :
1255 delete_end.ToTimeT(); 1255 delete_end.ToTimeT();
1256 1256
1257 // Remember Autofill profiles in the time range. 1257 // Remember Autofill profiles in the time range.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 1360
1361 1361
1362 bool AutofillTable::RemoveFormElementForID(int64 pair_id) { 1362 bool AutofillTable::RemoveFormElementForID(int64 pair_id) {
1363 sql::Statement s(db_->GetUniqueStatement( 1363 sql::Statement s(db_->GetUniqueStatement(
1364 "DELETE FROM autofill WHERE pair_id = ?")); 1364 "DELETE FROM autofill WHERE pair_id = ?"));
1365 if (!s) { 1365 if (!s) {
1366 NOTREACHED() << "Statement prepare failed"; 1366 NOTREACHED() << "Statement prepare failed";
1367 return false; 1367 return false;
1368 } 1368 }
1369 s.BindInt64(0, pair_id); 1369 s.BindInt64(0, pair_id);
1370 if (s.Run()) { 1370 if (s.Run())
1371 return RemoveFormElementForTimeRange(pair_id, base::Time(), base::Time(), 1371 return RemoveFormElementForTimeRange(pair_id, Time(), Time(), NULL);
1372 NULL); 1372
1373 }
1374 return false; 1373 return false;
1375 } 1374 }
1376 1375
1377 bool AutofillTable::AddAutofillGUIDToTrash(const std::string& guid) { 1376 bool AutofillTable::AddAutofillGUIDToTrash(const std::string& guid) {
1378 sql::Statement s(db_->GetUniqueStatement( 1377 sql::Statement s(db_->GetUniqueStatement(
1379 "INSERT INTO autofill_profiles_trash" 1378 "INSERT INTO autofill_profiles_trash"
1380 " (guid) " 1379 " (guid) "
1381 "VALUES (?)")); 1380 "VALUES (?)"));
1382 if (!s) { 1381 if (!s) {
1383 NOTREACHED(); 1382 NOTREACHED();
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
2153 "UPDATE autofill_profiles SET date_modified=? " 2152 "UPDATE autofill_profiles SET date_modified=? "
2154 "WHERE guid=?")); 2153 "WHERE guid=?"));
2155 s_date.BindInt64(0, date_item->second); 2154 s_date.BindInt64(0, date_item->second);
2156 s_date.BindString(1, iter->guid()); 2155 s_date.BindString(1, iter->guid());
2157 if (!s_date.Run()) 2156 if (!s_date.Run())
2158 return false; 2157 return false;
2159 } 2158 }
2160 2159
2161 return true; 2160 return true;
2162 } 2161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698