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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 DCHECK_EQ(channel_connectors_[name], connector); | 486 DCHECK_EQ(channel_connectors_[name], connector); |
506 channel_connectors_[name] = NULL; | 487 channel_connectors_[name] = NULL; |
507 } | 488 } |
508 | 489 |
509 void JingleSession::CreateChannels() { | 490 void JingleSession::CreateChannels() { |
510 StreamChannelCallback stream_callback( | 491 StreamChannelCallback stream_callback( |
511 base::Bind(&JingleSession::OnStreamChannelConnected, | 492 base::Bind(&JingleSession::OnStreamChannelConnected, |
512 base::Unretained(this))); | 493 base::Unretained(this))); |
513 CreateStreamChannel(kControlChannelName, stream_callback); | 494 CreateStreamChannel(kControlChannelName, stream_callback); |
514 CreateStreamChannel(kEventChannelName, stream_callback); | 495 CreateStreamChannel(kEventChannelName, stream_callback); |
515 CreateStreamChannel(kVideoChannelName, stream_callback); | |
516 } | 496 } |
517 | 497 |
518 void JingleSession::OnStreamChannelConnected(const std::string& name, | 498 void JingleSession::OnStreamChannelConnected(const std::string& name, |
519 net::StreamSocket* socket) { | 499 net::StreamSocket* socket) { |
520 OnChannelConnected(name, socket); | 500 OnChannelConnected(name, socket); |
521 } | 501 } |
522 | 502 |
523 void JingleSession::OnChannelConnected(const std::string& name, | 503 void JingleSession::OnChannelConnected(const std::string& name, |
524 net::Socket* socket) { | 504 net::Socket* socket) { |
525 if (!socket) { | 505 if (!socket) { |
526 LOG(ERROR) << "Failed to connect channel " << name | 506 LOG(ERROR) << "Failed to connect channel " << name |
527 << ". Terminating connection"; | 507 << ". Terminating connection"; |
528 CloseInternal(net::ERR_CONNECTION_CLOSED, true); | 508 CloseInternal(net::ERR_CONNECTION_CLOSED, true); |
529 return; | 509 return; |
530 } | 510 } |
531 | 511 |
532 if (name == kControlChannelName) { | 512 if (name == kControlChannelName) { |
533 control_channel_socket_.reset(socket); | 513 control_channel_socket_.reset(socket); |
534 } else if (name == kEventChannelName) { | 514 } else if (name == kEventChannelName) { |
535 event_channel_socket_.reset(socket); | 515 event_channel_socket_.reset(socket); |
536 } else if (name == kVideoChannelName) { | |
537 video_channel_socket_.reset(socket); | |
538 } else { | 516 } else { |
539 NOTREACHED(); | 517 NOTREACHED(); |
540 } | 518 } |
541 | 519 |
542 if (control_channel_socket_.get() && event_channel_socket_.get() && | 520 if (control_channel_socket_.get() && event_channel_socket_.get()) { |
543 video_channel_socket_.get()) { | |
544 // TODO(sergeyu): State should be set to CONNECTED in OnAccept | 521 // TODO(sergeyu): State should be set to CONNECTED in OnAccept |
545 // independent of the channels state. | 522 // independent of the channels state. |
546 SetState(CONNECTED); | 523 SetState(CONNECTED); |
547 } | 524 } |
548 } | 525 } |
549 | 526 |
550 const cricket::ContentInfo* JingleSession::GetContentInfo() const { | 527 const cricket::ContentInfo* JingleSession::GetContentInfo() const { |
551 const cricket::SessionDescription* session_description; | 528 const cricket::SessionDescription* session_description; |
552 // If we initiate the session, we get to specify the content name. When | 529 // If we initiate the session, we get to specify the content name. When |
553 // accepting one, the remote end specifies it. | 530 // accepting one, the remote end specifies it. |
(...skipping 17 matching lines...) Expand all Loading... |
571 | 548 |
572 state_ = new_state; | 549 state_ = new_state; |
573 if (!closed_ && state_change_callback_.get()) | 550 if (!closed_ && state_change_callback_.get()) |
574 state_change_callback_->Run(new_state); | 551 state_change_callback_->Run(new_state); |
575 } | 552 } |
576 } | 553 } |
577 | 554 |
578 } // namespace protocol | 555 } // namespace protocol |
579 | 556 |
580 } // namespace remoting | 557 } // namespace remoting |
OLD | NEW |