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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 channel_multiplexer_.reset(new ChannelMultiplexer(this, kMuxChannelName)); | 219 channel_multiplexer_.reset(new ChannelMultiplexer(this, kMuxChannelName)); |
220 return channel_multiplexer_.get(); | 220 return channel_multiplexer_.get(); |
221 } | 221 } |
222 | 222 |
223 void JingleSession::Close() { | 223 void JingleSession::Close() { |
224 DCHECK(CalledOnValidThread()); | 224 DCHECK(CalledOnValidThread()); |
225 | 225 |
226 CloseInternal(OK); | 226 CloseInternal(OK); |
227 } | 227 } |
228 | 228 |
| 229 void JingleSession::AddPendingRemoteCandidates(Transport* channel, |
| 230 const std::string& name) { |
| 231 std::list<JingleMessage::NamedCandidate>::iterator it = |
| 232 pending_remote_candidates_.begin(); |
| 233 while(it != pending_remote_candidates_.end()) { |
| 234 if (it->name == name) { |
| 235 channel->AddRemoteCandidate(it->candidate); |
| 236 it = pending_remote_candidates_.erase(it); |
| 237 } else { |
| 238 ++it; |
| 239 } |
| 240 } |
| 241 } |
| 242 |
229 void JingleSession::CreateStreamChannel( | 243 void JingleSession::CreateStreamChannel( |
230 const std::string& name, | 244 const std::string& name, |
231 const StreamChannelCallback& callback) { | 245 const StreamChannelCallback& callback) { |
232 DCHECK(!channels_[name]); | 246 DCHECK(!channels_[name]); |
233 | 247 |
234 scoped_ptr<ChannelAuthenticator> channel_authenticator = | 248 scoped_ptr<ChannelAuthenticator> channel_authenticator = |
235 authenticator_->CreateChannelAuthenticator(); | 249 authenticator_->CreateChannelAuthenticator(); |
236 scoped_ptr<StreamTransport> channel = | 250 scoped_ptr<StreamTransport> channel = |
237 session_manager_->transport_factory_->CreateStreamTransport(); | 251 session_manager_->transport_factory_->CreateStreamTransport(); |
238 channel->Initialize(name, this, channel_authenticator.Pass()); | 252 channel->Initialize(name, this, channel_authenticator.Pass()); |
239 channel->Connect(callback); | 253 channel->Connect(callback); |
| 254 AddPendingRemoteCandidates(channel.get(), name); |
240 channels_[name] = channel.release(); | 255 channels_[name] = channel.release(); |
241 } | 256 } |
242 | 257 |
243 void JingleSession::CreateDatagramChannel( | 258 void JingleSession::CreateDatagramChannel( |
244 const std::string& name, | 259 const std::string& name, |
245 const DatagramChannelCallback& callback) { | 260 const DatagramChannelCallback& callback) { |
246 DCHECK(!channels_[name]); | 261 DCHECK(!channels_[name]); |
247 | 262 |
248 scoped_ptr<ChannelAuthenticator> channel_authenticator = | 263 scoped_ptr<ChannelAuthenticator> channel_authenticator = |
249 authenticator_->CreateChannelAuthenticator(); | 264 authenticator_->CreateChannelAuthenticator(); |
250 scoped_ptr<DatagramTransport> channel = | 265 scoped_ptr<DatagramTransport> channel = |
251 session_manager_->transport_factory_->CreateDatagramTransport(); | 266 session_manager_->transport_factory_->CreateDatagramTransport(); |
252 channel->Initialize(name, this, channel_authenticator.Pass()); | 267 channel->Initialize(name, this, channel_authenticator.Pass()); |
253 channel->Connect(callback); | 268 channel->Connect(callback); |
| 269 AddPendingRemoteCandidates(channel.get(), name); |
254 channels_[name] = channel.release(); | 270 channels_[name] = channel.release(); |
255 } | 271 } |
256 | 272 |
257 void JingleSession::CancelChannelCreation(const std::string& name) { | 273 void JingleSession::CancelChannelCreation(const std::string& name) { |
258 ChannelsMap::iterator it = channels_.find(name); | 274 ChannelsMap::iterator it = channels_.find(name); |
259 if (it != channels_.end() && !it->second->is_connected()) { | 275 if (it != channels_.end() && !it->second->is_connected()) { |
260 delete it->second; | 276 delete it->second; |
261 DCHECK(!channels_[name]); | 277 DCHECK(!channels_[name]); |
262 } | 278 } |
263 } | 279 } |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 | 498 |
483 authenticator_->ProcessMessage(message.info.get(), base::Bind( | 499 authenticator_->ProcessMessage(message.info.get(), base::Bind( |
484 &JingleSession::ProcessAuthenticationStep, base::Unretained(this))); | 500 &JingleSession::ProcessAuthenticationStep, base::Unretained(this))); |
485 } | 501 } |
486 | 502 |
487 void JingleSession::ProcessTransportInfo(const JingleMessage& message) { | 503 void JingleSession::ProcessTransportInfo(const JingleMessage& message) { |
488 for (std::list<JingleMessage::NamedCandidate>::const_iterator it = | 504 for (std::list<JingleMessage::NamedCandidate>::const_iterator it = |
489 message.candidates.begin(); | 505 message.candidates.begin(); |
490 it != message.candidates.end(); ++it) { | 506 it != message.candidates.end(); ++it) { |
491 ChannelsMap::iterator channel = channels_.find(it->name); | 507 ChannelsMap::iterator channel = channels_.find(it->name); |
492 if (channel == channels_.end()) { | 508 if (channel != channels_.end()) { |
493 LOG(WARNING) << "Received candidate for unknown channel " << it->name; | 509 channel->second->AddRemoteCandidate(it->candidate); |
494 continue; | 510 } else { |
| 511 // Transport info was received before the channel was created. |
| 512 // This could happen due to messages being reordered on the wire. |
| 513 pending_remote_candidates_.push_back(*it); |
495 } | 514 } |
496 channel->second->AddRemoteCandidate(it->candidate); | |
497 } | 515 } |
498 } | 516 } |
499 | 517 |
500 void JingleSession::OnTerminate(const JingleMessage& message, | 518 void JingleSession::OnTerminate(const JingleMessage& message, |
501 const ReplyCallback& reply_callback) { | 519 const ReplyCallback& reply_callback) { |
502 if (state_ != CONNECTING && state_ != ACCEPTING && state_ != CONNECTED && | 520 if (state_ != CONNECTING && state_ != ACCEPTING && state_ != CONNECTED && |
503 state_ != AUTHENTICATED) { | 521 state_ != AUTHENTICATED) { |
504 LOG(WARNING) << "Received unexpected session-terminate message."; | 522 LOG(WARNING) << "Received unexpected session-terminate message."; |
505 reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST); | 523 reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST); |
506 return; | 524 return; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 DCHECK_NE(state_, FAILED); | 650 DCHECK_NE(state_, FAILED); |
633 | 651 |
634 state_ = new_state; | 652 state_ = new_state; |
635 if (event_handler_) | 653 if (event_handler_) |
636 event_handler_->OnSessionStateChange(new_state); | 654 event_handler_->OnSessionStateChange(new_state); |
637 } | 655 } |
638 } | 656 } |
639 | 657 |
640 } // namespace protocol | 658 } // namespace protocol |
641 } // namespace remoting | 659 } // namespace remoting |
OLD | NEW |