| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/sync/glue/history_model_worker.h" | 5 #include "chrome/browser/sync/glue/history_model_worker.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "chrome/browser/history/history.h" | 11 #include "chrome/browser/history/history.h" |
| 12 | 12 |
| 13 using base::WaitableEvent; | 13 using base::WaitableEvent; |
| 14 | 14 |
| 15 namespace browser_sync { | 15 namespace browser_sync { |
| 16 | 16 |
| 17 class WorkerTask : public HistoryDBTask { | 17 class WorkerTask : public HistoryDBTask { |
| 18 public: | 18 public: |
| 19 WorkerTask(Callback0::Type* work, WaitableEvent* done) | 19 WorkerTask( |
| 20 : work_(work), done_(done) {} | 20 const WorkCallback& work, |
| 21 WaitableEvent* done, |
| 22 UnrecoverableErrorInfo* error_info) |
| 23 : work_(work), done_(done), error_info_(error_info) {} |
| 21 | 24 |
| 22 virtual bool RunOnDBThread(history::HistoryBackend* backend, | 25 virtual bool RunOnDBThread(history::HistoryBackend* backend, |
| 23 history::HistoryDatabase* db) { | 26 history::HistoryDatabase* db) { |
| 24 work_->Run(); | 27 *error_info_ = work_.Run(); |
| 25 done_->Signal(); | 28 done_->Signal(); |
| 26 return true; | 29 return true; |
| 27 } | 30 } |
| 28 | 31 |
| 29 // Since the DoWorkAndWaitUntilDone() is syncronous, we don't need to run any | 32 // Since the DoWorkAndWaitUntilDone() is syncronous, we don't need to run any |
| 30 // code asynchronously on the main thread after completion. | 33 // code asynchronously on the main thread after completion. |
| 31 virtual void DoneRunOnMainThread() {} | 34 virtual void DoneRunOnMainThread() {} |
| 32 | 35 |
| 33 protected: | 36 protected: |
| 34 Callback0::Type* work_; | 37 WorkCallback work_; |
| 35 WaitableEvent* done_; | 38 WaitableEvent* done_; |
| 39 UnrecoverableErrorInfo* error_info_; |
| 36 }; | 40 }; |
| 37 | 41 |
| 38 | 42 |
| 39 HistoryModelWorker::HistoryModelWorker(HistoryService* history_service) | 43 HistoryModelWorker::HistoryModelWorker(HistoryService* history_service) |
| 40 : history_service_(history_service) { | 44 : history_service_(history_service) { |
| 41 CHECK(history_service); | 45 CHECK(history_service); |
| 42 } | 46 } |
| 43 | 47 |
| 44 HistoryModelWorker::~HistoryModelWorker() { | 48 HistoryModelWorker::~HistoryModelWorker() { |
| 45 } | 49 } |
| 46 | 50 |
| 47 void HistoryModelWorker::DoWorkAndWaitUntilDone(Callback0::Type* work) { | 51 UnrecoverableErrorInfo HistoryModelWorker::DoWorkAndWaitUntilDone( |
| 52 const WorkCallback& work) { |
| 48 WaitableEvent done(false, false); | 53 WaitableEvent done(false, false); |
| 49 scoped_refptr<WorkerTask> task(new WorkerTask(work, &done)); | 54 UnrecoverableErrorInfo error_info; |
| 55 scoped_refptr<WorkerTask> task(new WorkerTask(work, &done, &error_info)); |
| 50 history_service_->ScheduleDBTask(task.get(), &cancelable_consumer_); | 56 history_service_->ScheduleDBTask(task.get(), &cancelable_consumer_); |
| 51 done.Wait(); | 57 done.Wait(); |
| 58 return error_info; |
| 52 } | 59 } |
| 53 | 60 |
| 54 ModelSafeGroup HistoryModelWorker::GetModelSafeGroup() { | 61 ModelSafeGroup HistoryModelWorker::GetModelSafeGroup() { |
| 55 return GROUP_HISTORY; | 62 return GROUP_HISTORY; |
| 56 } | 63 } |
| 57 | 64 |
| 58 } // namespace browser_sync | 65 } // namespace browser_sync |
| OLD | NEW |