| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_manager.h" | 5 #include "remoting/protocol/jingle_session_manager.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
| 10 #include "remoting/jingle_glue/jingle_thread.h" | 10 #include "remoting/jingle_glue/jingle_thread.h" |
| 11 #include "third_party/libjingle/source/talk/p2p/base/constants.h" | 11 #include "third_party/libjingle/source/talk/p2p/base/constants.h" |
| 12 #include "third_party/libjingle/source/talk/p2p/base/transport.h" | 12 #include "third_party/libjingle/source/talk/p2p/base/transport.h" |
| 13 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 13 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 14 | 14 |
| 15 using cricket::ContentDescription; | 15 using cricket::ContentDescription; |
| 16 using cricket::SessionDescription; | 16 using cricket::SessionDescription; |
| 17 using buzz::QName; | 17 using buzz::QName; |
| 18 using buzz::XmlElement; | 18 using buzz::XmlElement; |
| 19 | 19 |
| 20 namespace remoting { | 20 namespace remoting { |
| 21 | |
| 22 namespace protocol { | 21 namespace protocol { |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| 26 const char kDefaultNs[] = ""; | 25 const char kDefaultNs[] = ""; |
| 27 | 26 |
| 28 const char kChromotingContentName[] = "chromoting"; | 27 const char kChromotingContentName[] = "chromoting"; |
| 29 | 28 |
| 30 // Following constants are used to format session description in XML. | 29 // Following constants are used to format session description in XML. |
| 31 const char kDescriptionTag[] = "description"; | 30 const char kDescriptionTag[] = "description"; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } else { | 143 } else { |
| 145 config->codec = ChannelConfig::CODEC_UNDEFINED; | 144 config->codec = ChannelConfig::CODEC_UNDEFINED; |
| 146 } | 145 } |
| 147 | 146 |
| 148 return true; | 147 return true; |
| 149 } | 148 } |
| 150 | 149 |
| 151 } // namespace | 150 } // namespace |
| 152 | 151 |
| 153 ContentDescription::ContentDescription( | 152 ContentDescription::ContentDescription( |
| 154 const CandidateChromotocolConfig* config) | 153 const CandidateSessionConfig* candidate_config) |
| 155 : candidate_config_(config) { | 154 : candidate_config_(candidate_config) { |
| 156 } | 155 } |
| 157 | 156 |
| 158 ContentDescription::~ContentDescription() { } | 157 ContentDescription::~ContentDescription() { } |
| 159 | 158 |
| 160 JingleSessionManager::JingleSessionManager( | 159 JingleSessionManager::JingleSessionManager( |
| 161 JingleThread* jingle_thread) | 160 JingleThread* jingle_thread) |
| 162 : jingle_thread_(jingle_thread), | 161 : jingle_thread_(jingle_thread), |
| 163 cricket_session_manager_(NULL), | 162 cricket_session_manager_(NULL), |
| 164 allow_local_ips_(false), | 163 allow_local_ips_(false), |
| 165 closed_(false) { | 164 closed_(false) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 closed_task->Run(); | 212 closed_task->Run(); |
| 214 delete closed_task; | 213 delete closed_task; |
| 215 } | 214 } |
| 216 | 215 |
| 217 void JingleSessionManager::set_allow_local_ips(bool allow_local_ips) { | 216 void JingleSessionManager::set_allow_local_ips(bool allow_local_ips) { |
| 218 allow_local_ips_ = allow_local_ips; | 217 allow_local_ips_ = allow_local_ips; |
| 219 } | 218 } |
| 220 | 219 |
| 221 scoped_refptr<protocol::Session> JingleSessionManager::Connect( | 220 scoped_refptr<protocol::Session> JingleSessionManager::Connect( |
| 222 const std::string& jid, | 221 const std::string& jid, |
| 223 CandidateChromotocolConfig* chromotocol_config, | 222 CandidateSessionConfig* candidate_config, |
| 224 protocol::Session::StateChangeCallback* state_change_callback) { | 223 protocol::Session::StateChangeCallback* state_change_callback) { |
| 225 // Can be called from any thread. | 224 // Can be called from any thread. |
| 226 scoped_refptr<JingleSession> jingle_session( | 225 scoped_refptr<JingleSession> jingle_session( |
| 227 new JingleSession(this)); | 226 new JingleSession(this)); |
| 228 jingle_session->set_candidate_config(chromotocol_config); | 227 jingle_session->set_candidate_config(candidate_config); |
| 229 message_loop()->PostTask( | 228 message_loop()->PostTask( |
| 230 FROM_HERE, NewRunnableMethod(this, &JingleSessionManager::DoConnect, | 229 FROM_HERE, NewRunnableMethod(this, &JingleSessionManager::DoConnect, |
| 231 jingle_session, jid, | 230 jingle_session, jid, |
| 232 state_change_callback)); | 231 state_change_callback)); |
| 233 return jingle_session; | 232 return jingle_session; |
| 234 } | 233 } |
| 235 | 234 |
| 236 void JingleSessionManager::DoConnect( | 235 void JingleSessionManager::DoConnect( |
| 237 scoped_refptr<JingleSession> jingle_session, | 236 scoped_refptr<JingleSession> jingle_session, |
| 238 const std::string& jid, | 237 const std::string& jid, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 IncomingSessionResponse response = protocol::SessionManager::DECLINE; | 312 IncomingSessionResponse response = protocol::SessionManager::DECLINE; |
| 314 | 313 |
| 315 // Always reject connection if there is no callback. | 314 // Always reject connection if there is no callback. |
| 316 if (incoming_session_callback_.get()) | 315 if (incoming_session_callback_.get()) |
| 317 incoming_session_callback_->Run(jingle_session, &response); | 316 incoming_session_callback_->Run(jingle_session, &response); |
| 318 | 317 |
| 319 switch (response) { | 318 switch (response) { |
| 320 case protocol::SessionManager::ACCEPT: { | 319 case protocol::SessionManager::ACCEPT: { |
| 321 // Connection must be configured by the callback. | 320 // Connection must be configured by the callback. |
| 322 DCHECK(jingle_session->config()); | 321 DCHECK(jingle_session->config()); |
| 323 CandidateChromotocolConfig* candidate_config = | 322 CandidateSessionConfig* candidate_config = |
| 324 CandidateChromotocolConfig::CreateFrom(jingle_session->config()); | 323 CandidateSessionConfig::CreateFrom(jingle_session->config()); |
| 325 cricket_session->Accept(CreateSessionDescription(candidate_config)); | 324 cricket_session->Accept(CreateSessionDescription(candidate_config)); |
| 326 break; | 325 break; |
| 327 } | 326 } |
| 328 | 327 |
| 329 case protocol::SessionManager::INCOMPATIBLE: { | 328 case protocol::SessionManager::INCOMPATIBLE: { |
| 330 cricket_session->Reject(cricket::STR_TERMINATE_INCOMPATIBLE_PARAMETERS); | 329 cricket_session->Reject(cricket::STR_TERMINATE_INCOMPATIBLE_PARAMETERS); |
| 331 break; | 330 break; |
| 332 } | 331 } |
| 333 | 332 |
| 334 case protocol::SessionManager::DECLINE: { | 333 case protocol::SessionManager::DECLINE: { |
| 335 cricket_session->Reject(cricket::STR_TERMINATE_DECLINE); | 334 cricket_session->Reject(cricket::STR_TERMINATE_DECLINE); |
| 336 break; | 335 break; |
| 337 } | 336 } |
| 338 | 337 |
| 339 default: { | 338 default: { |
| 340 NOTREACHED(); | 339 NOTREACHED(); |
| 341 } | 340 } |
| 342 } | 341 } |
| 343 } | 342 } |
| 344 | 343 |
| 345 // Parse content description generated by WriteContent(). | 344 // Parse content description generated by WriteContent(). |
| 346 bool JingleSessionManager::ParseContent( | 345 bool JingleSessionManager::ParseContent( |
| 347 cricket::SignalingProtocol protocol, | 346 cricket::SignalingProtocol protocol, |
| 348 const XmlElement* element, | 347 const XmlElement* element, |
| 349 const cricket::ContentDescription** content, | 348 const cricket::ContentDescription** content, |
| 350 cricket::ParseError* error) { | 349 cricket::ParseError* error) { |
| 351 if (element->Name() == QName(kChromotingXmlNamespace, kDescriptionTag)) { | 350 if (element->Name() == QName(kChromotingXmlNamespace, kDescriptionTag)) { |
| 352 scoped_ptr<CandidateChromotocolConfig> config( | 351 scoped_ptr<CandidateSessionConfig> config( |
| 353 CandidateChromotocolConfig::CreateEmpty()); | 352 CandidateSessionConfig::CreateEmpty()); |
| 354 const XmlElement* child = NULL; | 353 const XmlElement* child = NULL; |
| 355 | 354 |
| 356 // <control> tags. | 355 // <control> tags. |
| 357 QName control_tag(kChromotingXmlNamespace, kControlTag); | 356 QName control_tag(kChromotingXmlNamespace, kControlTag); |
| 358 child = element->FirstNamed(control_tag); | 357 child = element->FirstNamed(control_tag); |
| 359 while (child) { | 358 while (child) { |
| 360 ChannelConfig channel_config; | 359 ChannelConfig channel_config; |
| 361 if (!ParseChannelConfig(child, false, &channel_config)) | 360 if (!ParseChannelConfig(child, false, &channel_config)) |
| 362 return false; | 361 return false; |
| 363 config->AddControlConfig(channel_config); | 362 config->AddControlConfig(channel_config); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 cricket::SignalingProtocol protocol, | 424 cricket::SignalingProtocol protocol, |
| 426 const cricket::ContentDescription* content, | 425 const cricket::ContentDescription* content, |
| 427 XmlElement** elem, | 426 XmlElement** elem, |
| 428 cricket::WriteError* error) { | 427 cricket::WriteError* error) { |
| 429 const ContentDescription* desc = | 428 const ContentDescription* desc = |
| 430 static_cast<const ContentDescription*>(content); | 429 static_cast<const ContentDescription*>(content); |
| 431 | 430 |
| 432 XmlElement* root = new XmlElement( | 431 XmlElement* root = new XmlElement( |
| 433 QName(kChromotingXmlNamespace, kDescriptionTag), true); | 432 QName(kChromotingXmlNamespace, kDescriptionTag), true); |
| 434 | 433 |
| 435 const CandidateChromotocolConfig* config = desc->config(); | 434 const CandidateSessionConfig* config = desc->config(); |
| 436 std::vector<ChannelConfig>::const_iterator it; | 435 std::vector<ChannelConfig>::const_iterator it; |
| 437 | 436 |
| 438 for (it = config->control_configs().begin(); | 437 for (it = config->control_configs().begin(); |
| 439 it != config->control_configs().end(); ++it) { | 438 it != config->control_configs().end(); ++it) { |
| 440 root->AddElement(FormatChannelConfig(*it, kControlTag)); | 439 root->AddElement(FormatChannelConfig(*it, kControlTag)); |
| 441 } | 440 } |
| 442 | 441 |
| 443 for (it = config->event_configs().begin(); | 442 for (it = config->event_configs().begin(); |
| 444 it != config->event_configs().end(); ++it) { | 443 it != config->event_configs().end(); ++it) { |
| 445 root->AddElement(FormatChannelConfig(*it, kEventTag)); | 444 root->AddElement(FormatChannelConfig(*it, kEventTag)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 458 resolution_tag->AddAttr(QName(kDefaultNs, kHeightAttr), | 457 resolution_tag->AddAttr(QName(kDefaultNs, kHeightAttr), |
| 459 base::IntToString( | 458 base::IntToString( |
| 460 config->initial_resolution().height)); | 459 config->initial_resolution().height)); |
| 461 root->AddElement(resolution_tag); | 460 root->AddElement(resolution_tag); |
| 462 | 461 |
| 463 *elem = root; | 462 *elem = root; |
| 464 return true; | 463 return true; |
| 465 } | 464 } |
| 466 | 465 |
| 467 SessionDescription* JingleSessionManager::CreateSessionDescription( | 466 SessionDescription* JingleSessionManager::CreateSessionDescription( |
| 468 const CandidateChromotocolConfig* config) { | 467 const CandidateSessionConfig* config) { |
| 469 SessionDescription* desc = new SessionDescription(); | 468 SessionDescription* desc = new SessionDescription(); |
| 470 desc->AddContent(JingleSession::kChromotingContentName, | 469 desc->AddContent(JingleSession::kChromotingContentName, |
| 471 kChromotingXmlNamespace, | 470 kChromotingXmlNamespace, |
| 472 new ContentDescription(config)); | 471 new ContentDescription(config)); |
| 473 return desc; | 472 return desc; |
| 474 } | 473 } |
| 475 | 474 |
| 476 } // namespace protocol | 475 } // namespace protocol |
| 477 | |
| 478 } // namespace remoting | 476 } // namespace remoting |
| OLD | NEW |