diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-20 22:28:17 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-20 22:28:17 +0000 |
commit | 4d2b6fb574d019dab4080b3713d3d5e5aa0a91bd (patch) | |
tree | e384f04d2a7bc8403cf19929d84447782d6c7871 /chrome/browser/webdata | |
parent | e08a579d8d6701fa48eac6945248855bbb5a70a6 (diff) | |
download | chromium_src-4d2b6fb574d019dab4080b3713d3d5e5aa0a91bd.zip chromium_src-4d2b6fb574d019dab4080b3713d3d5e5aa0a91bd.tar.gz chromium_src-4d2b6fb574d019dab4080b3713d3d5e5aa0a91bd.tar.bz2 |
Pressing the Del key while a item is selected in the autocomplete popup deletes that suggestion from the DB.
BUG=6176
TEST=Bring up the autofill popup in a form. Select an item and press the Del key. The item should be removed from the popup and should not show on subsequent autofill popups.
Review URL: http://codereview.chromium.org/42258
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12221 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/webdata')
-rw-r--r-- | chrome/browser/webdata/web_data_service.cc | 24 | ||||
-rw-r--r-- | chrome/browser/webdata/web_data_service.h | 4 | ||||
-rw-r--r-- | chrome/browser/webdata/web_database.cc | 26 | ||||
-rw-r--r-- | chrome/browser/webdata/web_database.h | 5 |
4 files changed, 55 insertions, 4 deletions
diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc index 1687159..4f0dece 100644 --- a/chrome/browser/webdata/web_data_service.cc +++ b/chrome/browser/webdata/web_data_service.cc @@ -139,6 +139,20 @@ WebDataService::Handle WebDataService::GetFormValuesForElementName( return request->GetHandle(); } +void WebDataService::RemoveFormValueForElementName( + const std::wstring& name, const std::wstring& value) { + GenericRequest2<std::wstring, std::wstring>* request = + new GenericRequest2<std::wstring, std::wstring>(this, + GetNextRequestHandle(), + NULL, + name, value); + RegisterRequest(request); + ScheduleTask( + NewRunnableMethod(this, + &WebDataService::RemoveFormValueForElementNameImpl, + request)); +} + void WebDataService::RequestCompleted(Handle h) { pending_lock_.Acquire(); RequestMap::iterator i = pending_requests_.find(h); @@ -577,6 +591,16 @@ void WebDataService::RemoveFormElementsAddedBetweenImpl( request->RequestComplete(); } +void WebDataService::RemoveFormValueForElementNameImpl( + GenericRequest2<std::wstring, std::wstring>* request) { + if (db_ && !request->IsCancelled()) { + if (db_->RemoveFormElement(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 e6fc18d..efeaf05 100644 --- a/chrome/browser/webdata/web_data_service.h +++ b/chrome/browser/webdata/web_data_service.h @@ -382,6 +382,8 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> { // Removes form elements recorded for autofill from the database. void RemoveFormElementsAddedBetween(const base::Time& delete_begin, const base::Time& delete_end); + void RemoveFormValueForElementName(const std::wstring& name, + const std::wstring& value); protected: friend class TemplateURLModelTest; @@ -460,6 +462,8 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> { const std::wstring& name, const std::wstring& prefix, int limit); void RemoveFormElementsAddedBetweenImpl( GenericRequest2<base::Time, base::Time>* request); + void RemoveFormValueForElementNameImpl( + GenericRequest2<std::wstring, std::wstring>* request); ////////////////////////////////////////////////////////////////////////////// // diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc index f98c4013..b9b64f3 100644 --- a/chrome/browser/webdata/web_database.cc +++ b/chrome/browser/webdata/web_database.cc @@ -868,7 +868,7 @@ bool WebDatabase::ClearAutofillEmptyValueElements() { bool success = true; for (std::set<int64>::const_iterator iter = ids.begin(); iter != ids.end(); ++iter) { - if (!RemoveFormElement(*iter)) + if (!RemoveFormElementForID(*iter)) success = false; } @@ -1117,6 +1117,26 @@ bool WebDatabase::RemoveFormElementForTimeRange(int64 pair_id, return result; } +bool WebDatabase::RemoveFormElement(const std::wstring& name, + const std::wstring& value) { + // Find the id for that pair. + SQLStatement s; + if (s.prepare(db_, + "SELECT pair_id FROM autofill WHERE name = ? AND value= ?") != + SQLITE_OK) { + NOTREACHED() << "Statement 1 prepare failed"; + return false; + } + s.bind_wstring(0, name); + s.bind_wstring(1, value); + + int result = s.step(); + if (result != SQLITE_ROW) + return false; + + return RemoveFormElementForID(s.column_int64(0)); +} + bool WebDatabase::AddToCountOfFormElement(int64 pair_id, int delta) { int count = 0; @@ -1124,7 +1144,7 @@ bool WebDatabase::AddToCountOfFormElement(int64 pair_id, int delta) { return false; if (count + delta == 0) { - if (!RemoveFormElement(pair_id)) + if (!RemoveFormElementForID(pair_id)) return false; } else { if (!SetCountOfFormElement(pair_id, count + delta)) @@ -1133,7 +1153,7 @@ bool WebDatabase::AddToCountOfFormElement(int64 pair_id, int delta) { return true; } -bool WebDatabase::RemoveFormElement(int64 pair_id) { +bool WebDatabase::RemoveFormElementForID(int64 pair_id) { SQLStatement s; if (s.prepare(db_, "DELETE FROM autofill WHERE pair_id = ?") != SQLITE_OK) { diff --git a/chrome/browser/webdata/web_database.h b/chrome/browser/webdata/web_database.h index 95d4906..3584701 100644 --- a/chrome/browser/webdata/web_database.h +++ b/chrome/browser/webdata/web_database.h @@ -178,7 +178,10 @@ class WebDatabase { bool InsertPairIDAndDate(int64 pair_id, const base::Time date_created); // Removes row from the autofill tables given |pair_id|. - bool RemoveFormElement(int64 pair_id); + bool RemoveFormElementForID(int64 pair_id); + + // Removes row from the autofill tables for the given |name| |value| pair. + bool RemoveFormElement(const std::wstring& name, const std::wstring& value); ////////////////////////////////////////////////////////////////////////////// // |