| 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 "remoting/protocol/connection_to_client.h" | 5 #include "remoting/protocol/connection_to_client.h" |
| 6 | 6 |
| 7 #include "google/protobuf/message.h" | 7 #include "google/protobuf/message.h" |
| 8 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
| 9 #include "remoting/protocol/client_control_sender.h" | 9 #include "remoting/protocol/client_control_sender.h" |
| 10 #include "remoting/protocol/host_message_dispatcher.h" | 10 #include "remoting/protocol/host_message_dispatcher.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) { | 67 void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) { |
| 68 handler_->OnSequenceNumberUpdated(this, sequence_number); | 68 handler_->OnSequenceNumberUpdated(this, sequence_number); |
| 69 } | 69 } |
| 70 | 70 |
| 71 VideoStub* ConnectionToClient::video_stub() { | 71 VideoStub* ConnectionToClient::video_stub() { |
| 72 return video_writer_.get(); | 72 return video_writer_.get(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Return pointer to ClientStub. | 75 // Return pointer to ClientStub. |
| 76 ClientStub* ConnectionToClient::client_stub() { | 76 ClientStub* ConnectionToClient::client_stub() { |
| 77 return client_stub_.get(); | 77 return client_control_sender_.get(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void ConnectionToClient::set_host_stub(protocol::HostStub* host_stub) { | 80 void ConnectionToClient::set_host_stub(protocol::HostStub* host_stub) { |
| 81 host_stub_ = host_stub; | 81 host_stub_ = host_stub; |
| 82 } | 82 } |
| 83 | 83 |
| 84 void ConnectionToClient::set_input_stub(protocol::InputStub* input_stub) { | 84 void ConnectionToClient::set_input_stub(protocol::InputStub* input_stub) { |
| 85 input_stub_ = input_stub; | 85 input_stub_ = input_stub; |
| 86 } | 86 } |
| 87 | 87 |
| 88 void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) { | 88 void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) { |
| 89 if (state == protocol::Session::CONNECTED) { | |
| 90 client_stub_.reset(new ClientControlSender(session_->control_channel())); | |
| 91 video_writer_.reset(VideoWriter::Create(session_->config())); | |
| 92 video_writer_->Init(session_); | |
| 93 | |
| 94 dispatcher_.reset(new HostMessageDispatcher()); | |
| 95 dispatcher_->Initialize(this, host_stub_, input_stub_); | |
| 96 } | |
| 97 | |
| 98 // This method can be called from main thread so perform threading switching. | |
| 99 if (MessageLoop::current() != loop_) { | |
| 100 loop_->PostTask( | |
| 101 FROM_HERE, | |
| 102 NewRunnableMethod(this, &ConnectionToClient::StateChangeTask, state)); | |
| 103 } else { | |
| 104 StateChangeTask(state); | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 void ConnectionToClient::StateChangeTask(protocol::Session::State state) { | |
| 109 DCHECK_EQ(loop_, MessageLoop::current()); | 89 DCHECK_EQ(loop_, MessageLoop::current()); |
| 110 | 90 |
| 111 DCHECK(handler_); | 91 DCHECK(handler_); |
| 112 switch(state) { | 92 switch(state) { |
| 113 case protocol::Session::CONNECTING: | 93 case protocol::Session::CONNECTING: |
| 114 break; | 94 break; |
| 115 // Don't care about this message. | 95 // Don't care about this message. |
| 116 case protocol::Session::CONNECTED: | 96 case protocol::Session::CONNECTED: |
| 97 client_control_sender_.reset( |
| 98 new ClientControlSender(session_->control_channel())); |
| 99 video_writer_.reset(VideoWriter::Create(session_->config())); |
| 100 video_writer_->Init(session_); |
| 101 |
| 102 dispatcher_.reset(new HostMessageDispatcher()); |
| 103 dispatcher_->Initialize(this, host_stub_, input_stub_); |
| 104 |
| 117 handler_->OnConnectionOpened(this); | 105 handler_->OnConnectionOpened(this); |
| 118 break; | 106 break; |
| 119 case protocol::Session::CLOSED: | 107 case protocol::Session::CLOSED: |
| 108 CloseChannels(); |
| 120 handler_->OnConnectionClosed(this); | 109 handler_->OnConnectionClosed(this); |
| 121 break; | 110 break; |
| 122 case protocol::Session::FAILED: | 111 case protocol::Session::FAILED: |
| 112 CloseChannels(); |
| 123 handler_->OnConnectionFailed(this); | 113 handler_->OnConnectionFailed(this); |
| 124 break; | 114 break; |
| 125 default: | 115 default: |
| 126 // We shouldn't receive other states. | 116 // We shouldn't receive other states. |
| 127 NOTREACHED(); | 117 NOTREACHED(); |
| 128 } | 118 } |
| 129 } | 119 } |
| 130 | 120 |
| 121 void ConnectionToClient::CloseChannels() { |
| 122 if (video_writer_.get()) |
| 123 video_writer_->Close(); |
| 124 if (client_control_sender_.get()) |
| 125 client_control_sender_->Close(); |
| 126 } |
| 127 |
| 131 // OnClosed() is used as a callback for protocol::Session::Close(). | 128 // OnClosed() is used as a callback for protocol::Session::Close(). |
| 132 void ConnectionToClient::OnClosed() { | 129 void ConnectionToClient::OnClosed() { |
| 133 } | 130 } |
| 134 | 131 |
| 135 } // namespace protocol | 132 } // namespace protocol |
| 136 } // namespace remoting | 133 } // namespace remoting |
| OLD | NEW |