Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / remoting / host / client_session.h
blob1994144297897e2dc2edc3db623d7238dd765ca8
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.
5 #ifndef REMOTING_HOST_CLIENT_SESSION_H_
6 #define REMOTING_HOST_CLIENT_SESSION_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/sequenced_task_runner_helpers.h"
13 #include "base/threading/non_thread_safe.h"
14 #include "base/time/time.h"
15 #include "base/timer/timer.h"
16 #include "remoting/host/client_session_control.h"
17 #include "remoting/host/gnubby_auth_handler.h"
18 #include "remoting/host/host_extension_session_manager.h"
19 #include "remoting/host/mouse_clamping_filter.h"
20 #include "remoting/host/remote_input_filter.h"
21 #include "remoting/protocol/clipboard_echo_filter.h"
22 #include "remoting/protocol/clipboard_filter.h"
23 #include "remoting/protocol/clipboard_stub.h"
24 #include "remoting/protocol/connection_to_client.h"
25 #include "remoting/protocol/host_stub.h"
26 #include "remoting/protocol/input_event_tracker.h"
27 #include "remoting/protocol/input_filter.h"
28 #include "remoting/protocol/input_stub.h"
29 #include "remoting/protocol/pairing_registry.h"
30 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
32 namespace base {
33 class SingleThreadTaskRunner;
34 } // namespace base
36 namespace remoting {
38 class AudioPump;
39 class DesktopEnvironment;
40 class DesktopEnvironmentFactory;
41 class InputInjector;
42 class MouseShapePump;
43 class ScreenControls;
44 class VideoFramePump;
46 // A ClientSession keeps a reference to a connection to a client, and maintains
47 // per-client state.
48 class ClientSession
49 : public base::NonThreadSafe,
50 public protocol::HostStub,
51 public protocol::ConnectionToClient::EventHandler,
52 public ClientSessionControl {
53 public:
54 // Callback interface for passing events to the ChromotingHost.
55 class EventHandler {
56 public:
57 // Called after authentication has started.
58 virtual void OnSessionAuthenticating(ClientSession* client) = 0;
60 // Called after authentication has finished successfully. Returns true if
61 // the connection is allowed, or false otherwise.
62 virtual bool OnSessionAuthenticated(ClientSession* client) = 0;
64 // Called after we've finished connecting all channels.
65 virtual void OnSessionChannelsConnected(ClientSession* client) = 0;
67 // Called after authentication has failed. Must not tear down this
68 // object. OnSessionClosed() is notified after this handler
69 // returns.
70 virtual void OnSessionAuthenticationFailed(ClientSession* client) = 0;
72 // Called after connection has failed or after the client closed it.
73 virtual void OnSessionClosed(ClientSession* client) = 0;
75 // Called on notification of a route change event, when a channel is
76 // connected.
77 virtual void OnSessionRouteChange(
78 ClientSession* client,
79 const std::string& channel_name,
80 const protocol::TransportRoute& route) = 0;
82 protected:
83 virtual ~EventHandler() {}
86 // |event_handler| and |desktop_environment_factory| must outlive |this|.
87 // All |HostExtension|s in |extensions| must outlive |this|.
88 ClientSession(
89 EventHandler* event_handler,
90 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner,
91 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
92 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner,
93 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner,
94 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
95 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
96 scoped_ptr<protocol::ConnectionToClient> connection,
97 DesktopEnvironmentFactory* desktop_environment_factory,
98 const base::TimeDelta& max_duration,
99 scoped_refptr<protocol::PairingRegistry> pairing_registry,
100 const std::vector<HostExtension*>& extensions);
101 ~ClientSession() override;
103 // Returns the set of capabilities negotiated between client and host.
104 const std::string& capabilities() const { return capabilities_; }
106 // protocol::HostStub interface.
107 void NotifyClientResolution(
108 const protocol::ClientResolution& resolution) override;
109 void ControlVideo(const protocol::VideoControl& video_control) override;
110 void ControlAudio(const protocol::AudioControl& audio_control) override;
111 void SetCapabilities(const protocol::Capabilities& capabilities) override;
112 void RequestPairing(
113 const remoting::protocol::PairingRequest& pairing_request) override;
114 void DeliverClientMessage(const protocol::ExtensionMessage& message) override;
116 // protocol::ConnectionToClient::EventHandler interface.
117 void OnConnectionAuthenticating(
118 protocol::ConnectionToClient* connection) override;
119 void OnConnectionAuthenticated(
120 protocol::ConnectionToClient* connection) override;
121 void OnConnectionChannelsConnected(
122 protocol::ConnectionToClient* connection) override;
123 void OnConnectionClosed(protocol::ConnectionToClient* connection,
124 protocol::ErrorCode error) override;
125 void OnEventTimestamp(protocol::ConnectionToClient* connection,
126 int64 timestamp) override;
127 void OnRouteChange(protocol::ConnectionToClient* connection,
128 const std::string& channel_name,
129 const protocol::TransportRoute& route) override;
131 // ClientSessionControl interface.
132 const std::string& client_jid() const override;
133 void DisconnectSession() override;
134 void OnLocalMouseMoved(const webrtc::DesktopVector& position) override;
135 void SetDisableInputs(bool disable_inputs) override;
136 void ResetVideoPipeline() override;
138 void SetGnubbyAuthHandlerForTesting(GnubbyAuthHandler* gnubby_auth_handler);
140 protocol::ConnectionToClient* connection() const {
141 return connection_.get();
144 bool is_authenticated() { return is_authenticated_; }
146 const std::string* client_capabilities() const {
147 return client_capabilities_.get();
150 private:
151 // Creates a proxy for sending clipboard events to the client.
152 scoped_ptr<protocol::ClipboardStub> CreateClipboardProxy();
154 EventHandler* event_handler_;
156 // The connection to the client.
157 scoped_ptr<protocol::ConnectionToClient> connection_;
159 std::string client_jid_;
161 // Used to create a DesktopEnvironment instance for this session.
162 DesktopEnvironmentFactory* desktop_environment_factory_;
164 // The DesktopEnvironment instance for this session.
165 scoped_ptr<DesktopEnvironment> desktop_environment_;
167 // Filter used as the final element in the input pipeline.
168 protocol::InputFilter host_input_filter_;
170 // Tracker used to release pressed keys and buttons when disconnecting.
171 protocol::InputEventTracker input_tracker_;
173 // Filter used to disable remote inputs during local input activity.
174 RemoteInputFilter remote_input_filter_;
176 // Filter used to clamp mouse events to the current display dimensions.
177 MouseClampingFilter mouse_clamping_filter_;
179 // Filter to used to stop clipboard items sent from the client being echoed
180 // back to it. It is the final element in the clipboard (client -> host)
181 // pipeline.
182 protocol::ClipboardEchoFilter clipboard_echo_filter_;
184 // Filters used to manage enabling & disabling of input & clipboard.
185 protocol::InputFilter disable_input_filter_;
186 protocol::ClipboardFilter disable_clipboard_filter_;
188 // Factory for weak pointers to the client clipboard stub.
189 // This must appear after |clipboard_echo_filter_|, so that it won't outlive
190 // it.
191 base::WeakPtrFactory<protocol::ClipboardStub> client_clipboard_factory_;
193 // The maximum duration of this session.
194 // There is no maximum if this value is <= 0.
195 base::TimeDelta max_duration_;
197 // A timer that triggers a disconnect when the maximum session duration
198 // is reached.
199 base::OneShotTimer<ClientSession> max_duration_timer_;
201 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_;
202 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner_;
203 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner_;
204 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner_;
205 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
206 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
208 // Pumps for audio, video and mouse shape.
209 // |video_frame_pump_| and |mouse_shape_pump_| may be nullptr if the video
210 // stream is handled by an extension, see ResetVideoPipeline().
211 scoped_ptr<AudioPump> audio_pump_;
212 scoped_ptr<VideoFramePump> video_frame_pump_;
213 scoped_ptr<MouseShapePump> mouse_shape_pump_;
215 // The set of all capabilities supported by the client.
216 scoped_ptr<std::string> client_capabilities_;
218 // The set of all capabilities supported by the host.
219 std::string host_capabilities_;
221 // The set of all capabilities negotiated between client and host.
222 std::string capabilities_;
224 // Used to inject mouse and keyboard input and handle clipboard events.
225 scoped_ptr<InputInjector> input_injector_;
227 // Used to apply client-requested changes in screen resolution.
228 scoped_ptr<ScreenControls> screen_controls_;
230 // The pairing registry for PIN-less authentication.
231 scoped_refptr<protocol::PairingRegistry> pairing_registry_;
233 // Used to proxy gnubby auth traffic.
234 scoped_ptr<GnubbyAuthHandler> gnubby_auth_handler_;
236 // Used to manage extension functionality.
237 scoped_ptr<HostExtensionSessionManager> extension_manager_;
239 // Set to true if the client was authenticated successfully.
240 bool is_authenticated_;
242 // Used to store video channel pause & lossless parameters.
243 bool pause_video_;
244 bool lossless_video_encode_;
245 bool lossless_video_color_;
247 // Used to disable callbacks to |this| once DisconnectSession() has been
248 // called.
249 base::WeakPtrFactory<ClientSessionControl> weak_factory_;
251 DISALLOW_COPY_AND_ASSIGN(ClientSession);
254 } // namespace remoting
256 #endif // REMOTING_HOST_CLIENT_SESSION_H_