James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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 | |
James Robinson | b4b7af2 | 2014-12-05 11:21:01 -0800 | [diff] [blame] | 5 | #include "shell/task_runners.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 6 | |
| 7 | #include "base/threading/sequenced_worker_pool.h" |
Viet-Trung Luu | c678d0f | 2015-12-15 09:45:26 -0800 | [diff] [blame] | 8 | #include "mojo/edk/base_edk/platform_handle_watcher_impl.h" |
Viet-Trung Luu | 1da183c | 2015-11-18 15:41:35 -0800 | [diff] [blame] | 9 | #include "mojo/edk/base_edk/platform_task_runner_impl.h" |
Viet-Trung Luu | c678d0f | 2015-12-15 09:45:26 -0800 | [diff] [blame] | 10 | #include "mojo/edk/util/make_unique.h" |
Viet-Trung Luu | 1da183c | 2015-11-18 15:41:35 -0800 | [diff] [blame] | 11 | |
| 12 | using mojo::util::MakeRefCounted; |
Viet-Trung Luu | c678d0f | 2015-12-15 09:45:26 -0800 | [diff] [blame] | 13 | using mojo::util::MakeUnique; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 14 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 15 | namespace shell { |
| 16 | |
| 17 | namespace { |
| 18 | |
| 19 | const size_t kMaxBlockingPoolThreads = 3; |
| 20 | |
| 21 | scoped_ptr<base::Thread> CreateIOThread(const char* name) { |
| 22 | scoped_ptr<base::Thread> thread(new base::Thread(name)); |
| 23 | base::Thread::Options options; |
| 24 | options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 25 | thread->StartWithOptions(options); |
Viet-Trung Luu | b792c80 | 2015-10-27 11:27:35 -0700 | [diff] [blame] | 26 | return thread; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | } // namespace |
| 30 | |
| 31 | TaskRunners::TaskRunners( |
| 32 | const scoped_refptr<base::SingleThreadTaskRunner>& shell_runner) |
Viet-Trung Luu | 1da183c | 2015-11-18 15:41:35 -0800 | [diff] [blame] | 33 | : shell_runner_( |
| 34 | MakeRefCounted<base_edk::PlatformTaskRunnerImpl>(shell_runner)), |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 35 | io_thread_(CreateIOThread("io_thread")), |
Viet-Trung Luu | 1da183c | 2015-11-18 15:41:35 -0800 | [diff] [blame] | 36 | io_runner_(MakeRefCounted<base_edk::PlatformTaskRunnerImpl>( |
| 37 | io_thread_->task_runner())), |
Viet-Trung Luu | c678d0f | 2015-12-15 09:45:26 -0800 | [diff] [blame] | 38 | io_watcher_(MakeUnique<base_edk::PlatformHandleWatcherImpl>( |
| 39 | static_cast<base::MessageLoopForIO*>(io_thread_->message_loop()))), |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 40 | blocking_pool_(new base::SequencedWorkerPool(kMaxBlockingPoolThreads, |
Viet-Trung Luu | 1da183c | 2015-11-18 15:41:35 -0800 | [diff] [blame] | 41 | "blocking_pool")) {} |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 42 | |
| 43 | TaskRunners::~TaskRunners() { |
| 44 | blocking_pool_->Shutdown(); |
| 45 | } |
| 46 | |
| 47 | } // namespace shell |