OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/ref_counted.h" | 5 #include "base/memory/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/connection_to_client.h" | 10 #include "remoting/protocol/connection_to_client.h" |
11 #include "remoting/protocol/host_message_dispatcher.h" | 11 #include "remoting/protocol/host_message_dispatcher.h" |
12 #include "remoting/protocol/host_stub.h" | 12 #include "remoting/protocol/host_stub.h" |
13 #include "remoting/protocol/input_stub.h" | 13 #include "remoting/protocol/input_stub.h" |
14 #include "remoting/protocol/message_reader.h" | 14 #include "remoting/protocol/message_reader.h" |
15 #include "remoting/protocol/session.h" | 15 #include "remoting/protocol/session.h" |
16 | 16 |
17 namespace remoting { | 17 namespace remoting { |
18 namespace protocol { | 18 namespace protocol { |
19 | 19 |
20 HostMessageDispatcher::HostMessageDispatcher() : | 20 HostMessageDispatcher::HostMessageDispatcher() : |
21 host_stub_(NULL), | 21 host_stub_(NULL), |
22 input_stub_(NULL) { | 22 input_stub_(NULL) { |
23 } | 23 } |
24 | 24 |
25 HostMessageDispatcher::~HostMessageDispatcher() { | 25 HostMessageDispatcher::~HostMessageDispatcher() { |
26 } | 26 } |
27 | 27 |
28 void HostMessageDispatcher::Initialize( | 28 void HostMessageDispatcher::Initialize( |
29 protocol::Session* session, | 29 ConnectionToClient* connection, |
30 HostStub* host_stub, InputStub* input_stub) { | 30 HostStub* host_stub, InputStub* input_stub) { |
31 if (!session || !host_stub || !input_stub || | 31 if (!connection || !host_stub || !input_stub || |
32 !session->event_channel() || !session->control_channel()) { | 32 !connection->session()->event_channel() || |
| 33 !connection->session()->control_channel()) { |
33 return; | 34 return; |
34 } | 35 } |
35 | 36 |
36 control_message_reader_.reset(new ProtobufMessageReader<ControlMessage>()); | 37 control_message_reader_.reset(new ProtobufMessageReader<ControlMessage>()); |
37 event_message_reader_.reset(new ProtobufMessageReader<EventMessage>()); | 38 event_message_reader_.reset(new ProtobufMessageReader<EventMessage>()); |
| 39 connection_ = connection; |
38 host_stub_ = host_stub; | 40 host_stub_ = host_stub; |
39 input_stub_ = input_stub; | 41 input_stub_ = input_stub; |
40 | 42 |
41 // Initialize the readers on the sockets provided by channels. | 43 // Initialize the readers on the sockets provided by channels. |
42 event_message_reader_->Init( | 44 event_message_reader_->Init( |
43 session->event_channel(), | 45 connection->session()->event_channel(), |
44 NewCallback(this, &HostMessageDispatcher::OnEventMessageReceived)); | 46 NewCallback(this, &HostMessageDispatcher::OnEventMessageReceived)); |
45 control_message_reader_->Init( | 47 control_message_reader_->Init( |
46 session->control_channel(), | 48 connection->session()->control_channel(), |
47 NewCallback(this, &HostMessageDispatcher::OnControlMessageReceived)); | 49 NewCallback(this, &HostMessageDispatcher::OnControlMessageReceived)); |
48 } | 50 } |
49 | 51 |
50 void HostMessageDispatcher::OnControlMessageReceived( | 52 void HostMessageDispatcher::OnControlMessageReceived( |
51 ControlMessage* message, Task* done_task) { | 53 ControlMessage* message, Task* done_task) { |
52 // TODO(sergeyu): Add message validation. | 54 // TODO(sergeyu): Add message validation. |
53 if (message->has_begin_session_request()) { | 55 if (message->has_begin_session_request()) { |
54 host_stub_->BeginSessionRequest( | 56 host_stub_->BeginSessionRequest( |
55 &message->begin_session_request().credentials(), done_task); | 57 &message->begin_session_request().credentials(), done_task); |
56 return; | 58 return; |
57 } | 59 } |
58 if (message->has_suggest_resolution()) { | 60 if (message->has_suggest_resolution()) { |
59 host_stub_->SuggestResolution(&message->suggest_resolution(), done_task); | 61 host_stub_->SuggestResolution(&message->suggest_resolution(), done_task); |
60 return; | 62 return; |
61 } | 63 } |
62 LOG(WARNING) << "Invalid control message received."; | 64 LOG(WARNING) << "Invalid control message received."; |
63 done_task->Run(); | 65 done_task->Run(); |
64 delete done_task; | 66 delete done_task; |
65 } | 67 } |
66 | 68 |
67 void HostMessageDispatcher::OnEventMessageReceived( | 69 void HostMessageDispatcher::OnEventMessageReceived( |
68 EventMessage* message, Task* done_task) { | 70 EventMessage* message, Task* done_task) { |
69 // TODO(sergeyu): Add message validation. | 71 // TODO(sergeyu): Add message validation. |
| 72 connection_->UpdateSequenceNumber(message->sequence_number()); |
70 if (message->has_key_event()) { | 73 if (message->has_key_event()) { |
71 input_stub_->InjectKeyEvent(&message->key_event(), done_task); | 74 input_stub_->InjectKeyEvent(&message->key_event(), done_task); |
72 return; | 75 return; |
73 } | 76 } |
74 if (message->has_mouse_event()) { | 77 if (message->has_mouse_event()) { |
75 input_stub_->InjectMouseEvent(&message->mouse_event(), done_task); | 78 input_stub_->InjectMouseEvent(&message->mouse_event(), done_task); |
76 return; | 79 return; |
77 } | 80 } |
78 LOG(WARNING) << "Invalid event message received."; | 81 LOG(WARNING) << "Invalid event message received."; |
79 done_task->Run(); | 82 done_task->Run(); |
80 delete done_task; | 83 delete done_task; |
81 } | 84 } |
82 | 85 |
83 } // namespace protocol | 86 } // namespace protocol |
84 } // namespace remoting | 87 } // namespace remoting |
OLD | NEW |