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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 DCHECK(CalledOnValidThread()); | 75 DCHECK(CalledOnValidThread()); |
76 | 76 |
77 cricket_session_ = cricket_session; | 77 cricket_session_ = cricket_session; |
78 jid_ = cricket_session_->remote_name(); | 78 jid_ = cricket_session_->remote_name(); |
79 cricket_session_->SignalState.connect( | 79 cricket_session_->SignalState.connect( |
80 this, &JingleSession::OnSessionState); | 80 this, &JingleSession::OnSessionState); |
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, bool failed) { | 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(); | 91 control_channel_socket_.reset(); |
92 event_channel_socket_.reset(); | 92 event_channel_socket_.reset(); |
93 STLDeleteContainerPairSecondPointers(channel_connectors_.begin(), | 93 STLDeleteContainerPairSecondPointers(channel_connectors_.begin(), |
94 channel_connectors_.end()); | 94 channel_connectors_.end()); |
95 | 95 |
96 // Tear down the cricket session, including the cricket transport channels. | 96 // Tear down the cricket session, including the cricket transport channels. |
97 if (cricket_session_) { | 97 if (cricket_session_) { |
98 cricket_session_->Terminate(); | 98 std::string reason; |
| 99 switch (error) { |
| 100 case OK: |
| 101 reason = cricket::STR_TERMINATE_SUCCESS; |
| 102 break; |
| 103 case SESSION_REJECTED: |
| 104 reason = cricket::STR_TERMINATE_DECLINE; |
| 105 break; |
| 106 case INCOMPATIBLE_PROTOCOL: |
| 107 reason = cricket::STR_TERMINATE_INCOMPATIBLE_PARAMETERS; |
| 108 break; |
| 109 default: |
| 110 reason = cricket::STR_TERMINATE_ERROR; |
| 111 } |
| 112 cricket_session_->TerminateWithReason(reason); |
99 cricket_session_->SignalState.disconnect(this); | 113 cricket_session_->SignalState.disconnect(this); |
100 } | 114 } |
101 | 115 |
| 116 error_ = error; |
| 117 |
102 // Inform the StateChangeCallback, so calling code knows not to | 118 // Inform the StateChangeCallback, so calling code knows not to |
103 // touch any channels. Needs to be done in the end because the | 119 // touch any channels. Needs to be done in the end because the |
104 // session may be deleted in response to this event. | 120 // session may be deleted in response to this event. |
105 if (failed) | 121 if (error != OK) { |
106 SetState(FAILED); | 122 SetState(FAILED); |
107 else | 123 } else { |
108 SetState(CLOSED); | 124 SetState(CLOSED); |
| 125 } |
109 } | 126 } |
110 } | 127 } |
111 | 128 |
112 bool JingleSession::HasSession(cricket::Session* cricket_session) { | 129 bool JingleSession::HasSession(cricket::Session* cricket_session) { |
113 DCHECK(CalledOnValidThread()); | 130 DCHECK(CalledOnValidThread()); |
114 return cricket_session_ == cricket_session; | 131 return cricket_session_ == cricket_session; |
115 } | 132 } |
116 | 133 |
117 cricket::Session* JingleSession::ReleaseSession() { | 134 cricket::Session* JingleSession::ReleaseSession() { |
118 DCHECK(CalledOnValidThread()); | 135 DCHECK(CalledOnValidThread()); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 | 246 |
230 const std::string& JingleSession::shared_secret() { | 247 const std::string& JingleSession::shared_secret() { |
231 DCHECK(CalledOnValidThread()); | 248 DCHECK(CalledOnValidThread()); |
232 return shared_secret_; | 249 return shared_secret_; |
233 } | 250 } |
234 | 251 |
235 | 252 |
236 void JingleSession::Close() { | 253 void JingleSession::Close() { |
237 DCHECK(CalledOnValidThread()); | 254 DCHECK(CalledOnValidThread()); |
238 | 255 |
239 CloseInternal(net::ERR_CONNECTION_CLOSED, false); | 256 CloseInternal(net::ERR_CONNECTION_CLOSED, OK); |
240 } | 257 } |
241 | 258 |
242 void JingleSession::OnSessionState( | 259 void JingleSession::OnSessionState( |
243 BaseSession* session, BaseSession::State state) { | 260 BaseSession* session, BaseSession::State state) { |
244 DCHECK(CalledOnValidThread()); | 261 DCHECK(CalledOnValidThread()); |
245 DCHECK_EQ(cricket_session_, session); | 262 DCHECK_EQ(cricket_session_, session); |
246 | 263 |
247 if (state_ == FAILED || state_ == CLOSED) { | 264 if (state_ == FAILED || state_ == CLOSED) { |
248 // Don't do anything if we already closed. | 265 // Don't do anything if we already closed. |
249 return; | 266 return; |
(...skipping 27 matching lines...) Expand all Loading... |
277 break; | 294 break; |
278 } | 295 } |
279 } | 296 } |
280 | 297 |
281 void JingleSession::OnSessionError( | 298 void JingleSession::OnSessionError( |
282 BaseSession* session, BaseSession::Error error) { | 299 BaseSession* session, BaseSession::Error error) { |
283 DCHECK(CalledOnValidThread()); | 300 DCHECK(CalledOnValidThread()); |
284 DCHECK_EQ(cricket_session_, session); | 301 DCHECK_EQ(cricket_session_, session); |
285 | 302 |
286 if (error != cricket::Session::ERROR_NONE) { | 303 if (error != cricket::Session::ERROR_NONE) { |
287 CloseInternal(net::ERR_CONNECTION_ABORTED, true); | 304 // TODO(sergeyu): Report different errors depending on |error|. |
| 305 CloseInternal(net::ERR_CONNECTION_ABORTED, CHANNEL_CONNECTION_ERROR); |
288 } | 306 } |
289 } | 307 } |
290 | 308 |
291 void JingleSession::OnInitiate() { | 309 void JingleSession::OnInitiate() { |
292 DCHECK(CalledOnValidThread()); | 310 DCHECK(CalledOnValidThread()); |
293 jid_ = cricket_session_->remote_name(); | 311 jid_ = cricket_session_->remote_name(); |
294 | 312 |
295 if (!cricket_session_->initiator()) { | 313 if (!cricket_session_->initiator()) { |
296 const protocol::ContentDescription* content_description = | 314 const protocol::ContentDescription* content_description = |
297 static_cast<const protocol::ContentDescription*>( | 315 static_cast<const protocol::ContentDescription*>( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 } | 368 } |
351 | 369 |
352 void JingleSession::OnAccept() { | 370 void JingleSession::OnAccept() { |
353 DCHECK(CalledOnValidThread()); | 371 DCHECK(CalledOnValidThread()); |
354 | 372 |
355 // If we initiated the session, store the candidate configuration that the | 373 // If we initiated the session, store the candidate configuration that the |
356 // host responded with, to refer to later. | 374 // host responded with, to refer to later. |
357 if (cricket_session_->initiator()) { | 375 if (cricket_session_->initiator()) { |
358 if (!InitializeConfigFromDescription( | 376 if (!InitializeConfigFromDescription( |
359 cricket_session_->remote_description())) { | 377 cricket_session_->remote_description())) { |
360 CloseInternal(net::ERR_CONNECTION_FAILED, true); | 378 CloseInternal(net::ERR_CONNECTION_FAILED, INCOMPATIBLE_PROTOCOL); |
361 return; | 379 return; |
362 } | 380 } |
363 } | 381 } |
364 | 382 |
365 CreateChannels(); | 383 CreateChannels(); |
366 | 384 |
367 SetState(CONNECTED); | 385 SetState(CONNECTED); |
368 } | 386 } |
369 | 387 |
370 void JingleSession::OnTerminate() { | 388 void JingleSession::OnTerminate() { |
371 DCHECK(CalledOnValidThread()); | 389 DCHECK(CalledOnValidThread()); |
372 CloseInternal(net::ERR_CONNECTION_ABORTED, false); | 390 CloseInternal(net::ERR_CONNECTION_ABORTED, OK); |
373 } | 391 } |
374 | 392 |
375 void JingleSession::AcceptConnection() { | 393 void JingleSession::AcceptConnection() { |
376 SetState(CONNECTING); | 394 SetState(CONNECTING); |
377 | 395 |
378 if (!jingle_session_manager_->AcceptConnection(this, cricket_session_)) { | 396 if (!jingle_session_manager_->AcceptConnection(this, cricket_session_)) { |
379 Close(); | 397 Close(); |
380 // Release session so that JingleSessionManager::SessionDestroyed() | 398 // Release session so that JingleSessionManager::SessionDestroyed() |
381 // doesn't try to call cricket::SessionManager::DestroySession() for it. | 399 // doesn't try to call cricket::SessionManager::DestroySession() for it. |
382 ReleaseSession(); | 400 ReleaseSession(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 base::Bind(&JingleSession::OnChannelConnected, | 445 base::Bind(&JingleSession::OnChannelConnected, |
428 base::Unretained(this), &event_channel_socket_)); | 446 base::Unretained(this), &event_channel_socket_)); |
429 } | 447 } |
430 | 448 |
431 void JingleSession::OnChannelConnected( | 449 void JingleSession::OnChannelConnected( |
432 scoped_ptr<net::Socket>* socket_container, | 450 scoped_ptr<net::Socket>* socket_container, |
433 net::StreamSocket* socket) { | 451 net::StreamSocket* socket) { |
434 if (!socket) { | 452 if (!socket) { |
435 LOG(ERROR) << "Failed to connect control or events channel. " | 453 LOG(ERROR) << "Failed to connect control or events channel. " |
436 << "Terminating connection"; | 454 << "Terminating connection"; |
437 CloseInternal(net::ERR_CONNECTION_CLOSED, true); | 455 CloseInternal(net::ERR_CONNECTION_CLOSED, CHANNEL_CONNECTION_ERROR); |
438 return; | 456 return; |
439 } | 457 } |
440 | 458 |
441 socket_container->reset(socket); | 459 socket_container->reset(socket); |
442 | 460 |
443 if (control_channel_socket_.get() && event_channel_socket_.get()) | 461 if (control_channel_socket_.get() && event_channel_socket_.get()) |
444 SetState(CONNECTED_CHANNELS); | 462 SetState(CONNECTED_CHANNELS); |
445 } | 463 } |
446 | 464 |
447 const cricket::ContentInfo* JingleSession::GetContentInfo() const { | 465 const cricket::ContentInfo* JingleSession::GetContentInfo() const { |
(...skipping 19 matching lines...) Expand all Loading... |
467 DCHECK_NE(state_, FAILED); | 485 DCHECK_NE(state_, FAILED); |
468 | 486 |
469 state_ = new_state; | 487 state_ = new_state; |
470 if (!state_change_callback_.is_null()) | 488 if (!state_change_callback_.is_null()) |
471 state_change_callback_.Run(new_state); | 489 state_change_callback_.Run(new_state); |
472 } | 490 } |
473 } | 491 } |
474 | 492 |
475 } // namespace protocol | 493 } // namespace protocol |
476 } // namespace remoting | 494 } // namespace remoting |
OLD | NEW |