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

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

Issue 2376123003: [Sync] Move //components/sync to the syncer namespace. (Closed)
Patch Set: Rebase. 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 using browser_sync::UIModelWorker; 22 namespace syncer {
23 using syncer::SyncerError;
24 23
25 class UIModelWorkerVisitor { 24 class UIModelWorkerVisitor {
26 public: 25 public:
27 UIModelWorkerVisitor(base::WaitableEvent* was_run, bool quit_loop) 26 UIModelWorkerVisitor(base::WaitableEvent* was_run, bool quit_loop)
28 : quit_loop_when_run_(quit_loop), was_run_(was_run) {} 27 : quit_loop_when_run_(quit_loop), was_run_(was_run) {}
29 virtual ~UIModelWorkerVisitor() {} 28 virtual ~UIModelWorkerVisitor() {}
30 29
31 virtual syncer::SyncerError DoWork() { 30 virtual SyncerError DoWork() {
32 was_run_->Signal(); 31 was_run_->Signal();
33 if (quit_loop_when_run_) 32 if (quit_loop_when_run_)
34 base::MessageLoop::current()->QuitWhenIdle(); 33 base::MessageLoop::current()->QuitWhenIdle();
35 return syncer::SYNCER_OK; 34 return SYNCER_OK;
36 } 35 }
37 36
38 private: 37 private:
39 bool quit_loop_when_run_; 38 bool quit_loop_when_run_;
40 base::WaitableEvent* was_run_; 39 base::WaitableEvent* was_run_;
41 DISALLOW_COPY_AND_ASSIGN(UIModelWorkerVisitor); 40 DISALLOW_COPY_AND_ASSIGN(UIModelWorkerVisitor);
42 }; 41 };
43 42
44 // A faux-syncer that only interacts with its model safe worker. 43 // A faux-syncer that only interacts with its model safe worker.
45 class Syncer { 44 class Syncer {
46 public: 45 public:
47 explicit Syncer(UIModelWorker* worker) : worker_(worker) {} 46 explicit Syncer(UIModelWorker* worker) : worker_(worker) {}
48 ~Syncer() {} 47 ~Syncer() {}
49 48
50 void SyncShare(UIModelWorkerVisitor* visitor) { 49 void SyncShare(UIModelWorkerVisitor* visitor) {
51 // We wait until the callback is executed. So it is safe to use Unretained. 50 // We wait until the callback is executed. So it is safe to use Unretained.
52 syncer::WorkCallback c = 51 WorkCallback c =
53 base::Bind(&UIModelWorkerVisitor::DoWork, base::Unretained(visitor)); 52 base::Bind(&UIModelWorkerVisitor::DoWork, base::Unretained(visitor));
54 worker_->DoWorkAndWaitUntilDone(c); 53 worker_->DoWorkAndWaitUntilDone(c);
55 } 54 }
56 55
57 private: 56 private:
58 scoped_refptr<UIModelWorker> worker_; 57 scoped_refptr<UIModelWorker> worker_;
59 DISALLOW_COPY_AND_ASSIGN(Syncer); 58 DISALLOW_COPY_AND_ASSIGN(Syncer);
60 }; 59 };
61 60
62 class SyncUIModelWorkerTest : public testing::Test { 61 class SyncUIModelWorkerTest : public testing::Test {
(...skipping 30 matching lines...) Expand all
93 92
94 syncer_thread()->task_runner()->PostTask( 93 syncer_thread()->task_runner()->PostTask(
95 FROM_HERE, 94 FROM_HERE,
96 base::Bind(&Syncer::SyncShare, base::Unretained(syncer()), v.get())); 95 base::Bind(&Syncer::SyncShare, base::Unretained(syncer()), v.get()));
97 96
98 // We are on the UI thread, so run our loop to process the 97 // We are on the UI thread, so run our loop to process the
99 // (hopefully) scheduled task from a SyncShare invocation. 98 // (hopefully) scheduled task from a SyncShare invocation.
100 base::RunLoop().Run(); 99 base::RunLoop().Run();
101 syncer_thread()->Stop(); 100 syncer_thread()->Stop();
102 } 101 }
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