Chromium Code Reviews| Index: components/sync/engine/ui_model_worker.cc |
| diff --git a/components/sync/engine/ui_model_worker.cc b/components/sync/engine/ui_model_worker.cc |
| index 77fe9c7799a65db7437df9cc45edf62a0611467c..a9e90fb91dd1e64c9c89d5de75131af229591ae0 100644 |
| --- a/components/sync/engine/ui_model_worker.cc |
| +++ b/components/sync/engine/ui_model_worker.cc |
| @@ -6,90 +6,11 @@ |
| #include <utility> |
| -#include "base/bind.h" |
| -#include "base/bind_helpers.h" |
| -#include "base/callback.h" |
| -#include "components/sync/base/scoped_event_signal.h" |
| - |
| namespace syncer { |
| -namespace { |
| - |
| -class ScopedEventSignalWithWorker { |
| - public: |
| - ScopedEventSignalWithWorker(scoped_refptr<UIModelWorker> ui_model_worker, |
| - base::WaitableEvent* event) |
| - : ui_model_worker_(std::move(ui_model_worker)), |
| - scoped_event_signal_(event) {} |
| - |
| - ScopedEventSignalWithWorker(ScopedEventSignalWithWorker&&) = default; |
| - ScopedEventSignalWithWorker& operator=(ScopedEventSignalWithWorker&&) = |
| - default; |
| - |
| - bool IsStopped() const { return ui_model_worker_->IsStopped(); } |
| - |
| - private: |
| - // This reference prevents the event in |scoped_event_signal_| from being |
| - // signaled after being deleted. |
| - scoped_refptr<UIModelWorker> ui_model_worker_; |
| - |
| - ScopedEventSignal scoped_event_signal_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(ScopedEventSignalWithWorker); |
| -}; |
| - |
| -void CallDoWorkAndSignalEvent( |
| - const WorkCallback& work, |
| - ScopedEventSignalWithWorker scoped_event_signal_with_worker, |
| - SyncerError* error_info) { |
| - if (!scoped_event_signal_with_worker.IsStopped()) |
| - *error_info = work.Run(); |
| - // The event in |scoped_event_signal_with_worker| is signaled at the end of |
| - // this scope. |
| -} |
| - |
| -} // namespace |
| - |
| UIModelWorker::UIModelWorker( |
| scoped_refptr<base::SingleThreadTaskRunner> ui_thread) |
| - : ui_thread_(std::move(ui_thread)), |
| - work_done_or_abandoned_(base::WaitableEvent::ResetPolicy::MANUAL, |
| - base::WaitableEvent::InitialState::NOT_SIGNALED), |
| - stop_requested_(base::WaitableEvent::ResetPolicy::MANUAL, |
| - base::WaitableEvent::InitialState::NOT_SIGNALED) { |
| - sequence_checker_.DetachFromSequence(); |
| -} |
| - |
| -SyncerError UIModelWorker::DoWorkAndWaitUntilDoneImpl( |
| - const WorkCallback& work) { |
| - DCHECK(sequence_checker_.CalledOnValidSequence()); |
| - DCHECK(!ui_thread_->BelongsToCurrentThread()); |
| - |
| - SyncerError error_info; |
| - work_done_or_abandoned_.Reset(); |
| - |
| - if (!ui_thread_->PostTask( |
| - FROM_HERE, |
| - base::Bind(&CallDoWorkAndSignalEvent, work, |
| - base::Passed(syncer::ScopedEventSignalWithWorker( |
| - this, &work_done_or_abandoned_)), |
| - &error_info))) { |
| - DLOG(WARNING) << "Could not post work to UI loop."; |
| - error_info = CANNOT_DO_WORK; |
| - return error_info; |
| - } |
| - |
| - base::WaitableEvent* events[] = {&work_done_or_abandoned_, &stop_requested_}; |
| - base::WaitableEvent::WaitMany(events, arraysize(events)); |
| - |
| - return error_info; |
| -} |
| - |
| -void UIModelWorker::RequestStop() { |
| - DCHECK(ui_thread_->BelongsToCurrentThread()); |
| - ModelSafeWorker::RequestStop(); |
| - stop_requested_.Signal(); |
| -} |
|
skym
2017/04/06 00:34:54
Woo! So much simpler!
fdoray
2017/04/06 18:10:55
Acknowledged.
|
| + : ui_thread_(std::move(ui_thread)) {} |
| ModelSafeGroup UIModelWorker::GetModelSafeGroup() { |
| return GROUP_UI; |
| @@ -101,4 +22,8 @@ bool UIModelWorker::IsOnModelThread() { |
| UIModelWorker::~UIModelWorker() {} |
| +void UIModelWorker::ScheduleWork(base::Closure work) { |
| + ui_thread_->PostTask(FROM_HERE, std::move(work)); |
| +} |
| + |
| } // namespace syncer |