| 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/jingle_session.h" | 5 #include "remoting/protocol/jingle_session.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 authenticator_(authenticator), | 38 authenticator_(authenticator), |
| 39 state_(INITIALIZING), | 39 state_(INITIALIZING), |
| 40 error_(OK), | 40 error_(OK), |
| 41 closing_(false), | 41 closing_(false), |
| 42 cricket_session_(cricket_session), | 42 cricket_session_(cricket_session), |
| 43 config_set_(false), | 43 config_set_(false), |
| 44 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { | 44 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { |
| 45 jid_ = cricket_session_->remote_name(); | 45 jid_ = cricket_session_->remote_name(); |
| 46 cricket_session_->SignalState.connect(this, &JingleSession::OnSessionState); | 46 cricket_session_->SignalState.connect(this, &JingleSession::OnSessionState); |
| 47 cricket_session_->SignalError.connect(this, &JingleSession::OnSessionError); | 47 cricket_session_->SignalError.connect(this, &JingleSession::OnSessionError); |
| 48 cricket_session_->SignalReceivedTerminateReason.connect( |
| 49 this, &JingleSession::OnTerminateReason); |
| 48 } | 50 } |
| 49 | 51 |
| 50 JingleSession::~JingleSession() { | 52 JingleSession::~JingleSession() { |
| 51 // Reset the callback so that it's not called from Close(). | 53 // Reset the callback so that it's not called from Close(). |
| 52 state_change_callback_.Reset(); | 54 state_change_callback_.Reset(); |
| 53 Close(); | 55 Close(); |
| 54 jingle_session_manager_->SessionDestroyed(this); | 56 jingle_session_manager_->SessionDestroyed(this); |
| 55 DCHECK(channel_connectors_.empty()); | 57 DCHECK(channel_connectors_.empty()); |
| 56 } | 58 } |
| 57 | 59 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 BaseSession* session, BaseSession::Error error) { | 239 BaseSession* session, BaseSession::Error error) { |
| 238 DCHECK(CalledOnValidThread()); | 240 DCHECK(CalledOnValidThread()); |
| 239 DCHECK_EQ(cricket_session_, session); | 241 DCHECK_EQ(cricket_session_, session); |
| 240 | 242 |
| 241 if (error != cricket::Session::ERROR_NONE) { | 243 if (error != cricket::Session::ERROR_NONE) { |
| 242 // TODO(sergeyu): Report different errors depending on |error|. | 244 // TODO(sergeyu): Report different errors depending on |error|. |
| 243 CloseInternal(net::ERR_CONNECTION_ABORTED, CHANNEL_CONNECTION_ERROR); | 245 CloseInternal(net::ERR_CONNECTION_ABORTED, CHANNEL_CONNECTION_ERROR); |
| 244 } | 246 } |
| 245 } | 247 } |
| 246 | 248 |
| 249 void JingleSession::OnTerminateReason(cricket::Session* session, |
| 250 const std::string& reason) { |
| 251 terminate_reason_ = reason; |
| 252 } |
| 253 |
| 247 void JingleSession::OnInitiate() { | 254 void JingleSession::OnInitiate() { |
| 248 DCHECK(CalledOnValidThread()); | 255 DCHECK(CalledOnValidThread()); |
| 249 jid_ = cricket_session_->remote_name(); | 256 jid_ = cricket_session_->remote_name(); |
| 250 | 257 |
| 251 if (cricket_session_->initiator()) { | 258 if (cricket_session_->initiator()) { |
| 252 // Set state to CONNECTING if this is an outgoing message. We need | 259 // Set state to CONNECTING if this is an outgoing message. We need |
| 253 // to post this task because channel creation works only after we | 260 // to post this task because channel creation works only after we |
| 254 // return from this method. This is because | 261 // return from this method. This is because |
| 255 // JingleChannelConnector::Connect() needs to call | 262 // JingleChannelConnector::Connect() needs to call |
| 256 // set_incoming_only() on P2PTransportChannel, but | 263 // set_incoming_only() on P2PTransportChannel, but |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } | 332 } |
| 326 | 333 |
| 327 SetState(CONNECTED); | 334 SetState(CONNECTED); |
| 328 | 335 |
| 329 if (authenticator_->state() == Authenticator::ACCEPTED) | 336 if (authenticator_->state() == Authenticator::ACCEPTED) |
| 330 SetState(AUTHENTICATED); | 337 SetState(AUTHENTICATED); |
| 331 } | 338 } |
| 332 | 339 |
| 333 void JingleSession::OnTerminate() { | 340 void JingleSession::OnTerminate() { |
| 334 DCHECK(CalledOnValidThread()); | 341 DCHECK(CalledOnValidThread()); |
| 335 CloseInternal(net::ERR_CONNECTION_ABORTED, OK); | 342 |
| 343 if (terminate_reason_ == "success") { |
| 344 CloseInternal(net::ERR_CONNECTION_ABORTED, OK); |
| 345 } else if (terminate_reason_ == "decline") { |
| 346 CloseInternal(net::ERR_CONNECTION_ABORTED, AUTHENTICATION_FAILED); |
| 347 } else if (terminate_reason_ == "incompatible-protocol") { |
| 348 CloseInternal(net::ERR_CONNECTION_ABORTED, INCOMPATIBLE_PROTOCOL); |
| 349 } else { |
| 350 CloseInternal(net::ERR_CONNECTION_ABORTED, UNKNOWN_ERROR); |
| 351 } |
| 336 } | 352 } |
| 337 | 353 |
| 338 void JingleSession::AcceptConnection() { | 354 void JingleSession::AcceptConnection() { |
| 339 SetState(CONNECTING); | 355 SetState(CONNECTING); |
| 340 | 356 |
| 341 const cricket::SessionDescription* session_description = | 357 const cricket::SessionDescription* session_description = |
| 342 cricket_session_->remote_description(); | 358 cricket_session_->remote_description(); |
| 343 const cricket::ContentInfo* content = | 359 const cricket::ContentInfo* content = |
| 344 session_description->FirstContentByType(kChromotingXmlNamespace); | 360 session_description->FirstContentByType(kChromotingXmlNamespace); |
| 345 | 361 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 const buzz::XmlElement* authenticator_message) { | 484 const buzz::XmlElement* authenticator_message) { |
| 469 cricket::SessionDescription* desc = new cricket::SessionDescription(); | 485 cricket::SessionDescription* desc = new cricket::SessionDescription(); |
| 470 desc->AddContent( | 486 desc->AddContent( |
| 471 ContentDescription::kChromotingContentName, kChromotingXmlNamespace, | 487 ContentDescription::kChromotingContentName, kChromotingXmlNamespace, |
| 472 new ContentDescription(config, authenticator_message)); | 488 new ContentDescription(config, authenticator_message)); |
| 473 return desc; | 489 return desc; |
| 474 } | 490 } |
| 475 | 491 |
| 476 } // namespace protocol | 492 } // namespace protocol |
| 477 } // namespace remoting | 493 } // namespace remoting |
| OLD | NEW |