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" |
| 11 #include "base/sequenced_task_runner_helpers.h" |
10 #include "base/time.h" | 12 #include "base/time.h" |
11 #include "base/timer.h" | 13 #include "base/timer.h" |
12 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
13 #include "remoting/host/mouse_clamping_filter.h" | 15 #include "remoting/host/mouse_clamping_filter.h" |
14 #include "remoting/host/remote_input_filter.h" | 16 #include "remoting/host/remote_input_filter.h" |
15 #include "remoting/protocol/clipboard_echo_filter.h" | 17 #include "remoting/protocol/clipboard_echo_filter.h" |
16 #include "remoting/protocol/clipboard_filter.h" | 18 #include "remoting/protocol/clipboard_filter.h" |
17 #include "remoting/protocol/clipboard_stub.h" | 19 #include "remoting/protocol/clipboard_stub.h" |
18 #include "remoting/protocol/connection_to_client.h" | 20 #include "remoting/protocol/connection_to_client.h" |
19 #include "remoting/protocol/host_stub.h" | 21 #include "remoting/protocol/host_stub.h" |
20 #include "remoting/protocol/input_event_tracker.h" | 22 #include "remoting/protocol/input_event_tracker.h" |
21 #include "remoting/protocol/input_filter.h" | 23 #include "remoting/protocol/input_filter.h" |
22 #include "remoting/protocol/input_stub.h" | 24 #include "remoting/protocol/input_stub.h" |
23 #include "third_party/skia/include/core/SkPoint.h" | 25 #include "third_party/skia/include/core/SkPoint.h" |
24 | 26 |
| 27 namespace base { |
| 28 class SingleThreadTaskRunner; |
| 29 } // namespace base |
| 30 |
25 namespace remoting { | 31 namespace remoting { |
26 | 32 |
| 33 class AudioEncoder; |
| 34 class AudioScheduler; |
| 35 struct ClientSessionTraits; |
| 36 class DesktopEnvironment; |
| 37 class ScreenRecorder; |
| 38 class VideoEncoder; |
27 class VideoFrameCapturer; | 39 class VideoFrameCapturer; |
28 | 40 |
29 // A ClientSession keeps a reference to a connection to a client, and maintains | 41 // A ClientSession keeps a reference to a connection to a client, and maintains |
30 // per-client state. | 42 // per-client state. |
31 class ClientSession : public protocol::HostStub, | 43 class ClientSession |
32 public protocol::ConnectionToClient::EventHandler, | 44 : public base::RefCountedThreadSafe<ClientSession, ClientSessionTraits>, |
33 public base::NonThreadSafe { | 45 public protocol::HostStub, |
| 46 public protocol::ConnectionToClient::EventHandler, |
| 47 public base::NonThreadSafe { |
34 public: | 48 public: |
35 // Callback interface for passing events to the ChromotingHost. | 49 // Callback interface for passing events to the ChromotingHost. |
36 class EventHandler { | 50 class EventHandler { |
37 public: | 51 public: |
38 // Called after authentication has finished successfully. | 52 // Called after authentication has finished successfully. |
39 virtual void OnSessionAuthenticated(ClientSession* client) = 0; | 53 virtual void OnSessionAuthenticated(ClientSession* client) = 0; |
40 | 54 |
41 // Called after we've finished connecting all channels. | 55 // Called after we've finished connecting all channels. |
42 virtual void OnSessionChannelsConnected(ClientSession* client) = 0; | 56 virtual void OnSessionChannelsConnected(ClientSession* client) = 0; |
43 | 57 |
(...skipping 15 matching lines...) Expand all Loading... |
59 virtual void OnSessionRouteChange( | 73 virtual void OnSessionRouteChange( |
60 ClientSession* client, | 74 ClientSession* client, |
61 const std::string& channel_name, | 75 const std::string& channel_name, |
62 const protocol::TransportRoute& route) = 0; | 76 const protocol::TransportRoute& route) = 0; |
63 | 77 |
64 protected: | 78 protected: |
65 virtual ~EventHandler() {} | 79 virtual ~EventHandler() {} |
66 }; | 80 }; |
67 | 81 |
68 ClientSession(EventHandler* event_handler, | 82 ClientSession(EventHandler* event_handler, |
| 83 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, |
| 84 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, |
| 85 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
69 scoped_ptr<protocol::ConnectionToClient> connection, | 86 scoped_ptr<protocol::ConnectionToClient> connection, |
70 protocol::ClipboardStub* host_clipboard_stub, | 87 scoped_ptr<DesktopEnvironment> desktop_environment, |
71 protocol::InputStub* host_input_stub, | |
72 VideoFrameCapturer* capturer, | |
73 const base::TimeDelta& max_duration); | 88 const base::TimeDelta& max_duration); |
74 virtual ~ClientSession(); | |
75 | 89 |
76 // protocol::HostStub interface. | 90 // protocol::HostStub interface. |
77 virtual void NotifyClientDimensions( | 91 virtual void NotifyClientDimensions( |
78 const protocol::ClientDimensions& dimensions) OVERRIDE; | 92 const protocol::ClientDimensions& dimensions) OVERRIDE; |
79 virtual void ControlVideo( | 93 virtual void ControlVideo( |
80 const protocol::VideoControl& video_control) OVERRIDE; | 94 const protocol::VideoControl& video_control) OVERRIDE; |
81 | 95 |
82 // protocol::ConnectionToClient::EventHandler interface. | 96 // protocol::ConnectionToClient::EventHandler interface. |
83 virtual void OnConnectionAuthenticated( | 97 virtual void OnConnectionAuthenticated( |
84 protocol::ConnectionToClient* connection) OVERRIDE; | 98 protocol::ConnectionToClient* connection) OVERRIDE; |
85 virtual void OnConnectionChannelsConnected( | 99 virtual void OnConnectionChannelsConnected( |
86 protocol::ConnectionToClient* connection) OVERRIDE; | 100 protocol::ConnectionToClient* connection) OVERRIDE; |
87 virtual void OnConnectionClosed(protocol::ConnectionToClient* connection, | 101 virtual void OnConnectionClosed(protocol::ConnectionToClient* connection, |
88 protocol::ErrorCode error) OVERRIDE; | 102 protocol::ErrorCode error) OVERRIDE; |
89 virtual void OnSequenceNumberUpdated( | 103 virtual void OnSequenceNumberUpdated( |
90 protocol::ConnectionToClient* connection, int64 sequence_number) OVERRIDE; | 104 protocol::ConnectionToClient* connection, int64 sequence_number) OVERRIDE; |
91 virtual void OnRouteChange( | 105 virtual void OnRouteChange( |
92 protocol::ConnectionToClient* connection, | 106 protocol::ConnectionToClient* connection, |
93 const std::string& channel_name, | 107 const std::string& channel_name, |
94 const protocol::TransportRoute& route) OVERRIDE; | 108 const protocol::TransportRoute& route) OVERRIDE; |
95 | 109 |
96 // Disconnects the session and destroys the transport. Event handler | 110 // Disconnects the session and destroys the transport. Event handler |
97 // is guaranteed not to be called after this method is called. Can | 111 // is guaranteed not to be called after this method is called. The object |
98 // be called multiple times. The object should not be used after | 112 // should not be used after this method returns. |
99 // this method returns. | |
100 void Disconnect(); | 113 void Disconnect(); |
101 | 114 |
| 115 // Stop all recorders asynchronously. |done_task| is executed when the session |
| 116 // is completely stopped. |
| 117 void Stop(const base::Closure& done_task); |
| 118 |
102 protocol::ConnectionToClient* connection() const { | 119 protocol::ConnectionToClient* connection() const { |
103 return connection_.get(); | 120 return connection_.get(); |
104 } | 121 } |
105 | 122 |
| 123 DesktopEnvironment* desktop_environment() const { |
| 124 return desktop_environment_.get(); |
| 125 } |
| 126 |
106 const std::string& client_jid() { return client_jid_; } | 127 const std::string& client_jid() { return client_jid_; } |
107 | 128 |
108 bool is_authenticated() { return auth_input_filter_.enabled(); } | 129 bool is_authenticated() { return auth_input_filter_.enabled(); } |
109 | 130 |
110 // Indicate that local mouse activity has been detected. This causes remote | 131 // Indicate that local mouse activity has been detected. This causes remote |
111 // inputs to be ignored for a short time so that the local user will always | 132 // inputs to be ignored for a short time so that the local user will always |
112 // have the upper hand in 'pointer wars'. | 133 // have the upper hand in 'pointer wars'. |
113 void LocalMouseMoved(const SkIPoint& new_pos); | 134 void LocalMouseMoved(const SkIPoint& new_pos); |
114 | 135 |
115 // Disable handling of input events from this client. If the client has any | 136 // Disable handling of input events from this client. If the client has any |
116 // keys or mouse buttons pressed then these will be released. | 137 // keys or mouse buttons pressed then these will be released. |
117 void SetDisableInputs(bool disable_inputs); | 138 void SetDisableInputs(bool disable_inputs); |
118 | 139 |
| 140 private: |
| 141 friend class base::DeleteHelper<ClientSession>; |
| 142 friend struct ClientSessionTraits; |
| 143 virtual ~ClientSession(); |
| 144 |
119 // Creates a proxy for sending clipboard events to the client. | 145 // Creates a proxy for sending clipboard events to the client. |
120 scoped_ptr<protocol::ClipboardStub> CreateClipboardProxy(); | 146 scoped_ptr<protocol::ClipboardStub> CreateClipboardProxy(); |
121 | 147 |
122 private: | 148 void OnRecorderStopped(); |
| 149 |
| 150 // Creates an audio encoder for the specified configuration. |
| 151 static scoped_ptr<AudioEncoder> CreateAudioEncoder( |
| 152 const protocol::SessionConfig& config); |
| 153 |
| 154 // Creates a video encoder for the specified configuration. |
| 155 static VideoEncoder* CreateVideoEncoder( |
| 156 const protocol::SessionConfig& config); |
| 157 |
123 EventHandler* event_handler_; | 158 EventHandler* event_handler_; |
124 | 159 |
125 // The connection to the client. | 160 // The connection to the client. |
126 scoped_ptr<protocol::ConnectionToClient> connection_; | 161 scoped_ptr<protocol::ConnectionToClient> connection_; |
127 | 162 |
| 163 // The desktop environment used by this session. |
| 164 scoped_ptr<DesktopEnvironment> desktop_environment_; |
| 165 |
128 std::string client_jid_; | 166 std::string client_jid_; |
129 | 167 |
130 // The host clipboard and input stubs to which this object delegates. | 168 // The host clipboard and input stubs to which this object delegates. |
131 // These are the final elements in the clipboard & input pipelines, which | 169 // These are the final elements in the clipboard & input pipelines, which |
132 // appear in order below. | 170 // appear in order below. |
133 protocol::ClipboardStub* host_clipboard_stub_; | 171 protocol::ClipboardStub* host_clipboard_stub_; |
134 protocol::InputStub* host_input_stub_; | 172 protocol::InputStub* host_input_stub_; |
135 | 173 |
136 // Tracker used to release pressed keys and buttons when disconnecting. | 174 // Tracker used to release pressed keys and buttons when disconnecting. |
137 protocol::InputEventTracker input_tracker_; | 175 protocol::InputEventTracker input_tracker_; |
(...skipping 14 matching lines...) Expand all Loading... |
152 | 190 |
153 // Filters used to disable input & clipboard when we're not authenticated. | 191 // Filters used to disable input & clipboard when we're not authenticated. |
154 protocol::InputFilter auth_input_filter_; | 192 protocol::InputFilter auth_input_filter_; |
155 protocol::ClipboardFilter auth_clipboard_filter_; | 193 protocol::ClipboardFilter auth_clipboard_filter_; |
156 | 194 |
157 // Factory for weak pointers to the client clipboard stub. | 195 // Factory for weak pointers to the client clipboard stub. |
158 // This must appear after |clipboard_echo_filter_|, so that it won't outlive | 196 // This must appear after |clipboard_echo_filter_|, so that it won't outlive |
159 // it. | 197 // it. |
160 base::WeakPtrFactory<protocol::ClipboardStub> client_clipboard_factory_; | 198 base::WeakPtrFactory<protocol::ClipboardStub> client_clipboard_factory_; |
161 | 199 |
162 // VideoFrameCapturer, used to determine current screen size for ensuring | |
163 // injected mouse events fall within the screen area. | |
164 // TODO(lambroslambrou): Move floor-control logic, and clamping to screen | |
165 // area, out of this class (crbug.com/96508). | |
166 VideoFrameCapturer* capturer_; | |
167 | |
168 // The maximum duration of this session. | 200 // The maximum duration of this session. |
169 // There is no maximum if this value is <= 0. | 201 // There is no maximum if this value is <= 0. |
170 base::TimeDelta max_duration_; | 202 base::TimeDelta max_duration_; |
171 | 203 |
172 // A timer that triggers a disconnect when the maximum session duration | 204 // A timer that triggers a disconnect when the maximum session duration |
173 // is reached. | 205 // is reached. |
174 base::OneShotTimer<ClientSession> max_duration_timer_; | 206 base::OneShotTimer<ClientSession> max_duration_timer_; |
175 | 207 |
| 208 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; |
| 209 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; |
| 210 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
| 211 |
| 212 // Schedulers for audio and video capture. |
| 213 scoped_refptr<AudioScheduler> audio_scheduler_; |
| 214 scoped_refptr<ScreenRecorder> video_recorder_; |
| 215 |
| 216 // Number of screen recorders and audio schedulers that are currently being |
| 217 // used or shutdown. Used to delay shutdown if one or more |
| 218 // recorders/schedulers are asynchronously shutting down. |
| 219 int active_recorders_; |
| 220 |
| 221 // The task to be executed when the session is completely stopped. |
| 222 base::Closure done_task_; |
| 223 |
176 DISALLOW_COPY_AND_ASSIGN(ClientSession); | 224 DISALLOW_COPY_AND_ASSIGN(ClientSession); |
177 }; | 225 }; |
178 | 226 |
| 227 // Destroys |ClienSession| instances on the network thread. |
| 228 struct ClientSessionTraits { |
| 229 static void Destruct(const ClientSession* client); |
| 230 }; |
| 231 |
179 } // namespace remoting | 232 } // namespace remoting |
180 | 233 |
181 #endif // REMOTING_HOST_CLIENT_SESSION_H_ | 234 #endif // REMOTING_HOST_CLIENT_SESSION_H_ |
OLD | NEW |