Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: remoting/protocol/host_event_dispatcher.cc

Issue 2413553003: Add InputEventTimestampSource interface. (Closed)
Patch Set: address feedback Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 .client_timestamp =
36 base::TimeTicks::FromInternalValue(message->timestamp()),
37 .host_timestamp = base::TimeTicks::Now()});
33 38
34 if (message->has_key_event()) { 39 if (message->has_key_event()) {
35 const KeyEvent& event = message->key_event(); 40 const KeyEvent& event = message->key_event();
36 if (event.has_usb_keycode() && event.has_pressed()) { 41 if (event.has_usb_keycode() && event.has_pressed()) {
37 input_stub_->InjectKeyEvent(event); 42 input_stub_->InjectKeyEvent(event);
38 } else { 43 } else {
39 LOG(WARNING) << "Received invalid key event."; 44 LOG(WARNING) << "Received invalid key event.";
40 } 45 }
41 } else if (message->has_text_event()) { 46 } else if (message->has_text_event()) {
42 const TextEvent& event = message->text_event(); 47 const TextEvent& event = message->text_event();
43 if (event.has_text()) { 48 if (event.has_text()) {
44 input_stub_->InjectTextEvent(event); 49 input_stub_->InjectTextEvent(event);
45 } else { 50 } else {
46 LOG(WARNING) << "Received invalid text event."; 51 LOG(WARNING) << "Received invalid text event.";
47 } 52 }
48 } else if (message->has_mouse_event()) { 53 } else if (message->has_mouse_event()) {
49 input_stub_->InjectMouseEvent(message->mouse_event()); 54 input_stub_->InjectMouseEvent(message->mouse_event());
50 } else if (message->has_touch_event()) { 55 } else if (message->has_touch_event()) {
51 input_stub_->InjectTouchEvent(message->touch_event()); 56 input_stub_->InjectTouchEvent(message->touch_event());
52 } else { 57 } else {
53 LOG(WARNING) << "Unknown event message received."; 58 LOG(WARNING) << "Unknown event message received.";
54 } 59 }
55 } 60 }
56 61
57 } // namespace protocol 62 } // namespace protocol
58 } // namespace remoting 63 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698