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.
4
5// ChromotingClient is the controller for the Client implementation.
6
7#ifndef REMOTING_CLIENT_CHROMOTING_CLIENT_H_
8#define REMOTING_CLIENT_CHROMOTING_CLIENT_H_
9
10#include <string>
11
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"
20
21namespace base {
22class SingleThreadTaskRunner;
23}  // namespace base
24
25namespace remoting {
26
27namespace protocol {
28class CandidateSessionConfig;
29class TransportFactory;
30}  // namespace protocol
31
32class AudioDecodeScheduler;
33class AudioPlayer;
34class ClientContext;
35class ClientUserInterface;
36class FrameConsumerProxy;
37class FrameProducer;
38class VideoRenderer;
39class SignalStrategy;
40
41class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback,
42                         public protocol::ClientStub {
43 public:
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);
49
50  virtual ~ChromotingClient();
51
52  void SetProtocolConfigForTests(
53      scoped_ptr<protocol::CandidateSessionConfig> config);
54
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);
62
63  protocol::ConnectionToHost::State connection_state() const {
64    return connection_.state();
65  }
66
67  protocol::ClipboardStub* clipboard_forwarder() {
68    return connection_.clipboard_forwarder();
69  }
70  protocol::HostStub* host_stub() { return connection_.host_stub(); }
71  protocol::InputStub* input_stub() { return connection_.input_stub(); }
72
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;
80
81  // ClipboardStub implementation for receiving clipboard data from host.
82  virtual void InjectClipboardEvent(
83      const protocol::ClipboardEvent& event) OVERRIDE;
84
85  // CursorShapeStub implementation for receiving cursor shape updates.
86  virtual void SetCursorShape(
87      const protocol::CursorShapeInfo& cursor_shape) OVERRIDE;
88
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;
96
97 private:
98  // Called when the connection is authenticated.
99  void OnAuthenticated();
100
101  // Called when all channels are connected.
102  void OnChannelsConnected();
103
104  // The following are not owned by this class.
105  scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
106  ClientUserInterface* user_interface_;
107  VideoRenderer* video_renderer_;
108
109  protocol::ConnectionToHost connection_;
110
111  scoped_ptr<AudioDecodeScheduler> audio_decode_scheduler_;
112
113  std::string local_capabilities_;
114
115  // The set of all capabilities supported by the host.
116  std::string host_capabilities_;
117
118  // True if |protocol::Capabilities| message has been received.
119  bool host_capabilities_received_;
120
121  // Record the statistics of the connection.
122  ChromotingStats stats_;
123
124  DISALLOW_COPY_AND_ASSIGN(ChromotingClient);
125};
126
127}  // namespace remoting
128
129#endif  // REMOTING_CLIENT_CHROMOTING_CLIENT_H_
130