OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/edk/system/test/test_io_thread.h" | 5 #include "mojo/edk/system/test/test_io_thread.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "mojo/edk/util/waitable_event.h" | 8 #include "mojo/edk/util/waitable_event.h" |
9 | 9 |
10 using mojo::util::AutoResetWaitableEvent; | 10 using mojo::util::AutoResetWaitableEvent; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 io_task_runner_ = MakeRefCounted<base_edk::PlatformTaskRunnerImpl>( | 48 io_task_runner_ = MakeRefCounted<base_edk::PlatformTaskRunnerImpl>( |
49 message_loop()->task_runner()); | 49 message_loop()->task_runner()); |
50 } | 50 } |
51 | 51 |
52 void TestIOThread::Stop() { | 52 void TestIOThread::Stop() { |
53 // Note: It's okay to call |Stop()| even if the thread isn't running. | 53 // Note: It's okay to call |Stop()| even if the thread isn't running. |
54 io_thread_.Stop(); | 54 io_thread_.Stop(); |
55 io_thread_started_ = false; | 55 io_thread_started_ = false; |
56 } | 56 } |
57 | 57 |
| 58 bool TestIOThread::IsCurrentAndRunning() const { |
| 59 return base::MessageLoop::current() == io_thread_.message_loop() && |
| 60 io_thread_.message_loop()->is_running(); |
| 61 } |
| 62 |
58 void TestIOThread::PostTask(const base::Closure& task) { | 63 void TestIOThread::PostTask(const base::Closure& task) { |
59 io_task_runner_->PostTask(task); | 64 io_task_runner_->PostTask(task); |
60 } | 65 } |
61 | 66 |
62 void TestIOThread::PostTaskAndWait(const base::Closure& task) { | 67 void TestIOThread::PostTaskAndWait(const base::Closure& task) { |
63 AutoResetWaitableEvent event; | 68 AutoResetWaitableEvent event; |
64 io_task_runner_->PostTask(base::Bind(&PostTaskAndWaitHelper, &event, task)); | 69 io_task_runner_->PostTask(base::Bind(&PostTaskAndWaitHelper, &event, task)); |
65 event.Wait(); | 70 event.Wait(); |
66 } | 71 } |
67 | 72 |
68 } // namespace test | 73 } // namespace test |
69 } // namespace system | 74 } // namespace system |
70 } // namespace mojo | 75 } // namespace mojo |
OLD | NEW |