• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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"
22 
23 namespace base {
24 class SingleThreadTaskRunner;
25 }  // namespace base
26 
27 namespace remoting {
28 
29 namespace protocol {
30 class TransportFactory;
31 }  // namespace protocol
32 
33 class AudioDecodeScheduler;
34 class AudioPlayer;
35 class ClientContext;
36 class ClientUserInterface;
37 class FrameConsumerProxy;
38 class FrameProducer;
39 class VideoRenderer;
40 class SignalStrategy;
41 
42 class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback,
43                          public protocol::ClientStub {
44  public:
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);
52 
53   virtual ~ChromotingClient();
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::TransportFactory> transport_factory);
59 
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;
67 
68   // ClipboardStub implementation for receiving clipboard data from host.
69   virtual void InjectClipboardEvent(
70       const protocol::ClipboardEvent& event) OVERRIDE;
71 
72   // CursorShapeStub implementation for receiving cursor shape updates.
73   virtual void SetCursorShape(
74       const protocol::CursorShapeInfo& cursor_shape) OVERRIDE;
75 
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;
83 
84  private:
85   // Called when the connection is authenticated.
86   void OnAuthenticated();
87 
88   // Called when all channels are connected.
89   void OnChannelsConnected();
90 
91   // The following are not owned by this class.
92   ClientConfig config_;
93   scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
94   protocol::ConnectionToHost* connection_;
95   ClientUserInterface* user_interface_;
96   VideoRenderer* video_renderer_;
97 
98   scoped_ptr<AudioDecodeScheduler> audio_decode_scheduler_;
99 
100   // If non-NULL, this is called when the client is done.
101   base::Closure client_done_;
102 
103   // The set of all capabilities supported by the host.
104   std::string host_capabilities_;
105 
106   // True if |protocol::Capabilities| message has been received.
107   bool host_capabilities_received_;
108 
109   // Record the statistics of the connection.
110   ChromotingStats stats_;
111 
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_;
115 
116   DISALLOW_COPY_AND_ASSIGN(ChromotingClient);
117 };
118 
119 }  // namespace remoting
120 
121 #endif  // REMOTING_CLIENT_CHROMOTING_CLIENT_H_
122