Getting rid of GetDefaultProfile(), clean up of ProfileManager (which was in a seriou...
[chromium-blink-merge.git] / remoting / protocol / host_event_dispatcher.cc
blobc5206f420767e7ca2e2747f57fd628b1260cde14
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_(NULL) {
22 HostEventDispatcher::~HostEventDispatcher() {
25 void HostEventDispatcher::OnInitialized() {
26 reader_.Init(channel(), base::Bind(
27 &HostEventDispatcher::OnMessageReceived, base::Unretained(this)));
30 void HostEventDispatcher::OnMessageReceived(
31 scoped_ptr<EventMessage> message, const base::Closure& done_task) {
32 DCHECK(input_stub_);
34 base::ScopedClosureRunner done_runner(done_task);
36 if (message->has_sequence_number() && !sequence_number_callback_.is_null())
37 sequence_number_callback_.Run(message->sequence_number());
39 if (message->has_key_event()) {
40 const KeyEvent& event = message->key_event();
41 if (event.has_usb_keycode() && event.has_pressed()) {
42 input_stub_->InjectKeyEvent(event);
43 } else {
44 LOG(WARNING) << "Received invalid key event.";
46 } else if (message->has_mouse_event()) {
47 input_stub_->InjectMouseEvent(message->mouse_event());
48 } else {
49 LOG(WARNING) << "Unknown event message received.";
53 } // namespace protocol
54 } // namespace remoting