summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorpetersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-12 22:39:14 +0000
committerpetersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-12 22:39:14 +0000
commit603c1d0ce8f84241739005df226f5e31494dd3cd (patch)
tree509914ea91ab2fde93a3bdc156fd7c2902bf70f6 /chrome/browser
parent4fb8792e0d0960bf776f67e43e878beedd6f0463 (diff)
downloadchromium_src-603c1d0ce8f84241739005df226f5e31494dd3cd.zip
chromium_src-603c1d0ce8f84241739005df226f5e31494dd3cd.tar.gz
chromium_src-603c1d0ce8f84241739005df226f5e31494dd3cd.tar.bz2
New functions in WebDatabase and WebDataService for the removal of form entries made between two given times. BrowserDataRemover::Remove now clears autofill data.
BUG=3870 Review URL: http://codereview.chromium.org/9775 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5312 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browsing_data_remover.cc8
-rw-r--r--chrome/browser/webdata/web_data_service.cc23
-rw-r--r--chrome/browser/webdata/web_data_service.h6
-rw-r--r--chrome/browser/webdata/web_database.cc114
-rw-r--r--chrome/browser/webdata/web_database.h29
5 files changed, 172 insertions, 8 deletions
diff --git a/chrome/browser/browsing_data_remover.cc b/chrome/browser/browsing_data_remover.cc
index ac934ca..cfb5f9c 100644
--- a/chrome/browser/browsing_data_remover.cc
+++ b/chrome/browser/browsing_data_remover.cc
@@ -108,8 +108,12 @@ void BrowsingDataRemover::Remove(int remove_mask) {
}
if (remove_mask & REMOVE_FORM_DATA) {
- // TODO(jcampan): bug #3870 hook-up Peterson's code here.
- NOTREACHED() << "to be implemented";
+ UserMetrics::RecordAction(L"ClearBrowsingData_Autofill", profile_);
+ WebDataService* web_data_service =
+ profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
+
+ web_data_service->RemoveFormElementsAddedBetween(delete_begin_,
+ delete_end_);
}
if (remove_mask & REMOVE_CACHE) {
diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc
index 002977c..e3e3f44 100644
--- a/chrome/browser/webdata/web_data_service.cc
+++ b/chrome/browser/webdata/web_data_service.cc
@@ -342,6 +342,19 @@ void WebDataService::RemoveLoginsCreatedAfter(const Time delete_begin) {
RemoveLoginsCreatedBetween(delete_begin, Time());
}
+void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin,
+ const Time& delete_end) {
+ GenericRequest2<Time, Time>* request =
+ new GenericRequest2<Time, Time>(this,
+ GetNextRequestHandle(),
+ NULL,
+ delete_begin,
+ delete_end);
+ RegisterRequest(request);
+ ScheduleTask(NewRunnableMethod(this,
+ &WebDataService::RemoveFormElementsAddedBetweenImpl, request));
+}
+
WebDataService::Handle WebDataService::GetLogins(
const PasswordForm& form,
WebDataServiceConsumer* consumer) {
@@ -615,6 +628,16 @@ void WebDataService::GetFormValuesForElementNameImpl(WebDataRequest* request,
request->RequestComplete();
}
+void WebDataService::RemoveFormElementsAddedBetweenImpl(
+ GenericRequest2<Time, Time>* request) {
+ if (db_ && !request->IsCancelled()) {
+ if (db_->RemoveFormElementsAddedBetween(request->GetArgument1(),
+ request->GetArgument2()))
+ ScheduleCommit();
+ }
+ request->RequestComplete();
+}
+
////////////////////////////////////////////////////////////////////////////////
//
// Web Apps implementation.
diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h
index 86a7af88..3002140 100644
--- a/chrome/browser/webdata/web_data_service.h
+++ b/chrome/browser/webdata/web_data_service.h
@@ -372,6 +372,10 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> {
int limit,
WebDataServiceConsumer* consumer);
+ // Removes form elements recorded for autofill from the database.
+ void RemoveFormElementsAddedBetween(const base::Time& delete_begin,
+ const base::Time& delete_end);
+
protected:
friend class TemplateURLModelTest;
friend class TemplateURLModelTestingProfile;
@@ -445,6 +449,8 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> {
GenericRequest<std::vector<AutofillForm::Element> >* request);
void GetFormValuesForElementNameImpl(WebDataRequest* request,
const std::wstring& name, const std::wstring& prefix, int limit);
+ void RemoveFormElementsAddedBetweenImpl(
+ GenericRequest2<base::Time, base::Time>* request);
//////////////////////////////////////////////////////////////////////////////
//
diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc
index c22990c..28e7b08 100644
--- a/chrome/browser/webdata/web_database.cc
+++ b/chrome/browser/webdata/web_database.cc
@@ -4,6 +4,7 @@
#include <algorithm>
#include <limits>
+#include <vector>
#include "chrome/browser/webdata/web_database.h"
@@ -405,7 +406,7 @@ bool WebDatabase::InitAutofillDatesTable() {
}
if (sqlite3_exec(db_,
"CREATE INDEX autofill_dates_pair_id ON "
- "autofill (pair_id)",
+ "autofill_dates (pair_id)",
NULL, NULL, NULL) != SQLITE_OK) {
NOTREACHED();
return false;
@@ -958,6 +959,27 @@ bool WebDatabase::GetIDAndCountOfFormElement(
return true;
}
+bool WebDatabase::GetCountOfFormElement(int64 pair_id, int* count) {
+ SQLStatement s;
+
+ if (s.prepare(db_, "SELECT count FROM autofill "
+ " WHERE pair_id = ?") != SQLITE_OK) {
+ NOTREACHED() << "Statement prepare failed";
+ return false;
+ }
+
+ s.bind_int64(0, pair_id);
+
+ int result;
+ if ((result = s.step()) == SQLITE_ROW) {
+ *count = s.column_int(0);
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
bool WebDatabase::InsertFormElement(const AutofillForm::Element& element,
int64* pair_id) {
SQLStatement s;
@@ -985,7 +1007,7 @@ bool WebDatabase::InsertFormElement(const AutofillForm::Element& element,
}
bool WebDatabase::InsertPairIDAndDate(int64 pair_id,
- const Time& date_created) {
+ const Time date_created) {
SQLStatement s;
if (s.prepare(db_,
@@ -1083,14 +1105,100 @@ bool WebDatabase::GetFormValuesForElementName(const std::wstring& name,
s.bind_int(3, limit);
}
- int result;
values->clear();
+ int result;
while ((result = s.step()) == SQLITE_ROW)
values->push_back(s.column_string16(0));
return result == SQLITE_DONE;
}
+bool WebDatabase::RemoveFormElementsAddedBetween(const Time delete_begin,
+ const Time delete_end) {
+ SQLStatement s;
+ if (s.prepare(db_,
+ "SELECT DISTINCT pair_id FROM autofill_dates WHERE "
+ "date_created >= ? AND date_created < ?") != SQLITE_OK) {
+ NOTREACHED() << "Statement 1 prepare failed";
+ return false;
+ }
+ s.bind_int64(0, delete_begin.ToTimeT());
+ s.bind_int64(1,
+ delete_end.is_null() ?
+ std::numeric_limits<int64>::max() :
+ delete_end.ToTimeT());
+
+ std::vector<int64> pair_ids;
+ int result;
+ while ((result = s.step()) == SQLITE_ROW)
+ pair_ids.push_back(s.column_int64(0));
+
+ if (result != SQLITE_DONE) {
+ NOTREACHED();
+ return false;
+ }
+
+ for (std::vector<int64>::iterator itr = pair_ids.begin();
+ itr != pair_ids.end();
+ itr++) {
+ int how_many=0;
+ if (!RemovePairIDAndDate(*itr, delete_begin, delete_end, &how_many))
+ return false;
+ if (!AddToCountOfFormElement(*itr, -how_many))
+ return false;
+ }
+
+ return true;
+}
+
+bool WebDatabase::RemovePairIDAndDate(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 "
+ "date_created >= ? AND date_created < ?") != SQLITE_OK) {
+ NOTREACHED() << "Statement 1 prepare failed";
+ 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());
+
+ bool result = (s.step() == SQLITE_DONE);
+ *how_many = sqlite3_changes(db_);
+
+ return result;
+}
+
+bool WebDatabase::AddToCountOfFormElement(int64 pair_id, int delta) {
+ int count=0;
+ if (count+delta == 0 &&
+ !RemoveFormElement(pair_id)) {
+ return false;
+ } else {
+ if (!GetCountOfFormElement(pair_id, &count))
+ return false;
+ if (!SetCountOfFormElement(pair_id, count + delta))
+ return false;
+ }
+ return true;
+}
+
+bool WebDatabase::RemoveFormElement(int64 pair_id) {
+ SQLStatement s;
+ if (s.prepare(db_,
+ "DELETE FROM autofill WHERE pair_id = ?") != SQLITE_OK) {
+ NOTREACHED() << "Statement 1 prepare failed";
+ return false;
+ }
+ s.bind_int64(0, pair_id);
+
+ return (s.step() == SQLITE_DONE);
+}
+
void WebDatabase::MigrateOldVersionsAsNeeded() {
// Migrate if necessary.
int current_version = meta_table_.GetVersionNumber();
diff --git a/chrome/browser/webdata/web_database.h b/chrome/browser/webdata/web_database.h
index 3b5c660..4e47168 100644
--- a/chrome/browser/webdata/web_database.h
+++ b/chrome/browser/webdata/web_database.h
@@ -118,8 +118,6 @@ class WebDatabase {
//
//////////////////////////////////////////////////////////////////////////////
-
-
// Records the form elements in |elements| in the database in the autofill
// table.
bool AddAutofillFormElements(
@@ -136,12 +134,34 @@ class WebDatabase {
std::vector<std::wstring>* values,
int limit);
+ // Removes rows from autofill_dates if they were created on or after
+ // |delete_begin| and strictly before |delete_end|. Decrements the count of
+ // the corresponding rows in the autofill table, and removes those rows if the
+ // count goes to 0.
+ bool RemoveFormElementsAddedBetween(const base::Time delete_begin,
+ const base::Time delete_end);
+
+ // Removes from autofill_dates rows with given pair_id where date_created lies
+ // between delte_begin and delte_end.
+ bool RemovePairIDAndDate(int64 pair_id,
+ const base::Time delete_begin,
+ const base::Time delete_end,
+ int* how_many);
+
+ // Increments the count in the row corresponding to |pair_id| by |delta|.
+ // Removes the row from the table if the count becomes 0.
+ bool AddToCountOfFormElement(int64 pair_id, int delta);
+
// Gets the pair_id and count entries from name and value specified in
// |element|. Sets *count to 0 if there is no such row in the table.
bool GetIDAndCountOfFormElement(const AutofillForm::Element& element,
int64* pair_id,
int* count);
+ // Gets the count only given the pair_id.
+ bool GetCountOfFormElement(int64 pair_id,
+ int* count);
+
// Updates the count entry in the row corresponding to |pair_id| to |count|.
bool SetCountOfFormElement(int64 pair_id, int count);
@@ -150,7 +170,10 @@ class WebDatabase {
bool InsertFormElement(const AutofillForm::Element& element, int64* pair_id);
// Adds a new row to the autofill_dates table.
- bool InsertPairIDAndDate(int64 pair_id, const base::Time& date_created);
+ bool InsertPairIDAndDate(int64 pair_id, const base::Time date_created);
+
+ // Removes row from the autofill table given |pair_id|.
+ bool RemoveFormElement(int64 pair_id);
//////////////////////////////////////////////////////////////////////////////
//