OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 // Implementation of InputStub using sockets created from jingle connection. | |
6 // It sends messages through the socket after serializing it. | |
7 // | |
8 // Object of this class can only be created by ConnectionToHost. | |
9 // | |
10 // This class can be used on any thread. An object of socket is given to this | |
11 // class, its lifetime is strictly greater than this object. | |
12 | |
13 #ifndef REMOTING_PROTOCOL_INPUT_SENDER_H_ | |
14 #define REMOTING_PROTOCOL_INPUT_SENDER_H_ | |
15 | |
16 #include "base/basictypes.h" | |
17 #include "base/memory/ref_counted.h" | |
18 #include "remoting/protocol/input_stub.h" | |
19 | |
20 class Task; | |
21 | |
22 namespace base { | |
23 class MessageLoopProxy; | |
24 } // namespace base | |
25 | |
26 namespace net { | |
27 class Socket; | |
28 } // namespace net | |
29 | |
30 namespace remoting { | |
31 namespace protocol { | |
32 | |
33 class BufferedSocketWriter; | |
34 | |
35 // Implementation of InputStub that sends messages on a socket. Must | |
36 // be created and closed on the network thread, but can be used on any | |
37 // other thread. | |
38 class InputSender : public InputStub { | |
39 public: | |
40 // Create a stub using a socket. | |
41 explicit InputSender(base::MessageLoopProxy* message_loop, | |
42 net::Socket* socket); | |
43 virtual ~InputSender(); | |
44 | |
45 // InputStub implementation. | |
46 virtual void InjectKeyEvent(const KeyEvent& event); | |
47 virtual void InjectMouseEvent(const MouseEvent& event); | |
48 | |
49 // Stop writing. Must be called on the network thread when the | |
50 // underlying socket is being destroyed. | |
51 void Close(); | |
52 | |
53 private: | |
54 // Helper method to run the task and delete it afterwards. | |
55 void RunTask(Task* done); | |
56 | |
57 // Buffered socket writer holds the serialized message and sends it on the | |
58 // right thread. | |
59 scoped_refptr<BufferedSocketWriter> buffered_writer_; | |
60 | |
61 DISALLOW_COPY_AND_ASSIGN(InputSender); | |
62 }; | |
63 | |
64 } // namespace protocol | |
65 } // namespace remoting | |
66 | |
67 #endif // REMOTING_PROTOCOL_INPUT_SENDER_H_ | |
OLD | NEW |