| 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" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 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() {} |
| 37 |
| 36 WorkCallback work_; | 38 WorkCallback work_; |
| 37 WaitableEvent* done_; | 39 WaitableEvent* done_; |
| 38 SyncerError* error_; | 40 SyncerError* error_; |
| 39 }; | 41 }; |
| 40 | 42 |
| 41 | 43 |
| 42 HistoryModelWorker::HistoryModelWorker(HistoryService* history_service) | 44 HistoryModelWorker::HistoryModelWorker(HistoryService* history_service) |
| 43 : history_service_(history_service) { | 45 : history_service_(history_service) { |
| 44 CHECK(history_service); | 46 CHECK(history_service); |
| 45 } | 47 } |
| 46 | 48 |
| 47 HistoryModelWorker::~HistoryModelWorker() { | |
| 48 } | |
| 49 | |
| 50 SyncerError HistoryModelWorker::DoWorkAndWaitUntilDone( | 49 SyncerError HistoryModelWorker::DoWorkAndWaitUntilDone( |
| 51 const WorkCallback& work) { | 50 const WorkCallback& work) { |
| 52 WaitableEvent done(false, false); | 51 WaitableEvent done(false, false); |
| 53 SyncerError error = UNSET; | 52 SyncerError error = UNSET; |
| 54 scoped_refptr<WorkerTask> task(new WorkerTask(work, &done, &error)); | 53 scoped_refptr<WorkerTask> task(new WorkerTask(work, &done, &error)); |
| 55 history_service_->ScheduleDBTask(task.get(), &cancelable_consumer_); | 54 history_service_->ScheduleDBTask(task.get(), &cancelable_consumer_); |
| 56 done.Wait(); | 55 done.Wait(); |
| 57 return error; | 56 return error; |
| 58 } | 57 } |
| 59 | 58 |
| 60 ModelSafeGroup HistoryModelWorker::GetModelSafeGroup() { | 59 ModelSafeGroup HistoryModelWorker::GetModelSafeGroup() { |
| 61 return GROUP_HISTORY; | 60 return GROUP_HISTORY; |
| 62 } | 61 } |
| 63 | 62 |
| 63 HistoryModelWorker::~HistoryModelWorker() {} |
| 64 |
| 64 } // namespace browser_sync | 65 } // namespace browser_sync |
| OLD | NEW |