| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "chrome/browser/history/history.h" | 10 #include "chrome/browser/history/history.h" |
| 11 | 11 |
| 12 using base::WaitableEvent; | 12 using base::WaitableEvent; |
| 13 | 13 |
| 14 namespace browser_sync { | 14 namespace browser_sync { |
| 15 | 15 |
| 16 class WorkerTask : public HistoryDBTask { | 16 class WorkerTask : public HistoryDBTask { |
| 17 public: | 17 public: |
| 18 WorkerTask( | 18 WorkerTask( |
| 19 const csync::WorkCallback& work, | 19 const syncer::WorkCallback& work, |
| 20 WaitableEvent* done, | 20 WaitableEvent* done, |
| 21 csync::SyncerError* error) | 21 syncer::SyncerError* error) |
| 22 : work_(work), done_(done), error_(error) {} | 22 : work_(work), done_(done), error_(error) {} |
| 23 | 23 |
| 24 virtual bool RunOnDBThread(history::HistoryBackend* backend, | 24 virtual bool RunOnDBThread(history::HistoryBackend* backend, |
| 25 history::HistoryDatabase* db) { | 25 history::HistoryDatabase* db) { |
| 26 *error_ = work_.Run(); | 26 *error_ = work_.Run(); |
| 27 done_->Signal(); | 27 done_->Signal(); |
| 28 return true; | 28 return true; |
| 29 } | 29 } |
| 30 | 30 |
| 31 // Since the DoWorkAndWaitUntilDone() is syncronous, we don't need to run any | 31 // Since the DoWorkAndWaitUntilDone() is syncronous, we don't need to run any |
| 32 // code asynchronously on the main thread after completion. | 32 // code asynchronously on the main thread after completion. |
| 33 virtual void DoneRunOnMainThread() {} | 33 virtual void DoneRunOnMainThread() {} |
| 34 | 34 |
| 35 protected: | 35 protected: |
| 36 virtual ~WorkerTask() {} | 36 virtual ~WorkerTask() {} |
| 37 | 37 |
| 38 csync::WorkCallback work_; | 38 syncer::WorkCallback work_; |
| 39 WaitableEvent* done_; | 39 WaitableEvent* done_; |
| 40 csync::SyncerError* error_; | 40 syncer::SyncerError* error_; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 | 43 |
| 44 HistoryModelWorker::HistoryModelWorker(HistoryService* history_service) | 44 HistoryModelWorker::HistoryModelWorker(HistoryService* history_service) |
| 45 : history_service_(history_service) { | 45 : history_service_(history_service) { |
| 46 CHECK(history_service); | 46 CHECK(history_service); |
| 47 } | 47 } |
| 48 | 48 |
| 49 csync::SyncerError HistoryModelWorker::DoWorkAndWaitUntilDone( | 49 syncer::SyncerError HistoryModelWorker::DoWorkAndWaitUntilDone( |
| 50 const csync::WorkCallback& work) { | 50 const syncer::WorkCallback& work) { |
| 51 WaitableEvent done(false, false); | 51 WaitableEvent done(false, false); |
| 52 csync::SyncerError error = csync::UNSET; | 52 syncer::SyncerError error = syncer::UNSET; |
| 53 scoped_refptr<WorkerTask> task(new WorkerTask(work, &done, &error)); | 53 scoped_refptr<WorkerTask> task(new WorkerTask(work, &done, &error)); |
| 54 history_service_->ScheduleDBTask(task.get(), &cancelable_consumer_); | 54 history_service_->ScheduleDBTask(task.get(), &cancelable_consumer_); |
| 55 done.Wait(); | 55 done.Wait(); |
| 56 return error; | 56 return error; |
| 57 } | 57 } |
| 58 | 58 |
| 59 csync::ModelSafeGroup HistoryModelWorker::GetModelSafeGroup() { | 59 syncer::ModelSafeGroup HistoryModelWorker::GetModelSafeGroup() { |
| 60 return csync::GROUP_HISTORY; | 60 return syncer::GROUP_HISTORY; |
| 61 } | 61 } |
| 62 | 62 |
| 63 HistoryModelWorker::~HistoryModelWorker() {} | 63 HistoryModelWorker::~HistoryModelWorker() {} |
| 64 | 64 |
| 65 } // namespace browser_sync | 65 } // namespace browser_sync |
| OLD | NEW |