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/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/client_message_dispatcher.h" | 10 #include "remoting/protocol/client_message_dispatcher.h" |
11 #include "remoting/protocol/client_stub.h" | 11 #include "remoting/protocol/client_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 ClientMessageDispatcher::ClientMessageDispatcher() : client_stub_(NULL) { | 19 ClientMessageDispatcher::ClientMessageDispatcher() : client_stub_(NULL) { |
21 } | 20 } |
22 | 21 |
23 ClientMessageDispatcher::~ClientMessageDispatcher() { | 22 ClientMessageDispatcher::~ClientMessageDispatcher() { |
24 } | 23 } |
25 | 24 |
26 void ClientMessageDispatcher::Initialize( | 25 void ClientMessageDispatcher::Initialize( |
27 protocol::Session* session, ClientStub* client_stub) { | 26 protocol::Session* session, ClientStub* client_stub) { |
28 if (!session || !client_stub || !session->control_channel()) { | 27 if (!session || !client_stub || !session->control_channel()) { |
29 return; | 28 return; |
30 } | 29 } |
31 | 30 |
32 control_message_reader_.reset(new ProtobufMessageReader<ControlMessage>()); | 31 control_message_reader_.reset(new ProtobufMessageReader<ControlMessage>()); |
33 client_stub_ = client_stub; | 32 client_stub_ = client_stub; |
34 | 33 |
35 control_message_reader_->Init( | 34 control_message_reader_->Init( |
36 session->control_channel(), | 35 session->control_channel(), |
37 NewCallback(this, &ClientMessageDispatcher::OnControlMessageReceived)); | 36 NewCallback(this, &ClientMessageDispatcher::OnControlMessageReceived)); |
38 return; | 37 return; |
39 } | 38 } |
40 | 39 |
41 void ClientMessageDispatcher::OnControlMessageReceived( | 40 void ClientMessageDispatcher::OnControlMessageReceived( |
42 ControlMessage* message) { | 41 ControlMessage* message, Task* done_task) { |
43 scoped_refptr<RefCountedMessage<ControlMessage> > ref_msg = | 42 // TODO(sergeyu): Add message validation. |
44 new RefCountedMessage<ControlMessage>(message); | |
45 if (message->has_notify_resolution()) { | 43 if (message->has_notify_resolution()) { |
46 client_stub_->NotifyResolution( | 44 client_stub_->NotifyResolution( |
47 &message->notify_resolution(), NewDeleteTask(ref_msg)); | 45 &message->notify_resolution(), done_task); |
48 } else if (message->has_begin_session_response()) { | 46 } else if (message->has_begin_session_response()) { |
49 client_stub_->BeginSessionResponse( | 47 client_stub_->BeginSessionResponse( |
50 &message->begin_session_response().login_status(), | 48 &message->begin_session_response().login_status(), done_task); |
51 NewDeleteTask(ref_msg)); | |
52 } else { | 49 } else { |
53 NOTREACHED() << "Invalid control message received"; | 50 LOG(WARNING) << "Invalid control message received."; |
| 51 done_task->Run(); |
| 52 delete done_task; |
54 } | 53 } |
55 } | 54 } |
56 | 55 |
57 } // namespace protocol | 56 } // namespace protocol |
58 } // namespace remoting | 57 } // namespace remoting |
OLD | NEW |