| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "remoting/base/constants.h" | 19 #include "remoting/base/constants.h" |
| 20 #include "remoting/protocol/authenticator.h" | 20 #include "remoting/protocol/authenticator.h" |
| 21 #include "remoting/protocol/content_description.h" | 21 #include "remoting/protocol/content_description.h" |
| 22 #include "remoting/protocol/jingle_messages.h" | 22 #include "remoting/protocol/jingle_messages.h" |
| 23 #include "remoting/protocol/jingle_session_manager.h" | 23 #include "remoting/protocol/jingle_session_manager.h" |
| 24 #include "remoting/protocol/session_config.h" | 24 #include "remoting/protocol/session_config.h" |
| 25 #include "remoting/protocol/transport.h" |
| 25 #include "remoting/signaling/iq_sender.h" | 26 #include "remoting/signaling/iq_sender.h" |
| 26 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 27 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
| 27 #include "third_party/webrtc/p2p/base/candidate.h" | 28 #include "third_party/webrtc/p2p/base/candidate.h" |
| 28 | 29 |
| 29 using buzz::XmlElement; | 30 using buzz::XmlElement; |
| 30 | 31 |
| 31 namespace remoting { | 32 namespace remoting { |
| 32 namespace protocol { | 33 namespace protocol { |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 62 | 63 |
| 63 JingleSession::JingleSession(JingleSessionManager* session_manager) | 64 JingleSession::JingleSession(JingleSessionManager* session_manager) |
| 64 : session_manager_(session_manager), | 65 : session_manager_(session_manager), |
| 65 event_handler_(nullptr), | 66 event_handler_(nullptr), |
| 66 state_(INITIALIZING), | 67 state_(INITIALIZING), |
| 67 error_(OK), | 68 error_(OK), |
| 68 weak_factory_(this) { | 69 weak_factory_(this) { |
| 69 } | 70 } |
| 70 | 71 |
| 71 JingleSession::~JingleSession() { | 72 JingleSession::~JingleSession() { |
| 72 transport_.reset(); | |
| 73 | |
| 74 STLDeleteContainerPointers(pending_requests_.begin(), | 73 STLDeleteContainerPointers(pending_requests_.begin(), |
| 75 pending_requests_.end()); | 74 pending_requests_.end()); |
| 76 STLDeleteContainerPointers(transport_info_requests_.begin(), | 75 STLDeleteContainerPointers(transport_info_requests_.begin(), |
| 77 transport_info_requests_.end()); | 76 transport_info_requests_.end()); |
| 78 | 77 |
| 79 session_manager_->SessionDestroyed(this); | 78 session_manager_->SessionDestroyed(this); |
| 80 } | 79 } |
| 81 | 80 |
| 82 void JingleSession::SetEventHandler(Session::EventHandler* event_handler) { | 81 void JingleSession::SetEventHandler(Session::EventHandler* event_handler) { |
| 83 DCHECK(CalledOnValidThread()); | 82 DCHECK(thread_checker_.CalledOnValidThread()); |
| 84 DCHECK(event_handler); | 83 DCHECK(event_handler); |
| 85 event_handler_ = event_handler; | 84 event_handler_ = event_handler; |
| 86 } | 85 } |
| 87 | 86 |
| 88 ErrorCode JingleSession::error() { | 87 ErrorCode JingleSession::error() { |
| 89 DCHECK(CalledOnValidThread()); | 88 DCHECK(thread_checker_.CalledOnValidThread()); |
| 90 return error_; | 89 return error_; |
| 91 } | 90 } |
| 92 | 91 |
| 93 void JingleSession::StartConnection(const std::string& peer_jid, | 92 void JingleSession::StartConnection(const std::string& peer_jid, |
| 94 scoped_ptr<Authenticator> authenticator) { | 93 scoped_ptr<Authenticator> authenticator) { |
| 95 DCHECK(CalledOnValidThread()); | 94 DCHECK(thread_checker_.CalledOnValidThread()); |
| 96 DCHECK(authenticator.get()); | 95 DCHECK(authenticator.get()); |
| 97 DCHECK_EQ(authenticator->state(), Authenticator::MESSAGE_READY); | 96 DCHECK_EQ(authenticator->state(), Authenticator::MESSAGE_READY); |
| 98 | 97 |
| 99 peer_jid_ = peer_jid; | 98 peer_jid_ = peer_jid; |
| 100 authenticator_ = std::move(authenticator); | 99 authenticator_ = std::move(authenticator); |
| 101 | 100 |
| 102 // Generate random session ID. There are usually not more than 1 | 101 // Generate random session ID. There are usually not more than 1 |
| 103 // concurrent session per host, so a random 64-bit integer provides | 102 // concurrent session per host, so a random 64-bit integer provides |
| 104 // enough entropy. In the worst case connection will fail when two | 103 // enough entropy. In the worst case connection will fail when two |
| 105 // clients generate the same session ID concurrently. | 104 // clients generate the same session ID concurrently. |
| 106 session_id_ = base::Uint64ToString( | 105 session_id_ = base::Uint64ToString( |
| 107 base::RandGenerator(std::numeric_limits<uint64_t>::max())); | 106 base::RandGenerator(std::numeric_limits<uint64_t>::max())); |
| 108 | 107 |
| 109 transport_ = session_manager_->transport_factory_->CreateTransport(); | |
| 110 | |
| 111 // Send session-initiate message. | 108 // Send session-initiate message. |
| 112 JingleMessage message(peer_jid_, JingleMessage::SESSION_INITIATE, | 109 JingleMessage message(peer_jid_, JingleMessage::SESSION_INITIATE, |
| 113 session_id_); | 110 session_id_); |
| 114 message.initiator = session_manager_->signal_strategy_->GetLocalJid(); | 111 message.initiator = session_manager_->signal_strategy_->GetLocalJid(); |
| 115 message.description.reset(new ContentDescription( | 112 message.description.reset(new ContentDescription( |
| 116 session_manager_->protocol_config_->Clone(), | 113 session_manager_->protocol_config_->Clone(), |
| 117 authenticator_->GetNextMessage())); | 114 authenticator_->GetNextMessage())); |
| 118 SendMessage(message); | 115 SendMessage(message); |
| 119 | 116 |
| 120 SetState(CONNECTING); | 117 SetState(CONNECTING); |
| 121 } | 118 } |
| 122 | 119 |
| 123 void JingleSession::InitializeIncomingConnection( | 120 void JingleSession::InitializeIncomingConnection( |
| 124 const JingleMessage& initiate_message, | 121 const JingleMessage& initiate_message, |
| 125 scoped_ptr<Authenticator> authenticator) { | 122 scoped_ptr<Authenticator> authenticator) { |
| 126 DCHECK(CalledOnValidThread()); | 123 DCHECK(thread_checker_.CalledOnValidThread()); |
| 127 DCHECK(initiate_message.description.get()); | 124 DCHECK(initiate_message.description.get()); |
| 128 DCHECK(authenticator.get()); | 125 DCHECK(authenticator.get()); |
| 129 DCHECK_EQ(authenticator->state(), Authenticator::WAITING_MESSAGE); | 126 DCHECK_EQ(authenticator->state(), Authenticator::WAITING_MESSAGE); |
| 130 | 127 |
| 131 peer_jid_ = initiate_message.from; | 128 peer_jid_ = initiate_message.from; |
| 132 authenticator_ = std::move(authenticator); | 129 authenticator_ = std::move(authenticator); |
| 133 session_id_ = initiate_message.sid; | 130 session_id_ = initiate_message.sid; |
| 134 | 131 |
| 135 SetState(ACCEPTING); | 132 SetState(ACCEPTING); |
| 136 | 133 |
| 137 config_ = | 134 config_ = |
| 138 SessionConfig::SelectCommon(initiate_message.description->config(), | 135 SessionConfig::SelectCommon(initiate_message.description->config(), |
| 139 session_manager_->protocol_config_.get()); | 136 session_manager_->protocol_config_.get()); |
| 140 if (!config_) { | 137 if (!config_) { |
| 141 LOG(WARNING) << "Rejecting connection from " << peer_jid_ | 138 LOG(WARNING) << "Rejecting connection from " << peer_jid_ |
| 142 << " because no compatible configuration has been found."; | 139 << " because no compatible configuration has been found."; |
| 143 Close(INCOMPATIBLE_PROTOCOL); | 140 Close(INCOMPATIBLE_PROTOCOL); |
| 144 return; | 141 return; |
| 145 } | 142 } |
| 146 | |
| 147 transport_ = session_manager_->transport_factory_->CreateTransport(); | |
| 148 } | 143 } |
| 149 | 144 |
| 150 void JingleSession::AcceptIncomingConnection( | 145 void JingleSession::AcceptIncomingConnection( |
| 151 const JingleMessage& initiate_message) { | 146 const JingleMessage& initiate_message) { |
| 152 DCHECK(config_); | 147 DCHECK(config_); |
| 153 | 148 |
| 154 // Process the first authentication message. | 149 // Process the first authentication message. |
| 155 const buzz::XmlElement* first_auth_message = | 150 const buzz::XmlElement* first_auth_message = |
| 156 initiate_message.description->authenticator_message(); | 151 initiate_message.description->authenticator_message(); |
| 157 | 152 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 OnAuthenticated(); | 188 OnAuthenticated(); |
| 194 } else { | 189 } else { |
| 195 DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE); | 190 DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE); |
| 196 if (authenticator_->started()) { | 191 if (authenticator_->started()) { |
| 197 SetState(AUTHENTICATING); | 192 SetState(AUTHENTICATING); |
| 198 } | 193 } |
| 199 } | 194 } |
| 200 } | 195 } |
| 201 | 196 |
| 202 const std::string& JingleSession::jid() { | 197 const std::string& JingleSession::jid() { |
| 203 DCHECK(CalledOnValidThread()); | 198 DCHECK(thread_checker_.CalledOnValidThread()); |
| 204 return peer_jid_; | 199 return peer_jid_; |
| 205 } | 200 } |
| 206 | 201 |
| 207 const SessionConfig& JingleSession::config() { | 202 const SessionConfig& JingleSession::config() { |
| 208 DCHECK(CalledOnValidThread()); | 203 DCHECK(thread_checker_.CalledOnValidThread()); |
| 209 return *config_; | 204 return *config_; |
| 210 } | 205 } |
| 211 | 206 |
| 212 Transport* JingleSession::GetTransport() { | 207 void JingleSession::SetTransport(Transport* transport) { |
| 213 DCHECK(CalledOnValidThread()); | 208 DCHECK(thread_checker_.CalledOnValidThread()); |
| 214 return transport_.get(); | 209 DCHECK(!transport_); |
| 210 DCHECK(transport); |
| 211 transport_ = transport; |
| 212 } |
| 213 |
| 214 void JingleSession::SendTransportInfo( |
| 215 scoped_ptr<buzz::XmlElement> transport_info) { |
| 216 DCHECK(thread_checker_.CalledOnValidThread()); |
| 217 DCHECK_EQ(state_, AUTHENTICATED); |
| 218 |
| 219 JingleMessage message(peer_jid_, JingleMessage::TRANSPORT_INFO, session_id_); |
| 220 message.transport_info = std::move(transport_info); |
| 221 |
| 222 scoped_ptr<IqRequest> request = session_manager_->iq_sender()->SendIq( |
| 223 message.ToXml(), base::Bind(&JingleSession::OnTransportInfoResponse, |
| 224 base::Unretained(this))); |
| 225 if (request) { |
| 226 request->SetTimeout(base::TimeDelta::FromSeconds(kTransportInfoTimeout)); |
| 227 transport_info_requests_.push_back(request.release()); |
| 228 } else { |
| 229 LOG(ERROR) << "Failed to send a transport-info message"; |
| 230 } |
| 215 } | 231 } |
| 216 | 232 |
| 217 void JingleSession::Close(protocol::ErrorCode error) { | 233 void JingleSession::Close(protocol::ErrorCode error) { |
| 218 DCHECK(CalledOnValidThread()); | 234 DCHECK(thread_checker_.CalledOnValidThread()); |
| 219 | |
| 220 transport_.reset(); | |
| 221 | 235 |
| 222 if (is_session_active()) { | 236 if (is_session_active()) { |
| 223 // Send session-terminate message with the appropriate error code. | 237 // Send session-terminate message with the appropriate error code. |
| 224 JingleMessage::Reason reason; | 238 JingleMessage::Reason reason; |
| 225 switch (error) { | 239 switch (error) { |
| 226 case OK: | 240 case OK: |
| 227 reason = JingleMessage::SUCCESS; | 241 reason = JingleMessage::SUCCESS; |
| 228 break; | 242 break; |
| 229 case SESSION_REJECTED: | 243 case SESSION_REJECTED: |
| 230 case AUTHENTICATION_FAILED: | 244 case AUTHENTICATION_FAILED: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 257 if (state_ != FAILED && state_ != CLOSED) { | 271 if (state_ != FAILED && state_ != CLOSED) { |
| 258 if (error != OK) { | 272 if (error != OK) { |
| 259 SetState(FAILED); | 273 SetState(FAILED); |
| 260 } else { | 274 } else { |
| 261 SetState(CLOSED); | 275 SetState(CLOSED); |
| 262 } | 276 } |
| 263 } | 277 } |
| 264 } | 278 } |
| 265 | 279 |
| 266 void JingleSession::SendMessage(const JingleMessage& message) { | 280 void JingleSession::SendMessage(const JingleMessage& message) { |
| 267 DCHECK(CalledOnValidThread()); | 281 DCHECK(thread_checker_.CalledOnValidThread()); |
| 268 | 282 |
| 269 scoped_ptr<IqRequest> request = session_manager_->iq_sender()->SendIq( | 283 scoped_ptr<IqRequest> request = session_manager_->iq_sender()->SendIq( |
| 270 message.ToXml(), | 284 message.ToXml(), |
| 271 base::Bind(&JingleSession::OnMessageResponse, | 285 base::Bind(&JingleSession::OnMessageResponse, |
| 272 base::Unretained(this), | 286 base::Unretained(this), |
| 273 message.action)); | 287 message.action)); |
| 274 | 288 |
| 275 int timeout = kDefaultMessageTimeout; | 289 int timeout = kDefaultMessageTimeout; |
| 276 if (message.action == JingleMessage::SESSION_INITIATE || | 290 if (message.action == JingleMessage::SESSION_INITIATE || |
| 277 message.action == JingleMessage::SESSION_ACCEPT) { | 291 message.action == JingleMessage::SESSION_ACCEPT) { |
| 278 timeout = kSessionInitiateAndAcceptTimeout; | 292 timeout = kSessionInitiateAndAcceptTimeout; |
| 279 } | 293 } |
| 280 if (request) { | 294 if (request) { |
| 281 request->SetTimeout(base::TimeDelta::FromSeconds(timeout)); | 295 request->SetTimeout(base::TimeDelta::FromSeconds(timeout)); |
| 282 pending_requests_.insert(request.release()); | 296 pending_requests_.insert(request.release()); |
| 283 } else { | 297 } else { |
| 284 LOG(ERROR) << "Failed to send a " | 298 LOG(ERROR) << "Failed to send a " |
| 285 << JingleMessage::GetActionName(message.action) << " message"; | 299 << JingleMessage::GetActionName(message.action) << " message"; |
| 286 } | 300 } |
| 287 } | 301 } |
| 288 | 302 |
| 289 void JingleSession::OnMessageResponse( | 303 void JingleSession::OnMessageResponse( |
| 290 JingleMessage::ActionType request_type, | 304 JingleMessage::ActionType request_type, |
| 291 IqRequest* request, | 305 IqRequest* request, |
| 292 const buzz::XmlElement* response) { | 306 const buzz::XmlElement* response) { |
| 293 DCHECK(CalledOnValidThread()); | 307 DCHECK(thread_checker_.CalledOnValidThread()); |
| 294 | 308 |
| 295 // Delete the request from the list of pending requests. | 309 // Delete the request from the list of pending requests. |
| 296 pending_requests_.erase(request); | 310 pending_requests_.erase(request); |
| 297 delete request; | 311 delete request; |
| 298 | 312 |
| 299 // Ignore all responses after session was closed. | 313 // Ignore all responses after session was closed. |
| 300 if (state_ == CLOSED || state_ == FAILED) | 314 if (state_ == CLOSED || state_ == FAILED) |
| 301 return; | 315 return; |
| 302 | 316 |
| 303 std::string type_str = JingleMessage::GetActionName(request_type); | 317 std::string type_str = JingleMessage::GetActionName(request_type); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 315 << " message: \"" << response->Str() | 329 << " message: \"" << response->Str() |
| 316 << "\". Terminating the session."; | 330 << "\". Terminating the session."; |
| 317 | 331 |
| 318 // TODO(sergeyu): There may be different reasons for error | 332 // TODO(sergeyu): There may be different reasons for error |
| 319 // here. Parse the response stanza to find failure reason. | 333 // here. Parse the response stanza to find failure reason. |
| 320 Close(PEER_IS_OFFLINE); | 334 Close(PEER_IS_OFFLINE); |
| 321 } | 335 } |
| 322 } | 336 } |
| 323 } | 337 } |
| 324 | 338 |
| 325 void JingleSession::OnOutgoingTransportInfo( | |
| 326 scoped_ptr<XmlElement> transport_info) { | |
| 327 DCHECK(CalledOnValidThread()); | |
| 328 | |
| 329 JingleMessage message(peer_jid_, JingleMessage::TRANSPORT_INFO, session_id_); | |
| 330 message.transport_info = std::move(transport_info); | |
| 331 | |
| 332 scoped_ptr<IqRequest> request = session_manager_->iq_sender()->SendIq( | |
| 333 message.ToXml(), base::Bind(&JingleSession::OnTransportInfoResponse, | |
| 334 base::Unretained(this))); | |
| 335 if (request) { | |
| 336 request->SetTimeout(base::TimeDelta::FromSeconds(kTransportInfoTimeout)); | |
| 337 transport_info_requests_.push_back(request.release()); | |
| 338 } else { | |
| 339 LOG(ERROR) << "Failed to send a transport-info message"; | |
| 340 } | |
| 341 } | |
| 342 | |
| 343 void JingleSession::OnTransportRouteChange(const std::string& channel_name, | |
| 344 const TransportRoute& route) { | |
| 345 DCHECK(CalledOnValidThread()); | |
| 346 | |
| 347 event_handler_->OnSessionRouteChange(channel_name, route); | |
| 348 } | |
| 349 | |
| 350 void JingleSession::OnTransportConnected() { | |
| 351 DCHECK(CalledOnValidThread()); | |
| 352 DCHECK_EQ(state_, AUTHENTICATED); | |
| 353 SetState(CONNECTED); | |
| 354 } | |
| 355 | |
| 356 void JingleSession::OnTransportError(ErrorCode error) { | |
| 357 DCHECK(CalledOnValidThread()); | |
| 358 | |
| 359 Close(error); | |
| 360 } | |
| 361 | |
| 362 void JingleSession::OnTransportInfoResponse(IqRequest* request, | 339 void JingleSession::OnTransportInfoResponse(IqRequest* request, |
| 363 const buzz::XmlElement* response) { | 340 const buzz::XmlElement* response) { |
| 364 DCHECK(CalledOnValidThread()); | 341 DCHECK(thread_checker_.CalledOnValidThread()); |
| 365 DCHECK(!transport_info_requests_.empty()); | 342 DCHECK(!transport_info_requests_.empty()); |
| 366 | 343 |
| 367 // Consider transport-info requests sent before this one lost and delete | 344 // Consider transport-info requests sent before this one lost and delete |
| 368 // corresponding IqRequest objects. | 345 // corresponding IqRequest objects. |
| 369 while (transport_info_requests_.front() != request) { | 346 while (transport_info_requests_.front() != request) { |
| 370 delete transport_info_requests_.front(); | 347 delete transport_info_requests_.front(); |
| 371 transport_info_requests_.pop_front(); | 348 transport_info_requests_.pop_front(); |
| 372 } | 349 } |
| 373 | 350 |
| 374 // Delete the |request| itself. | 351 // Delete the |request| itself. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 385 const std::string& type = response->Attr(buzz::QName(std::string(), "type")); | 362 const std::string& type = response->Attr(buzz::QName(std::string(), "type")); |
| 386 if (type != "result") { | 363 if (type != "result") { |
| 387 LOG(ERROR) << "Received error in response to transport-info message: \"" | 364 LOG(ERROR) << "Received error in response to transport-info message: \"" |
| 388 << response->Str() << "\". Terminating the session."; | 365 << response->Str() << "\". Terminating the session."; |
| 389 Close(PEER_IS_OFFLINE); | 366 Close(PEER_IS_OFFLINE); |
| 390 } | 367 } |
| 391 } | 368 } |
| 392 | 369 |
| 393 void JingleSession::OnIncomingMessage(const JingleMessage& message, | 370 void JingleSession::OnIncomingMessage(const JingleMessage& message, |
| 394 const ReplyCallback& reply_callback) { | 371 const ReplyCallback& reply_callback) { |
| 395 DCHECK(CalledOnValidThread()); | 372 DCHECK(thread_checker_.CalledOnValidThread()); |
| 396 | 373 |
| 397 if (message.from != peer_jid_) { | 374 if (message.from != peer_jid_) { |
| 398 // Ignore messages received from a different Jid. | 375 // Ignore messages received from a different Jid. |
| 399 reply_callback.Run(JingleMessageReply::INVALID_SID); | 376 reply_callback.Run(JingleMessageReply::INVALID_SID); |
| 400 return; | 377 return; |
| 401 } | 378 } |
| 402 | 379 |
| 403 switch (message.action) { | 380 switch (message.action) { |
| 404 case JingleMessage::SESSION_ACCEPT: | 381 case JingleMessage::SESSION_ACCEPT: |
| 405 OnAccept(message, reply_callback); | 382 OnAccept(message, reply_callback); |
| 406 break; | 383 break; |
| 407 | 384 |
| 408 case JingleMessage::SESSION_INFO: | 385 case JingleMessage::SESSION_INFO: |
| 409 OnSessionInfo(message, reply_callback); | 386 OnSessionInfo(message, reply_callback); |
| 410 break; | 387 break; |
| 411 | 388 |
| 412 case JingleMessage::TRANSPORT_INFO: | 389 case JingleMessage::TRANSPORT_INFO: |
| 413 if (message.transport_info && | 390 if (!transport_) { |
| 414 transport_->ProcessTransportInfo(message.transport_info.get())) { | 391 LOG(ERROR) << "Received unexpected transport-info message."; |
| 415 reply_callback.Run(JingleMessageReply::NONE); | 392 reply_callback.Run(JingleMessageReply::NONE); |
| 416 } else { | 393 return; |
| 394 } |
| 395 |
| 396 if (!message.transport_info || |
| 397 !transport_->ProcessTransportInfo( |
| 398 message.transport_info.get())) { |
| 417 reply_callback.Run(JingleMessageReply::BAD_REQUEST); | 399 reply_callback.Run(JingleMessageReply::BAD_REQUEST); |
| 400 return; |
| 418 } | 401 } |
| 402 |
| 403 reply_callback.Run(JingleMessageReply::NONE); |
| 419 break; | 404 break; |
| 420 | 405 |
| 421 case JingleMessage::SESSION_TERMINATE: | 406 case JingleMessage::SESSION_TERMINATE: |
| 422 OnTerminate(message, reply_callback); | 407 OnTerminate(message, reply_callback); |
| 423 break; | 408 break; |
| 424 | 409 |
| 425 default: | 410 default: |
| 426 reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST); | 411 reply_callback.Run(JingleMessageReply::UNEXPECTED_REQUEST); |
| 427 } | 412 } |
| 428 } | 413 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 } | 521 } |
| 537 if (!session_manager_->protocol_config_->IsSupported(*config_)) { | 522 if (!session_manager_->protocol_config_->IsSupported(*config_)) { |
| 538 LOG(ERROR) << "session-accept specifies an invalid configuration"; | 523 LOG(ERROR) << "session-accept specifies an invalid configuration"; |
| 539 return false; | 524 return false; |
| 540 } | 525 } |
| 541 | 526 |
| 542 return true; | 527 return true; |
| 543 } | 528 } |
| 544 | 529 |
| 545 void JingleSession::ProcessAuthenticationStep() { | 530 void JingleSession::ProcessAuthenticationStep() { |
| 546 DCHECK(CalledOnValidThread()); | 531 DCHECK(thread_checker_.CalledOnValidThread()); |
| 547 DCHECK_NE(authenticator_->state(), Authenticator::PROCESSING_MESSAGE); | 532 DCHECK_NE(authenticator_->state(), Authenticator::PROCESSING_MESSAGE); |
| 548 | 533 |
| 549 if (state_ != ACCEPTED && state_ != AUTHENTICATING) { | 534 if (state_ != ACCEPTED && state_ != AUTHENTICATING) { |
| 550 DCHECK(state_ == FAILED || state_ == CLOSED); | 535 DCHECK(state_ == FAILED || state_ == CLOSED); |
| 551 // The remote host closed the connection while the authentication was being | 536 // The remote host closed the connection while the authentication was being |
| 552 // processed asynchronously, nothing to do. | 537 // processed asynchronously, nothing to do. |
| 553 return; | 538 return; |
| 554 } | 539 } |
| 555 | 540 |
| 556 if (authenticator_->state() == Authenticator::MESSAGE_READY) { | 541 if (authenticator_->state() == Authenticator::MESSAGE_READY) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 578 void JingleSession::ContinueAuthenticationStep() { | 563 void JingleSession::ContinueAuthenticationStep() { |
| 579 if (authenticator_->state() == Authenticator::ACCEPTED) { | 564 if (authenticator_->state() == Authenticator::ACCEPTED) { |
| 580 OnAuthenticated(); | 565 OnAuthenticated(); |
| 581 } else if (authenticator_->state() == Authenticator::REJECTED) { | 566 } else if (authenticator_->state() == Authenticator::REJECTED) { |
| 582 Close(AuthRejectionReasonToErrorCode( | 567 Close(AuthRejectionReasonToErrorCode( |
| 583 authenticator_->rejection_reason())); | 568 authenticator_->rejection_reason())); |
| 584 } | 569 } |
| 585 } | 570 } |
| 586 | 571 |
| 587 void JingleSession::OnAuthenticated() { | 572 void JingleSession::OnAuthenticated() { |
| 588 transport_->Start(this, authenticator_.get()); | 573 transport_->Start(authenticator_.get(), |
| 574 base::Bind(&JingleSession::SendTransportInfo, |
| 575 weak_factory_.GetWeakPtr())); |
| 589 | 576 |
| 590 SetState(AUTHENTICATED); | 577 SetState(AUTHENTICATED); |
| 591 } | 578 } |
| 592 | 579 |
| 593 void JingleSession::SetState(State new_state) { | 580 void JingleSession::SetState(State new_state) { |
| 594 DCHECK(CalledOnValidThread()); | 581 DCHECK(thread_checker_.CalledOnValidThread()); |
| 595 | 582 |
| 596 if (new_state != state_) { | 583 if (new_state != state_) { |
| 597 DCHECK_NE(state_, CLOSED); | 584 DCHECK_NE(state_, CLOSED); |
| 598 DCHECK_NE(state_, FAILED); | 585 DCHECK_NE(state_, FAILED); |
| 599 | 586 |
| 600 state_ = new_state; | 587 state_ = new_state; |
| 601 if (event_handler_) | 588 if (event_handler_) |
| 602 event_handler_->OnSessionStateChange(new_state); | 589 event_handler_->OnSessionStateChange(new_state); |
| 603 } | 590 } |
| 604 } | 591 } |
| 605 | 592 |
| 606 bool JingleSession::is_session_active() { | 593 bool JingleSession::is_session_active() { |
| 607 return state_ == CONNECTING || state_ == ACCEPTING || state_ == ACCEPTED || | 594 return state_ == CONNECTING || state_ == ACCEPTING || state_ == ACCEPTED || |
| 608 state_ == AUTHENTICATING || state_ == AUTHENTICATED; | 595 state_ == AUTHENTICATING || state_ == AUTHENTICATED; |
| 609 } | 596 } |
| 610 | 597 |
| 611 } // namespace protocol | 598 } // namespace protocol |
| 612 } // namespace remoting | 599 } // namespace remoting |
| OLD | NEW |