blob: aed1f99485c731441869c490f87e0234c2c986c7 [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#ifndef SHELL_TASK_RUNNERS_H_
6#define SHELL_TASK_RUNNERS_H_
James Robinson646469d2014-10-03 15:33:28 -07007
Viet-Trung Luuc678d0f2015-12-15 09:45:26 -08008#include <memory>
9
James Robinson646469d2014-10-03 15:33:28 -070010#include "base/macros.h"
11#include "base/memory/ref_counted.h"
12#include "base/memory/scoped_ptr.h"
skyostilb454cd32015-06-10 10:24:06 -070013#include "base/single_thread_task_runner.h"
James Robinson646469d2014-10-03 15:33:28 -070014#include "base/threading/thread.h"
Viet-Trung Luuc678d0f2015-12-15 09:45:26 -080015#include "mojo/edk/platform/platform_handle_watcher.h"
Viet-Trung Luu6bcf7112015-11-23 12:46:55 -080016#include "mojo/edk/platform/task_runner.h"
Viet-Trung Luu1da183c2015-11-18 15:41:35 -080017#include "mojo/edk/util/ref_ptr.h"
James Robinson646469d2014-10-03 15:33:28 -070018
19namespace base {
20class SequencedWorkerPool;
21}
22
James Robinson646469d2014-10-03 15:33:28 -070023namespace shell {
24
25// A context object that contains the common task runners for the shell's main
26// process.
27class TaskRunners {
28 public:
29 explicit TaskRunners(
30 const scoped_refptr<base::SingleThreadTaskRunner>& shell_runner);
31 ~TaskRunners();
32
Viet-Trung Luu6bcf7112015-11-23 12:46:55 -080033 const mojo::util::RefPtr<mojo::platform::TaskRunner>& shell_runner() const {
Viet-Trung Luu1da183c2015-11-18 15:41:35 -080034 return shell_runner_;
James Robinson646469d2014-10-03 15:33:28 -070035 }
36
Viet-Trung Luu6bcf7112015-11-23 12:46:55 -080037 const mojo::util::RefPtr<mojo::platform::TaskRunner>& io_runner() const {
Viet-Trung Luu1da183c2015-11-18 15:41:35 -080038 return io_runner_;
James Robinson646469d2014-10-03 15:33:28 -070039 }
40
Viet-Trung Luuc678d0f2015-12-15 09:45:26 -080041 mojo::platform::PlatformHandleWatcher* io_watcher() const {
42 return io_watcher_.get();
43 }
44
James Robinson646469d2014-10-03 15:33:28 -070045 base::SequencedWorkerPool* blocking_pool() const {
46 return blocking_pool_.get();
47 }
48
49 private:
Viet-Trung Luu6bcf7112015-11-23 12:46:55 -080050 mojo::util::RefPtr<mojo::platform::TaskRunner> shell_runner_;
James Robinson646469d2014-10-03 15:33:28 -070051 scoped_ptr<base::Thread> io_thread_;
Viet-Trung Luu6bcf7112015-11-23 12:46:55 -080052 mojo::util::RefPtr<mojo::platform::TaskRunner> io_runner_;
Viet-Trung Luuc678d0f2015-12-15 09:45:26 -080053 std::unique_ptr<mojo::platform::PlatformHandleWatcher> io_watcher_;
James Robinson646469d2014-10-03 15:33:28 -070054
55 scoped_refptr<base::SequencedWorkerPool> blocking_pool_;
56
57 DISALLOW_COPY_AND_ASSIGN(TaskRunners);
58};
59
60} // namespace shell
James Robinson646469d2014-10-03 15:33:28 -070061
James Robinsonb4b7af22014-12-05 11:21:01 -080062#endif // SHELL_TASK_RUNNERS_H_