chromoting_host_context.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2012 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#ifndef REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_
6#define REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_
7
8#include "base/gtest_prod_util.h"
9#include "base/memory/ref_counted.h"
10#include "base/threading/thread.h"
11
12namespace base {
13class SingleThreadTaskRunner;
14}  // namespace base
15
16namespace net {
17class URLRequestContextGetter;
18}  // namespace net
19
20namespace remoting {
21
22class AutoThreadTaskRunner;
23
24// A class that manages threads and running context for the chromoting host
25// process.  This class is virtual only for testing purposes (see below).
26class ChromotingHostContext {
27 public:
28  // Create a context.
29  ChromotingHostContext(
30      scoped_refptr<AutoThreadTaskRunner> ui_task_runner);
31  virtual ~ChromotingHostContext();
32
33  void ReleaseTaskRunners();
34
35  // TODO(ajwong): Move the Start method out of this class. Then
36  // create a static factory for construction, and destruction.  We
37  // should be able to remove the need for virtual functions below
38  // with that design, while preserving the relative simplicity of
39  // this API.
40  virtual bool Start();
41
42  // Task runner for the thread used for audio capture and encoding.
43  virtual base::SingleThreadTaskRunner* audio_task_runner();
44
45  // Task runner for the thread used by the ScreenRecorder to capture
46  // the screen.
47  virtual base::SingleThreadTaskRunner* capture_task_runner();
48
49  // Task runner for the thread used to encode video streams.
50  virtual base::SingleThreadTaskRunner* encode_task_runner();
51
52  // Task runner for the thread that is used for blocking file
53  // IO. This thread is used by the URLRequestContext to read proxy
54  // configuration and by NatConfig to read policy configs.
55  virtual base::SingleThreadTaskRunner* file_task_runner();
56
57  // Task runner for the thread that is used by the EventExecutor.
58  //
59  // TODO(sergeyu): Do we need a separate thread for EventExecutor?
60  // Can we use some other thread instead?
61  virtual base::SingleThreadTaskRunner* input_task_runner();
62
63  // Task runner for the thread used for network IO. This thread runs
64  // a libjingle message loop, and is the only thread on which
65  // libjingle code may be run.
66  virtual base::SingleThreadTaskRunner* network_task_runner();
67
68  // Task runner for the thread that is used for the UI. In the NPAPI
69  // plugin this corresponds to the main plugin thread.
70  virtual base::SingleThreadTaskRunner* ui_task_runner();
71
72  const scoped_refptr<net::URLRequestContextGetter>&
73      url_request_context_getter();
74
75 private:
76  FRIEND_TEST_ALL_PREFIXES(ChromotingHostContextTest, StartAndStop);
77
78  // A thread that hosts audio capture and encoding.
79  base::Thread audio_thread_;
80
81  // A thread that hosts screen capture.
82  base::Thread capture_thread_;
83
84  // A thread that hosts all encode operations.
85  base::Thread encode_thread_;
86
87  // Thread for blocking IO operations.
88  base::Thread file_thread_;
89
90  // A thread that hosts input injection.
91  base::Thread input_thread_;
92
93  // A thread that hosts all network operations.
94  base::Thread network_thread_;
95
96  // Task runners wrapping the above threads. These should be declared after
97  // the corresponding threads to guarantee proper order of destruction.
98  scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_;
99  scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_;
100  scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_;
101  scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
102  scoped_refptr<base::SingleThreadTaskRunner> input_task_runner_;
103  scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
104
105  scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
106
107  scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
108
109  DISALLOW_COPY_AND_ASSIGN(ChromotingHostContext);
110};
111
112}  // namespace remoting
113
114#endif  // REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_
115