summaryrefslogtreecommitdiffstats
path: root/remoting/protocol/input_sender.h
blob: cbbdb06f73b677514a6ecde3a1fcfd5026a4470c (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
// Copyright (c) 2010 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.

// Implementation of InputStub using sockets created from jingle connection.
// It sends messages through the socket after serializing it.
//
// Object of this class can only be created by ConnectionToHost.
//
// This class can be used on any thread. An object of socket is given to this
// class, its lifetime is strictly greater than this object.

#ifndef REMOTING_PROTOCOL_INPUT_SENDER_H_
#define REMOTING_PROTOCOL_INPUT_SENDER_H_

#include "base/basictypes.h"
#include "base/ref_counted.h"
#include "remoting/protocol/input_stub.h"

class Task;

namespace net {
class Socket;
}  // namespace net

namespace remoting {
namespace protocol {

class BufferedSocketWriter;

class InputSender : public InputStub {
 public:
  // Create a stub using a socket.
  explicit InputSender(net::Socket* socket);
  virtual ~InputSender();

  // InputStub implementation.
  virtual void InjectKeyEvent(const KeyEvent* event, Task* done);
  virtual void InjectMouseEvent(const MouseEvent* event, Task* done);

 private:
  // Helper method to run the task and delete it afterwards.
  void RunTask(Task* done);

  // Buffered socket writer holds the serialized message and sends it on the
  // right thread.
  scoped_refptr<BufferedSocketWriter> buffered_writer_;

  DISALLOW_COPY_AND_ASSIGN(InputSender);
};

}  // namespace protocol
}  // namespace remoting

#endif  // REMOTING_PROTOCOL_INPUT_SENDER_H_