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

Side by Side Diff: components/sync/driver/glue/ui_model_worker_unittest.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 <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
18 #include "base/threading/thread.h" 18 #include "base/threading/thread.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 namespace syncer { 22 using browser_sync::UIModelWorker;
23 using syncer::SyncerError;
23 24
24 class UIModelWorkerVisitor { 25 class UIModelWorkerVisitor {
25 public: 26 public:
26 UIModelWorkerVisitor(base::WaitableEvent* was_run, bool quit_loop) 27 UIModelWorkerVisitor(base::WaitableEvent* was_run, bool quit_loop)
27 : quit_loop_when_run_(quit_loop), was_run_(was_run) {} 28 : quit_loop_when_run_(quit_loop), was_run_(was_run) {}
28 virtual ~UIModelWorkerVisitor() {} 29 virtual ~UIModelWorkerVisitor() {}
29 30
30 virtual SyncerError DoWork() { 31 virtual syncer::SyncerError DoWork() {
31 was_run_->Signal(); 32 was_run_->Signal();
32 if (quit_loop_when_run_) 33 if (quit_loop_when_run_)
33 base::MessageLoop::current()->QuitWhenIdle(); 34 base::MessageLoop::current()->QuitWhenIdle();
34 return SYNCER_OK; 35 return syncer::SYNCER_OK;
35 } 36 }
36 37
37 private: 38 private:
38 bool quit_loop_when_run_; 39 bool quit_loop_when_run_;
39 base::WaitableEvent* was_run_; 40 base::WaitableEvent* was_run_;
40 DISALLOW_COPY_AND_ASSIGN(UIModelWorkerVisitor); 41 DISALLOW_COPY_AND_ASSIGN(UIModelWorkerVisitor);
41 }; 42 };
42 43
43 // A faux-syncer that only interacts with its model safe worker. 44 // A faux-syncer that only interacts with its model safe worker.
44 class Syncer { 45 class Syncer {
45 public: 46 public:
46 explicit Syncer(UIModelWorker* worker) : worker_(worker) {} 47 explicit Syncer(UIModelWorker* worker) : worker_(worker) {}
47 ~Syncer() {} 48 ~Syncer() {}
48 49
49 void SyncShare(UIModelWorkerVisitor* visitor) { 50 void SyncShare(UIModelWorkerVisitor* visitor) {
50 // We wait until the callback is executed. So it is safe to use Unretained. 51 // We wait until the callback is executed. So it is safe to use Unretained.
51 WorkCallback c = 52 syncer::WorkCallback c =
52 base::Bind(&UIModelWorkerVisitor::DoWork, base::Unretained(visitor)); 53 base::Bind(&UIModelWorkerVisitor::DoWork, base::Unretained(visitor));
53 worker_->DoWorkAndWaitUntilDone(c); 54 worker_->DoWorkAndWaitUntilDone(c);
54 } 55 }
55 56
56 private: 57 private:
57 scoped_refptr<UIModelWorker> worker_; 58 scoped_refptr<UIModelWorker> worker_;
58 DISALLOW_COPY_AND_ASSIGN(Syncer); 59 DISALLOW_COPY_AND_ASSIGN(Syncer);
59 }; 60 };
60 61
61 class SyncUIModelWorkerTest : public testing::Test { 62 class SyncUIModelWorkerTest : public testing::Test {
(...skipping 30 matching lines...) Expand all
92 93
93 syncer_thread()->task_runner()->PostTask( 94 syncer_thread()->task_runner()->PostTask(
94 FROM_HERE, 95 FROM_HERE,
95 base::Bind(&Syncer::SyncShare, base::Unretained(syncer()), v.get())); 96 base::Bind(&Syncer::SyncShare, base::Unretained(syncer()), v.get()));
96 97
97 // We are on the UI thread, so run our loop to process the 98 // We are on the UI thread, so run our loop to process the
98 // (hopefully) scheduled task from a SyncShare invocation. 99 // (hopefully) scheduled task from a SyncShare invocation.
99 base::RunLoop().Run(); 100 base::RunLoop().Run();
100 syncer_thread()->Stop(); 101 syncer_thread()->Stop();
101 } 102 }
102
103 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/driver/glue/ui_model_worker.cc ('k') | components/sync/driver/invalidation_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698