| 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_host.h" | 5 #include "remoting/protocol/connection_to_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "remoting/base/constants.h" | 10 #include "remoting/base/constants.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 event_callback_(NULL), | 37 event_callback_(NULL), |
| 38 dispatcher_(new ClientMessageDispatcher()), | 38 dispatcher_(new ClientMessageDispatcher()), |
| 39 client_stub_(NULL), | 39 client_stub_(NULL), |
| 40 video_stub_(NULL) { | 40 video_stub_(NULL) { |
| 41 } | 41 } |
| 42 | 42 |
| 43 ConnectionToHost::~ConnectionToHost() { | 43 ConnectionToHost::~ConnectionToHost() { |
| 44 } | 44 } |
| 45 | 45 |
| 46 InputStub* ConnectionToHost::input_stub() { | 46 InputStub* ConnectionToHost::input_stub() { |
| 47 return input_stub_.get(); | 47 return input_sender_.get(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 HostStub* ConnectionToHost::host_stub() { | 50 HostStub* ConnectionToHost::host_stub() { |
| 51 return host_stub_.get(); | 51 return host_control_sender_.get(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void ConnectionToHost::Connect(scoped_refptr<XmppProxy> xmpp_proxy, | 54 void ConnectionToHost::Connect(scoped_refptr<XmppProxy> xmpp_proxy, |
| 55 const std::string& your_jid, | 55 const std::string& your_jid, |
| 56 const std::string& host_jid, | 56 const std::string& host_jid, |
| 57 const std::string& host_public_key, | 57 const std::string& host_public_key, |
| 58 const std::string& access_code, | 58 const std::string& access_code, |
| 59 HostEventCallback* event_callback, | 59 HostEventCallback* event_callback, |
| 60 ClientStub* client_stub, | 60 ClientStub* client_stub, |
| 61 VideoStub* video_stub) { | 61 VideoStub* video_stub) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 180 } |
| 181 | 181 |
| 182 void ConnectionToHost::OnSessionStateChange( | 182 void ConnectionToHost::OnSessionStateChange( |
| 183 Session::State state) { | 183 Session::State state) { |
| 184 DCHECK_EQ(message_loop_, MessageLoop::current()); | 184 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 185 DCHECK(event_callback_); | 185 DCHECK(event_callback_); |
| 186 | 186 |
| 187 switch (state) { | 187 switch (state) { |
| 188 case Session::FAILED: | 188 case Session::FAILED: |
| 189 state_ = STATE_FAILED; | 189 state_ = STATE_FAILED; |
| 190 CloseChannels(); |
| 190 event_callback_->OnConnectionFailed(this); | 191 event_callback_->OnConnectionFailed(this); |
| 191 break; | 192 break; |
| 192 | 193 |
| 193 case Session::CLOSED: | 194 case Session::CLOSED: |
| 194 state_ = STATE_CLOSED; | 195 state_ = STATE_CLOSED; |
| 196 CloseChannels(); |
| 195 event_callback_->OnConnectionClosed(this); | 197 event_callback_->OnConnectionClosed(this); |
| 196 break; | 198 break; |
| 197 | 199 |
| 198 case Session::CONNECTED: | 200 case Session::CONNECTED: |
| 199 state_ = STATE_CONNECTED; | 201 state_ = STATE_CONNECTED; |
| 200 // Initialize reader and writer. | 202 // Initialize reader and writer. |
| 201 video_reader_.reset(VideoReader::Create(session_->config())); | 203 video_reader_.reset(VideoReader::Create(session_->config())); |
| 202 video_reader_->Init(session_, video_stub_); | 204 video_reader_->Init(session_, video_stub_); |
| 203 host_stub_.reset(new HostControlSender(session_->control_channel())); | 205 host_control_sender_.reset( |
| 206 new HostControlSender(session_->control_channel())); |
| 204 dispatcher_->Initialize(session_.get(), client_stub_); | 207 dispatcher_->Initialize(session_.get(), client_stub_); |
| 205 event_callback_->OnConnectionOpened(this); | 208 event_callback_->OnConnectionOpened(this); |
| 206 break; | 209 break; |
| 207 | 210 |
| 208 default: | 211 default: |
| 209 // Ignore the other states by default. | 212 // Ignore the other states by default. |
| 210 break; | 213 break; |
| 211 } | 214 } |
| 212 } | 215 } |
| 213 | 216 |
| 217 void ConnectionToHost::CloseChannels() { |
| 218 if (input_sender_.get()) |
| 219 input_sender_->Close(); |
| 220 |
| 221 if (host_control_sender_.get()) |
| 222 host_control_sender_->Close(); |
| 223 } |
| 224 |
| 214 void ConnectionToHost::OnClientAuthenticated() { | 225 void ConnectionToHost::OnClientAuthenticated() { |
| 215 // TODO(hclam): Don't send anything except authentication request if it is | 226 // TODO(hclam): Don't send anything except authentication request if it is |
| 216 // not authenticated. | 227 // not authenticated. |
| 217 state_ = STATE_AUTHENTICATED; | 228 state_ = STATE_AUTHENTICATED; |
| 218 | 229 |
| 219 // Create and enable the input stub now that we're authenticated. | 230 // Create and enable the input stub now that we're authenticated. |
| 220 input_stub_.reset(new InputSender(session_->event_channel())); | 231 input_sender_.reset(new InputSender(session_->event_channel())); |
| 221 } | 232 } |
| 222 | 233 |
| 223 ConnectionToHost::State ConnectionToHost::state() const { | 234 ConnectionToHost::State ConnectionToHost::state() const { |
| 224 return state_; | 235 return state_; |
| 225 } | 236 } |
| 226 | 237 |
| 227 } // namespace protocol | 238 } // namespace protocol |
| 228 } // namespace remoting | 239 } // namespace remoting |
| OLD | NEW |