blob: 1440b8d94fe84f6b1a0bd3cfca63d4d4cf63f78e [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// 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 Robinsonb4b7af22014-12-05 11:21:01 -08005#include "shell/task_runners.h"
James Robinson646469d2014-10-03 15:33:28 -07006
7#include "base/threading/sequenced_worker_pool.h"
Viet-Trung Luuc678d0f2015-12-15 09:45:26 -08008#include "mojo/edk/base_edk/platform_handle_watcher_impl.h"
Viet-Trung Luu1da183c2015-11-18 15:41:35 -08009#include "mojo/edk/base_edk/platform_task_runner_impl.h"
Viet-Trung Luuc678d0f2015-12-15 09:45:26 -080010#include "mojo/edk/util/make_unique.h"
Viet-Trung Luu1da183c2015-11-18 15:41:35 -080011
12using mojo::util::MakeRefCounted;
Viet-Trung Luuc678d0f2015-12-15 09:45:26 -080013using mojo::util::MakeUnique;
James Robinson646469d2014-10-03 15:33:28 -070014
James Robinson646469d2014-10-03 15:33:28 -070015namespace shell {
16
17namespace {
18
19const size_t kMaxBlockingPoolThreads = 3;
20
21scoped_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 Luub792c802015-10-27 11:27:35 -070026 return thread;
James Robinson646469d2014-10-03 15:33:28 -070027}
28
29} // namespace
30
31TaskRunners::TaskRunners(
32 const scoped_refptr<base::SingleThreadTaskRunner>& shell_runner)
Viet-Trung Luu1da183c2015-11-18 15:41:35 -080033 : shell_runner_(
34 MakeRefCounted<base_edk::PlatformTaskRunnerImpl>(shell_runner)),
James Robinson646469d2014-10-03 15:33:28 -070035 io_thread_(CreateIOThread("io_thread")),
Viet-Trung Luu1da183c2015-11-18 15:41:35 -080036 io_runner_(MakeRefCounted<base_edk::PlatformTaskRunnerImpl>(
37 io_thread_->task_runner())),
Viet-Trung Luuc678d0f2015-12-15 09:45:26 -080038 io_watcher_(MakeUnique<base_edk::PlatformHandleWatcherImpl>(
39 static_cast<base::MessageLoopForIO*>(io_thread_->message_loop()))),
James Robinson646469d2014-10-03 15:33:28 -070040 blocking_pool_(new base::SequencedWorkerPool(kMaxBlockingPoolThreads,
Viet-Trung Luu1da183c2015-11-18 15:41:35 -080041 "blocking_pool")) {}
James Robinson646469d2014-10-03 15:33:28 -070042
43TaskRunners::~TaskRunners() {
44 blocking_pool_->Shutdown();
45}
46
47} // namespace shell