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 "base/memory/weak_ptr.h"
15 #include "remoting/client/client_config.h"
16 #include "remoting/client/chromoting_stats.h"
17 #include "remoting/protocol/client_stub.h"
18 #include "remoting/protocol/clipboard_stub.h"
19 #include "remoting/protocol/connection_to_host.h"
20 #include "remoting/protocol/input_stub.h"
21 #include "remoting/protocol/video_stub.h"
24 class SingleThreadTaskRunner
;
30 class TransportFactory
;
31 } // namespace protocol
33 class AudioDecodeScheduler
;
36 class ClientUserInterface
;
37 class FrameConsumerProxy
;
42 class ChromotingClient
: public protocol::ConnectionToHost::HostEventCallback
,
43 public protocol::ClientStub
{
45 // |audio_player| may be null, in which case audio will not be requested.
46 ChromotingClient(const ClientConfig
& config
,
47 ClientContext
* client_context
,
48 protocol::ConnectionToHost
* connection
,
49 ClientUserInterface
* user_interface
,
50 VideoRenderer
* video_renderer
,
51 scoped_ptr
<AudioPlayer
> audio_player
);
53 virtual ~ChromotingClient();
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::TransportFactory
> transport_factory
);
60 // ClientStub implementation.
61 virtual void SetCapabilities(
62 const protocol::Capabilities
& capabilities
) OVERRIDE
;
63 virtual void SetPairingResponse(
64 const protocol::PairingResponse
& pairing_response
) OVERRIDE
;
65 virtual void DeliverHostMessage(
66 const protocol::ExtensionMessage
& message
) OVERRIDE
;
68 // ClipboardStub implementation for receiving clipboard data from host.
69 virtual void InjectClipboardEvent(
70 const protocol::ClipboardEvent
& event
) OVERRIDE
;
72 // CursorShapeStub implementation for receiving cursor shape updates.
73 virtual void SetCursorShape(
74 const protocol::CursorShapeInfo
& cursor_shape
) OVERRIDE
;
76 // ConnectionToHost::HostEventCallback implementation.
77 virtual void OnConnectionState(
78 protocol::ConnectionToHost::State state
,
79 protocol::ErrorCode error
) OVERRIDE
;
80 virtual void OnConnectionReady(bool ready
) OVERRIDE
;
81 virtual void OnRouteChanged(const std::string
& channel_name
,
82 const protocol::TransportRoute
& route
) OVERRIDE
;
85 // Called when the connection is authenticated.
86 void OnAuthenticated();
88 // Called when all channels are connected.
89 void OnChannelsConnected();
91 // The following are not owned by this class.
93 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
94 protocol::ConnectionToHost
* connection_
;
95 ClientUserInterface
* user_interface_
;
96 VideoRenderer
* video_renderer_
;
98 scoped_ptr
<AudioDecodeScheduler
> audio_decode_scheduler_
;
100 // If non-NULL, this is called when the client is done.
101 base::Closure client_done_
;
103 // The set of all capabilities supported by the host.
104 std::string host_capabilities_
;
106 // True if |protocol::Capabilities| message has been received.
107 bool host_capabilities_received_
;
109 // Record the statistics of the connection.
110 ChromotingStats stats_
;
112 // WeakPtr used to avoid tasks accessing the client after it is deleted.
113 base::WeakPtr
<ChromotingClient
> weak_ptr_
;
114 base::WeakPtrFactory
<ChromotingClient
> weak_factory_
;
116 DISALLOW_COPY_AND_ASSIGN(ChromotingClient
);
119 } // namespace remoting
121 #endif // REMOTING_CLIENT_CHROMOTING_CLIENT_H_