Chromium Code Reviews| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 LOG(ERROR) << "Failed to send a transport-info message"; | 233 LOG(ERROR) << "Failed to send a transport-info message"; |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 | 236 |
| 237 void JingleSession::Close(protocol::ErrorCode error) { | 237 void JingleSession::Close(protocol::ErrorCode error) { |
| 238 DCHECK(thread_checker_.CalledOnValidThread()); | 238 DCHECK(thread_checker_.CalledOnValidThread()); |
| 239 | 239 |
| 240 if (is_session_active()) { | 240 if (is_session_active()) { |
| 241 // Send session-terminate message with the appropriate error code. | 241 // Send session-terminate message with the appropriate error code. |
| 242 JingleMessage::Reason reason; | 242 JingleMessage::Reason reason; |
| 243 ErrorCode error_code = UNKNOWN_ERROR; | |
|
Sergey Ulanov
2016/06/02 09:26:04
I think we want to set error_code for _all_ errors
Hzj_jie
2016/06/02 22:00:19
Done.
| |
| 243 switch (error) { | 244 switch (error) { |
| 244 case OK: | 245 case OK: |
| 245 reason = JingleMessage::SUCCESS; | 246 reason = JingleMessage::SUCCESS; |
| 246 break; | 247 break; |
| 247 case SESSION_REJECTED: | 248 case SESSION_REJECTED: |
| 249 reason = JingleMessage::DECLINE; | |
| 250 error_code = SESSION_REJECTED; | |
| 248 case AUTHENTICATION_FAILED: | 251 case AUTHENTICATION_FAILED: |
| 249 reason = JingleMessage::DECLINE; | 252 reason = JingleMessage::DECLINE; |
| 253 error_code = AUTHENTICATION_FAILED; | |
| 250 break; | 254 break; |
| 251 case INVALID_ACCOUNT: | 255 case INVALID_ACCOUNT: |
| 252 // TODO(zijiehe): Instead of using SECURITY_ERROR Jingle reason, add a | 256 reason = JingleMessage::DECLINE; |
| 253 // new tag under crd namespace to export detail error reason to client. | 257 error_code = INVALID_ACCOUNT; |
| 254 reason = JingleMessage::SECURITY_ERROR; | |
| 255 break; | 258 break; |
| 256 case INCOMPATIBLE_PROTOCOL: | 259 case INCOMPATIBLE_PROTOCOL: |
| 257 reason = JingleMessage::INCOMPATIBLE_PARAMETERS; | 260 reason = JingleMessage::INCOMPATIBLE_PARAMETERS; |
| 258 break; | 261 break; |
| 259 case HOST_OVERLOAD: | 262 case HOST_OVERLOAD: |
| 260 reason = JingleMessage::CANCEL; | 263 reason = JingleMessage::CANCEL; |
| 261 break; | 264 break; |
| 262 case MAX_SESSION_LENGTH: | 265 case MAX_SESSION_LENGTH: |
| 263 reason = JingleMessage::EXPIRED; | 266 reason = JingleMessage::EXPIRED; |
| 264 break; | 267 break; |
| 265 case HOST_CONFIGURATION_ERROR: | 268 case HOST_CONFIGURATION_ERROR: |
| 266 reason = JingleMessage::FAILED_APPLICATION; | 269 reason = JingleMessage::FAILED_APPLICATION; |
| 267 break; | 270 break; |
| 268 default: | 271 default: |
| 269 reason = JingleMessage::GENERAL_ERROR; | 272 reason = JingleMessage::GENERAL_ERROR; |
| 270 } | 273 } |
| 271 | 274 |
| 272 JingleMessage message(peer_address_, JingleMessage::SESSION_TERMINATE, | 275 JingleMessage message(peer_address_, JingleMessage::SESSION_TERMINATE, |
| 273 session_id_); | 276 session_id_); |
| 274 message.reason = reason; | 277 message.reason = reason; |
| 278 message.error_code = error_code; | |
|
Sergey Ulanov
2016/06/02 09:26:04
message.error_code = error; and remove error_code
Hzj_jie
2016/06/02 22:00:19
Done.
| |
| 275 SendMessage(message); | 279 SendMessage(message); |
| 276 } | 280 } |
| 277 | 281 |
| 278 error_ = error; | 282 error_ = error; |
| 279 | 283 |
| 280 if (state_ != FAILED && state_ != CLOSED) { | 284 if (state_ != FAILED && state_ != CLOSED) { |
| 281 if (error != OK) { | 285 if (error != OK) { |
| 282 SetState(FAILED); | 286 SetState(FAILED); |
| 283 } else { | 287 } else { |
| 284 SetState(CLOSED); | 288 SetState(CLOSED); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 void JingleSession::OnTerminate(const JingleMessage& message, | 478 void JingleSession::OnTerminate(const JingleMessage& message, |
| 475 const ReplyCallback& reply_callback) { | 479 const ReplyCallback& reply_callback) { |
| 476 if (!is_session_active()) { | 480 if (!is_session_active()) { |
| 477 LOG(WARNING) << "Received unexpected session-terminate message."; | 481 LOG(WARNING) << "Received unexpected session-terminate message."; |
| 478 reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST); | 482 reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST); |
| 479 return; | 483 return; |
| 480 } | 484 } |
| 481 | 485 |
| 482 reply_callback.Run(JingleMessageReply::NONE); | 486 reply_callback.Run(JingleMessageReply::NONE); |
| 483 | 487 |
| 484 switch (message.reason) { | 488 switch (message.error_code) { |
|
Sergey Ulanov
2016/06/02 09:26:04
You don't need this switch.
Just replace it with
Hzj_jie
2016/06/02 22:00:19
Done.
| |
| 485 case JingleMessage::SUCCESS: | 489 case SESSION_REJECTED: |
| 486 if (state_ == CONNECTING) { | 490 // For backward compatibility, we still use AUTHENTICATION_FAILED for |
| 487 error_ = SESSION_REJECTED; | 491 // SESSION_REJECTED error. |
| 488 } else { | |
| 489 error_ = OK; | |
| 490 } | |
| 491 break; | |
| 492 case JingleMessage::DECLINE: | |
| 493 error_ = AUTHENTICATION_FAILED; | 492 error_ = AUTHENTICATION_FAILED; |
| 494 break; | 493 break; |
| 495 case JingleMessage::SECURITY_ERROR: | 494 case AUTHENTICATION_FAILED: |
| 495 error_ = AUTHENTICATION_FAILED; | |
| 496 break; | |
| 497 case INVALID_ACCOUNT: | |
| 496 error_ = INVALID_ACCOUNT; | 498 error_ = INVALID_ACCOUNT; |
| 497 break; | 499 break; |
| 498 case JingleMessage::CANCEL: | |
| 499 error_ = HOST_OVERLOAD; | |
| 500 break; | |
| 501 case JingleMessage::EXPIRED: | |
| 502 error_ = MAX_SESSION_LENGTH; | |
| 503 break; | |
| 504 case JingleMessage::INCOMPATIBLE_PARAMETERS: | |
| 505 error_ = INCOMPATIBLE_PROTOCOL; | |
| 506 break; | |
| 507 case JingleMessage::FAILED_APPLICATION: | |
| 508 error_ = HOST_CONFIGURATION_ERROR; | |
| 509 break; | |
| 510 case JingleMessage::GENERAL_ERROR: | |
| 511 error_ = CHANNEL_CONNECTION_ERROR; | |
| 512 break; | |
| 513 default: | 500 default: |
| 514 error_ = UNKNOWN_ERROR; | 501 switch (message.reason) { |
|
Sergey Ulanov
2016/06/02 09:26:04
switch inside a switch is hard for humans to parse
Hzj_jie
2016/06/02 22:00:19
Done.
| |
| 502 case JingleMessage::SUCCESS: | |
| 503 if (state_ == CONNECTING) { | |
| 504 error_ = SESSION_REJECTED; | |
| 505 } else { | |
| 506 error_ = OK; | |
| 507 } | |
| 508 break; | |
| 509 case JingleMessage::DECLINE: | |
| 510 error_ = AUTHENTICATION_FAILED; | |
| 511 break; | |
| 512 case JingleMessage::CANCEL: | |
| 513 error_ = HOST_OVERLOAD; | |
| 514 break; | |
| 515 case JingleMessage::EXPIRED: | |
| 516 error_ = MAX_SESSION_LENGTH; | |
| 517 break; | |
| 518 case JingleMessage::INCOMPATIBLE_PARAMETERS: | |
| 519 error_ = INCOMPATIBLE_PROTOCOL; | |
| 520 break; | |
| 521 case JingleMessage::FAILED_APPLICATION: | |
| 522 error_ = HOST_CONFIGURATION_ERROR; | |
| 523 break; | |
| 524 case JingleMessage::GENERAL_ERROR: | |
| 525 error_ = CHANNEL_CONNECTION_ERROR; | |
| 526 break; | |
| 527 default: | |
| 528 error_ = UNKNOWN_ERROR; | |
| 529 } | |
| 515 } | 530 } |
| 516 | 531 |
| 517 if (error_ != OK) { | 532 if (error_ != OK) { |
| 518 SetState(FAILED); | 533 SetState(FAILED); |
| 519 } else { | 534 } else { |
| 520 SetState(CLOSED); | 535 SetState(CLOSED); |
| 521 } | 536 } |
| 522 } | 537 } |
| 523 | 538 |
| 524 bool JingleSession::InitializeConfigFromDescription( | 539 bool JingleSession::InitializeConfigFromDescription( |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 } | 616 } |
| 602 } | 617 } |
| 603 | 618 |
| 604 bool JingleSession::is_session_active() { | 619 bool JingleSession::is_session_active() { |
| 605 return state_ == CONNECTING || state_ == ACCEPTING || state_ == ACCEPTED || | 620 return state_ == CONNECTING || state_ == ACCEPTING || state_ == ACCEPTED || |
| 606 state_ == AUTHENTICATING || state_ == AUTHENTICATED; | 621 state_ == AUTHENTICATING || state_ == AUTHENTICATED; |
| 607 } | 622 } |
| 608 | 623 |
| 609 } // namespace protocol | 624 } // namespace protocol |
| 610 } // namespace remoting | 625 } // namespace remoting |
| OLD | NEW |