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

Unified Diff: chrome/browser/webdata/web_database.cc

Issue 21217: Don't store empty values for autofill (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/webdata/web_database.h ('k') | chrome/browser/webdata/web_database_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/webdata/web_database.cc
===================================================================
--- chrome/browser/webdata/web_database.cc (revision 9373)
+++ chrome/browser/webdata/web_database.cc (working copy)
@@ -105,7 +105,7 @@
using base::Time;
// Current version number.
-static const int kCurrentVersionNumber = 21;
+static const int kCurrentVersionNumber = 22;
static const int kCompatibleVersionNumber = 21;
// Keys used in the meta table.
@@ -846,6 +846,30 @@
return result;
}
+bool WebDatabase::ClearAutofillEmptyValueElements() {
+ SQLStatement s;
+
+ if (s.prepare(db_, "SELECT pair_id FROM autofill "
+ "WHERE TRIM(value)= \"\"") != SQLITE_OK) {
+ NOTREACHED() << "Statement prepare failed";
+ return false;
+ }
+
+ std::set<int64> ids;
+ int result;
+ while ((result = s.step()) == SQLITE_ROW)
+ ids.insert(s.column_int64(0));
+
+ bool success = true;
+ for (std::set<int64>::const_iterator iter = ids.begin(); iter != ids.end();
+ ++iter) {
+ if (!RemoveFormElement(*iter))
+ success = false;
+ }
+
+ return success;
+}
+
bool WebDatabase::GetIDAndCountOfFormElement(
const AutofillForm::Element& element, int64* pair_id, int* count) {
SQLStatement s;
@@ -1054,8 +1078,10 @@
itr != pair_ids.end();
itr++) {
int how_many = 0;
- if (!RemovePairIDAndDate(*itr, delete_begin, delete_end, &how_many))
+ if (!RemoveFormElementForTimeRange(*itr, delete_begin, delete_end,
+ &how_many)) {
return false;
+ }
if (!AddToCountOfFormElement(*itr, -how_many))
return false;
}
@@ -1063,8 +1089,10 @@
return true;
}
-bool WebDatabase::RemovePairIDAndDate(int64 pair_id, const Time delete_begin,
- const Time delete_end, int* how_many) {
+bool WebDatabase::RemoveFormElementForTimeRange(int64 pair_id,
+ const Time delete_begin,
+ const Time delete_end,
+ int* how_many) {
SQLStatement s;
if (s.prepare(db_,
"DELETE FROM autofill_dates WHERE pair_id = ? AND "
@@ -1073,14 +1101,13 @@
return false;
}
s.bind_int64(0, pair_id);
- s.bind_int64(1, delete_begin.ToTimeT());
- s.bind_int64(2,
- delete_end.is_null() ?
- std::numeric_limits<int64>::max() :
- delete_end.ToTimeT());
+ s.bind_int64(1, delete_begin.is_null() ? 0 : delete_begin.ToTimeT());
+ s.bind_int64(2, delete_end.is_null() ? std::numeric_limits<int64>::max() :
+ delete_end.ToTimeT());
bool result = (s.step() == SQLITE_DONE);
- *how_many = sqlite3_changes(db_);
+ if (how_many)
+ *how_many = sqlite3_changes(db_);
return result;
}
@@ -1105,12 +1132,14 @@
SQLStatement s;
if (s.prepare(db_,
"DELETE FROM autofill WHERE pair_id = ?") != SQLITE_OK) {
- NOTREACHED() << "Statement 1 prepare failed";
+ NOTREACHED() << "Statement prepare failed";
return false;
}
s.bind_int64(0, pair_id);
+ if (s.step() != SQLITE_DONE)
+ return false;
- return (s.step() == SQLITE_DONE);
+ return RemoveFormElementForTimeRange(pair_id, Time(), Time(), NULL);
}
void WebDatabase::MigrateOldVersionsAsNeeded() {
@@ -1141,6 +1170,15 @@
std::min(21, kCompatibleVersionNumber));
// FALL THROUGH
+ case 21:
+ if (!ClearAutofillEmptyValueElements()) {
+ NOTREACHED() << "Failed to clean-up autofill DB.";
+ }
+ meta_table_.SetVersionNumber(22);
+ // No change in the compatibility version number.
+
+ // FALL THROUGH
+
// Add successive versions here. Each should set the version number and
// compatible version number as appropriate, then fall through to the next
// case.
« no previous file with comments | « chrome/browser/webdata/web_database.h ('k') | chrome/browser/webdata/web_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698