Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 const std::string& name, | 230 const std::string& name, |
| 231 const StreamChannelCallback& callback) { | 231 const StreamChannelCallback& callback) { |
| 232 DCHECK(!channels_[name]); | 232 DCHECK(!channels_[name]); |
| 233 | 233 |
| 234 scoped_ptr<ChannelAuthenticator> channel_authenticator = | 234 scoped_ptr<ChannelAuthenticator> channel_authenticator = |
| 235 authenticator_->CreateChannelAuthenticator(); | 235 authenticator_->CreateChannelAuthenticator(); |
| 236 scoped_ptr<StreamTransport> channel = | 236 scoped_ptr<StreamTransport> channel = |
| 237 session_manager_->transport_factory_->CreateStreamTransport(); | 237 session_manager_->transport_factory_->CreateStreamTransport(); |
| 238 channel->Initialize(name, this, channel_authenticator.Pass()); | 238 channel->Initialize(name, this, channel_authenticator.Pass()); |
| 239 channel->Connect(callback); | 239 channel->Connect(callback); |
| 240 // Check if any remote candidates were already received for this channel. | |
|
Wez
2013/07/12 22:43:24
nit: Blank line before this comment.
rmsousa
2013/07/13 00:11:47
Moved to the header for the new function.
| |
| 241 std::list<JingleMessage::NamedCandidate>::iterator it = | |
|
Wez
2013/07/12 22:43:24
nit: This code fragment is identical to the one in
rmsousa
2013/07/13 00:11:47
Done.
| |
| 242 pending_remote_candidates_.begin(); | |
| 243 while(it != pending_remote_candidates_.end()) { | |
| 244 if (it->name == name) { | |
| 245 channel->AddRemoteCandidate(it->candidate); | |
| 246 it = pending_remote_candidates_.erase(it); | |
| 247 } else { | |
| 248 ++it; | |
| 249 } | |
| 250 } | |
| 240 channels_[name] = channel.release(); | 251 channels_[name] = channel.release(); |
| 241 } | 252 } |
| 242 | 253 |
| 243 void JingleSession::CreateDatagramChannel( | 254 void JingleSession::CreateDatagramChannel( |
| 244 const std::string& name, | 255 const std::string& name, |
| 245 const DatagramChannelCallback& callback) { | 256 const DatagramChannelCallback& callback) { |
| 246 DCHECK(!channels_[name]); | 257 DCHECK(!channels_[name]); |
| 247 | 258 |
| 248 scoped_ptr<ChannelAuthenticator> channel_authenticator = | 259 scoped_ptr<ChannelAuthenticator> channel_authenticator = |
| 249 authenticator_->CreateChannelAuthenticator(); | 260 authenticator_->CreateChannelAuthenticator(); |
| 250 scoped_ptr<DatagramTransport> channel = | 261 scoped_ptr<DatagramTransport> channel = |
| 251 session_manager_->transport_factory_->CreateDatagramTransport(); | 262 session_manager_->transport_factory_->CreateDatagramTransport(); |
| 252 channel->Initialize(name, this, channel_authenticator.Pass()); | 263 channel->Initialize(name, this, channel_authenticator.Pass()); |
| 253 channel->Connect(callback); | 264 channel->Connect(callback); |
|
Wez
2013/07/12 22:43:24
nit: Blank line before this comment.
rmsousa
2013/07/13 00:11:47
Moved to the header for the new function.
| |
| 265 // Check if any remote candidates were already received for this channel. | |
| 266 std::list<JingleMessage::NamedCandidate>::iterator it = | |
| 267 pending_remote_candidates_.begin(); | |
| 268 while(it != pending_remote_candidates_.end()) { | |
| 269 if (it->name == name) { | |
| 270 channel->AddRemoteCandidate(it->candidate); | |
| 271 it = pending_remote_candidates_.erase(it); | |
| 272 } else { | |
| 273 ++it; | |
| 274 } | |
| 275 } | |
| 254 channels_[name] = channel.release(); | 276 channels_[name] = channel.release(); |
| 255 } | 277 } |
| 256 | 278 |
| 257 void JingleSession::CancelChannelCreation(const std::string& name) { | 279 void JingleSession::CancelChannelCreation(const std::string& name) { |
| 258 ChannelsMap::iterator it = channels_.find(name); | 280 ChannelsMap::iterator it = channels_.find(name); |
| 259 if (it != channels_.end() && !it->second->is_connected()) { | 281 if (it != channels_.end() && !it->second->is_connected()) { |
|
Wez
2013/07/12 22:43:24
nit: Clear any candidates received for cancelled c
rmsousa
2013/07/13 00:11:47
The candidates are removed from the list and added
| |
| 260 delete it->second; | 282 delete it->second; |
| 261 DCHECK(!channels_[name]); | 283 DCHECK(!channels_[name]); |
| 262 } | 284 } |
| 263 } | 285 } |
| 264 | 286 |
| 265 void JingleSession::OnTransportCandidate(Transport* transport, | 287 void JingleSession::OnTransportCandidate(Transport* transport, |
| 266 const cricket::Candidate& candidate) { | 288 const cricket::Candidate& candidate) { |
| 267 pending_candidates_.push_back(JingleMessage::NamedCandidate( | 289 pending_candidates_.push_back(JingleMessage::NamedCandidate( |
| 268 transport->name(), candidate)); | 290 transport->name(), candidate)); |
| 269 | 291 |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 | 504 |
| 483 authenticator_->ProcessMessage(message.info.get(), base::Bind( | 505 authenticator_->ProcessMessage(message.info.get(), base::Bind( |
| 484 &JingleSession::ProcessAuthenticationStep, base::Unretained(this))); | 506 &JingleSession::ProcessAuthenticationStep, base::Unretained(this))); |
| 485 } | 507 } |
| 486 | 508 |
| 487 void JingleSession::ProcessTransportInfo(const JingleMessage& message) { | 509 void JingleSession::ProcessTransportInfo(const JingleMessage& message) { |
| 488 for (std::list<JingleMessage::NamedCandidate>::const_iterator it = | 510 for (std::list<JingleMessage::NamedCandidate>::const_iterator it = |
| 489 message.candidates.begin(); | 511 message.candidates.begin(); |
| 490 it != message.candidates.end(); ++it) { | 512 it != message.candidates.end(); ++it) { |
| 491 ChannelsMap::iterator channel = channels_.find(it->name); | 513 ChannelsMap::iterator channel = channels_.find(it->name); |
| 492 if (channel == channels_.end()) { | 514 if (channel != channels_.end()) { |
| 493 LOG(WARNING) << "Received candidate for unknown channel " << it->name; | 515 channel->second->AddRemoteCandidate(it->candidate); |
| 494 continue; | 516 } else { |
| 517 // Transport info was received before the channel was created. | |
| 518 // This could happen due to messages being reordered on the wire. | |
| 519 pending_remote_candidates_.push_back(*it); | |
| 495 } | 520 } |
| 496 channel->second->AddRemoteCandidate(it->candidate); | |
| 497 } | 521 } |
| 498 } | 522 } |
| 499 | 523 |
| 500 void JingleSession::OnTerminate(const JingleMessage& message, | 524 void JingleSession::OnTerminate(const JingleMessage& message, |
| 501 const ReplyCallback& reply_callback) { | 525 const ReplyCallback& reply_callback) { |
| 502 if (state_ != CONNECTING && state_ != ACCEPTING && state_ != CONNECTED && | 526 if (state_ != CONNECTING && state_ != ACCEPTING && state_ != CONNECTED && |
| 503 state_ != AUTHENTICATED) { | 527 state_ != AUTHENTICATED) { |
| 504 LOG(WARNING) << "Received unexpected session-terminate message."; | 528 LOG(WARNING) << "Received unexpected session-terminate message."; |
| 505 reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST); | 529 reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST); |
| 506 return; | 530 return; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 632 DCHECK_NE(state_, FAILED); | 656 DCHECK_NE(state_, FAILED); |
| 633 | 657 |
| 634 state_ = new_state; | 658 state_ = new_state; |
| 635 if (event_handler_) | 659 if (event_handler_) |
| 636 event_handler_->OnSessionStateChange(new_state); | 660 event_handler_->OnSessionStateChange(new_state); |
| 637 } | 661 } |
| 638 } | 662 } |
| 639 | 663 |
| 640 } // namespace protocol | 664 } // namespace protocol |
| 641 } // namespace remoting | 665 } // namespace remoting |
| OLD | NEW |