| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 cricket_session_->SignalError.connect( | 81 cricket_session_->SignalError.connect( |
| 82 this, &JingleSession::OnSessionError); | 82 this, &JingleSession::OnSessionError); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void JingleSession::CloseInternal(int result, Error error) { | 85 void JingleSession::CloseInternal(int result, Error error) { |
| 86 DCHECK(CalledOnValidThread()); | 86 DCHECK(CalledOnValidThread()); |
| 87 | 87 |
| 88 if (state_ != FAILED && state_ != CLOSED && !closing_) { | 88 if (state_ != FAILED && state_ != CLOSED && !closing_) { |
| 89 closing_ = true; | 89 closing_ = true; |
| 90 | 90 |
| 91 control_channel_socket_.reset(); | |
| 92 event_channel_socket_.reset(); | |
| 93 STLDeleteContainerPairSecondPointers(channel_connectors_.begin(), | 91 STLDeleteContainerPairSecondPointers(channel_connectors_.begin(), |
| 94 channel_connectors_.end()); | 92 channel_connectors_.end()); |
| 95 | 93 |
| 96 // Tear down the cricket session, including the cricket transport channels. | 94 // Tear down the cricket session, including the cricket transport channels. |
| 97 if (cricket_session_) { | 95 if (cricket_session_) { |
| 98 std::string reason; | 96 std::string reason; |
| 99 switch (error) { | 97 switch (error) { |
| 100 case OK: | 98 case OK: |
| 101 reason = cricket::STR_TERMINATE_SUCCESS; | 99 reason = cricket::STR_TERMINATE_SUCCESS; |
| 102 break; | 100 break; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 171 } |
| 174 | 172 |
| 175 void JingleSession::CancelChannelCreation(const std::string& name) { | 173 void JingleSession::CancelChannelCreation(const std::string& name) { |
| 176 ChannelConnectorsMap::iterator it = channel_connectors_.find(name); | 174 ChannelConnectorsMap::iterator it = channel_connectors_.find(name); |
| 177 if (it != channel_connectors_.end()) { | 175 if (it != channel_connectors_.end()) { |
| 178 delete it->second; | 176 delete it->second; |
| 179 channel_connectors_.erase(it); | 177 channel_connectors_.erase(it); |
| 180 } | 178 } |
| 181 } | 179 } |
| 182 | 180 |
| 183 net::Socket* JingleSession::control_channel() { | |
| 184 DCHECK(CalledOnValidThread()); | |
| 185 return control_channel_socket_.get(); | |
| 186 } | |
| 187 | |
| 188 net::Socket* JingleSession::event_channel() { | |
| 189 DCHECK(CalledOnValidThread()); | |
| 190 return event_channel_socket_.get(); | |
| 191 } | |
| 192 | |
| 193 const std::string& JingleSession::jid() { | 181 const std::string& JingleSession::jid() { |
| 194 DCHECK(CalledOnValidThread()); | 182 DCHECK(CalledOnValidThread()); |
| 195 return jid_; | 183 return jid_; |
| 196 } | 184 } |
| 197 | 185 |
| 198 const CandidateSessionConfig* JingleSession::candidate_config() { | 186 const CandidateSessionConfig* JingleSession::candidate_config() { |
| 199 DCHECK(CalledOnValidThread()); | 187 DCHECK(CalledOnValidThread()); |
| 200 DCHECK(candidate_config_.get()); | 188 DCHECK(candidate_config_.get()); |
| 201 return candidate_config_.get(); | 189 return candidate_config_.get(); |
| 202 } | 190 } |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 // If we initiated the session, store the candidate configuration that the | 369 // If we initiated the session, store the candidate configuration that the |
| 382 // host responded with, to refer to later. | 370 // host responded with, to refer to later. |
| 383 if (cricket_session_->initiator()) { | 371 if (cricket_session_->initiator()) { |
| 384 if (!InitializeConfigFromDescription( | 372 if (!InitializeConfigFromDescription( |
| 385 cricket_session_->remote_description())) { | 373 cricket_session_->remote_description())) { |
| 386 CloseInternal(net::ERR_CONNECTION_FAILED, INCOMPATIBLE_PROTOCOL); | 374 CloseInternal(net::ERR_CONNECTION_FAILED, INCOMPATIBLE_PROTOCOL); |
| 387 return; | 375 return; |
| 388 } | 376 } |
| 389 } | 377 } |
| 390 | 378 |
| 391 CreateChannels(); | |
| 392 | |
| 393 SetState(CONNECTED); | 379 SetState(CONNECTED); |
| 394 } | 380 } |
| 395 | 381 |
| 396 void JingleSession::OnTerminate() { | 382 void JingleSession::OnTerminate() { |
| 397 DCHECK(CalledOnValidThread()); | 383 DCHECK(CalledOnValidThread()); |
| 398 CloseInternal(net::ERR_CONNECTION_ABORTED, OK); | 384 CloseInternal(net::ERR_CONNECTION_ABORTED, OK); |
| 399 } | 385 } |
| 400 | 386 |
| 401 void JingleSession::AcceptConnection() { | 387 void JingleSession::AcceptConnection() { |
| 402 SetState(CONNECTING); | 388 SetState(CONNECTING); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 cricket_session_->GetTransport(content_name)->ConnectChannels(); | 422 cricket_session_->GetTransport(content_name)->ConnectChannels(); |
| 437 } | 423 } |
| 438 | 424 |
| 439 void JingleSession::OnChannelConnectorFinished( | 425 void JingleSession::OnChannelConnectorFinished( |
| 440 const std::string& name, JingleChannelConnector* connector) { | 426 const std::string& name, JingleChannelConnector* connector) { |
| 441 DCHECK(CalledOnValidThread()); | 427 DCHECK(CalledOnValidThread()); |
| 442 DCHECK_EQ(channel_connectors_[name], connector); | 428 DCHECK_EQ(channel_connectors_[name], connector); |
| 443 channel_connectors_.erase(name); | 429 channel_connectors_.erase(name); |
| 444 } | 430 } |
| 445 | 431 |
| 446 void JingleSession::CreateChannels() { | |
| 447 CreateStreamChannel( | |
| 448 kControlChannelName, | |
| 449 base::Bind(&JingleSession::OnChannelConnected, | |
| 450 base::Unretained(this), &control_channel_socket_)); | |
| 451 CreateStreamChannel( | |
| 452 kEventChannelName, | |
| 453 base::Bind(&JingleSession::OnChannelConnected, | |
| 454 base::Unretained(this), &event_channel_socket_)); | |
| 455 } | |
| 456 | |
| 457 void JingleSession::OnChannelConnected( | |
| 458 scoped_ptr<net::Socket>* socket_container, | |
| 459 net::StreamSocket* socket) { | |
| 460 if (!socket) { | |
| 461 LOG(ERROR) << "Failed to connect control or events channel. " | |
| 462 << "Terminating connection"; | |
| 463 CloseInternal(net::ERR_CONNECTION_CLOSED, CHANNEL_CONNECTION_ERROR); | |
| 464 return; | |
| 465 } | |
| 466 | |
| 467 socket_container->reset(socket); | |
| 468 | |
| 469 if (control_channel_socket_.get() && event_channel_socket_.get()) | |
| 470 SetState(CONNECTED_CHANNELS); | |
| 471 } | |
| 472 | |
| 473 const cricket::ContentInfo* JingleSession::GetContentInfo() const { | 432 const cricket::ContentInfo* JingleSession::GetContentInfo() const { |
| 474 const cricket::SessionDescription* session_description; | 433 const cricket::SessionDescription* session_description; |
| 475 // If we initiate the session, we get to specify the content name. When | 434 // If we initiate the session, we get to specify the content name. When |
| 476 // accepting one, the remote end specifies it. | 435 // accepting one, the remote end specifies it. |
| 477 if (cricket_session_->initiator()) { | 436 if (cricket_session_->initiator()) { |
| 478 session_description = cricket_session_->local_description(); | 437 session_description = cricket_session_->local_description(); |
| 479 } else { | 438 } else { |
| 480 session_description = cricket_session_->remote_description(); | 439 session_description = cricket_session_->remote_description(); |
| 481 } | 440 } |
| 482 const cricket::ContentInfo* content = | 441 const cricket::ContentInfo* content = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 493 DCHECK_NE(state_, FAILED); | 452 DCHECK_NE(state_, FAILED); |
| 494 | 453 |
| 495 state_ = new_state; | 454 state_ = new_state; |
| 496 if (!state_change_callback_.is_null()) | 455 if (!state_change_callback_.is_null()) |
| 497 state_change_callback_.Run(new_state); | 456 state_change_callback_.Run(new_state); |
| 498 } | 457 } |
| 499 } | 458 } |
| 500 | 459 |
| 501 } // namespace protocol | 460 } // namespace protocol |
| 502 } // namespace remoting | 461 } // namespace remoting |
| OLD | NEW |