Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / protocol / host_event_dispatcher.cc
blob8006eac3242191b1cbd944e4389cde0ca64f9e31
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
3 // found in the LICENSE file.
5 #include "remoting/protocol/host_event_dispatcher.h"
7 #include "base/callback_helpers.h"
8 #include "net/socket/stream_socket.h"
9 #include "remoting/base/constants.h"
10 #include "remoting/proto/event.pb.h"
11 #include "remoting/proto/internal.pb.h"
12 #include "remoting/protocol/input_stub.h"
14 namespace remoting {
15 namespace protocol {
17 HostEventDispatcher::HostEventDispatcher()
18 : ChannelDispatcherBase(kEventChannelName),
19 input_stub_(nullptr),
20 parser_(base::Bind(&HostEventDispatcher::OnMessageReceived,
21 base::Unretained(this)),
22 reader()) {
25 HostEventDispatcher::~HostEventDispatcher() {
28 void HostEventDispatcher::OnMessageReceived(scoped_ptr<EventMessage> message,
29 const base::Closure& done_task) {
30 DCHECK(input_stub_);
32 base::ScopedClosureRunner done_runner(done_task);
34 if (message->has_timestamp() && !event_timestamp_callback_.is_null())
35 event_timestamp_callback_.Run(message->timestamp());
37 if (message->has_key_event()) {
38 const KeyEvent& event = message->key_event();
39 if (event.has_usb_keycode() && event.has_pressed()) {
40 input_stub_->InjectKeyEvent(event);
41 } else {
42 LOG(WARNING) << "Received invalid key event.";
44 } else if (message->has_text_event()) {
45 const TextEvent& event = message->text_event();
46 if (event.has_text()) {
47 input_stub_->InjectTextEvent(event);
48 } else {
49 LOG(WARNING) << "Received invalid text event.";
51 } else if (message->has_mouse_event()) {
52 input_stub_->InjectMouseEvent(message->mouse_event());
53 } else if (message->has_touch_event()) {
54 input_stub_->InjectTouchEvent(message->touch_event());
55 } else {
56 LOG(WARNING) << "Unknown event message received.";
60 } // namespace protocol
61 } // namespace remoting