summaryrefslogtreecommitdiffstats
path: root/chrome/browser/webdata/web_database.cc
diff options
context:
space:
mode:
authorskrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-25 00:31:47 +0000
committerskrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-25 00:31:47 +0000
commit8d21ff3b6bc3fccb7d9494dac318c79930087b1f (patch)
tree34b1d38fe94b383df846bf44fcf8d65f9df2eee8 /chrome/browser/webdata/web_database.cc
parentc03aa00ce4aa44a48927a087663c8f6dbcd1f06c (diff)
downloadchromium_src-8d21ff3b6bc3fccb7d9494dac318c79930087b1f.zip
chromium_src-8d21ff3b6bc3fccb7d9494dac318c79930087b1f.tar.gz
chromium_src-8d21ff3b6bc3fccb7d9494dac318c79930087b1f.tar.bz2
Implement WebDatabase::UpdateAutofillEntries()
This new method will replace existing autofill entries with the list provided as the argument. Provided entries that don't exist are added. BUG=36713 Review URL: http://codereview.chromium.org/660023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39959 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/webdata/web_database.cc')
-rw-r--r--chrome/browser/webdata/web_database.cc60
1 files changed, 60 insertions, 0 deletions
diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc
index f6b875b..7f8c3c7 100644
--- a/chrome/browser/webdata/web_database.cc
+++ b/chrome/browser/webdata/web_database.cc
@@ -1041,6 +1041,66 @@ bool WebDatabase::GetAllAutofillEntries(std::vector<AutofillEntry>* entries) {
return s.Succeeded();
}
+bool WebDatabase::UpdateAutofillEntries(
+ const std::vector<AutofillEntry>& entries) {
+ if (!entries.size())
+ return true;
+
+ // Remove all existing entries.
+ for (size_t i = 0; i < entries.size(); i++) {
+ std::string sql = "SELECT pair_id FROM autofill "
+ "WHERE name = ? AND value = ?";
+ sql::Statement s(db_.GetUniqueStatement(sql.c_str()));
+ if (!s.is_valid()) {
+ NOTREACHED() << "Statement prepare failed";
+ return false;
+ }
+
+ s.BindString(0, UTF16ToUTF8(entries[i].key().name()));
+ s.BindString(1, UTF16ToUTF8(entries[i].key().value()));
+ if (s.Step()) {
+ if (!RemoveFormElementForID(s.ColumnInt64(0)))
+ return false;
+ }
+ }
+
+ // Insert all the supplied autofill entries.
+ for (size_t i = 0; i < entries.size(); i++) {
+ if (!InsertAutofillEntry(entries[i]))
+ return false;
+ }
+
+ return true;
+}
+
+bool WebDatabase::InsertAutofillEntry(const AutofillEntry& entry) {
+ std::string sql = "INSERT INTO autofill (name, value, value_lower, count) "
+ "VALUES (?, ?, ?, ?)";
+ sql::Statement s(db_.GetUniqueStatement(sql.c_str()));
+ if (!s.is_valid()) {
+ NOTREACHED() << "Statement prepare failed";
+ return false;
+ }
+
+ s.BindString(0, UTF16ToUTF8(entry.key().name()));
+ s.BindString(1, UTF16ToUTF8(entry.key().value()));
+ s.BindString(2, UTF16ToUTF8(l10n_util::ToLower(entry.key().value())));
+ s.BindInt(3, entry.timestamps().size());
+
+ if (!s.Run()) {
+ NOTREACHED();
+ return false;
+ }
+
+ int64 pair_id = db_.GetLastInsertRowId();
+ for (size_t i = 0; i < entry.timestamps().size(); i++) {
+ if (!InsertPairIDAndDate(pair_id, entry.timestamps()[i]))
+ return false;
+ }
+
+ return true;
+}
+
bool WebDatabase::InsertFormElement(const FormField& element,
int64* pair_id) {
sql::Statement s(db_.GetUniqueStatement(