OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_ | 5 #ifndef REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_ |
6 #define REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_ | 6 #define REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_ |
7 | 7 |
| 8 #include <memory> |
| 9 |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
12 | 13 |
13 namespace base { | 14 namespace base { |
14 class SingleThreadTaskRunner; | 15 class SingleThreadTaskRunner; |
15 } // namespace base | 16 } // namespace base |
16 | 17 |
17 namespace net { | 18 namespace net { |
18 class URLRequestContextGetter; | 19 class URLRequestContextGetter; |
19 } // namespace net | 20 } // namespace net |
20 | 21 |
21 namespace remoting { | 22 namespace remoting { |
22 | 23 |
23 class AutoThreadTaskRunner; | 24 class AutoThreadTaskRunner; |
24 | 25 |
25 // A class that manages threads and running context for the chromoting host | 26 // A class that manages threads and running context for the chromoting host |
26 // process. This class is virtual only for testing purposes (see below). | 27 // process. This class is virtual only for testing purposes (see below). |
27 class ChromotingHostContext { | 28 class ChromotingHostContext { |
28 public: | 29 public: |
29 // Create threads and URLRequestContextGetter for use by a host. | 30 // Create threads and URLRequestContextGetter for use by a host. |
30 // During shutdown the caller should tear-down the ChromotingHostContext and | 31 // During shutdown the caller should tear-down the ChromotingHostContext and |
31 // then continue to run until |ui_task_runner| is no longer referenced. | 32 // then continue to run until |ui_task_runner| is no longer referenced. |
32 // nullptr is returned if any threads fail to start. | 33 // nullptr is returned if any threads fail to start. |
33 static scoped_ptr<ChromotingHostContext> Create( | 34 static std::unique_ptr<ChromotingHostContext> Create( |
34 scoped_refptr<AutoThreadTaskRunner> ui_task_runner); | 35 scoped_refptr<AutoThreadTaskRunner> ui_task_runner); |
35 | 36 |
36 #if defined(OS_CHROMEOS) | 37 #if defined(OS_CHROMEOS) |
37 // Attaches task runners to the relevant browser threads for the chromoting | 38 // Attaches task runners to the relevant browser threads for the chromoting |
38 // host. Must be called on the UI thread of the browser process. | 39 // host. Must be called on the UI thread of the browser process. |
39 // remoting::UrlRequestContextGetter returns ContainerURLRequestContext under | 40 // remoting::UrlRequestContextGetter returns ContainerURLRequestContext under |
40 // the hood which spawns two new threads per instance. Since | 41 // the hood which spawns two new threads per instance. Since |
41 // ChromotingHostContext can be destroyed from any thread, as its owner | 42 // ChromotingHostContext can be destroyed from any thread, as its owner |
42 // (It2MeHost) is ref-counted, joining the created threads during shutdown | 43 // (It2MeHost) is ref-counted, joining the created threads during shutdown |
43 // violates the "Disallow IO" thread restrictions on some task runners (e.g. | 44 // violates the "Disallow IO" thread restrictions on some task runners (e.g. |
44 // the IO Thread of the browser process). | 45 // the IO Thread of the browser process). |
45 // Instead, we re-use the |url_request_context_getter| in the browser process. | 46 // Instead, we re-use the |url_request_context_getter| in the browser process. |
46 static scoped_ptr<ChromotingHostContext> CreateForChromeOS( | 47 static std::unique_ptr<ChromotingHostContext> CreateForChromeOS( |
47 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, | 48 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
48 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 49 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
49 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 50 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
50 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); | 51 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); |
51 #endif // defined(OS_CHROMEOS) | 52 #endif // defined(OS_CHROMEOS) |
52 | 53 |
53 ~ChromotingHostContext(); | 54 ~ChromotingHostContext(); |
54 | 55 |
55 scoped_ptr<ChromotingHostContext> Copy(); | 56 std::unique_ptr<ChromotingHostContext> Copy(); |
56 | 57 |
57 // Task runner for the thread that is used for the UI. | 58 // Task runner for the thread that is used for the UI. |
58 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() const; | 59 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() const; |
59 | 60 |
60 // Task runner for the thread used for audio capture and encoding. | 61 // Task runner for the thread used for audio capture and encoding. |
61 scoped_refptr<AutoThreadTaskRunner> audio_task_runner() const; | 62 scoped_refptr<AutoThreadTaskRunner> audio_task_runner() const; |
62 | 63 |
63 // Task runner for the thread that is used for blocking file | 64 // Task runner for the thread that is used for blocking file |
64 // IO. This thread is used by the URLRequestContext to read proxy | 65 // IO. This thread is used by the URLRequestContext to read proxy |
65 // configuration and by NatConfig to read policy configs. | 66 // configuration and by NatConfig to read policy configs. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 121 |
121 // Serves URLRequestContexts that use the network and UI task runners. | 122 // Serves URLRequestContexts that use the network and UI task runners. |
122 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 123 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
123 | 124 |
124 DISALLOW_COPY_AND_ASSIGN(ChromotingHostContext); | 125 DISALLOW_COPY_AND_ASSIGN(ChromotingHostContext); |
125 }; | 126 }; |
126 | 127 |
127 } // namespace remoting | 128 } // namespace remoting |
128 | 129 |
129 #endif // REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_ | 130 #endif // REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_ |
OLD | NEW |