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

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

Issue 6271004: Changed MessageReader so that it doesn't read from the socket if there are (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: proper handling of empty messages Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/ref_counted.h" 5 #include "base/ref_counted.h"
6 #include "net/base/io_buffer.h" 6 #include "net/base/io_buffer.h"
7 #include "remoting/proto/control.pb.h" 7 #include "remoting/proto/control.pb.h"
8 #include "remoting/proto/event.pb.h" 8 #include "remoting/proto/event.pb.h"
9 #include "remoting/proto/internal.pb.h" 9 #include "remoting/proto/internal.pb.h"
10 #include "remoting/protocol/host_message_dispatcher.h" 10 #include "remoting/protocol/host_message_dispatcher.h"
11 #include "remoting/protocol/host_stub.h" 11 #include "remoting/protocol/host_stub.h"
12 #include "remoting/protocol/input_stub.h" 12 #include "remoting/protocol/input_stub.h"
13 #include "remoting/protocol/message_reader.h" 13 #include "remoting/protocol/message_reader.h"
14 #include "remoting/protocol/ref_counted_message.h"
15 #include "remoting/protocol/session.h" 14 #include "remoting/protocol/session.h"
16 15
17 namespace remoting { 16 namespace remoting {
18 namespace protocol { 17 namespace protocol {
19 18
20 HostMessageDispatcher::HostMessageDispatcher() : 19 HostMessageDispatcher::HostMessageDispatcher() :
21 host_stub_(NULL), 20 host_stub_(NULL),
22 input_stub_(NULL) { 21 input_stub_(NULL) {
23 } 22 }
24 23
(...skipping 15 matching lines...) Expand all
40 39
41 // Initialize the readers on the sockets provided by channels. 40 // Initialize the readers on the sockets provided by channels.
42 event_message_reader_->Init( 41 event_message_reader_->Init(
43 session->event_channel(), 42 session->event_channel(),
44 NewCallback(this, &HostMessageDispatcher::OnEventMessageReceived)); 43 NewCallback(this, &HostMessageDispatcher::OnEventMessageReceived));
45 control_message_reader_->Init( 44 control_message_reader_->Init(
46 session->control_channel(), 45 session->control_channel(),
47 NewCallback(this, &HostMessageDispatcher::OnControlMessageReceived)); 46 NewCallback(this, &HostMessageDispatcher::OnControlMessageReceived));
48 } 47 }
49 48
50 void HostMessageDispatcher::OnControlMessageReceived(ControlMessage* message) { 49 void HostMessageDispatcher::OnControlMessageReceived(
51 scoped_refptr<RefCountedMessage<ControlMessage> > ref_msg = 50 ControlMessage* message, Task* done_task) {
52 new RefCountedMessage<ControlMessage>(message);
53 if (message->has_suggest_resolution()) { 51 if (message->has_suggest_resolution()) {
54 host_stub_->SuggestResolution( 52 host_stub_->SuggestResolution(&message->suggest_resolution(), done_task);
55 &message->suggest_resolution(), NewDeleteTask(ref_msg));
56 } else if (message->has_begin_session_request()) { 53 } else if (message->has_begin_session_request()) {
57 host_stub_->BeginSessionRequest( 54 host_stub_->BeginSessionRequest(
58 &message->begin_session_request().credentials(), 55 &message->begin_session_request().credentials(), done_task);
59 NewDeleteTask(ref_msg));
60 } else { 56 } else {
61 NOTREACHED() << "Invalid control message received"; 57 LOG(ERROR) << "Invalid control message received.";
Alpha Left Google 2011/01/20 20:54:52 Same here NOTREACHED is better, we should be more
58 done_task->Run();
59 delete done_task;
62 } 60 }
63 } 61 }
64 62
65 void HostMessageDispatcher::OnEventMessageReceived( 63 void HostMessageDispatcher::OnEventMessageReceived(
66 EventMessage* message) { 64 EventMessage* message, Task* done_task) {
67 scoped_refptr<RefCountedMessage<EventMessage> > ref_msg = 65 if (message->has_key()) {
68 new RefCountedMessage<EventMessage>(message); 66 input_stub_->InjectKeyEvent(&message->key(), done_task);
69 for (int i = 0; i < message->event_size(); ++i) { 67 } else if (message->has_mouse()) {
70 if (message->event(i).has_key()) { 68 input_stub_->InjectMouseEvent(&message->mouse(), done_task);
71 input_stub_->InjectKeyEvent( 69 } else {
72 &message->event(i).key(), NewDeleteTask(ref_msg)); 70 LOG(ERROR) << "Invalid event message received.";
73 } 71 done_task->Run();
74 if (message->event(i).has_mouse()) { 72 delete done_task;
75 input_stub_->InjectMouseEvent(
76 &message->event(i).mouse(), NewDeleteTask(ref_msg));
77 }
78 } 73 }
79 } 74 }
80 75
81 } // namespace protocol 76 } // namespace protocol
82 } // namespace remoting 77 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698