OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/protocol/host_event_dispatcher.h" | 5 #include "remoting/protocol/host_event_dispatcher.h" |
6 | 6 |
| 7 #include "base/memory/ref_counted.h" |
7 #include "net/socket/stream_socket.h" | 8 #include "net/socket/stream_socket.h" |
8 #include "remoting/base/compound_buffer.h" | 9 #include "remoting/base/compound_buffer.h" |
9 #include "remoting/base/constants.h" | 10 #include "remoting/base/constants.h" |
10 #include "remoting/proto/event.pb.h" | 11 #include "remoting/proto/event.pb.h" |
11 #include "remoting/proto/internal.pb.h" | 12 #include "remoting/proto/internal.pb.h" |
12 #include "remoting/protocol/input_stub.h" | 13 #include "remoting/protocol/input_stub.h" |
13 #include "remoting/protocol/message_serialization.h" | 14 #include "remoting/protocol/message_serialization.h" |
14 | 15 |
15 namespace remoting { | 16 namespace remoting { |
16 namespace protocol { | 17 namespace protocol { |
17 | 18 |
18 HostEventDispatcher::HostEventDispatcher() | 19 HostEventDispatcher::HostEventDispatcher() |
19 : ChannelDispatcherBase(kEventChannelName) {} | 20 : ChannelDispatcherBase(kEventChannelName), |
| 21 event_timestamps_source_(new InputEventTimestampsSourceImpl()) {} |
| 22 |
20 HostEventDispatcher::~HostEventDispatcher() {} | 23 HostEventDispatcher::~HostEventDispatcher() {} |
21 | 24 |
22 void HostEventDispatcher::OnIncomingMessage( | 25 void HostEventDispatcher::OnIncomingMessage( |
23 std::unique_ptr<CompoundBuffer> buffer) { | 26 std::unique_ptr<CompoundBuffer> buffer) { |
24 DCHECK(input_stub_); | 27 DCHECK(input_stub_); |
25 | 28 |
26 std::unique_ptr<EventMessage> message = | 29 std::unique_ptr<EventMessage> message = |
27 ParseMessage<EventMessage>(buffer.get()); | 30 ParseMessage<EventMessage>(buffer.get()); |
28 if (!message) | 31 if (!message) |
29 return; | 32 return; |
30 | 33 |
31 if (!on_input_event_callback_.is_null()) | 34 event_timestamps_source_->OnEventReceived(InputEventTimestamps{ |
32 on_input_event_callback_.Run(message->timestamp()); | 35 base::TimeTicks::FromInternalValue(message->timestamp()), |
| 36 base::TimeTicks::Now()}); |
33 | 37 |
34 if (message->has_key_event()) { | 38 if (message->has_key_event()) { |
35 const KeyEvent& event = message->key_event(); | 39 const KeyEvent& event = message->key_event(); |
36 if (event.has_usb_keycode() && event.has_pressed()) { | 40 if (event.has_usb_keycode() && event.has_pressed()) { |
37 input_stub_->InjectKeyEvent(event); | 41 input_stub_->InjectKeyEvent(event); |
38 } else { | 42 } else { |
39 LOG(WARNING) << "Received invalid key event."; | 43 LOG(WARNING) << "Received invalid key event."; |
40 } | 44 } |
41 } else if (message->has_text_event()) { | 45 } else if (message->has_text_event()) { |
42 const TextEvent& event = message->text_event(); | 46 const TextEvent& event = message->text_event(); |
43 if (event.has_text()) { | 47 if (event.has_text()) { |
44 input_stub_->InjectTextEvent(event); | 48 input_stub_->InjectTextEvent(event); |
45 } else { | 49 } else { |
46 LOG(WARNING) << "Received invalid text event."; | 50 LOG(WARNING) << "Received invalid text event."; |
47 } | 51 } |
48 } else if (message->has_mouse_event()) { | 52 } else if (message->has_mouse_event()) { |
49 input_stub_->InjectMouseEvent(message->mouse_event()); | 53 input_stub_->InjectMouseEvent(message->mouse_event()); |
50 } else if (message->has_touch_event()) { | 54 } else if (message->has_touch_event()) { |
51 input_stub_->InjectTouchEvent(message->touch_event()); | 55 input_stub_->InjectTouchEvent(message->touch_event()); |
52 } else { | 56 } else { |
53 LOG(WARNING) << "Unknown event message received."; | 57 LOG(WARNING) << "Unknown event message received."; |
54 } | 58 } |
55 } | 59 } |
56 | 60 |
57 } // namespace protocol | 61 } // namespace protocol |
58 } // namespace remoting | 62 } // namespace remoting |
OLD | NEW |