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