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 | #ifndef SHELL_TASK_RUNNERS_H_ |
| 6 | #define SHELL_TASK_RUNNERS_H_ |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 7 | |
Viet-Trung Luu | c678d0f | 2015-12-15 09:45:26 -0800 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 10 | #include "base/macros.h" |
| 11 | #include "base/memory/ref_counted.h" |
| 12 | #include "base/memory/scoped_ptr.h" |
skyostil | b454cd3 | 2015-06-10 10:24:06 -0700 | [diff] [blame] | 13 | #include "base/single_thread_task_runner.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 14 | #include "base/threading/thread.h" |
Viet-Trung Luu | c678d0f | 2015-12-15 09:45:26 -0800 | [diff] [blame] | 15 | #include "mojo/edk/platform/platform_handle_watcher.h" |
Viet-Trung Luu | 6bcf711 | 2015-11-23 12:46:55 -0800 | [diff] [blame] | 16 | #include "mojo/edk/platform/task_runner.h" |
Viet-Trung Luu | 1da183c | 2015-11-18 15:41:35 -0800 | [diff] [blame] | 17 | #include "mojo/edk/util/ref_ptr.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 18 | |
| 19 | namespace base { |
| 20 | class SequencedWorkerPool; |
| 21 | } |
| 22 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 23 | namespace shell { |
| 24 | |
| 25 | // A context object that contains the common task runners for the shell's main |
| 26 | // process. |
| 27 | class TaskRunners { |
| 28 | public: |
| 29 | explicit TaskRunners( |
| 30 | const scoped_refptr<base::SingleThreadTaskRunner>& shell_runner); |
| 31 | ~TaskRunners(); |
| 32 | |
Viet-Trung Luu | 6bcf711 | 2015-11-23 12:46:55 -0800 | [diff] [blame] | 33 | const mojo::util::RefPtr<mojo::platform::TaskRunner>& shell_runner() const { |
Viet-Trung Luu | 1da183c | 2015-11-18 15:41:35 -0800 | [diff] [blame] | 34 | return shell_runner_; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Viet-Trung Luu | 6bcf711 | 2015-11-23 12:46:55 -0800 | [diff] [blame] | 37 | const mojo::util::RefPtr<mojo::platform::TaskRunner>& io_runner() const { |
Viet-Trung Luu | 1da183c | 2015-11-18 15:41:35 -0800 | [diff] [blame] | 38 | return io_runner_; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Viet-Trung Luu | c678d0f | 2015-12-15 09:45:26 -0800 | [diff] [blame] | 41 | mojo::platform::PlatformHandleWatcher* io_watcher() const { |
| 42 | return io_watcher_.get(); |
| 43 | } |
| 44 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 45 | base::SequencedWorkerPool* blocking_pool() const { |
| 46 | return blocking_pool_.get(); |
| 47 | } |
| 48 | |
| 49 | private: |
Viet-Trung Luu | 6bcf711 | 2015-11-23 12:46:55 -0800 | [diff] [blame] | 50 | mojo::util::RefPtr<mojo::platform::TaskRunner> shell_runner_; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 51 | scoped_ptr<base::Thread> io_thread_; |
Viet-Trung Luu | 6bcf711 | 2015-11-23 12:46:55 -0800 | [diff] [blame] | 52 | mojo::util::RefPtr<mojo::platform::TaskRunner> io_runner_; |
Viet-Trung Luu | c678d0f | 2015-12-15 09:45:26 -0800 | [diff] [blame] | 53 | std::unique_ptr<mojo::platform::PlatformHandleWatcher> io_watcher_; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 54 | |
| 55 | scoped_refptr<base::SequencedWorkerPool> blocking_pool_; |
| 56 | |
| 57 | DISALLOW_COPY_AND_ASSIGN(TaskRunners); |
| 58 | }; |
| 59 | |
| 60 | } // namespace shell |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 61 | |
James Robinson | b4b7af2 | 2014-12-05 11:21:01 -0800 | [diff] [blame] | 62 | #endif // SHELL_TASK_RUNNERS_H_ |