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