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

Unified Diff: chrome/browser/sync/glue/ui_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/ui_model_worker.h ('k') | chrome/browser/sync/glue/ui_model_worker_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/glue/ui_model_worker.cc
diff --git a/chrome/browser/sync/glue/ui_model_worker.cc b/chrome/browser/sync/glue/ui_model_worker.cc
index c0336ba2ed8994b746bd6dfa766b010d1f10d2b9..c9de1e85648cd961cad3d2e8d794b10889ce4110 100644
--- a/chrome/browser/sync/glue/ui_model_worker.cc
+++ b/chrome/browser/sync/glue/ui_model_worker.cc
@@ -45,8 +45,9 @@ void CallDoWorkAndSignalCallback(const syncer::WorkCallback& work,
} // namespace
-UIModelWorker::UIModelWorker()
- : state_(WORKING),
+UIModelWorker::UIModelWorker(syncer::WorkerLoopDestructionObserver* observer)
+ : syncer::ModelSafeWorker(observer),
+ state_(WORKING),
syncapi_has_shutdown_(false),
syncapi_event_(&lock_) {
}
@@ -76,7 +77,12 @@ void UIModelWorker::Stop() {
state_ = STOPPED;
}
-syncer::SyncerError UIModelWorker::DoWorkAndWaitUntilDone(
+void UIModelWorker::RegisterForLoopDestruction() {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ MessageLoop::current()->AddDestructionObserver(this);
+}
+
+syncer::SyncerError UIModelWorker::DoWorkAndWaitUntilDoneImpl(
const syncer::WorkCallback& work) {
// In most cases, this method is called in WORKING state. It is possible this
// gets called when we are in the RUNNING_MANUAL_SHUTDOWN_PUMP state, because
@@ -92,15 +98,14 @@ syncer::SyncerError UIModelWorker::DoWorkAndWaitUntilDone(
return work.Run();
}
- // Create an unsignaled event to wait on.
- base::WaitableEvent work_done(false, false);
{
// We lock only to avoid PostTask'ing a NULL pending_work_ (because it
// could get Run() in Stop() and call OnTaskCompleted before we post).
// The task is owned by the message loop as per usual.
base::AutoLock lock(lock_);
DCHECK(pending_work_.is_null());
- pending_work_ = base::Bind(&CallDoWorkAndSignalCallback, work, &work_done,
+ pending_work_ = base::Bind(&CallDoWorkAndSignalCallback, work,
+ work_done_or_stopped(),
base::Unretained(this), &error_info);
if (!BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, pending_work_)) {
DLOG(WARNING) << "Could not post work to UI loop.";
@@ -111,7 +116,7 @@ syncer::SyncerError UIModelWorker::DoWorkAndWaitUntilDone(
}
}
syncapi_event_.Signal(); // Notify that the syncapi produced work for us.
- work_done.Wait();
+ work_done_or_stopped()->Wait();
return error_info;
}
« no previous file with comments | « chrome/browser/sync/glue/ui_model_worker.h ('k') | chrome/browser/sync/glue/ui_model_worker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698