Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / remoting / client / chromoting_client.h
blobd6fc09bc2b8964850074d5899e1cfc0a0a244a99
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 <list>
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 #include "remoting/jingle_glue/xmpp_proxy.h"
24 namespace base {
25 class SingleThreadTaskRunner;
26 } // namespace base
28 namespace remoting {
30 namespace protocol {
31 class TransportFactory;
32 } // namespace protocol
34 class AudioDecodeScheduler;
35 class AudioPlayer;
36 class ClientContext;
37 class ClientUserInterface;
38 class FrameConsumerProxy;
39 class FrameProducer;
40 class RectangleUpdateDecoder;
42 class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback,
43 public protocol::ClientStub {
44 public:
45 ChromotingClient(const ClientConfig& config,
46 ClientContext* client_context,
47 protocol::ConnectionToHost* connection,
48 ClientUserInterface* user_interface,
49 scoped_refptr<FrameConsumerProxy> frame_consumer,
50 scoped_ptr<AudioPlayer> audio_player);
52 virtual ~ChromotingClient();
54 // Start/stop the client. Must be called on the main thread.
55 void Start(scoped_refptr<XmppProxy> xmpp_proxy,
56 scoped_ptr<protocol::TransportFactory> transport_factory);
57 void Stop(const base::Closure& shutdown_task);
59 FrameProducer* GetFrameProducer();
61 // Return the stats recorded by this client.
62 ChromotingStats* GetStats();
64 // ClipboardStub implementation for receiving clipboard data from host.
65 virtual void InjectClipboardEvent(const protocol::ClipboardEvent& event)
66 OVERRIDE;
68 // CursorShapeStub implementation for receiving cursor shape updates.
69 virtual void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape)
70 OVERRIDE;
72 // ConnectionToHost::HostEventCallback implementation.
73 virtual void OnConnectionState(
74 protocol::ConnectionToHost::State state,
75 protocol::ErrorCode error) OVERRIDE;
76 virtual void OnConnectionReady(bool ready) OVERRIDE;
78 private:
79 // Initializes connection.
80 void Initialize();
82 void OnDisconnected(const base::Closure& shutdown_task);
84 // The following are not owned by this class.
85 ClientConfig config_;
86 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
87 protocol::ConnectionToHost* connection_;
88 ClientUserInterface* user_interface_;
89 scoped_refptr<RectangleUpdateDecoder> rectangle_decoder_;
91 scoped_ptr<AudioDecodeScheduler> audio_decode_scheduler_;
93 // If non-NULL, this is called when the client is done.
94 base::Closure client_done_;
96 // Record the statistics of the connection.
97 ChromotingStats stats_;
99 // WeakPtr used to avoid tasks accessing the client after it is deleted.
100 base::WeakPtrFactory<ChromotingClient> weak_factory_;
101 base::WeakPtr<ChromotingClient> weak_ptr_;
103 DISALLOW_COPY_AND_ASSIGN(ChromotingClient);
106 } // namespace remoting
108 #endif // REMOTING_CLIENT_CHROMOTING_CLIENT_H_