OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | |
5 #include "base/callback.h" | 6 #include "base/callback.h" |
6 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
7 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
9 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
10 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
11 #include "chrome/browser/sync/glue/ui_model_worker.h" | 12 #include "chrome/browser/sync/glue/ui_model_worker.h" |
13 #include "chrome/browser/sync/sessions/unrecoverable_error_info.h" | |
12 #include "content/browser/browser_thread.h" | 14 #include "content/browser/browser_thread.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
14 | 16 |
15 using browser_sync::UIModelWorker; | 17 using browser_sync::UIModelWorker; |
18 using browser_sync::sessions::UnrecoverableErrorInfo; | |
16 | 19 |
17 // Various boilerplate, primarily for the StopWithPendingWork test. | 20 // Various boilerplate, primarily for the StopWithPendingWork test. |
18 | 21 |
19 class UIModelWorkerVisitor { | 22 class UIModelWorkerVisitor { |
20 public: | 23 public: |
21 UIModelWorkerVisitor(base::WaitableEvent* was_run, | 24 UIModelWorkerVisitor(base::WaitableEvent* was_run, |
22 bool quit_loop) | 25 bool quit_loop) |
23 : quit_loop_when_run_(quit_loop), | 26 : quit_loop_when_run_(quit_loop), |
24 was_run_(was_run) { } | 27 was_run_(was_run) { } |
25 virtual ~UIModelWorkerVisitor() { } | 28 virtual ~UIModelWorkerVisitor() { } |
26 | 29 |
27 virtual void DoWork() { | 30 virtual UnrecoverableErrorInfo DoWork() { |
28 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 31 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
29 was_run_->Signal(); | 32 was_run_->Signal(); |
30 if (quit_loop_when_run_) | 33 if (quit_loop_when_run_) |
31 MessageLoop::current()->Quit(); | 34 MessageLoop::current()->Quit(); |
35 return UnrecoverableErrorInfo(); | |
32 } | 36 } |
33 | 37 |
34 private: | 38 private: |
35 bool quit_loop_when_run_; | 39 bool quit_loop_when_run_; |
36 base::WaitableEvent* was_run_; | 40 base::WaitableEvent* was_run_; |
37 DISALLOW_COPY_AND_ASSIGN(UIModelWorkerVisitor); | 41 DISALLOW_COPY_AND_ASSIGN(UIModelWorkerVisitor); |
38 }; | 42 }; |
39 | 43 |
40 // A faux-syncer that only interacts with its model safe worker. | 44 // A faux-syncer that only interacts with its model safe worker. |
41 class Syncer { | 45 class Syncer { |
42 public: | 46 public: |
43 explicit Syncer(UIModelWorker* worker) : worker_(worker) {} | 47 explicit Syncer(UIModelWorker* worker) : worker_(worker) {} |
44 ~Syncer() {} | 48 ~Syncer() {} |
45 | 49 |
46 void SyncShare(UIModelWorkerVisitor* visitor) { | 50 void SyncShare(UIModelWorkerVisitor* visitor) { |
47 scoped_ptr<Callback0::Type> c(NewCallback(visitor, | 51 browser_sync::WorkCallback c = base::Bind(&UIModelWorkerVisitor::DoWork, |
akalin
2011/10/26 00:25:05
comment about unretained
lipalani1
2011/10/26 01:39:11
Done.
| |
48 &UIModelWorkerVisitor::DoWork)); | 52 base::Unretained(visitor)); |
49 worker_->DoWorkAndWaitUntilDone(c.get()); | 53 worker_->DoWorkAndWaitUntilDone(c); |
50 } | 54 } |
51 private: | 55 private: |
52 scoped_refptr<UIModelWorker> worker_; | 56 scoped_refptr<UIModelWorker> worker_; |
53 DISALLOW_COPY_AND_ASSIGN(Syncer); | 57 DISALLOW_COPY_AND_ASSIGN(Syncer); |
54 }; | 58 }; |
55 | 59 |
56 // A task run from the SyncerThread to "sync share", ie tell the Syncer to | 60 // A task run from the SyncerThread to "sync share", ie tell the Syncer to |
57 // ask its ModelSafeWorker to do something. | 61 // ask its ModelSafeWorker to do something. |
58 class FakeSyncShareTask : public Task { | 62 class FakeSyncShareTask : public Task { |
59 public: | 63 public: |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 new FakeSyncShareTask(syncer(), fox3.get())); | 221 new FakeSyncShareTask(syncer(), fox3.get())); |
218 | 222 |
219 // This is what gets the UI thread blocked until NotifyExitRequested, | 223 // This is what gets the UI thread blocked until NotifyExitRequested, |
220 // which is called when FakeSyncapiShutdownTask runs and deletes the syncer. | 224 // which is called when FakeSyncapiShutdownTask runs and deletes the syncer. |
221 bmw()->Stop(); | 225 bmw()->Stop(); |
222 | 226 |
223 // Was the thread killed? | 227 // Was the thread killed? |
224 EXPECT_FALSE(syncer_thread()->IsRunning()); | 228 EXPECT_FALSE(syncer_thread()->IsRunning()); |
225 core_thread()->Stop(); | 229 core_thread()->Stop(); |
226 } | 230 } |
OLD | NEW |