summaryrefslogtreecommitdiffstats
path: root/chrome/browser/webdata/web_data_service.cc
diff options
context:
space:
mode:
authormichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-29 23:40:52 +0000
committermichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-29 23:40:52 +0000
commitf12f7b760a595f1cfa2bbac81078b48ce613901d (patch)
tree01e1a45a277e64bde59557ca6e50fa87145197ec /chrome/browser/webdata/web_data_service.cc
parent81545760b52a29fbcc7a594b5b81fd1d7cdcf8ec (diff)
downloadchromium_src-f12f7b760a595f1cfa2bbac81078b48ce613901d.zip
chromium_src-f12f7b760a595f1cfa2bbac81078b48ce613901d.tar.gz
chromium_src-f12f7b760a595f1cfa2bbac81078b48ce613901d.tar.bz2
Revert 35339 - Change WDS to use the DB thread rather than its own thread.
This cleanup was requested by brettw and was started to make it easier for the sync service to post tasks to the WDS thread (now the DB thread). This simplifies the WDS a bit since it no longer has to manage its own thread, and can assume that the DB thread is running throughout its lifetime. One change in behavior that is significant is that previous to this change, the WDS worker thread would always be joined when Shutdown() was called from Profile::~Profile(). Now the Shutdown() method schedules a task that can extend the lifetime of the WDS past the lifetime of the Profile instance. Review URL: http://codereview.chromium.org/524003 TBR=skrul@chromium.org Review URL: http://codereview.chromium.org/521013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35356 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/webdata/web_data_service.cc')
-rw-r--r--chrome/browser/webdata/web_data_service.cc45
1 files changed, 37 insertions, 8 deletions
diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc
index d25492b..4407cdd 100644
--- a/chrome/browser/webdata/web_data_service.cc
+++ b/chrome/browser/webdata/web_data_service.cc
@@ -29,7 +29,7 @@ using webkit_glue::FormField;
using webkit_glue::PasswordForm;
WebDataService::WebDataService()
- : is_running_(false),
+ : thread_(NULL),
db_(NULL),
failed_init_(false),
should_commit_(false),
@@ -38,8 +38,8 @@ WebDataService::WebDataService()
}
WebDataService::~WebDataService() {
- if (is_running_ && db_) {
- DLOG_ASSERT("WebDataService dtor called without Shutdown");
+ if (thread_) {
+ Shutdown();
}
}
@@ -51,18 +51,47 @@ bool WebDataService::Init(const FilePath& profile_path) {
bool WebDataService::InitWithPath(const FilePath& path) {
path_ = path;
- is_running_ = true;
+
+ thread_ = new base::Thread("Chrome_WebDataThread");
+ if (!thread_->Start()) {
+ delete thread_;
+ thread_ = NULL;
+ return false;
+ }
+
ScheduleTask(NewRunnableMethod(this,
&WebDataService::InitializeDatabaseIfNecessary));
return true;
}
+class ShutdownTask : public Task {
+ public:
+ explicit ShutdownTask(WebDataService* wds) : service_(wds) {
+ }
+ virtual void Run() {
+ service_->ShutdownDatabase();
+ }
+
+ private:
+
+ WebDataService* service_;
+};
+
void WebDataService::Shutdown() {
- UnloadDatabase();
+ if (thread_) {
+ // We cannot use NewRunnableMethod() because this can be called from our
+ // destructor. NewRunnableMethod() would AddRef() this instance.
+ ScheduleTask(new ShutdownTask(this));
+
+ // The thread destructor sends a message to terminate the thread and waits
+ // until the thread has exited.
+ delete thread_;
+ thread_ = NULL;
+ }
}
bool WebDataService::IsRunning() const {
- return is_running_;
+ return thread_ != NULL;
}
void WebDataService::UnloadDatabase() {
@@ -77,8 +106,8 @@ void WebDataService::ScheduleCommit() {
}
void WebDataService::ScheduleTask(Task* t) {
- if (is_running_)
- ChromeThread::PostTask(ChromeThread::DB, FROM_HERE, t);
+ if (thread_)
+ thread_->message_loop()->PostTask(FROM_HERE, t);
else
NOTREACHED() << "Task scheduled after Shutdown()";
}