OLD | NEW |
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/engine/browser_thread_model_worker.h" | 5 #include "components/sync/engine/browser_thread_model_worker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 BrowserThreadModelWorker* worker() { return worker_.get(); } | 32 BrowserThreadModelWorker* worker() { return worker_.get(); } |
33 base::OneShotTimer* timer() { return &timer_; } | 33 base::OneShotTimer* timer() { return &timer_; } |
34 base::WeakPtrFactory<SyncBrowserThreadModelWorkerTest>* factory() { | 34 base::WeakPtrFactory<SyncBrowserThreadModelWorkerTest>* factory() { |
35 return &weak_factory_; | 35 return &weak_factory_; |
36 } | 36 } |
37 | 37 |
38 // Schedule DoWork to be executed on the DB thread and have the test fail if | 38 // Schedule DoWork to be executed on the DB thread and have the test fail if |
39 // DoWork hasn't executed within action_timeout(). | 39 // DoWork hasn't executed within action_timeout(). |
40 void ScheduleWork() { | 40 void ScheduleWork() { |
41 // We wait until the callback is done. So it is safe to use unretained. | 41 // We wait until the callback is done. So it is safe to use unretained. |
| 42 WorkCallback c = base::Bind(&SyncBrowserThreadModelWorkerTest::DoWork, |
| 43 base::Unretained(this)); |
42 timer()->Start(FROM_HERE, TestTimeouts::action_timeout(), this, | 44 timer()->Start(FROM_HERE, TestTimeouts::action_timeout(), this, |
43 &SyncBrowserThreadModelWorkerTest::Timeout); | 45 &SyncBrowserThreadModelWorkerTest::Timeout); |
44 worker()->DoWorkAndWaitUntilDone(base::BindOnce( | 46 worker()->DoWorkAndWaitUntilDone(c); |
45 &SyncBrowserThreadModelWorkerTest::DoWork, base::Unretained(this))); | |
46 } | 47 } |
47 | 48 |
48 // This is the work that will be scheduled to be done on the DB thread. | 49 // This is the work that will be scheduled to be done on the DB thread. |
49 SyncerError DoWork() { | 50 SyncerError DoWork() { |
50 EXPECT_TRUE(db_thread_.task_runner()->BelongsToCurrentThread()); | 51 EXPECT_TRUE(db_thread_.task_runner()->BelongsToCurrentThread()); |
51 main_message_loop_.task_runner()->PostTask( | 52 main_message_loop_.task_runner()->PostTask( |
52 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 53 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
53 did_do_work_ = true; | 54 did_do_work_ = true; |
54 return SYNCER_OK; | 55 return SYNCER_OK; |
55 } | 56 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 base::ThreadTaskRunnerHandle::Get()->PostTask( | 88 base::ThreadTaskRunnerHandle::Get()->PostTask( |
88 FROM_HERE, base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork, | 89 FROM_HERE, base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork, |
89 factory()->GetWeakPtr())); | 90 factory()->GetWeakPtr())); |
90 base::RunLoop().Run(); | 91 base::RunLoop().Run(); |
91 EXPECT_TRUE(did_do_work()); | 92 EXPECT_TRUE(did_do_work()); |
92 } | 93 } |
93 | 94 |
94 } // namespace | 95 } // namespace |
95 | 96 |
96 } // namespace syncer | 97 } // namespace syncer |
OLD | NEW |