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_CLIENT_SESSION_H_ | 5 #ifndef REMOTING_HOST_CLIENT_SESSION_H_ |
6 #define REMOTING_HOST_CLIENT_SESSION_H_ | 6 #define REMOTING_HOST_CLIENT_SESSION_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 #include "base/timer.h" | 11 #include "base/timer.h" |
12 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" |
13 #include "remoting/host/remote_input_filter.h" | 13 #include "remoting/host/remote_input_filter.h" |
14 #include "remoting/protocol/clipboard_echo_filter.h" | 14 #include "remoting/protocol/clipboard_echo_filter.h" |
15 #include "remoting/protocol/clipboard_filter.h" | 15 #include "remoting/protocol/clipboard_filter.h" |
16 #include "remoting/protocol/clipboard_stub.h" | 16 #include "remoting/protocol/clipboard_stub.h" |
17 #include "remoting/protocol/connection_to_client.h" | 17 #include "remoting/protocol/connection_to_client.h" |
18 #include "remoting/protocol/host_stub.h" | 18 #include "remoting/protocol/host_stub.h" |
19 #include "remoting/protocol/input_event_tracker.h" | 19 #include "remoting/protocol/input_event_tracker.h" |
20 #include "remoting/protocol/input_filter.h" | 20 #include "remoting/protocol/input_filter.h" |
21 #include "remoting/protocol/input_stub.h" | 21 #include "remoting/protocol/input_stub.h" |
22 #include "remoting/protocol/mouse_input_filter.h" | 22 #include "remoting/protocol/mouse_input_filter.h" |
23 #include "third_party/skia/include/core/SkPoint.h" | 23 #include "third_party/skia/include/core/SkPoint.h" |
24 | 24 |
| 25 namespace base { |
| 26 class SingleThreadTaskRunner; |
| 27 } // namespace base |
| 28 |
25 namespace remoting { | 29 namespace remoting { |
26 | 30 |
| 31 class AudioEncoder; |
| 32 class AudioScheduler; |
| 33 class DesktopEnvironment; |
| 34 class Encoder; |
| 35 class ScreenRecorder; |
27 class VideoFrameCapturer; | 36 class VideoFrameCapturer; |
28 | 37 |
29 // A ClientSession keeps a reference to a connection to a client, and maintains | 38 // A ClientSession keeps a reference to a connection to a client, and maintains |
30 // per-client state. | 39 // per-client state. |
31 class ClientSession : public protocol::HostStub, | 40 class ClientSession : public protocol::HostStub, |
32 public protocol::InputStub, | 41 public protocol::InputStub, |
33 public protocol::ConnectionToClient::EventHandler, | 42 public protocol::ConnectionToClient::EventHandler, |
34 public base::NonThreadSafe { | 43 public base::NonThreadSafe { |
35 public: | 44 public: |
36 // Callback interface for passing events to the ChromotingHost. | 45 // Callback interface for passing events to the ChromotingHost. |
(...skipping 23 matching lines...) Expand all Loading... |
60 virtual void OnSessionRouteChange( | 69 virtual void OnSessionRouteChange( |
61 ClientSession* client, | 70 ClientSession* client, |
62 const std::string& channel_name, | 71 const std::string& channel_name, |
63 const protocol::TransportRoute& route) = 0; | 72 const protocol::TransportRoute& route) = 0; |
64 | 73 |
65 protected: | 74 protected: |
66 virtual ~EventHandler() {} | 75 virtual ~EventHandler() {} |
67 }; | 76 }; |
68 | 77 |
69 ClientSession(EventHandler* event_handler, | 78 ClientSession(EventHandler* event_handler, |
| 79 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, |
| 80 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, |
| 81 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
70 scoped_ptr<protocol::ConnectionToClient> connection, | 82 scoped_ptr<protocol::ConnectionToClient> connection, |
71 protocol::ClipboardStub* host_clipboard_stub, | 83 scoped_ptr<DesktopEnvironment> desktop_environment, |
72 protocol::InputStub* host_input_stub, | |
73 VideoFrameCapturer* capturer, | |
74 const base::TimeDelta& max_duration); | 84 const base::TimeDelta& max_duration); |
75 virtual ~ClientSession(); | |
76 | 85 |
77 // protocol::InputStub interface. | 86 // protocol::InputStub interface. |
78 virtual void InjectKeyEvent(const protocol::KeyEvent& event) OVERRIDE; | 87 virtual void InjectKeyEvent(const protocol::KeyEvent& event) OVERRIDE; |
79 virtual void InjectMouseEvent(const protocol::MouseEvent& event) OVERRIDE; | 88 virtual void InjectMouseEvent(const protocol::MouseEvent& event) OVERRIDE; |
80 | 89 |
81 // protocol::HostStub interface. | 90 // protocol::HostStub interface. |
82 virtual void NotifyClientDimensions( | 91 virtual void NotifyClientDimensions( |
83 const protocol::ClientDimensions& dimensions) OVERRIDE; | 92 const protocol::ClientDimensions& dimensions) OVERRIDE; |
84 virtual void ControlVideo( | 93 virtual void ControlVideo( |
85 const protocol::VideoControl& video_control) OVERRIDE; | 94 const protocol::VideoControl& video_control) OVERRIDE; |
(...skipping 11 matching lines...) Expand all Loading... |
97 protocol::ConnectionToClient* connection, | 106 protocol::ConnectionToClient* connection, |
98 const std::string& channel_name, | 107 const std::string& channel_name, |
99 const protocol::TransportRoute& route) OVERRIDE; | 108 const protocol::TransportRoute& route) OVERRIDE; |
100 | 109 |
101 // Disconnects the session and destroys the transport. Event handler | 110 // Disconnects the session and destroys the transport. Event handler |
102 // is guaranteed not to be called after this method is called. Can | 111 // is guaranteed not to be called after this method is called. Can |
103 // be called multiple times. The object should not be used after | 112 // be called multiple times. The object should not be used after |
104 // this method returns. | 113 // this method returns. |
105 void Disconnect(); | 114 void Disconnect(); |
106 | 115 |
| 116 // Stop all recorders asynchronously and deletes |this| once they are stopped. |
| 117 // StopAndDelete() is the only way to destoy a |ClientSession| instance. |
| 118 void StopAndDelete(); |
| 119 |
107 protocol::ConnectionToClient* connection() const { | 120 protocol::ConnectionToClient* connection() const { |
108 return connection_.get(); | 121 return connection_.get(); |
109 } | 122 } |
110 | 123 |
| 124 DesktopEnvironment* desktop_environment() const { |
| 125 return desktop_environment_.get(); |
| 126 } |
| 127 |
111 const std::string& client_jid() { return client_jid_; } | 128 const std::string& client_jid() { return client_jid_; } |
112 | 129 |
113 bool is_authenticated() { return is_authenticated_; } | 130 bool is_authenticated() { return is_authenticated_; } |
114 | 131 |
115 // Indicate that local mouse activity has been detected. This causes remote | 132 // Indicate that local mouse activity has been detected. This causes remote |
116 // inputs to be ignored for a short time so that the local user will always | 133 // inputs to be ignored for a short time so that the local user will always |
117 // have the upper hand in 'pointer wars'. | 134 // have the upper hand in 'pointer wars'. |
118 void LocalMouseMoved(const SkIPoint& new_pos); | 135 void LocalMouseMoved(const SkIPoint& new_pos); |
119 | 136 |
120 // Disable handling of input events from this client. If the client has any | 137 // Disable handling of input events from this client. If the client has any |
121 // keys or mouse buttons pressed then these will be released. | 138 // keys or mouse buttons pressed then these will be released. |
122 void SetDisableInputs(bool disable_inputs); | 139 void SetDisableInputs(bool disable_inputs); |
123 | 140 |
| 141 private: |
| 142 virtual ~ClientSession(); |
| 143 |
124 // Creates a proxy for sending clipboard events to the client. | 144 // Creates a proxy for sending clipboard events to the client. |
125 scoped_ptr<protocol::ClipboardStub> CreateClipboardProxy(); | 145 scoped_ptr<protocol::ClipboardStub> CreateClipboardProxy(); |
126 | 146 |
127 private: | 147 void OnRecorderStopped(); |
| 148 |
| 149 // Creates encoder for the specified configuration. |
| 150 static Encoder* CreateEncoder(const protocol::SessionConfig& config); |
| 151 |
| 152 // Creates an audio encoder for the specified configuration. |
| 153 static scoped_ptr<AudioEncoder> CreateAudioEncoder( |
| 154 const protocol::SessionConfig& config); |
| 155 |
128 EventHandler* event_handler_; | 156 EventHandler* event_handler_; |
129 | 157 |
130 // The connection to the client. | 158 // The connection to the client. |
131 scoped_ptr<protocol::ConnectionToClient> connection_; | 159 scoped_ptr<protocol::ConnectionToClient> connection_; |
132 | 160 |
| 161 // The desktop environment used by this session. |
| 162 scoped_ptr<DesktopEnvironment> desktop_environment_; |
| 163 |
133 std::string client_jid_; | 164 std::string client_jid_; |
134 bool is_authenticated_; | 165 bool is_authenticated_; |
135 | 166 |
136 // The host clipboard and input stubs to which this object delegates. | 167 // The host clipboard and input stubs to which this object delegates. |
137 // These are the final elements in the clipboard & input pipelines, which | 168 // These are the final elements in the clipboard & input pipelines, which |
138 // appear in order below. | 169 // appear in order below. |
139 protocol::ClipboardStub* host_clipboard_stub_; | 170 protocol::ClipboardStub* host_clipboard_stub_; |
140 protocol::InputStub* host_input_stub_; | 171 protocol::InputStub* host_input_stub_; |
141 | 172 |
142 // Tracker used to release pressed keys and buttons when disconnecting. | 173 // Tracker used to release pressed keys and buttons when disconnecting. |
(...skipping 29 matching lines...) Expand all Loading... |
172 VideoFrameCapturer* capturer_; | 203 VideoFrameCapturer* capturer_; |
173 | 204 |
174 // The maximum duration of this session. | 205 // The maximum duration of this session. |
175 // There is no maximum if this value is <= 0. | 206 // There is no maximum if this value is <= 0. |
176 base::TimeDelta max_duration_; | 207 base::TimeDelta max_duration_; |
177 | 208 |
178 // A timer that triggers a disconnect when the maximum session duration | 209 // A timer that triggers a disconnect when the maximum session duration |
179 // is reached. | 210 // is reached. |
180 base::OneShotTimer<ClientSession> max_duration_timer_; | 211 base::OneShotTimer<ClientSession> max_duration_timer_; |
181 | 212 |
| 213 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; |
| 214 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; |
| 215 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
| 216 |
| 217 // Schedulers for audio and video capture. |
| 218 scoped_refptr<AudioScheduler> audio_scheduler_; |
| 219 scoped_refptr<ScreenRecorder> video_recorder_; |
| 220 |
| 221 // Number of screen recorders and audio schedulers that are currently being |
| 222 // used or shutdown. Used to delay shutdown if one or more |
| 223 // recorders/schedulers are asynchronously shutting down. |
| 224 int active_recorders_; |
| 225 |
182 DISALLOW_COPY_AND_ASSIGN(ClientSession); | 226 DISALLOW_COPY_AND_ASSIGN(ClientSession); |
183 }; | 227 }; |
184 | 228 |
185 } // namespace remoting | 229 } // namespace remoting |
186 | 230 |
187 #endif // REMOTING_HOST_CLIENT_SESSION_H_ | 231 #endif // REMOTING_HOST_CLIENT_SESSION_H_ |
OLD | NEW |