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/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 namespace remoting { | 26 namespace remoting { |
27 | 27 |
28 namespace protocol { | 28 namespace protocol { |
29 | 29 |
30 const char JingleSession::kChromotingContentName[] = "chromoting"; | 30 const char JingleSession::kChromotingContentName[] = "chromoting"; |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 const char kControlChannelName[] = "control"; | 34 const char kControlChannelName[] = "control"; |
35 const char kEventChannelName[] = "event"; | 35 const char kEventChannelName[] = "event"; |
36 const char kVideoChannelName[] = "video"; | |
37 | 36 |
38 const int kMasterKeyLength = 16; | 37 const int kMasterKeyLength = 16; |
39 const int kChannelKeyLength = 16; | 38 const int kChannelKeyLength = 16; |
40 | 39 |
41 std::string GenerateRandomMasterKey() { | 40 std::string GenerateRandomMasterKey() { |
42 std::string result; | 41 std::string result; |
43 result.resize(kMasterKeyLength); | 42 result.resize(kMasterKeyLength); |
44 base::RandBytes(&result[0], result.size()); | 43 base::RandBytes(&result[0], result.size()); |
45 return result; | 44 return result; |
46 } | 45 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 152 |
154 // Inform the StateChangeCallback, so calling code knows not to touch any | 153 // Inform the StateChangeCallback, so calling code knows not to touch any |
155 // channels. | 154 // channels. |
156 if (failed) | 155 if (failed) |
157 SetState(FAILED); | 156 SetState(FAILED); |
158 else | 157 else |
159 SetState(CLOSED); | 158 SetState(CLOSED); |
160 | 159 |
161 control_channel_socket_.reset(); | 160 control_channel_socket_.reset(); |
162 event_channel_socket_.reset(); | 161 event_channel_socket_.reset(); |
163 video_channel_socket_.reset(); | |
164 STLDeleteContainerPairSecondPointers(channel_connectors_.begin(), | 162 STLDeleteContainerPairSecondPointers(channel_connectors_.begin(), |
165 channel_connectors_.end()); | 163 channel_connectors_.end()); |
166 | 164 |
167 // Tear down the cricket session, including the cricket transport channels. | 165 // Tear down the cricket session, including the cricket transport channels. |
168 if (cricket_session_) { | 166 if (cricket_session_) { |
169 cricket_session_->Terminate(); | 167 cricket_session_->Terminate(); |
170 cricket_session_->SignalState.disconnect(this); | 168 cricket_session_->SignalState.disconnect(this); |
171 } | 169 } |
172 | 170 |
173 closed_ = true; | 171 closed_ = true; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 net::Socket* JingleSession::control_channel() { | 215 net::Socket* JingleSession::control_channel() { |
218 DCHECK(CalledOnValidThread()); | 216 DCHECK(CalledOnValidThread()); |
219 return control_channel_socket_.get(); | 217 return control_channel_socket_.get(); |
220 } | 218 } |
221 | 219 |
222 net::Socket* JingleSession::event_channel() { | 220 net::Socket* JingleSession::event_channel() { |
223 DCHECK(CalledOnValidThread()); | 221 DCHECK(CalledOnValidThread()); |
224 return event_channel_socket_.get(); | 222 return event_channel_socket_.get(); |
225 } | 223 } |
226 | 224 |
227 net::Socket* JingleSession::video_channel() { | |
228 DCHECK(CalledOnValidThread()); | |
229 return video_channel_socket_.get(); | |
230 } | |
231 | |
232 net::Socket* JingleSession::video_rtp_channel() { | |
233 DCHECK(CalledOnValidThread()); | |
234 NOTREACHED(); | |
235 return NULL; | |
236 } | |
237 | |
238 net::Socket* JingleSession::video_rtcp_channel() { | |
239 DCHECK(CalledOnValidThread()); | |
240 NOTREACHED(); | |
241 return NULL; | |
242 } | |
243 | |
244 const std::string& JingleSession::jid() { | 225 const std::string& JingleSession::jid() { |
245 // TODO(sergeyu): Fix ChromotingHost so that it doesn't call this | 226 // TODO(sergeyu): Fix ChromotingHost so that it doesn't call this |
246 // method on invalid thread and uncomment this DCHECK. | 227 // method on invalid thread and uncomment this DCHECK. |
247 // See crbug.com/88600 . | 228 // See crbug.com/88600 . |
248 // DCHECK(CalledOnValidThread()); | 229 // DCHECK(CalledOnValidThread()); |
249 return jid_; | 230 return jid_; |
250 } | 231 } |
251 | 232 |
252 const CandidateSessionConfig* JingleSession::candidate_config() { | 233 const CandidateSessionConfig* JingleSession::candidate_config() { |
253 DCHECK(CalledOnValidThread()); | 234 DCHECK(CalledOnValidThread()); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 // host responded with, to refer to later. | 427 // host responded with, to refer to later. |
447 if (cricket_session_->initiator()) { | 428 if (cricket_session_->initiator()) { |
448 if (!InitializeConfigFromDescription( | 429 if (!InitializeConfigFromDescription( |
449 cricket_session_->remote_description())) { | 430 cricket_session_->remote_description())) { |
450 CloseInternal(net::ERR_CONNECTION_FAILED, true); | 431 CloseInternal(net::ERR_CONNECTION_FAILED, true); |
451 return; | 432 return; |
452 } | 433 } |
453 } | 434 } |
454 | 435 |
455 CreateChannels(); | 436 CreateChannels(); |
| 437 |
| 438 SetState(CONNECTED); |
456 } | 439 } |
457 | 440 |
458 void JingleSession::OnTerminate() { | 441 void JingleSession::OnTerminate() { |
459 DCHECK(CalledOnValidThread()); | 442 DCHECK(CalledOnValidThread()); |
460 CloseInternal(net::ERR_CONNECTION_ABORTED, false); | 443 CloseInternal(net::ERR_CONNECTION_ABORTED, false); |
461 } | 444 } |
462 | 445 |
463 void JingleSession::AcceptConnection() { | 446 void JingleSession::AcceptConnection() { |
| 447 SetState(CONNECTING); |
| 448 |
464 if (!jingle_session_manager_->AcceptConnection(this, cricket_session_)) { | 449 if (!jingle_session_manager_->AcceptConnection(this, cricket_session_)) { |
465 Close(); | 450 Close(); |
466 // Release session so that JingleSessionManager::SessionDestroyed() | 451 // Release session so that JingleSessionManager::SessionDestroyed() |
467 // doesn't try to call cricket::SessionManager::DestroySession() for it. | 452 // doesn't try to call cricket::SessionManager::DestroySession() for it. |
468 ReleaseSession(); | 453 ReleaseSession(); |
469 delete this; | 454 delete this; |
470 return; | 455 return; |
471 } | 456 } |
472 | |
473 // Set state to CONNECTING if the session is being accepted. | |
474 SetState(CONNECTING); | |
475 } | 457 } |
476 | 458 |
477 void JingleSession::AddChannelConnector( | 459 void JingleSession::AddChannelConnector( |
478 const std::string& name, JingleChannelConnector* connector) { | 460 const std::string& name, JingleChannelConnector* connector) { |
479 DCHECK(channel_connectors_.find(name) == channel_connectors_.end()); | 461 DCHECK(channel_connectors_.find(name) == channel_connectors_.end()); |
480 | 462 |
481 const std::string& content_name = GetContentInfo()->name; | 463 const std::string& content_name = GetContentInfo()->name; |
482 cricket::TransportChannel* raw_channel = | 464 cricket::TransportChannel* raw_channel = |
483 cricket_session_->CreateChannel(content_name, name); | 465 cricket_session_->CreateChannel(content_name, name); |
484 | 466 |
(...skipping 20 matching lines...) Expand all Loading... |
505 DCHECK_EQ(channel_connectors_[name], connector); | 487 DCHECK_EQ(channel_connectors_[name], connector); |
506 channel_connectors_[name] = NULL; | 488 channel_connectors_[name] = NULL; |
507 } | 489 } |
508 | 490 |
509 void JingleSession::CreateChannels() { | 491 void JingleSession::CreateChannels() { |
510 StreamChannelCallback stream_callback( | 492 StreamChannelCallback stream_callback( |
511 base::Bind(&JingleSession::OnStreamChannelConnected, | 493 base::Bind(&JingleSession::OnStreamChannelConnected, |
512 base::Unretained(this))); | 494 base::Unretained(this))); |
513 CreateStreamChannel(kControlChannelName, stream_callback); | 495 CreateStreamChannel(kControlChannelName, stream_callback); |
514 CreateStreamChannel(kEventChannelName, stream_callback); | 496 CreateStreamChannel(kEventChannelName, stream_callback); |
515 CreateStreamChannel(kVideoChannelName, stream_callback); | |
516 } | 497 } |
517 | 498 |
518 void JingleSession::OnStreamChannelConnected(const std::string& name, | 499 void JingleSession::OnStreamChannelConnected(const std::string& name, |
519 net::StreamSocket* socket) { | 500 net::StreamSocket* socket) { |
520 OnChannelConnected(name, socket); | 501 OnChannelConnected(name, socket); |
521 } | 502 } |
522 | 503 |
523 void JingleSession::OnChannelConnected(const std::string& name, | 504 void JingleSession::OnChannelConnected(const std::string& name, |
524 net::Socket* socket) { | 505 net::Socket* socket) { |
525 if (!socket) { | 506 if (!socket) { |
526 LOG(ERROR) << "Failed to connect channel " << name | 507 LOG(ERROR) << "Failed to connect channel " << name |
527 << ". Terminating connection"; | 508 << ". Terminating connection"; |
528 CloseInternal(net::ERR_CONNECTION_CLOSED, true); | 509 CloseInternal(net::ERR_CONNECTION_CLOSED, true); |
529 return; | 510 return; |
530 } | 511 } |
531 | 512 |
532 if (name == kControlChannelName) { | 513 if (name == kControlChannelName) { |
533 control_channel_socket_.reset(socket); | 514 control_channel_socket_.reset(socket); |
534 } else if (name == kEventChannelName) { | 515 } else if (name == kEventChannelName) { |
535 event_channel_socket_.reset(socket); | 516 event_channel_socket_.reset(socket); |
536 } else if (name == kVideoChannelName) { | |
537 video_channel_socket_.reset(socket); | |
538 } else { | 517 } else { |
539 NOTREACHED(); | 518 NOTREACHED(); |
540 } | 519 } |
541 | 520 |
542 if (control_channel_socket_.get() && event_channel_socket_.get() && | 521 if (control_channel_socket_.get() && event_channel_socket_.get()) |
543 video_channel_socket_.get()) { | 522 SetState(CONNECTED_CHANNELS); |
544 // TODO(sergeyu): State should be set to CONNECTED in OnAccept | |
545 // independent of the channels state. | |
546 SetState(CONNECTED); | |
547 } | |
548 } | 523 } |
549 | 524 |
550 const cricket::ContentInfo* JingleSession::GetContentInfo() const { | 525 const cricket::ContentInfo* JingleSession::GetContentInfo() const { |
551 const cricket::SessionDescription* session_description; | 526 const cricket::SessionDescription* session_description; |
552 // If we initiate the session, we get to specify the content name. When | 527 // If we initiate the session, we get to specify the content name. When |
553 // accepting one, the remote end specifies it. | 528 // accepting one, the remote end specifies it. |
554 if (cricket_session_->initiator()) { | 529 if (cricket_session_->initiator()) { |
555 session_description = cricket_session_->local_description(); | 530 session_description = cricket_session_->local_description(); |
556 } else { | 531 } else { |
557 session_description = cricket_session_->remote_description(); | 532 session_description = cricket_session_->remote_description(); |
(...skipping 13 matching lines...) Expand all Loading... |
571 | 546 |
572 state_ = new_state; | 547 state_ = new_state; |
573 if (!closed_ && state_change_callback_.get()) | 548 if (!closed_ && state_change_callback_.get()) |
574 state_change_callback_->Run(new_state); | 549 state_change_callback_->Run(new_state); |
575 } | 550 } |
576 } | 551 } |
577 | 552 |
578 } // namespace protocol | 553 } // namespace protocol |
579 | 554 |
580 } // namespace remoting | 555 } // namespace remoting |
OLD | NEW |