Home | History | Annotate | Download | only in client
      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 RectangleUpdateDecoder;
     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                    scoped_refptr<FrameConsumerProxy> frame_consumer,
     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   FrameProducer* GetFrameProducer();
     61 
     62   // Return the stats recorded by this client.
     63   ChromotingStats* GetStats();
     64 
     65   // ClientStub implementation.
     66   virtual void SetCapabilities(
     67       const protocol::Capabilities& capabilities) OVERRIDE;
     68   virtual void SetPairingResponse(
     69       const protocol::PairingResponse& pairing_response) OVERRIDE;
     70   virtual void DeliverHostMessage(
     71       const protocol::ExtensionMessage& message) OVERRIDE;
     72 
     73   // ClipboardStub implementation for receiving clipboard data from host.
     74   virtual void InjectClipboardEvent(
     75       const protocol::ClipboardEvent& event) OVERRIDE;
     76 
     77   // CursorShapeStub implementation for receiving cursor shape updates.
     78   virtual void SetCursorShape(
     79       const protocol::CursorShapeInfo& cursor_shape) OVERRIDE;
     80 
     81   // ConnectionToHost::HostEventCallback implementation.
     82   virtual void OnConnectionState(
     83       protocol::ConnectionToHost::State state,
     84       protocol::ErrorCode error) OVERRIDE;
     85   virtual void OnConnectionReady(bool ready) OVERRIDE;
     86 
     87  private:
     88   // Called when the connection is authenticated.
     89   void OnAuthenticated();
     90 
     91   // Called when all channels are connected.
     92   void OnChannelsConnected();
     93 
     94   // The following are not owned by this class.
     95   ClientConfig config_;
     96   scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
     97   protocol::ConnectionToHost* connection_;
     98   ClientUserInterface* user_interface_;
     99   scoped_refptr<RectangleUpdateDecoder> rectangle_decoder_;
    100 
    101   scoped_ptr<AudioDecodeScheduler> audio_decode_scheduler_;
    102 
    103   // If non-NULL, this is called when the client is done.
    104   base::Closure client_done_;
    105 
    106   // The set of all capabilities supported by the host.
    107   std::string host_capabilities_;
    108 
    109   // True if |protocol::Capabilities| message has been received.
    110   bool host_capabilities_received_;
    111 
    112   // Record the statistics of the connection.
    113   ChromotingStats stats_;
    114 
    115   // WeakPtr used to avoid tasks accessing the client after it is deleted.
    116   base::WeakPtrFactory<ChromotingClient> weak_factory_;
    117   base::WeakPtr<ChromotingClient> weak_ptr_;
    118 
    119   DISALLOW_COPY_AND_ASSIGN(ChromotingClient);
    120 };
    121 
    122 }  // namespace remoting
    123 
    124 #endif  // REMOTING_CLIENT_CHROMOTING_CLIENT_H_
    125