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 // ChromotingClient is the controller for the Client implementation.
7 #ifndef REMOTING_CLIENT_CHROMOTING_CLIENT_H_
8 #define REMOTING_CLIENT_CHROMOTING_CLIENT_H_
12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "remoting/client/chromoting_stats.h"
15 #include "remoting/protocol/client_stub.h"
16 #include "remoting/protocol/clipboard_stub.h"
17 #include "remoting/protocol/connection_to_host.h"
18 #include "remoting/protocol/input_stub.h"
19 #include "remoting/protocol/video_stub.h"
22 class SingleThreadTaskRunner
;
28 class CandidateSessionConfig
;
29 class TransportFactory
;
30 } // namespace protocol
32 class AudioDecodeScheduler
;
35 class ClientUserInterface
;
36 class FrameConsumerProxy
;
41 class ChromotingClient
: public protocol::ConnectionToHost::HostEventCallback
,
42 public protocol::ClientStub
{
44 // |audio_player| may be null, in which case audio will not be requested.
45 ChromotingClient(ClientContext
* client_context
,
46 ClientUserInterface
* user_interface
,
47 VideoRenderer
* video_renderer
,
48 scoped_ptr
<AudioPlayer
> audio_player
);
50 virtual ~ChromotingClient();
52 void SetProtocolConfigForTests(
53 scoped_ptr
<protocol::CandidateSessionConfig
> config
);
55 // Start the client. Must be called on the main thread. |signal_strategy|
56 // must outlive the client.
57 void Start(SignalStrategy
* signal_strategy
,
58 scoped_ptr
<protocol::Authenticator
> authenticator
,
59 scoped_ptr
<protocol::TransportFactory
> transport_factory
,
60 const std::string
& host_jid
,
61 const std::string
& capabilities
);
63 protocol::ConnectionToHost::State
connection_state() const {
64 return connection_
.state();
67 protocol::ClipboardStub
* clipboard_forwarder() {
68 return connection_
.clipboard_forwarder();
70 protocol::HostStub
* host_stub() { return connection_
.host_stub(); }
71 protocol::InputStub
* input_stub() { return connection_
.input_stub(); }
73 // ClientStub implementation.
74 virtual void SetCapabilities(
75 const protocol::Capabilities
& capabilities
) OVERRIDE
;
76 virtual void SetPairingResponse(
77 const protocol::PairingResponse
& pairing_response
) OVERRIDE
;
78 virtual void DeliverHostMessage(
79 const protocol::ExtensionMessage
& message
) OVERRIDE
;
81 // ClipboardStub implementation for receiving clipboard data from host.
82 virtual void InjectClipboardEvent(
83 const protocol::ClipboardEvent
& event
) OVERRIDE
;
85 // CursorShapeStub implementation for receiving cursor shape updates.
86 virtual void SetCursorShape(
87 const protocol::CursorShapeInfo
& cursor_shape
) OVERRIDE
;
89 // ConnectionToHost::HostEventCallback implementation.
90 virtual void OnConnectionState(
91 protocol::ConnectionToHost::State state
,
92 protocol::ErrorCode error
) OVERRIDE
;
93 virtual void OnConnectionReady(bool ready
) OVERRIDE
;
94 virtual void OnRouteChanged(const std::string
& channel_name
,
95 const protocol::TransportRoute
& route
) OVERRIDE
;
98 // Called when the connection is authenticated.
99 void OnAuthenticated();
101 // Called when all channels are connected.
102 void OnChannelsConnected();
104 // The following are not owned by this class.
105 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
106 ClientUserInterface
* user_interface_
;
107 VideoRenderer
* video_renderer_
;
109 protocol::ConnectionToHost connection_
;
111 scoped_ptr
<AudioDecodeScheduler
> audio_decode_scheduler_
;
113 std::string local_capabilities_
;
115 // The set of all capabilities supported by the host.
116 std::string host_capabilities_
;
118 // True if |protocol::Capabilities| message has been received.
119 bool host_capabilities_received_
;
121 // Record the statistics of the connection.
122 ChromotingStats stats_
;
124 DISALLOW_COPY_AND_ASSIGN(ChromotingClient
);
127 } // namespace remoting
129 #endif // REMOTING_CLIENT_CHROMOTING_CLIENT_H_