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_
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/mouse_clamping_filter.h"
18 #include "remoting/host/remote_input_filter.h"
19 #include "remoting/protocol/clipboard_echo_filter.h"
20 #include "remoting/protocol/clipboard_filter.h"
21 #include "remoting/protocol/clipboard_stub.h"
22 #include "remoting/protocol/connection_to_client.h"
23 #include "remoting/protocol/host_stub.h"
24 #include "remoting/protocol/input_event_tracker.h"
25 #include "remoting/protocol/input_filter.h"
26 #include "remoting/protocol/input_stub.h"
27 #include "remoting/protocol/pairing_registry.h"
28 #include "third_party/skia/include/core/SkPoint.h"
29 #include "third_party/skia/include/core/SkSize.h"
32 class SingleThreadTaskRunner
;
39 class DesktopEnvironment
;
40 class DesktopEnvironmentFactory
;
46 // A ClientSession keeps a reference to a connection to a client, and maintains
49 : public base::NonThreadSafe
,
50 public protocol::HostStub
,
51 public protocol::ConnectionToClient::EventHandler
,
52 public ClientSessionControl
{
54 // Callback interface for passing events to the ChromotingHost.
57 // Called after authentication has finished successfully. Returns true if
58 // the connection is allowed, or false otherwise.
59 virtual bool OnSessionAuthenticated(ClientSession
* client
) = 0;
61 // Called after we've finished connecting all channels.
62 virtual void OnSessionChannelsConnected(ClientSession
* client
) = 0;
64 // Called after authentication has failed. Must not tear down this
65 // object. OnSessionClosed() is notified after this handler
67 virtual void OnSessionAuthenticationFailed(ClientSession
* client
) = 0;
69 // Called after connection has failed or after the client closed it.
70 virtual void OnSessionClosed(ClientSession
* client
) = 0;
72 // Called to notify of each message's sequence number. The
73 // callback must not tear down this object.
74 virtual void OnSessionSequenceNumber(ClientSession
* client
,
75 int64 sequence_number
) = 0;
77 // Called on notification of a route change event, when a channel is
79 virtual void OnSessionRouteChange(
80 ClientSession
* client
,
81 const std::string
& channel_name
,
82 const protocol::TransportRoute
& route
) = 0;
85 virtual ~EventHandler() {}
88 // |event_handler| and |desktop_environment_factory| must outlive |this|.
90 EventHandler
* event_handler
,
91 scoped_refptr
<base::SingleThreadTaskRunner
> audio_task_runner
,
92 scoped_refptr
<base::SingleThreadTaskRunner
> input_task_runner
,
93 scoped_refptr
<base::SingleThreadTaskRunner
> video_capture_task_runner
,
94 scoped_refptr
<base::SingleThreadTaskRunner
> video_encode_task_runner
,
95 scoped_refptr
<base::SingleThreadTaskRunner
> network_task_runner
,
96 scoped_refptr
<base::SingleThreadTaskRunner
> ui_task_runner
,
97 scoped_ptr
<protocol::ConnectionToClient
> connection
,
98 DesktopEnvironmentFactory
* desktop_environment_factory
,
99 const base::TimeDelta
& max_duration
,
100 scoped_refptr
<protocol::PairingRegistry
> pairing_registry
);
101 virtual ~ClientSession();
103 // protocol::HostStub interface.
104 virtual void NotifyClientResolution(
105 const protocol::ClientResolution
& resolution
) OVERRIDE
;
106 virtual void ControlVideo(
107 const protocol::VideoControl
& video_control
) OVERRIDE
;
108 virtual void ControlAudio(
109 const protocol::AudioControl
& audio_control
) OVERRIDE
;
110 virtual void SetCapabilities(
111 const protocol::Capabilities
& capabilities
) OVERRIDE
;
112 virtual void RequestPairing(
113 const remoting::protocol::PairingRequest
& pairing_request
) OVERRIDE
;
114 virtual void DeliverClientMessage(
115 const protocol::ExtensionMessage
& message
) OVERRIDE
;
117 // protocol::ConnectionToClient::EventHandler interface.
118 virtual void OnConnectionAuthenticated(
119 protocol::ConnectionToClient
* connection
) OVERRIDE
;
120 virtual void OnConnectionChannelsConnected(
121 protocol::ConnectionToClient
* connection
) OVERRIDE
;
122 virtual void OnConnectionClosed(protocol::ConnectionToClient
* connection
,
123 protocol::ErrorCode error
) OVERRIDE
;
124 virtual void OnSequenceNumberUpdated(
125 protocol::ConnectionToClient
* connection
, int64 sequence_number
) OVERRIDE
;
126 virtual void OnRouteChange(
127 protocol::ConnectionToClient
* connection
,
128 const std::string
& channel_name
,
129 const protocol::TransportRoute
& route
) OVERRIDE
;
131 // ClientSessionControl interface.
132 virtual const std::string
& client_jid() const OVERRIDE
;
133 virtual void DisconnectSession() OVERRIDE
;
134 virtual void OnLocalMouseMoved(const SkIPoint
& position
) OVERRIDE
;
135 virtual void SetDisableInputs(bool disable_inputs
) OVERRIDE
;
137 protocol::ConnectionToClient
* connection() const {
138 return connection_
.get();
141 bool is_authenticated() { return auth_input_filter_
.enabled(); }
144 // Creates a proxy for sending clipboard events to the client.
145 scoped_ptr
<protocol::ClipboardStub
> CreateClipboardProxy();
147 // Creates an audio encoder for the specified configuration.
148 static scoped_ptr
<AudioEncoder
> CreateAudioEncoder(
149 const protocol::SessionConfig
& config
);
151 // Creates a video encoder for the specified configuration.
152 static scoped_ptr
<VideoEncoder
> CreateVideoEncoder(
153 const protocol::SessionConfig
& config
);
155 EventHandler
* event_handler_
;
157 // The connection to the client.
158 scoped_ptr
<protocol::ConnectionToClient
> connection_
;
160 std::string client_jid_
;
162 // Used to disable callbacks to |this| once DisconnectSession() has been
164 base::WeakPtrFactory
<ClientSessionControl
> control_factory_
;
166 // Used to create a DesktopEnvironment instance for this session.
167 DesktopEnvironmentFactory
* desktop_environment_factory_
;
169 // The DesktopEnvironment instance for this session.
170 scoped_ptr
<DesktopEnvironment
> desktop_environment_
;
172 // Filter used as the final element in the input pipeline.
173 protocol::InputFilter host_input_filter_
;
175 // Tracker used to release pressed keys and buttons when disconnecting.
176 protocol::InputEventTracker input_tracker_
;
178 // Filter used to disable remote inputs during local input activity.
179 RemoteInputFilter remote_input_filter_
;
181 // Filter used to clamp mouse events to the current display dimensions.
182 MouseClampingFilter mouse_clamping_filter_
;
184 // Filter to used to stop clipboard items sent from the client being echoed
185 // back to it. It is the final element in the clipboard (client -> host)
187 protocol::ClipboardEchoFilter clipboard_echo_filter_
;
189 // Filters used to manage enabling & disabling of input & clipboard.
190 protocol::InputFilter disable_input_filter_
;
191 protocol::ClipboardFilter disable_clipboard_filter_
;
193 // Filters used to disable input & clipboard when we're not authenticated.
194 protocol::InputFilter auth_input_filter_
;
195 protocol::ClipboardFilter auth_clipboard_filter_
;
197 // Factory for weak pointers to the client clipboard stub.
198 // This must appear after |clipboard_echo_filter_|, so that it won't outlive
200 base::WeakPtrFactory
<protocol::ClipboardStub
> client_clipboard_factory_
;
202 // The maximum duration of this session.
203 // There is no maximum if this value is <= 0.
204 base::TimeDelta max_duration_
;
206 // A timer that triggers a disconnect when the maximum session duration
208 base::OneShotTimer
<ClientSession
> max_duration_timer_
;
210 scoped_refptr
<base::SingleThreadTaskRunner
> audio_task_runner_
;
211 scoped_refptr
<base::SingleThreadTaskRunner
> input_task_runner_
;
212 scoped_refptr
<base::SingleThreadTaskRunner
> video_capture_task_runner_
;
213 scoped_refptr
<base::SingleThreadTaskRunner
> video_encode_task_runner_
;
214 scoped_refptr
<base::SingleThreadTaskRunner
> network_task_runner_
;
215 scoped_refptr
<base::SingleThreadTaskRunner
> ui_task_runner_
;
217 // Schedulers for audio and video capture.
218 scoped_refptr
<AudioScheduler
> audio_scheduler_
;
219 scoped_refptr
<VideoScheduler
> video_scheduler_
;
221 // The set of all capabilities supported by the client.
222 scoped_ptr
<std::string
> client_capabilities_
;
224 // The set of all capabilities supported by the host.
225 std::string host_capabilities_
;
227 // Used to inject mouse and keyboard input and handle clipboard events.
228 scoped_ptr
<InputInjector
> input_injector_
;
230 // Used to apply client-requested changes in screen resolution.
231 scoped_ptr
<ScreenControls
> screen_controls_
;
233 // The pairing registry for PIN-less authentication.
234 scoped_refptr
<protocol::PairingRegistry
> pairing_registry_
;
236 DISALLOW_COPY_AND_ASSIGN(ClientSession
);
239 } // namespace remoting
241 #endif // REMOTING_HOST_CLIENT_SESSION_H_