Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: remoting/protocol/jingle_session.cc

Issue 8537020: Send correct termination reason when session is terminated by the host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 PEER_IS_OFFLINE:
104 reason = cricket::STR_TERMINATE_ERROR;
105 break;
106 case SESSION_REJECTED:
107 reason = cricket::STR_TERMINATE_DECLINE;
108 break;
109 case INCOMPATIBLE_PROTOCOL:
110 reason = cricket::STR_TERMINATE_INCOMPATIBLE_PARAMETERS;
111 break;
112 case CHANNEL_CONNECTION_ERROR:
Wez 2011/11/11 23:10:09 Would it make more sense to have a default: case f
Sergey Ulanov 2011/11/12 00:02:52 Done.
113 reason = cricket::STR_TERMINATE_ERROR;
114 break;
115 }
116 cricket_session_->TerminateWithReason(reason);
99 cricket_session_->SignalState.disconnect(this); 117 cricket_session_->SignalState.disconnect(this);
100 } 118 }
101 119
102 // Inform the StateChangeCallback, so calling code knows not to 120 // Inform the StateChangeCallback, so calling code knows not to
103 // touch any channels. Needs to be done in the end because the 121 // touch any channels. Needs to be done in the end because the
104 // session may be deleted in response to this event. 122 // session may be deleted in response to this event.
105 if (failed) 123 if (error != OK) {
106 SetState(FAILED); 124 SetState(FAILED);
107 else 125 } else {
108 SetState(CLOSED); 126 SetState(CLOSED);
127 }
109 } 128 }
110 } 129 }
111 130
112 bool JingleSession::HasSession(cricket::Session* cricket_session) { 131 bool JingleSession::HasSession(cricket::Session* cricket_session) {
113 DCHECK(CalledOnValidThread()); 132 DCHECK(CalledOnValidThread());
114 return cricket_session_ == cricket_session; 133 return cricket_session_ == cricket_session;
115 } 134 }
116 135
117 cricket::Session* JingleSession::ReleaseSession() { 136 cricket::Session* JingleSession::ReleaseSession() {
118 DCHECK(CalledOnValidThread()); 137 DCHECK(CalledOnValidThread());
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 248
230 const std::string& JingleSession::shared_secret() { 249 const std::string& JingleSession::shared_secret() {
231 DCHECK(CalledOnValidThread()); 250 DCHECK(CalledOnValidThread());
232 return shared_secret_; 251 return shared_secret_;
233 } 252 }
234 253
235 254
236 void JingleSession::Close() { 255 void JingleSession::Close() {
237 DCHECK(CalledOnValidThread()); 256 DCHECK(CalledOnValidThread());
238 257
239 CloseInternal(net::ERR_CONNECTION_CLOSED, false); 258 CloseInternal(net::ERR_CONNECTION_CLOSED, OK);
240 } 259 }
241 260
242 void JingleSession::OnSessionState( 261 void JingleSession::OnSessionState(
243 BaseSession* session, BaseSession::State state) { 262 BaseSession* session, BaseSession::State state) {
244 DCHECK(CalledOnValidThread()); 263 DCHECK(CalledOnValidThread());
245 DCHECK_EQ(cricket_session_, session); 264 DCHECK_EQ(cricket_session_, session);
246 265
247 if (state_ == FAILED || state_ == CLOSED) { 266 if (state_ == FAILED || state_ == CLOSED) {
248 // Don't do anything if we already closed. 267 // Don't do anything if we already closed.
249 return; 268 return;
(...skipping 27 matching lines...) Expand all
277 break; 296 break;
278 } 297 }
279 } 298 }
280 299
281 void JingleSession::OnSessionError( 300 void JingleSession::OnSessionError(
282 BaseSession* session, BaseSession::Error error) { 301 BaseSession* session, BaseSession::Error error) {
283 DCHECK(CalledOnValidThread()); 302 DCHECK(CalledOnValidThread());
284 DCHECK_EQ(cricket_session_, session); 303 DCHECK_EQ(cricket_session_, session);
285 304
286 if (error != cricket::Session::ERROR_NONE) { 305 if (error != cricket::Session::ERROR_NONE) {
287 CloseInternal(net::ERR_CONNECTION_ABORTED, true); 306 // TODO(sergeyu): Report different errors depending on |error|.
307 CloseInternal(net::ERR_CONNECTION_ABORTED, CHANNEL_CONNECTION_ERROR);
288 } 308 }
289 } 309 }
290 310
291 void JingleSession::OnInitiate() { 311 void JingleSession::OnInitiate() {
292 DCHECK(CalledOnValidThread()); 312 DCHECK(CalledOnValidThread());
293 jid_ = cricket_session_->remote_name(); 313 jid_ = cricket_session_->remote_name();
294 314
295 if (!cricket_session_->initiator()) { 315 if (!cricket_session_->initiator()) {
296 const protocol::ContentDescription* content_description = 316 const protocol::ContentDescription* content_description =
297 static_cast<const protocol::ContentDescription*>( 317 static_cast<const protocol::ContentDescription*>(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } 370 }
351 371
352 void JingleSession::OnAccept() { 372 void JingleSession::OnAccept() {
353 DCHECK(CalledOnValidThread()); 373 DCHECK(CalledOnValidThread());
354 374
355 // If we initiated the session, store the candidate configuration that the 375 // If we initiated the session, store the candidate configuration that the
356 // host responded with, to refer to later. 376 // host responded with, to refer to later.
357 if (cricket_session_->initiator()) { 377 if (cricket_session_->initiator()) {
358 if (!InitializeConfigFromDescription( 378 if (!InitializeConfigFromDescription(
359 cricket_session_->remote_description())) { 379 cricket_session_->remote_description())) {
360 CloseInternal(net::ERR_CONNECTION_FAILED, true); 380 CloseInternal(net::ERR_CONNECTION_FAILED, INCOMPATIBLE_PROTOCOL);
361 return; 381 return;
362 } 382 }
363 } 383 }
364 384
365 CreateChannels(); 385 CreateChannels();
366 386
367 SetState(CONNECTED); 387 SetState(CONNECTED);
368 } 388 }
369 389
370 void JingleSession::OnTerminate() { 390 void JingleSession::OnTerminate() {
371 DCHECK(CalledOnValidThread()); 391 DCHECK(CalledOnValidThread());
372 CloseInternal(net::ERR_CONNECTION_ABORTED, false); 392 CloseInternal(net::ERR_CONNECTION_ABORTED, OK);
373 } 393 }
374 394
375 void JingleSession::AcceptConnection() { 395 void JingleSession::AcceptConnection() {
376 SetState(CONNECTING); 396 SetState(CONNECTING);
377 397
378 if (!jingle_session_manager_->AcceptConnection(this, cricket_session_)) { 398 if (!jingle_session_manager_->AcceptConnection(this, cricket_session_)) {
379 Close(); 399 Close();
380 // Release session so that JingleSessionManager::SessionDestroyed() 400 // Release session so that JingleSessionManager::SessionDestroyed()
381 // doesn't try to call cricket::SessionManager::DestroySession() for it. 401 // doesn't try to call cricket::SessionManager::DestroySession() for it.
382 ReleaseSession(); 402 ReleaseSession();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 base::Bind(&JingleSession::OnChannelConnected, 447 base::Bind(&JingleSession::OnChannelConnected,
428 base::Unretained(this), &event_channel_socket_)); 448 base::Unretained(this), &event_channel_socket_));
429 } 449 }
430 450
431 void JingleSession::OnChannelConnected( 451 void JingleSession::OnChannelConnected(
432 scoped_ptr<net::Socket>* socket_container, 452 scoped_ptr<net::Socket>* socket_container,
433 net::StreamSocket* socket) { 453 net::StreamSocket* socket) {
434 if (!socket) { 454 if (!socket) {
435 LOG(ERROR) << "Failed to connect control or events channel. " 455 LOG(ERROR) << "Failed to connect control or events channel. "
436 << "Terminating connection"; 456 << "Terminating connection";
437 CloseInternal(net::ERR_CONNECTION_CLOSED, true); 457 CloseInternal(net::ERR_CONNECTION_CLOSED, CHANNEL_CONNECTION_ERROR);
438 return; 458 return;
439 } 459 }
440 460
441 socket_container->reset(socket); 461 socket_container->reset(socket);
442 462
443 if (control_channel_socket_.get() && event_channel_socket_.get()) 463 if (control_channel_socket_.get() && event_channel_socket_.get())
444 SetState(CONNECTED_CHANNELS); 464 SetState(CONNECTED_CHANNELS);
445 } 465 }
446 466
447 const cricket::ContentInfo* JingleSession::GetContentInfo() const { 467 const cricket::ContentInfo* JingleSession::GetContentInfo() const {
(...skipping 19 matching lines...) Expand all
467 DCHECK_NE(state_, FAILED); 487 DCHECK_NE(state_, FAILED);
468 488
469 state_ = new_state; 489 state_ = new_state;
470 if (!state_change_callback_.is_null()) 490 if (!state_change_callback_.is_null())
471 state_change_callback_.Run(new_state); 491 state_change_callback_.Run(new_state);
472 } 492 }
473 } 493 }
474 494
475 } // namespace protocol 495 } // namespace protocol
476 } // namespace remoting 496 } // namespace remoting
OLDNEW
« remoting/protocol/jingle_session.h ('K') | « remoting/protocol/jingle_session.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698