Ensure low-memory renderers retry failed loads correctly.
[chromium-blink-merge.git] / remoting / client / chromoting_client.h
blobce7fbcf065134edc2fdc5184afa55577ae23705c
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_
10 #include <string>
12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "remoting/protocol/client_stub.h"
15 #include "remoting/protocol/clipboard_stub.h"
16 #include "remoting/protocol/connection_to_host.h"
17 #include "remoting/protocol/connection_to_host_impl.h"
18 #include "remoting/protocol/input_stub.h"
19 #include "remoting/protocol/performance_tracker.h"
20 #include "remoting/protocol/video_stub.h"
22 namespace base {
23 class SingleThreadTaskRunner;
24 } // namespace base
26 namespace remoting {
28 namespace protocol {
29 class CandidateSessionConfig;
30 class TransportFactory;
31 } // namespace protocol
33 class AudioDecodeScheduler;
34 class AudioPlayer;
35 class ClientContext;
36 class ClientUserInterface;
37 class FrameConsumerProxy;
38 class FrameProducer;
39 class VideoRenderer;
40 class SignalStrategy;
42 class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback,
43 public protocol::ClientStub {
44 public:
45 // |client_context|, |user_interface| and |video_renderer| must outlive the
46 // client. |audio_player| may be null, in which case audio will not be
47 // requested.
48 ChromotingClient(ClientContext* client_context,
49 ClientUserInterface* user_interface,
50 VideoRenderer* video_renderer,
51 scoped_ptr<AudioPlayer> audio_player);
53 ~ChromotingClient() override;
55 void set_protocol_config(scoped_ptr<protocol::CandidateSessionConfig> config);
57 // Used to set fake/mock objects for tests which use the ChromotingClient.
58 void SetConnectionToHostForTests(
59 scoped_ptr<protocol::ConnectionToHost> connection_to_host);
61 // Start the client. Must be called on the main thread. |signal_strategy|
62 // must outlive the client.
63 void Start(SignalStrategy* signal_strategy,
64 scoped_ptr<protocol::Authenticator> authenticator,
65 scoped_ptr<protocol::TransportFactory> transport_factory,
66 const std::string& host_jid,
67 const std::string& capabilities);
69 protocol::ConnectionToHost::State connection_state() const {
70 return connection_->state();
73 protocol::ClipboardStub* clipboard_forwarder() {
74 return connection_->clipboard_forwarder();
76 protocol::HostStub* host_stub() { return connection_->host_stub(); }
77 protocol::InputStub* input_stub() { return connection_->input_stub(); }
79 // ClientStub implementation.
80 void SetCapabilities(const protocol::Capabilities& capabilities) override;
81 void SetPairingResponse(
82 const protocol::PairingResponse& pairing_response) override;
83 void DeliverHostMessage(const protocol::ExtensionMessage& message) override;
85 // ClipboardStub implementation for receiving clipboard data from host.
86 void InjectClipboardEvent(const protocol::ClipboardEvent& event) override;
88 // CursorShapeStub implementation for receiving cursor shape updates.
89 void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override;
91 // ConnectionToHost::HostEventCallback implementation.
92 void OnConnectionState(protocol::ConnectionToHost::State state,
93 protocol::ErrorCode error) override;
94 void OnConnectionReady(bool ready) override;
95 void OnRouteChanged(const std::string& channel_name,
96 const protocol::TransportRoute& route) override;
98 private:
99 // Called when the connection is authenticated.
100 void OnAuthenticated();
102 // Called when all channels are connected.
103 void OnChannelsConnected();
105 // The following are not owned by this class.
106 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
107 ClientUserInterface* user_interface_;
108 VideoRenderer* video_renderer_;
110 scoped_ptr<protocol::ConnectionToHost> connection_;
112 scoped_ptr<AudioDecodeScheduler> audio_decode_scheduler_;
114 std::string local_capabilities_;
116 // The set of all capabilities supported by the host.
117 std::string host_capabilities_;
119 // True if |protocol::Capabilities| message has been received.
120 bool host_capabilities_received_;
122 // Record the statistics of the connection.
123 protocol::PerformanceTracker perf_tracker_;
125 DISALLOW_COPY_AND_ASSIGN(ChromotingClient);
128 } // namespace remoting
130 #endif // REMOTING_CLIENT_CHROMOTING_CLIENT_H_