| 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 15 matching lines...) Expand all Loading... |
| 77 } | 77 } |
| 78 | 78 |
| 79 void ConnectionToHost::Disconnect(const base::Closure& shutdown_task) { | 79 void ConnectionToHost::Disconnect(const base::Closure& shutdown_task) { |
| 80 if (MessageLoop::current() != message_loop_) { | 80 if (MessageLoop::current() != message_loop_) { |
| 81 message_loop_->PostTask( | 81 message_loop_->PostTask( |
| 82 FROM_HERE, base::Bind(&ConnectionToHost::Disconnect, | 82 FROM_HERE, base::Bind(&ConnectionToHost::Disconnect, |
| 83 base::Unretained(this), shutdown_task)); | 83 base::Unretained(this), shutdown_task)); |
| 84 return; | 84 return; |
| 85 } | 85 } |
| 86 | 86 |
| 87 CloseChannels(); |
| 88 |
| 87 if (session_) { | 89 if (session_) { |
| 88 session_->Close( | 90 session_->Close( |
| 89 NewRunnableMethod(this, &ConnectionToHost::OnDisconnected, | 91 NewRunnableMethod(this, &ConnectionToHost::OnDisconnected, |
| 90 shutdown_task)); | 92 shutdown_task)); |
| 91 } else { | 93 } else { |
| 92 OnDisconnected(shutdown_task); | 94 OnDisconnected(shutdown_task); |
| 93 } | 95 } |
| 94 } | 96 } |
| 95 | 97 |
| 96 void ConnectionToHost::InitSession() { | 98 void ConnectionToHost::InitSession() { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 182 } |
| 181 | 183 |
| 182 void ConnectionToHost::OnSessionStateChange( | 184 void ConnectionToHost::OnSessionStateChange( |
| 183 Session::State state) { | 185 Session::State state) { |
| 184 DCHECK_EQ(message_loop_, MessageLoop::current()); | 186 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 185 DCHECK(event_callback_); | 187 DCHECK(event_callback_); |
| 186 | 188 |
| 187 switch (state) { | 189 switch (state) { |
| 188 case Session::FAILED: | 190 case Session::FAILED: |
| 189 state_ = STATE_FAILED; | 191 state_ = STATE_FAILED; |
| 192 CloseChannels(); |
| 190 event_callback_->OnConnectionFailed(this); | 193 event_callback_->OnConnectionFailed(this); |
| 191 break; | 194 break; |
| 192 | 195 |
| 193 case Session::CLOSED: | 196 case Session::CLOSED: |
| 194 state_ = STATE_CLOSED; | 197 state_ = STATE_CLOSED; |
| 198 CloseChannels(); |
| 195 event_callback_->OnConnectionClosed(this); | 199 event_callback_->OnConnectionClosed(this); |
| 196 break; | 200 break; |
| 197 | 201 |
| 198 case Session::CONNECTED: | 202 case Session::CONNECTED: |
| 199 state_ = STATE_CONNECTED; | 203 state_ = STATE_CONNECTED; |
| 200 // Initialize reader and writer. | 204 // Initialize reader and writer. |
| 201 video_reader_.reset(VideoReader::Create(session_->config())); | 205 video_reader_.reset(VideoReader::Create(session_->config())); |
| 202 video_reader_->Init(session_, video_stub_); | 206 video_reader_->Init(session_, video_stub_); |
| 203 host_stub_.reset(new HostControlSender(session_->control_channel())); | 207 host_control_sender_.reset( |
| 208 new HostControlSender(session_->control_channel())); |
| 204 dispatcher_->Initialize(session_.get(), client_stub_); | 209 dispatcher_->Initialize(session_.get(), client_stub_); |
| 205 event_callback_->OnConnectionOpened(this); | 210 event_callback_->OnConnectionOpened(this); |
| 206 break; | 211 break; |
| 207 | 212 |
| 208 default: | 213 default: |
| 209 // Ignore the other states by default. | 214 // Ignore the other states by default. |
| 210 break; | 215 break; |
| 211 } | 216 } |
| 212 } | 217 } |
| 213 | 218 |
| 219 void ConnectionToHost::CloseChannels() { |
| 220 if (input_sender_.get()) |
| 221 input_sender_->Close(); |
| 222 |
| 223 if (host_control_sender_.get()) |
| 224 host_control_sender_->Close(); |
| 225 } |
| 226 |
| 214 void ConnectionToHost::OnClientAuthenticated() { | 227 void ConnectionToHost::OnClientAuthenticated() { |
| 215 // TODO(hclam): Don't send anything except authentication request if it is | 228 // TODO(hclam): Don't send anything except authentication request if it is |
| 216 // not authenticated. | 229 // not authenticated. |
| 217 state_ = STATE_AUTHENTICATED; | 230 state_ = STATE_AUTHENTICATED; |
| 218 | 231 |
| 219 // Create and enable the input stub now that we're authenticated. | 232 // Create and enable the input stub now that we're authenticated. |
| 220 input_stub_.reset(new InputSender(session_->event_channel())); | 233 input_sender_.reset(new InputSender(session_->event_channel())); |
| 221 } | 234 } |
| 222 | 235 |
| 223 ConnectionToHost::State ConnectionToHost::state() const { | 236 ConnectionToHost::State ConnectionToHost::state() const { |
| 224 return state_; | 237 return state_; |
| 225 } | 238 } |
| 226 | 239 |
| 227 } // namespace protocol | 240 } // namespace protocol |
| 228 } // namespace remoting | 241 } // namespace remoting |
| OLD | NEW |