| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 BrowserThreadModelWorker* worker() { return worker_.get(); } | 35 BrowserThreadModelWorker* worker() { return worker_.get(); } |
| 36 OneShotTimer<SyncBrowserThreadModelWorkerTest>* timer() { return &timer_; } | 36 OneShotTimer<SyncBrowserThreadModelWorkerTest>* timer() { return &timer_; } |
| 37 base::WeakPtrFactory<SyncBrowserThreadModelWorkerTest>* factory() { | 37 base::WeakPtrFactory<SyncBrowserThreadModelWorkerTest>* factory() { |
| 38 return &weak_factory_; | 38 return &weak_factory_; |
| 39 } | 39 } |
| 40 | 40 |
| 41 // Schedule DoWork to be executed on the DB thread and have the test fail if | 41 // Schedule DoWork to be executed on the DB thread and have the test fail if |
| 42 // DoWork hasn't executed within action_timeout_ms() ms. | 42 // DoWork hasn't executed within action_timeout_ms() ms. |
| 43 void ScheduleWork() { | 43 void ScheduleWork() { |
| 44 // We wait until the callback is done. So it is safe to use unretained. | 44 // We wait until the callback is done. So it is safe to use unretained. |
| 45 syncer::WorkCallback c = | 45 syncer::WorkCallback c = |
| 46 base::Bind(&SyncBrowserThreadModelWorkerTest::DoWork, | 46 base::Bind(&SyncBrowserThreadModelWorkerTest::DoWork, |
| 47 base::Unretained(this)); | 47 base::Unretained(this)); |
| 48 timer()->Start( | 48 timer()->Start( |
| 49 FROM_HERE, | 49 FROM_HERE, |
| 50 TimeDelta::FromMilliseconds(TestTimeouts::action_timeout_ms()), | 50 TimeDelta::FromMilliseconds(TestTimeouts::action_timeout_ms()), |
| 51 this, | 51 this, |
| 52 &SyncBrowserThreadModelWorkerTest::Timeout); | 52 &SyncBrowserThreadModelWorkerTest::Timeout); |
| 53 worker()->DoWorkAndWaitUntilDone(c); | 53 worker()->DoWorkAndWaitUntilDone(c); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // This is the work that will be scheduled to be done on the DB thread. | 56 // This is the work that will be scheduled to be done on the DB thread. |
| 57 syncer::SyncerError DoWork() { | 57 syncer::SyncerError DoWork() { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 MessageLoop::current()->PostTask(FROM_HERE, | 98 MessageLoop::current()->PostTask(FROM_HERE, |
| 99 base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork, | 99 base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork, |
| 100 factory()->GetWeakPtr())); | 100 factory()->GetWeakPtr())); |
| 101 MessageLoop::current()->Run(); | 101 MessageLoop::current()->Run(); |
| 102 EXPECT_TRUE(did_do_work()); | 102 EXPECT_TRUE(did_do_work()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 } // namespace | 105 } // namespace |
| 106 | 106 |
| 107 } // namespace browser_sync | 107 } // namespace browser_sync |
| OLD | NEW |