OLD | NEW |
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/message_loop_proxy.h" | 5 #include "net/base/io_buffer.h" |
| 6 #include "remoting/base/multiple_array_input_stream.h" |
6 #include "remoting/proto/control.pb.h" | 7 #include "remoting/proto/control.pb.h" |
7 #include "remoting/proto/event.pb.h" | 8 #include "remoting/proto/event.pb.h" |
| 9 #include "remoting/protocol/chromotocol_connection.h" |
8 #include "remoting/protocol/host_message_dispatcher.h" | 10 #include "remoting/protocol/host_message_dispatcher.h" |
9 #include "remoting/protocol/host_control_message_handler.h" | 11 #include "remoting/protocol/host_control_message_handler.h" |
10 #include "remoting/protocol/host_event_message_handler.h" | 12 #include "remoting/protocol/host_event_message_handler.h" |
11 #include "remoting/protocol/stream_reader.h" | 13 #include "remoting/protocol/message_reader.h" |
12 | 14 |
13 namespace remoting { | 15 namespace remoting { |
14 | 16 |
15 HostMessageDispatcher::HostMessageDispatcher( | 17 HostMessageDispatcher::HostMessageDispatcher() { |
16 base::MessageLoopProxy* message_loop_proxy, | |
17 ChromotingConnection* connection, | |
18 HostControlMessageHandler* control_message_handler, | |
19 HostEventMessageHandler* event_message_handler) | |
20 : message_loop_proxy_(message_loop_proxy), | |
21 control_message_handler_(control_message_handler), | |
22 event_message_handler_(event_message_handler) { | |
23 } | 18 } |
24 | 19 |
25 HostMessageDispatcher::~HostMessageDispatcher() { | 20 HostMessageDispatcher::~HostMessageDispatcher() { |
26 } | 21 } |
27 | 22 |
| 23 bool HostMessageDispatcher::Initialize( |
| 24 ChromotocolConnection* connection, |
| 25 HostControlMessageHandler* control_message_handler, |
| 26 HostEventMessageHandler* event_message_handler) { |
| 27 if (!connection || !control_message_handler || !event_message_handler || |
| 28 !connection->event_channel() || !connection->control_channel()) { |
| 29 return false; |
| 30 } |
| 31 |
| 32 control_message_reader_.reset(new MessageReader()); |
| 33 event_message_reader_.reset(new MessageReader()); |
| 34 control_message_handler_.reset(control_message_handler); |
| 35 event_message_handler_.reset(event_message_handler); |
| 36 |
| 37 // Initialize the readers on the sockets provided by channels. |
| 38 event_message_reader_->Init<ClientEventMessage>( |
| 39 connection->event_channel(), |
| 40 NewCallback(this, &HostMessageDispatcher::OnEventMessageReceived)); |
| 41 control_message_reader_->Init<ClientControlMessage>( |
| 42 connection->control_channel(), |
| 43 NewCallback(this, &HostMessageDispatcher::OnControlMessageReceived)); |
| 44 return true; |
| 45 } |
| 46 |
| 47 void HostMessageDispatcher::OnControlMessageReceived( |
| 48 ClientControlMessage* message) { |
| 49 scoped_refptr<RefCountedMessage<ClientControlMessage> > ref_msg = |
| 50 new RefCountedMessage<ClientControlMessage>(message); |
| 51 if (message->has_suggest_screen_resolution_request()) { |
| 52 control_message_handler_->OnSuggestScreenResolutionRequest( |
| 53 message->suggest_screen_resolution_request(), |
| 54 NewRunnableFunction( |
| 55 &DeleteMessage<RefCountedMessage<ClientControlMessage> >, |
| 56 ref_msg)); |
| 57 } |
| 58 } |
| 59 |
| 60 void HostMessageDispatcher::OnEventMessageReceived( |
| 61 ClientEventMessage* message) { |
| 62 // TODO(hclam): Implement. |
| 63 } |
| 64 |
28 } // namespace remoting | 65 } // namespace remoting |
OLD | NEW |