OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/ref_counted.h" |
| 6 #include "net/base/io_buffer.h" |
| 7 #include "remoting/proto/control.pb.h" |
| 8 #include "remoting/proto/event.pb.h" |
| 9 #include "remoting/proto/internal.pb.h" |
| 10 #include "remoting/protocol/client_message_dispatcher.h" |
| 11 #include "remoting/protocol/client_stub.h" |
| 12 #include "remoting/protocol/input_stub.h" |
| 13 #include "remoting/protocol/message_reader.h" |
| 14 #include "remoting/protocol/ref_counted_message.h" |
| 15 #include "remoting/protocol/session.h" |
| 16 |
| 17 namespace remoting { |
| 18 namespace protocol { |
| 19 |
| 20 ClientMessageDispatcher::ClientMessageDispatcher() : client_stub_(NULL) { |
| 21 } |
| 22 |
| 23 ClientMessageDispatcher::~ClientMessageDispatcher() { |
| 24 } |
| 25 |
| 26 void ClientMessageDispatcher::Initialize( |
| 27 protocol::Session* session, ClientStub* client_stub) { |
| 28 if (!session || !client_stub || !session->control_channel()) { |
| 29 return; |
| 30 } |
| 31 |
| 32 control_message_reader_.reset(new MessageReader()); |
| 33 client_stub_ = client_stub; |
| 34 |
| 35 control_message_reader_->Init<ControlMessage>( |
| 36 session->control_channel(), |
| 37 NewCallback(this, &ClientMessageDispatcher::OnControlMessageReceived)); |
| 38 return; |
| 39 } |
| 40 |
| 41 void ClientMessageDispatcher::OnControlMessageReceived( |
| 42 ControlMessage* message) { |
| 43 scoped_refptr<RefCountedMessage<ControlMessage> > ref_msg = |
| 44 new RefCountedMessage<ControlMessage>(message); |
| 45 if (message->has_notify_resolution()) { |
| 46 client_stub_->NotifyResolution( |
| 47 &message->notify_resolution(), NewDeleteTask(ref_msg)); |
| 48 } else if (message->has_begin_session_response()) { |
| 49 client_stub_->BeginSessionResponse( |
| 50 &message->begin_session_response().login_status(), |
| 51 NewDeleteTask(ref_msg)); |
| 52 } else { |
| 53 NOTREACHED() << "Invalid control message received"; |
| 54 } |
| 55 } |
| 56 |
| 57 } // namespace protocol |
| 58 } // namespace remoting |
OLD | NEW |