| 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 2980728bb3c9cf4a44a27bf1a42793178be9a976..2625a5f1ffc12c7cf2f36a7bbfe4be30275cbe61 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:
|
| + ~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::WorkerObserver* observer)
|
| + : syncer::ModelSafeWorker(observer),
|
| + history_service_(history_service) {
|
| CHECK(history_service.get());
|
| }
|
|
|
| +void HistoryModelWorker::RegisterForLoopDestruction() {
|
| + CHECK(history_service_.get());
|
| + history_service_->ScheduleDBTask(new AddDBThreadObserverTask(this),
|
| + &cancelable_consumer_);
|
| +}
|
| +
|
| syncer::SyncerError HistoryModelWorker::DoWorkAndWaitUntilDone(
|
| - const syncer::WorkCallback& work) {
|
| + const syncer::WorkCallback& work,
|
| + base::WaitableEvent* done) {
|
| 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_, done,
|
| + &error))) {
|
| + done->Wait();
|
| } else {
|
| error = syncer::CANNOT_DO_WORK;
|
| }
|
|
|