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

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

Issue 12389010: Refactor of Authenticator to allow it to ProcessMessage asynchronously and then call a callback (Closed) Base URL: http://git.chromium.org/chromium/src.git@host_key_pair
Patch Set: Created 7 years, 9 months 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
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 // Process the first authentication message. 140 // Process the first authentication message.
141 const buzz::XmlElement* first_auth_message = 141 const buzz::XmlElement* first_auth_message =
142 initiate_message.description->authenticator_message(); 142 initiate_message.description->authenticator_message();
143 143
144 if (!first_auth_message) { 144 if (!first_auth_message) {
145 CloseInternal(INCOMPATIBLE_PROTOCOL); 145 CloseInternal(INCOMPATIBLE_PROTOCOL);
146 return; 146 return;
147 } 147 }
148 148
149 DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE); 149 DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE);
150 authenticator_->ProcessMessage(first_auth_message); 150 authenticator_->ProcessMessage(base::Bind(
151 &JingleSession::ContinueAcceptIncomingConnection,
152 // Authenticator is owned by JingleSession, and cannot outlive it.
153 base::Unretained(this)), first_auth_message);
154 }
155
156 void JingleSession::ContinueAcceptIncomingConnection() {
Sergey Ulanov 2013/02/28 08:05:16 This change introduces another state that wasn't p
rmsousa 2013/02/28 23:29:23 AcceptIncomingConnection is called after Initializ
151 if (authenticator_->state() == Authenticator::REJECTED) { 157 if (authenticator_->state() == Authenticator::REJECTED) {
152 CloseInternal(AuthRejectionReasonToErrorCode( 158 CloseInternal(AuthRejectionReasonToErrorCode(
153 authenticator_->rejection_reason())); 159 authenticator_->rejection_reason()));
154 return; 160 return;
155 } 161 }
156 162
157 // Send the session-accept message. 163 // Send the session-accept message.
158 JingleMessage message(peer_jid_, JingleMessage::SESSION_ACCEPT, 164 JingleMessage message(peer_jid_, JingleMessage::SESSION_ACCEPT,
159 session_id_); 165 session_id_);
160 166
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 434
429 const buzz::XmlElement* auth_message = 435 const buzz::XmlElement* auth_message =
430 message.description->authenticator_message(); 436 message.description->authenticator_message();
431 if (!auth_message) { 437 if (!auth_message) {
432 DLOG(WARNING) << "Received session-accept without authentication message " 438 DLOG(WARNING) << "Received session-accept without authentication message "
433 << auth_message->Str(); 439 << auth_message->Str();
434 CloseInternal(INCOMPATIBLE_PROTOCOL); 440 CloseInternal(INCOMPATIBLE_PROTOCOL);
435 return; 441 return;
436 } 442 }
437 443
438 DCHECK(authenticator_->state() == Authenticator::WAITING_MESSAGE);
439 authenticator_->ProcessMessage(auth_message);
440
441 if (!InitializeConfigFromDescription(message.description.get())) { 444 if (!InitializeConfigFromDescription(message.description.get())) {
442 CloseInternal(INCOMPATIBLE_PROTOCOL); 445 CloseInternal(INCOMPATIBLE_PROTOCOL);
443 return; 446 return;
444 } 447 }
445 448
446 // In case there is transport information in the accept message. 449 // In case there is transport information in the accept message.
447 ProcessTransportInfo(message); 450 ProcessTransportInfo(message);
448 451
449 SetState(CONNECTED); 452 SetState(CONNECTED);
450 453
451 // Process authentication. 454 DCHECK(authenticator_->state() == Authenticator::WAITING_MESSAGE);
452 if (authenticator_->state() == Authenticator::ACCEPTED) { 455 authenticator_->ProcessMessage(base::Bind(
453 SetState(AUTHENTICATED); 456 &JingleSession::ProcessAuthenticationStep,
454 } else { 457 // Authenticator is owned by JingleSession, and cannot outlive it.
455 ProcessAuthenticationStep(); 458 base::Unretained(this)), auth_message);
456 }
457 } 459 }
458 460
459 void JingleSession::OnSessionInfo(const JingleMessage& message, 461 void JingleSession::OnSessionInfo(const JingleMessage& message,
460 const ReplyCallback& reply_callback) { 462 const ReplyCallback& reply_callback) {
461 if (!message.info.get() || 463 if (!message.info.get() ||
462 !Authenticator::IsAuthenticatorMessage(message.info.get())) { 464 !Authenticator::IsAuthenticatorMessage(message.info.get())) {
463 reply_callback.Run(JingleMessageReply::UNSUPPORTED_INFO); 465 reply_callback.Run(JingleMessageReply::UNSUPPORTED_INFO);
464 return; 466 return;
465 } 467 }
466 468
467 if (state_ != CONNECTED || 469 if (state_ != CONNECTED ||
468 authenticator_->state() != Authenticator::WAITING_MESSAGE) { 470 authenticator_->state() != Authenticator::WAITING_MESSAGE) {
469 LOG(WARNING) << "Received unexpected authenticator message " 471 LOG(WARNING) << "Received unexpected authenticator message "
470 << message.info->Str(); 472 << message.info->Str();
471 reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST); 473 reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST);
472 CloseInternal(INCOMPATIBLE_PROTOCOL); 474 CloseInternal(INCOMPATIBLE_PROTOCOL);
473 return; 475 return;
474 } 476 }
475 477
476 reply_callback.Run(JingleMessageReply::NONE); 478 reply_callback.Run(JingleMessageReply::NONE);
477 479
478 authenticator_->ProcessMessage(message.info.get()); 480 authenticator_->ProcessMessage(base::Bind(
479 ProcessAuthenticationStep(); 481 &JingleSession::ProcessAuthenticationStep,
482 // Authenticator is owned by JingleSession, and cannot outlive it.
483 base::Unretained(this)), message.info.get());
480 } 484 }
481 485
482 void JingleSession::ProcessTransportInfo(const JingleMessage& message) { 486 void JingleSession::ProcessTransportInfo(const JingleMessage& message) {
483 for (std::list<JingleMessage::NamedCandidate>::const_iterator it = 487 for (std::list<JingleMessage::NamedCandidate>::const_iterator it =
484 message.candidates.begin(); 488 message.candidates.begin();
485 it != message.candidates.end(); ++it) { 489 it != message.candidates.end(); ++it) {
486 ChannelsMap::iterator channel = channels_.find(it->name); 490 ChannelsMap::iterator channel = channels_.find(it->name);
487 if (channel == channels_.end()) { 491 if (channel == channels_.end()) {
488 LOG(WARNING) << "Received candidate for unknown channel " << it->name; 492 LOG(WARNING) << "Received candidate for unknown channel " << it->name;
489 continue; 493 continue;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 547 }
544 if (!candidate_config()->IsSupported(config_)) { 548 if (!candidate_config()->IsSupported(config_)) {
545 LOG(ERROR) << "session-accept specifies an invalid configuration"; 549 LOG(ERROR) << "session-accept specifies an invalid configuration";
546 return false; 550 return false;
547 } 551 }
548 552
549 return true; 553 return true;
550 } 554 }
551 555
552 void JingleSession::ProcessAuthenticationStep() { 556 void JingleSession::ProcessAuthenticationStep() {
557 DCHECK(CalledOnValidThread());
553 DCHECK_EQ(state_, CONNECTED); 558 DCHECK_EQ(state_, CONNECTED);
554 559
555 if (authenticator_->state() == Authenticator::MESSAGE_READY) { 560 if (authenticator_->state() == Authenticator::MESSAGE_READY) {
556 JingleMessage message(peer_jid_, JingleMessage::SESSION_INFO, session_id_); 561 JingleMessage message(peer_jid_, JingleMessage::SESSION_INFO, session_id_);
557 message.info = authenticator_->GetNextMessage(); 562 message.info = authenticator_->GetNextMessage();
558 DCHECK(message.info.get()); 563 DCHECK(message.info.get());
559 SendMessage(message); 564 SendMessage(message);
560 } 565 }
561 DCHECK_NE(authenticator_->state(), Authenticator::MESSAGE_READY); 566 DCHECK_NE(authenticator_->state(), Authenticator::MESSAGE_READY);
562 567
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 DCHECK_NE(state_, FAILED); 622 DCHECK_NE(state_, FAILED);
618 623
619 state_ = new_state; 624 state_ = new_state;
620 if (event_handler_) 625 if (event_handler_)
621 event_handler_->OnSessionStateChange(new_state); 626 event_handler_->OnSessionStateChange(new_state);
622 } 627 }
623 } 628 }
624 629
625 } // namespace protocol 630 } // namespace protocol
626 } // namespace remoting 631 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698