| 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 "components/sync/driver/glue/ui_model_worker.h" | 5 #include "components/sync/driver/glue/ui_model_worker.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/message_loop/message_loop.h" | 11 #include "base/callback.h" |
| 10 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | |
| 12 #include "base/threading/thread_restrictions.h" | |
| 13 #include "components/sync/base/scoped_event_signal.h" | 13 #include "components/sync/base/scoped_event_signal.h" |
| 14 | 14 |
| 15 namespace syncer { | 15 namespace syncer { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 void CallDoWorkAndSignalEvent(const WorkCallback& work, | 19 void CallDoWorkAndSignalEvent(const WorkCallback& work, |
| 20 syncer::ScopedEventSignal scoped_event_signal, | 20 syncer::ScopedEventSignal scoped_event_signal, |
| 21 SyncerError* error_info) { | 21 SyncerError* error_info) { |
| 22 *error_info = work.Run(); | 22 *error_info = work.Run(); |
| 23 // The event in |scoped_event_signal| is signaled at the end of this scope. | 23 // The event in |scoped_event_signal| is signaled at the end of this scope. |
| 24 } | 24 } |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 UIModelWorker::UIModelWorker( | 28 UIModelWorker::UIModelWorker( |
| 29 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, | 29 scoped_refptr<base::SingleThreadTaskRunner> ui_thread) |
| 30 WorkerLoopDestructionObserver* observer) | 30 : ui_thread_(std::move(ui_thread)) {} |
| 31 : ModelSafeWorker(observer), ui_thread_(ui_thread) {} | |
| 32 | |
| 33 void UIModelWorker::RegisterForLoopDestruction() { | |
| 34 CHECK(ui_thread_->BelongsToCurrentThread()); | |
| 35 SetWorkingLoopToCurrent(); | |
| 36 } | |
| 37 | 31 |
| 38 SyncerError UIModelWorker::DoWorkAndWaitUntilDoneImpl( | 32 SyncerError UIModelWorker::DoWorkAndWaitUntilDoneImpl( |
| 39 const WorkCallback& work) { | 33 const WorkCallback& work) { |
| 40 SyncerError error_info; | 34 SyncerError error_info; |
| 41 if (ui_thread_->BelongsToCurrentThread()) { | 35 if (ui_thread_->BelongsToCurrentThread()) { |
| 42 DLOG(WARNING) << "DoWorkAndWaitUntilDone called from " | 36 DLOG(WARNING) << "DoWorkAndWaitUntilDone called from " |
| 43 << "ui_loop_. Probably a nested invocation?"; | 37 << "ui_loop_. Probably a nested invocation?"; |
| 44 return work.Run(); | 38 return work.Run(); |
| 45 } | 39 } |
| 46 | 40 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 64 return error_info; | 58 return error_info; |
| 65 } | 59 } |
| 66 | 60 |
| 67 ModelSafeGroup UIModelWorker::GetModelSafeGroup() { | 61 ModelSafeGroup UIModelWorker::GetModelSafeGroup() { |
| 68 return GROUP_UI; | 62 return GROUP_UI; |
| 69 } | 63 } |
| 70 | 64 |
| 71 UIModelWorker::~UIModelWorker() {} | 65 UIModelWorker::~UIModelWorker() {} |
| 72 | 66 |
| 73 } // namespace syncer | 67 } // namespace syncer |
| OLD | NEW |