summaryrefslogtreecommitdiffstats
path: root/remoting/client/chromoting_client.h
blob: a03d5bc17f274ebc3cd7604a22dd754a64a9ecc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ChromotingClient is the controller for the Client implementation.

#ifndef REMOTING_CLIENT_CHROMOTING_CLIENT_H_
#define REMOTING_CLIENT_CHROMOTING_CLIENT_H_

#include <list>

#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "remoting/client/client_config.h"
#include "remoting/client/chromoting_stats.h"
#include "remoting/protocol/client_stub.h"
#include "remoting/protocol/clipboard_stub.h"
#include "remoting/protocol/connection_to_host.h"
#include "remoting/protocol/input_stub.h"
#include "remoting/protocol/video_stub.h"
#include "remoting/jingle_glue/xmpp_proxy.h"

namespace base {
class SingleThreadTaskRunner;
}  // namespace base

namespace remoting {

namespace protocol {
class TransportFactory;
}  // namespace protocol

class AudioDecodeScheduler;
class AudioPlayer;
class ClientContext;
class ClientUserInterface;
class RectangleUpdateDecoder;

class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback,
                         public protocol::ClientStub {
 public:
  // Objects passed in are not owned by this class.
  ChromotingClient(const ClientConfig& config,
                   ClientContext* client_context,
                   protocol::ConnectionToHost* connection,
                   ClientUserInterface* user_interface,
                   RectangleUpdateDecoder* rectangle_decoder,
                   scoped_ptr<AudioPlayer> audio_player);

  virtual ~ChromotingClient();

  // Start/stop the client. Must be called on the main thread.
  void Start(scoped_refptr<XmppProxy> xmpp_proxy,
             scoped_ptr<protocol::TransportFactory> transport_factory);
  void Stop(const base::Closure& shutdown_task);

  // Return the stats recorded by this client.
  ChromotingStats* GetStats();

  // ClipboardStub implementation for receiving clipboard data from host.
  virtual void InjectClipboardEvent(const protocol::ClipboardEvent& event)
      OVERRIDE;

  // CursorShapeStub implementation for receiving cursor shape updates.
  virtual void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape)
      OVERRIDE;

  // ConnectionToHost::HostEventCallback implementation.
  virtual void OnConnectionState(
      protocol::ConnectionToHost::State state,
      protocol::ErrorCode error) OVERRIDE;
  virtual void OnConnectionReady(bool ready) OVERRIDE;

 private:
  // Initializes connection.
  void Initialize();

  void OnDisconnected(const base::Closure& shutdown_task);

  // The following are not owned by this class.
  ClientConfig config_;
  scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
  protocol::ConnectionToHost* connection_;
  ClientUserInterface* user_interface_;
  // TODO(kxing): Make ChromotingClient own RectangleUpdateDecoder.
  RectangleUpdateDecoder* rectangle_decoder_;

  scoped_ptr<AudioDecodeScheduler> audio_decode_scheduler_;

  // If non-NULL, this is called when the client is done.
  base::Closure client_done_;

  // Record the statistics of the connection.
  ChromotingStats stats_;

  // WeakPtr used to avoid tasks accessing the client after it is deleted.
  base::WeakPtrFactory<ChromotingClient> weak_factory_;
  base::WeakPtr<ChromotingClient> weak_ptr_;

  DISALLOW_COPY_AND_ASSIGN(ChromotingClient);
};

}  // namespace remoting

#endif  // REMOTING_CLIENT_CHROMOTING_CLIENT_H_