Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: components/sync/driver/glue/ui_model_worker.cc

Issue 2388673002: Revert of [Sync] Move //components/sync to the syncer namespace. (patchset #5 id:40001 of https://co (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
11 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 11 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
12 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
13 13
14 namespace syncer { 14 namespace browser_sync {
15 15
16 namespace { 16 namespace {
17 17
18 // A simple callback to signal a waitable event after running a closure. 18 // A simple callback to signal a waitable event after running a closure.
19 void CallDoWorkAndSignalCallback(const WorkCallback& work, 19 void CallDoWorkAndSignalCallback(const syncer::WorkCallback& work,
20 base::WaitableEvent* work_done, 20 base::WaitableEvent* work_done,
21 SyncerError* error_info) { 21 syncer::SyncerError* error_info) {
22 if (work.is_null()) { 22 if (work.is_null()) {
23 // This can happen during tests or cases where there are more than just the 23 // This can happen during tests or cases where there are more than just the
24 // default UIModelWorker in existence and it gets destroyed before 24 // default UIModelWorker in existence and it gets destroyed before
25 // the main UI loop has terminated. There is no easy way to assert the 25 // the main UI loop has terminated. There is no easy way to assert the
26 // loop is running / not running at the moment, so we just provide cancel 26 // loop is running / not running at the moment, so we just provide cancel
27 // semantics here and short-circuit. 27 // semantics here and short-circuit.
28 // TODO(timsteele): Maybe we should have the message loop destruction 28 // TODO(timsteele): Maybe we should have the message loop destruction
29 // observer fire when the loop has ended, just a bit before it 29 // observer fire when the loop has ended, just a bit before it
30 // actually gets destroyed. 30 // actually gets destroyed.
31 return; 31 return;
32 } 32 }
33 33
34 *error_info = work.Run(); 34 *error_info = work.Run();
35 35
36 work_done->Signal(); // Unblock the syncer thread that scheduled us. 36 work_done->Signal(); // Unblock the syncer thread that scheduled us.
37 } 37 }
38 38
39 } // namespace 39 } // namespace
40 40
41 UIModelWorker::UIModelWorker( 41 UIModelWorker::UIModelWorker(
42 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, 42 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
43 WorkerLoopDestructionObserver* observer) 43 syncer::WorkerLoopDestructionObserver* observer)
44 : ModelSafeWorker(observer), ui_thread_(ui_thread) {} 44 : syncer::ModelSafeWorker(observer), ui_thread_(ui_thread) {}
45 45
46 void UIModelWorker::RegisterForLoopDestruction() { 46 void UIModelWorker::RegisterForLoopDestruction() {
47 CHECK(ui_thread_->BelongsToCurrentThread()); 47 CHECK(ui_thread_->BelongsToCurrentThread());
48 SetWorkingLoopToCurrent(); 48 SetWorkingLoopToCurrent();
49 } 49 }
50 50
51 SyncerError UIModelWorker::DoWorkAndWaitUntilDoneImpl( 51 syncer::SyncerError UIModelWorker::DoWorkAndWaitUntilDoneImpl(
52 const WorkCallback& work) { 52 const syncer::WorkCallback& work) {
53 SyncerError error_info; 53 syncer::SyncerError error_info;
54 if (ui_thread_->BelongsToCurrentThread()) { 54 if (ui_thread_->BelongsToCurrentThread()) {
55 DLOG(WARNING) << "DoWorkAndWaitUntilDone called from " 55 DLOG(WARNING) << "DoWorkAndWaitUntilDone called from "
56 << "ui_loop_. Probably a nested invocation?"; 56 << "ui_loop_. Probably a nested invocation?";
57 return work.Run(); 57 return work.Run();
58 } 58 }
59 59
60 if (!ui_thread_->PostTask(FROM_HERE, 60 if (!ui_thread_->PostTask(FROM_HERE,
61 base::Bind(&CallDoWorkAndSignalCallback, work, 61 base::Bind(&CallDoWorkAndSignalCallback, work,
62 work_done_or_stopped(), &error_info))) { 62 work_done_or_stopped(), &error_info))) {
63 DLOG(WARNING) << "Could not post work to UI loop."; 63 DLOG(WARNING) << "Could not post work to UI loop.";
64 error_info = CANNOT_DO_WORK; 64 error_info = syncer::CANNOT_DO_WORK;
65 return error_info; 65 return error_info;
66 } 66 }
67 work_done_or_stopped()->Wait(); 67 work_done_or_stopped()->Wait();
68 68
69 return error_info; 69 return error_info;
70 } 70 }
71 71
72 ModelSafeGroup UIModelWorker::GetModelSafeGroup() { 72 syncer::ModelSafeGroup UIModelWorker::GetModelSafeGroup() {
73 return GROUP_UI; 73 return syncer::GROUP_UI;
74 } 74 }
75 75
76 UIModelWorker::~UIModelWorker() {} 76 UIModelWorker::~UIModelWorker() {}
77 77
78 } // namespace syncer 78 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/sync/driver/glue/ui_model_worker.h ('k') | components/sync/driver/glue/ui_model_worker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698