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

Unified Diff: chrome/browser/sync/glue/history_model_worker.cc

Issue 14046031: Worker changes to prepare for lock-free shutdown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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/sync/glue/history_model_worker.h ('k') | chrome/browser/sync/glue/password_model_worker.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/glue/history_model_worker.cc
diff --git a/chrome/browser/sync/glue/history_model_worker.cc b/chrome/browser/sync/glue/history_model_worker.cc
index 5e6aa8017febb77917d0a8814da54fe0487a2e92..205bb6cfa1950e37f50eec9fcb27b743e65c8058 100644
--- a/chrome/browser/sync/glue/history_model_worker.cc
+++ b/chrome/browser/sync/glue/history_model_worker.cc
@@ -7,7 +7,6 @@
#include "base/memory/ref_counted.h"
#include "base/message_loop.h"
#include "base/synchronization/waitable_event.h"
-#include "chrome/browser/history/history_db_task.h"
#include "content/public/browser/browser_thread.h"
using base::WaitableEvent;
@@ -30,8 +29,8 @@ class WorkerTask : public history::HistoryDBTask {
return true;
}
- // Since the DoWorkAndWaitUntilDone() is syncronous, we don't need to run any
- // code asynchronously on the main thread after completion.
+ // Since the DoWorkAndWaitUntilDone() is synchronous, we don't need to run
+ // any code asynchronously on the main thread after completion.
virtual void DoneRunOnMainThread() OVERRIDE {}
protected:
@@ -42,6 +41,25 @@ class WorkerTask : public history::HistoryDBTask {
syncer::SyncerError* error_;
};
+class AddDBThreadObserverTask : public history::HistoryDBTask {
+ public:
+ AddDBThreadObserverTask(HistoryModelWorker* history_worker)
+ : history_worker_(history_worker) {}
+
+ virtual bool RunOnDBThread(history::HistoryBackend* backend,
+ history::HistoryDatabase* db) OVERRIDE {
+ MessageLoop::current()->AddDestructionObserver(history_worker_.get());
+ return true;
+ }
+
+ virtual void DoneRunOnMainThread() OVERRIDE {}
+
+ private:
+ virtual ~AddDBThreadObserverTask() {}
+
+ scoped_refptr<HistoryModelWorker> history_worker_;
+};
+
namespace {
// Post the work task on |history_service|'s DB thread from the UI
@@ -64,21 +82,28 @@ void PostWorkerTask(const base::WeakPtr<HistoryService>& history_service,
} // namespace
HistoryModelWorker::HistoryModelWorker(
- const base::WeakPtr<HistoryService>& history_service)
- : history_service_(history_service) {
+ const base::WeakPtr<HistoryService>& history_service,
+ syncer::WorkerLoopDestructionObserver* observer)
+ : syncer::ModelSafeWorker(observer),
+ history_service_(history_service) {
CHECK(history_service.get());
}
-syncer::SyncerError HistoryModelWorker::DoWorkAndWaitUntilDone(
+void HistoryModelWorker::RegisterForLoopDestruction() {
+ CHECK(history_service_.get());
+ history_service_->ScheduleDBTask(new AddDBThreadObserverTask(this),
+ &cancelable_consumer_);
+}
+
+syncer::SyncerError HistoryModelWorker::DoWorkAndWaitUntilDoneImpl(
const syncer::WorkCallback& work) {
syncer::SyncerError error = syncer::UNSET;
- WaitableEvent done(false, false);
if (BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&PostWorkerTask,
- history_service_, work,
- &cancelable_consumer_,
- &done, &error))) {
- done.Wait();
+ base::Bind(&PostWorkerTask, history_service_,
+ work, &cancelable_consumer_,
+ work_done_or_stopped(),
+ &error))) {
+ work_done_or_stopped()->Wait();
} else {
error = syncer::CANNOT_DO_WORK;
}
« no previous file with comments | « chrome/browser/sync/glue/history_model_worker.h ('k') | chrome/browser/sync/glue/password_model_worker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698