diff options
author | caitkp@chromium.org <caitkp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-14 04:58:44 +0000 |
---|---|---|
committer | caitkp@chromium.org <caitkp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-14 04:58:44 +0000 |
commit | 301528546d702e1d3adf2cf3ba178b556d0bb9a2 (patch) | |
tree | 42585cb0faebcd47c525d80a9318947ac6d3bd75 /components/webdata/common | |
parent | eabd1732d9b306cfe229bdbde08907c0a70c25a1 (diff) | |
download | chromium_src-301528546d702e1d3adf2cf3ba178b556d0bb9a2.zip chromium_src-301528546d702e1d3adf2cf3ba178b556d0bb9a2.tar.gz chromium_src-301528546d702e1d3adf2cf3ba178b556d0bb9a2.tar.bz2 |
Create an interface which SyncableServices can use for making changes directly on the Autofill DB.
TBR=akalin@chromium.org (c/b/sync/)
BUG=230920
Review URL: https://chromiumcodereview.appspot.com/14679005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199904 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/webdata/common')
4 files changed, 50 insertions, 10 deletions
diff --git a/components/webdata/common/web_data_service_backend.cc b/components/webdata/common/web_data_service_backend.cc index 3b945b0b..300b182 100644 --- a/components/webdata/common/web_data_service_backend.cc +++ b/components/webdata/common/web_data_service_backend.cc @@ -73,23 +73,40 @@ void WebDataServiceBackend::ShutdownDatabase(bool should_reinit) { void WebDataServiceBackend::DBWriteTaskWrapper( const WebDatabaseService::WriteTask& task, scoped_ptr<WebDataRequest> request) { + if (request->IsCancelled()) + return; + + ExecuteWriteTask(task); + request_manager_->RequestCompleted(request.Pass()); +} + +void WebDataServiceBackend::ExecuteWriteTask( + const WebDatabaseService::WriteTask& task) { LoadDatabaseIfNecessary(); - if (db_ && init_status_ == sql::INIT_OK && !request->IsCancelled()) { + if (db_ && init_status_ == sql::INIT_OK) { WebDatabase::State state = task.Run(db_.get()); if (state == WebDatabase::COMMIT_NEEDED) Commit(); } - request_manager_->RequestCompleted(request.Pass()); } void WebDataServiceBackend::DBReadTaskWrapper( const WebDatabaseService::ReadTask& task, scoped_ptr<WebDataRequest> request) { + if (request->IsCancelled()) + return; + + request->SetResult(ExecuteReadTask(task).Pass()); + request_manager_->RequestCompleted(request.Pass()); +} + +scoped_ptr<WDTypedResult> WebDataServiceBackend::ExecuteReadTask( + const WebDatabaseService::ReadTask& task) { LoadDatabaseIfNecessary(); - if (db_ && init_status_ == sql::INIT_OK && !request->IsCancelled()) { - request->SetResult(task.Run(db_.get()).Pass()); + if (db_ && init_status_ == sql::INIT_OK) { + return task.Run(db_.get()); } - request_manager_->RequestCompleted(request.Pass()); + return scoped_ptr<WDTypedResult>(NULL); } WebDataServiceBackend::~WebDataServiceBackend() { diff --git a/components/webdata/common/web_data_service_backend.h b/components/webdata/common/web_data_service_backend.h index 0e1d8f2..c12ade6 100644 --- a/components/webdata/common/web_data_service_backend.h +++ b/components/webdata/common/web_data_service_backend.h @@ -13,6 +13,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" #include "components/webdata/common/web_database_service.h" +#include "components/webdata/common/webdata_export.h" #include "content/public/browser/browser_thread.h" @@ -29,7 +30,9 @@ class Location; // WebDatabaseService. It is refcounted to allow asynchronous destruction on the // DB thread. -class WebDataServiceBackend +// TODO(caitkp): Rename this class to WebDatabaseBackend. + +class WEBDATA_EXPORT WebDataServiceBackend : public base::RefCountedThreadSafe< WebDataServiceBackend, content::BrowserThread::DeleteOnDBThread> { @@ -62,7 +65,10 @@ class WebDataServiceBackend // possible to re-initialize the DB after the shutdown. void ShutdownDatabase(bool should_reinit); - // Task wrappers to run database tasks. + // Task wrappers to update requests and and notify |request_manager_|. These + // are used in cases where the request is being made from the UI thread and an + // asyncronous callback is required to notify the client of |request|'s + // completion. void DBWriteTaskWrapper( const WebDatabaseService::WriteTask& task, scoped_ptr<WebDataRequest> request); @@ -70,18 +76,28 @@ class WebDataServiceBackend const WebDatabaseService::ReadTask& task, scoped_ptr<WebDataRequest> request); + // Task runners to run database tasks. + void ExecuteWriteTask(const WebDatabaseService::WriteTask& task); + scoped_ptr<WDTypedResult> ExecuteReadTask( + const WebDatabaseService::ReadTask& task); + const scoped_refptr<WebDataRequestManager>& request_manager() { return request_manager_; } WebDatabase* database() { return db_.get(); } + protected: + virtual ~WebDataServiceBackend(); + private: friend struct content::BrowserThread::DeleteOnThread< content::BrowserThread::DB>; friend class base::DeleteHelper<WebDataServiceBackend>; - - virtual ~WebDataServiceBackend(); + // We have to friend RCTS<> so WIN shared-lib build is happy + // (http://crbug/112250). + friend class base::RefCountedThreadSafe<WebDataServiceBackend, + content::BrowserThread::DeleteOnDBThread>; // Commit the current transaction. void Commit(); diff --git a/components/webdata/common/web_database_service.cc b/components/webdata/common/web_database_service.cc index baef346..ddbf733 100644 --- a/components/webdata/common/web_database_service.cc +++ b/components/webdata/common/web_database_service.cc @@ -91,6 +91,10 @@ WebDatabase* WebDatabaseService::GetDatabaseOnDB() const { return wds_backend_->database(); } +scoped_refptr<WebDataServiceBackend> WebDatabaseService::GetBackend() const { + return wds_backend_; +} + void WebDatabaseService::ScheduleDBTask( const tracked_objects::Location& from_here, const WriteTask& task) { diff --git a/components/webdata/common/web_database_service.h b/components/webdata/common/web_database_service.h index 1bdfca8..c8b1bfa 100644 --- a/components/webdata/common/web_database_service.h +++ b/components/webdata/common/web_database_service.h @@ -71,10 +71,13 @@ class WEBDATA_EXPORT WebDatabaseService // Unloads database and will not reload. virtual void ShutdownDatabase(); - // Gets a ptr to the WebDatabase (owned by WebDatabaseService). + // Gets a pointer to the WebDatabase (owned by WebDatabaseService). // TODO(caitkp): remove this method once SyncServices no longer depend on it. virtual WebDatabase* GetDatabaseOnDB() const; + // Returns a pointer to the WebDataServiceBackend. + scoped_refptr<WebDataServiceBackend> GetBackend() const; + // Schedule an update/write task on the DB thread. virtual void ScheduleDBTask( const tracked_objects::Location& from_here, |