| 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 "base/test/test_io_thread.h" | 5 #include "base/test/test_io_thread.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace base { | 9 namespace base { |
| 10 | 10 |
| 11 TestIOThread::TestIOThread(Mode mode) | 11 TestIOThread::TestIOThread(Mode mode) |
| 12 : io_thread_("test_io_thread"), io_thread_started_(false) { | 12 : io_thread_("test_io_thread"), io_thread_started_(false) { |
| 13 switch (mode) { | 13 switch (mode) { |
| 14 case kAutoStart: | 14 case kAutoStart: |
| 15 Start(); | 15 Start(); |
| 16 return; | 16 return; |
| 17 case kManualStart: | 17 case kManualStart: |
| 18 return; | 18 return; |
| 19 } | 19 } |
| 20 CHECK(false) << "Invalid mode"; | 20 // Invalid mode |
| 21 CHECK(false); |
| 21 } | 22 } |
| 22 | 23 |
| 23 TestIOThread::~TestIOThread() { | 24 TestIOThread::~TestIOThread() { |
| 24 Stop(); | 25 Stop(); |
| 25 } | 26 } |
| 26 | 27 |
| 27 void TestIOThread::Start() { | 28 void TestIOThread::Start() { |
| 28 CHECK(!io_thread_started_); | 29 CHECK(!io_thread_started_); |
| 29 io_thread_started_ = true; | 30 io_thread_started_ = true; |
| 30 CHECK(io_thread_.StartWithOptions( | 31 CHECK(io_thread_.StartWithOptions( |
| 31 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 32 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 32 } | 33 } |
| 33 | 34 |
| 34 void TestIOThread::Stop() { | 35 void TestIOThread::Stop() { |
| 35 // Note: It's okay to call |Stop()| even if the thread isn't running. | 36 // Note: It's okay to call |Stop()| even if the thread isn't running. |
| 36 io_thread_.Stop(); | 37 io_thread_.Stop(); |
| 37 io_thread_started_ = false; | 38 io_thread_started_ = false; |
| 38 } | 39 } |
| 39 | 40 |
| 40 void TestIOThread::PostTask(const tracked_objects::Location& from_here, | 41 void TestIOThread::PostTask(const tracked_objects::Location& from_here, |
| 41 const base::Closure& task) { | 42 const base::Closure& task) { |
| 42 task_runner()->PostTask(from_here, task); | 43 task_runner()->PostTask(from_here, task); |
| 43 } | 44 } |
| 44 | 45 |
| 45 } // namespace base | 46 } // namespace base |
| OLD | NEW |