| 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/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "third_party/skia/include/core/SkPoint.h" | 25 #include "third_party/skia/include/core/SkPoint.h" |
| 26 #include "third_party/skia/include/core/SkSize.h" | 26 #include "third_party/skia/include/core/SkSize.h" |
| 27 | 27 |
| 28 namespace base { | 28 namespace base { |
| 29 class SingleThreadTaskRunner; | 29 class SingleThreadTaskRunner; |
| 30 } // namespace base | 30 } // namespace base |
| 31 | 31 |
| 32 namespace remoting { | 32 namespace remoting { |
| 33 | 33 |
| 34 class AudioEncoder; | 34 class AudioEncoder; |
| 35 class AudioScheduler; | |
| 36 struct ClientSessionTraits; | 35 struct ClientSessionTraits; |
| 37 class DesktopEnvironment; | 36 class DesktopEnvironment; |
| 38 class DesktopEnvironmentFactory; | 37 class DesktopEnvironmentFactory; |
| 39 class VideoEncoder; | 38 class VideoEncoder; |
| 40 class VideoFrameCapturer; | |
| 41 class VideoScheduler; | |
| 42 | 39 |
| 43 // A ClientSession keeps a reference to a connection to a client, and maintains | 40 // A ClientSession keeps a reference to a connection to a client, and maintains |
| 44 // per-client state. | 41 // per-client state. |
| 45 class ClientSession | 42 class ClientSession |
| 46 : public base::RefCountedThreadSafe<ClientSession, ClientSessionTraits>, | 43 : public base::RefCountedThreadSafe<ClientSession, ClientSessionTraits>, |
| 47 public protocol::HostStub, | 44 public protocol::HostStub, |
| 48 public protocol::ConnectionToClient::EventHandler, | 45 public protocol::ConnectionToClient::EventHandler, |
| 49 public base::NonThreadSafe { | 46 public base::NonThreadSafe { |
| 50 public: | 47 public: |
| 51 // Callback interface for passing events to the ChromotingHost. | 48 // Callback interface for passing events to the ChromotingHost. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 81 |
| 85 protected: | 82 protected: |
| 86 virtual ~EventHandler() {} | 83 virtual ~EventHandler() {} |
| 87 }; | 84 }; |
| 88 | 85 |
| 89 // |event_handler| must outlive |this|. |desktop_environment_factory| is only | 86 // |event_handler| must outlive |this|. |desktop_environment_factory| is only |
| 90 // used by the constructor to create an instance of DesktopEnvironment. | 87 // used by the constructor to create an instance of DesktopEnvironment. |
| 91 ClientSession( | 88 ClientSession( |
| 92 EventHandler* event_handler, | 89 EventHandler* event_handler, |
| 93 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, | 90 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, |
| 91 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
| 94 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner, | 92 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner, |
| 95 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner, | 93 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner, |
| 96 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | 94 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
| 95 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 97 scoped_ptr<protocol::ConnectionToClient> connection, | 96 scoped_ptr<protocol::ConnectionToClient> connection, |
| 98 DesktopEnvironmentFactory* desktop_environment_factory, | 97 DesktopEnvironmentFactory* desktop_environment_factory, |
| 99 const base::TimeDelta& max_duration); | 98 const base::TimeDelta& max_duration); |
| 100 | 99 |
| 101 // protocol::HostStub interface. | 100 // protocol::HostStub interface. |
| 102 virtual void NotifyClientDimensions( | 101 virtual void NotifyClientDimensions( |
| 103 const protocol::ClientDimensions& dimensions) OVERRIDE; | 102 const protocol::ClientDimensions& dimensions) OVERRIDE; |
| 104 virtual void ControlVideo( | 103 virtual void ControlVideo( |
| 105 const protocol::VideoControl& video_control) OVERRIDE; | 104 const protocol::VideoControl& video_control) OVERRIDE; |
| 106 virtual void ControlAudio( | 105 virtual void ControlAudio( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 118 virtual void OnRouteChange( | 117 virtual void OnRouteChange( |
| 119 protocol::ConnectionToClient* connection, | 118 protocol::ConnectionToClient* connection, |
| 120 const std::string& channel_name, | 119 const std::string& channel_name, |
| 121 const protocol::TransportRoute& route) OVERRIDE; | 120 const protocol::TransportRoute& route) OVERRIDE; |
| 122 | 121 |
| 123 // Disconnects the session, tears down transport resources and stops scheduler | 122 // Disconnects the session, tears down transport resources and stops scheduler |
| 124 // components. |event_handler_| is guaranteed not to be called after this | 123 // components. |event_handler_| is guaranteed not to be called after this |
| 125 // method returns. | 124 // method returns. |
| 126 void Disconnect(); | 125 void Disconnect(); |
| 127 | 126 |
| 128 // Stops the ClientSession, and calls |stopped_task| on |network_task_runner_| | 127 // Stops the ClientSession. |
| 129 // when fully stopped. | 128 void Stop(); |
| 130 void Stop(const base::Closure& stopped_task); | |
| 131 | 129 |
| 132 protocol::ConnectionToClient* connection() const { | 130 protocol::ConnectionToClient* connection() const { |
| 133 return connection_.get(); | 131 return connection_.get(); |
| 134 } | 132 } |
| 135 | 133 |
| 136 DesktopEnvironment* desktop_environment() const { | 134 DesktopEnvironment* desktop_environment() const { |
| 137 return desktop_environment_.get(); | 135 return desktop_environment_.get(); |
| 138 } | 136 } |
| 139 | 137 |
| 140 const std::string& client_jid() { return client_jid_; } | 138 const std::string& client_jid() { return client_jid_; } |
| 141 | 139 |
| 142 bool is_authenticated() { return auth_input_filter_.enabled(); } | 140 bool is_authenticated() { return auth_input_filter_.enabled(); } |
| 143 | 141 |
| 144 // Indicate that local mouse activity has been detected. This causes remote | 142 // Indicate that local mouse activity has been detected. This causes remote |
| 145 // inputs to be ignored for a short time so that the local user will always | 143 // inputs to be ignored for a short time so that the local user will always |
| 146 // have the upper hand in 'pointer wars'. | 144 // have the upper hand in 'pointer wars'. |
| 147 void LocalMouseMoved(const SkIPoint& new_pos); | 145 void LocalMouseMoved(const SkIPoint& new_pos); |
| 148 | 146 |
| 149 // Disable handling of input events from this client. If the client has any | 147 // Disable handling of input events from this client. If the client has any |
| 150 // keys or mouse buttons pressed then these will be released. | 148 // keys or mouse buttons pressed then these will be released. |
| 151 void SetDisableInputs(bool disable_inputs); | 149 void SetDisableInputs(bool disable_inputs); |
| 152 | 150 |
| 153 private: | 151 private: |
| 154 friend class base::DeleteHelper<ClientSession>; | 152 friend class base::DeleteHelper<ClientSession>; |
| 155 friend struct ClientSessionTraits; | 153 friend struct ClientSessionTraits; |
| 156 virtual ~ClientSession(); | 154 virtual ~ClientSession(); |
| 157 | 155 |
| 158 // Creates a proxy for sending clipboard events to the client. | |
| 159 scoped_ptr<protocol::ClipboardStub> CreateClipboardProxy(); | |
| 160 | |
| 161 void OnRecorderStopped(); | |
| 162 | |
| 163 // Creates an audio encoder for the specified configuration. | 156 // Creates an audio encoder for the specified configuration. |
| 164 static scoped_ptr<AudioEncoder> CreateAudioEncoder( | 157 static scoped_ptr<AudioEncoder> CreateAudioEncoder( |
| 165 const protocol::SessionConfig& config); | 158 const protocol::SessionConfig& config); |
| 166 | 159 |
| 167 // Creates a video encoder for the specified configuration. | 160 // Creates a video encoder for the specified configuration. |
| 168 static scoped_ptr<VideoEncoder> CreateVideoEncoder( | 161 static scoped_ptr<VideoEncoder> CreateVideoEncoder( |
| 169 const protocol::SessionConfig& config); | 162 const protocol::SessionConfig& config); |
| 170 | 163 |
| 171 EventHandler* event_handler_; | 164 EventHandler* event_handler_; |
| 172 | 165 |
| 173 // The connection to the client. | 166 // The connection to the client. |
| 174 scoped_ptr<protocol::ConnectionToClient> connection_; | 167 scoped_ptr<protocol::ConnectionToClient> connection_; |
| 175 | 168 |
| 176 // Used to disable callbacks to |connection_| once it is disconnected. | 169 // Used to disable callbacks to |connection_| once it is disconnected. |
| 177 base::WeakPtrFactory<protocol::ConnectionToClient> connection_factory_; | 170 base::WeakPtrFactory<protocol::ConnectionToClient> connection_factory_; |
| 178 | 171 |
| 172 std::string client_jid_; |
| 173 |
| 179 // The desktop environment used by this session. | 174 // The desktop environment used by this session. |
| 180 scoped_ptr<DesktopEnvironment> desktop_environment_; | 175 scoped_ptr<DesktopEnvironment> desktop_environment_; |
| 181 | 176 |
| 182 std::string client_jid_; | |
| 183 | |
| 184 // The host clipboard and input stubs to which this object delegates. | 177 // The host clipboard and input stubs to which this object delegates. |
| 185 // These are the final elements in the clipboard & input pipelines, which | 178 // These are the final elements in the clipboard & input pipelines, which |
| 186 // appear in order below. | 179 // appear in order below. |
| 187 protocol::ClipboardStub* host_clipboard_stub_; | 180 protocol::ClipboardStub* host_clipboard_stub_; |
| 188 protocol::InputStub* host_input_stub_; | 181 protocol::InputStub* host_input_stub_; |
| 189 | 182 |
| 190 // Tracker used to release pressed keys and buttons when disconnecting. | 183 // Tracker used to release pressed keys and buttons when disconnecting. |
| 191 protocol::InputEventTracker input_tracker_; | 184 protocol::InputEventTracker input_tracker_; |
| 192 | 185 |
| 193 // Filter used to disable remote inputs during local input activity. | 186 // Filter used to disable remote inputs during local input activity. |
| 194 RemoteInputFilter remote_input_filter_; | 187 RemoteInputFilter remote_input_filter_; |
| 195 | 188 |
| 196 // Filter used to clamp mouse events to the current display dimensions. | 189 // Filter used to clamp mouse events to the current display dimensions. |
| 197 MouseClampingFilter mouse_clamping_filter_; | 190 MouseClampingFilter mouse_clamping_filter_; |
| 198 | 191 |
| 199 // Filter to used to stop clipboard items sent from the client being echoed | 192 // Filter to used to stop clipboard items sent from the client being echoed |
| 200 // back to it. | 193 // back to it. |
| 201 protocol::ClipboardEchoFilter clipboard_echo_filter_; | 194 protocol::ClipboardEchoFilter clipboard_echo_filter_; |
| 202 | 195 |
| 203 // Filters used to manage enabling & disabling of input & clipboard. | 196 // Filters used to manage enabling & disabling of input & clipboard. |
| 204 protocol::InputFilter disable_input_filter_; | 197 protocol::InputFilter disable_input_filter_; |
| 205 protocol::ClipboardFilter disable_clipboard_filter_; | 198 protocol::ClipboardFilter disable_clipboard_filter_; |
| 206 | 199 |
| 207 // Filters used to disable input & clipboard when we're not authenticated. | 200 // Filters used to disable input & clipboard when we're not authenticated. |
| 208 protocol::InputFilter auth_input_filter_; | 201 protocol::InputFilter auth_input_filter_; |
| 209 protocol::ClipboardFilter auth_clipboard_filter_; | 202 protocol::ClipboardFilter auth_clipboard_filter_; |
| 210 | 203 |
| 211 // Factory for weak pointers to the client clipboard stub. | |
| 212 // This must appear after |clipboard_echo_filter_|, so that it won't outlive | |
| 213 // it. | |
| 214 base::WeakPtrFactory<protocol::ClipboardStub> client_clipboard_factory_; | |
| 215 | |
| 216 // The maximum duration of this session. | 204 // The maximum duration of this session. |
| 217 // There is no maximum if this value is <= 0. | 205 // There is no maximum if this value is <= 0. |
| 218 base::TimeDelta max_duration_; | 206 base::TimeDelta max_duration_; |
| 219 | 207 |
| 220 // A timer that triggers a disconnect when the maximum session duration | 208 // A timer that triggers a disconnect when the maximum session duration |
| 221 // is reached. | 209 // is reached. |
| 222 base::OneShotTimer<ClientSession> max_duration_timer_; | 210 base::OneShotTimer<ClientSession> max_duration_timer_; |
| 223 | 211 |
| 224 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; | 212 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; |
| 213 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner_; |
| 225 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner_; | 214 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner_; |
| 226 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner_; | 215 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner_; |
| 227 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 216 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
| 228 | 217 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 229 // Schedulers for audio and video capture. | |
| 230 scoped_refptr<AudioScheduler> audio_scheduler_; | |
| 231 scoped_refptr<VideoScheduler> video_scheduler_; | |
| 232 | |
| 233 // Number of screen recorders and audio schedulers that are currently being | |
| 234 // used or shutdown. Used to delay shutdown if one or more | |
| 235 // recorders/schedulers are asynchronously shutting down. | |
| 236 int active_recorders_; | |
| 237 | |
| 238 // Task to execute once the session is completely stopped. | |
| 239 base::Closure stopped_task_; | |
| 240 | 218 |
| 241 DISALLOW_COPY_AND_ASSIGN(ClientSession); | 219 DISALLOW_COPY_AND_ASSIGN(ClientSession); |
| 242 }; | 220 }; |
| 243 | 221 |
| 244 // Destroys |ClienSession| instances on the network thread. | 222 // Destroys |ClienSession| instances on the network thread. |
| 245 struct ClientSessionTraits { | 223 struct ClientSessionTraits { |
| 246 static void Destruct(const ClientSession* client); | 224 static void Destruct(const ClientSession* client); |
| 247 }; | 225 }; |
| 248 | 226 |
| 249 } // namespace remoting | 227 } // namespace remoting |
| 250 | 228 |
| 251 #endif // REMOTING_HOST_CLIENT_SESSION_H_ | 229 #endif // REMOTING_HOST_CLIENT_SESSION_H_ |
| OLD | NEW |