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