diff --git a/remoting/jingle_glue/iq_request.cc b/remoting/jingle_glue/iq_request.cc index 3ea27262d5532e..0e93c5670a50a6 100644 --- a/remoting/jingle_glue/iq_request.cc +++ b/remoting/jingle_glue/iq_request.cc @@ -16,7 +16,8 @@ buzz::XmlElement* IqRequest::MakeIqStanza(const std::string& type, const std::string& id) { buzz::XmlElement* stanza = new buzz::XmlElement(buzz::QN_IQ); stanza->AddAttr(buzz::QN_TYPE, type); - stanza->AddAttr(buzz::QN_TO, addressee); + if (!addressee.empty()) + stanza->AddAttr(buzz::QN_TO, addressee); stanza->AddAttr(buzz::QN_ID, id); stanza->AddElement(iq_body); return stanza; diff --git a/remoting/jingle_glue/jingle_info_request.cc b/remoting/jingle_glue/jingle_info_request.cc index d8529a6fd22e48..b8866b5bc46976 100644 --- a/remoting/jingle_glue/jingle_info_request.cc +++ b/remoting/jingle_glue/jingle_info_request.cc @@ -21,20 +21,12 @@ JingleInfoRequest::JingleInfoRequest(IqRequest* request) JingleInfoRequest::~JingleInfoRequest() { } -void JingleInfoRequest::Run(Task* done) { - done_cb_.reset(done); +void JingleInfoRequest::Send(const OnJingleInfoCallback& callback) { + on_jingle_info_cb_ = callback; request_->SendIq(buzz::STR_GET, buzz::STR_EMPTY, new buzz::XmlElement(buzz::QN_JINGLE_INFO_QUERY, true)); } -void JingleInfoRequest::SetCallback(OnJingleInfoCallback* callback) { - on_jingle_info_cb_.reset(callback); -} - -void JingleInfoRequest::DetachCallback() { - on_jingle_info_cb_.reset(); -} - void JingleInfoRequest::OnResponse(const buzz::XmlElement* stanza) { std::vector relay_hosts; std::vector stun_hosts; @@ -81,14 +73,7 @@ void JingleInfoRequest::OnResponse(const buzz::XmlElement* stanza) { } } - if (on_jingle_info_cb_.get()) { - on_jingle_info_cb_->Run(relay_token, relay_hosts, stun_hosts); - } else { - LOG(INFO) << "Iq reply parsed with no callback. Dropping" << stanza->Str(); - } - - DetachCallback(); - done_cb_->Run(); + on_jingle_info_cb_.Run(relay_token, relay_hosts, stun_hosts); } } // namespace remoting diff --git a/remoting/jingle_glue/jingle_info_request.h b/remoting/jingle_glue/jingle_info_request.h index fee561f343aaff..9a63f82a4125a5 100644 --- a/remoting/jingle_glue/jingle_info_request.h +++ b/remoting/jingle_glue/jingle_info_request.h @@ -9,7 +9,7 @@ #include #include "base/basictypes.h" -#include "base/callback_old.h" +#include "base/callback.h" #include "base/memory/scoped_ptr.h" class Task; @@ -26,13 +26,10 @@ namespace remoting { class IqRequest; -// JingleInfoRequest handles making an IQ request to the Google talk network for -// discovering stun/relay information for use in establishing a Jingle -// connection. -// -// Clients should instantiate this class, and set a callback to receive the -// configuration information. The query will be made when Run() is called. The -// query is finisehd when the |done| task given to Run() is invokved. +// JingleInfoRequest handles requesting STUN/Relay infromation from +// the Google Talk network. The query is made when Send() is +// called. The callback given to Send() is called when response to the +// request is received. // // This class is not threadsafe and should be used on the same thread it is // created on. @@ -44,23 +41,20 @@ class JingleInfoRequest { // passed by pointer so the receive may call swap on them. The receiver does // NOT own the arguments, which are guaranteed only to be alive for the // duration of the callback. - typedef Callback3&, - const std::vector&>::Type - OnJingleInfoCallback; + typedef base::Callback&, + const std::vector&)> OnJingleInfoCallback; explicit JingleInfoRequest(IqRequest* request); ~JingleInfoRequest(); - void Run(Task* done); - void SetCallback(OnJingleInfoCallback* callback); - void DetachCallback(); + void Send(const OnJingleInfoCallback& callback); private: void OnResponse(const buzz::XmlElement* stanza); scoped_ptr request_; - scoped_ptr on_jingle_info_cb_; - scoped_ptr done_cb_; + OnJingleInfoCallback on_jingle_info_cb_; DISALLOW_COPY_AND_ASSIGN(JingleInfoRequest); }; diff --git a/remoting/protocol/jingle_session_manager.cc b/remoting/protocol/jingle_session_manager.cc index 077c115acfc9b0..5411c681120c0b 100644 --- a/remoting/protocol/jingle_session_manager.cc +++ b/remoting/protocol/jingle_session_manager.cc @@ -6,6 +6,7 @@ #include +#include "base/bind.h" #include "base/message_loop.h" #include "base/string_util.h" #include "base/task.h" @@ -88,6 +89,8 @@ void JingleSessionManager::Init( talk_base::Thread::Current())); } + // Initialize |port_allocator_|. + // We always use PseudoTcp to provide a reliable channel. However // when it is used together with TCP the performance is very bad // so we explicitly disables TCP connections. @@ -101,20 +104,24 @@ void JingleSessionManager::Init( jingle_info_request_.reset( new JingleInfoRequest(signal_strategy_->CreateIqRequest())); - jingle_info_request_->SetCallback( - NewCallback(this, &JingleSessionManager::OnJingleInfo)); - jingle_info_request_->Run( - task_factory_.NewRunnableMethod( - &JingleSessionManager::DoStartSessionManager)); + jingle_info_request_->Send(base::Bind( + &JingleSessionManager::OnJingleInfo, base::Unretained(this))); } else { port_allocator_flags |= cricket::PORTALLOCATOR_DISABLE_STUN | cricket::PORTALLOCATOR_DISABLE_RELAY; port_allocator_.reset( new cricket::BasicPortAllocator( network_manager_.get(), socket_factory_.get())); - DoStartSessionManager(); } port_allocator_->set_flags(port_allocator_flags); + + // Initialize |cricket_session_manager_|. + cricket_session_manager_.reset( + new cricket::SessionManager(port_allocator_.get())); + cricket_session_manager_->AddClient(kChromotingXmlNamespace, this); + + jingle_signaling_connector_.reset(new JingleSignalingConnector( + signal_strategy_, cricket_session_manager_.get())); } void JingleSessionManager::Close() { @@ -287,17 +294,6 @@ void JingleSessionManager::OnJingleInfo( } } -void JingleSessionManager::DoStartSessionManager() { - DCHECK(CalledOnValidThread()); - - cricket_session_manager_.reset( - new cricket::SessionManager(port_allocator_.get())); - cricket_session_manager_->AddClient(kChromotingXmlNamespace, this); - - jingle_signaling_connector_.reset(new JingleSignalingConnector( - signal_strategy_, cricket_session_manager_.get())); -} - // Parse content description generated by WriteContent(). bool JingleSessionManager::ParseContent( cricket::SignalingProtocol protocol, diff --git a/remoting/protocol/jingle_session_manager.h b/remoting/protocol/jingle_session_manager.h index 4d7c3c978be2b6..58a5cf99ec9c9e 100644 --- a/remoting/protocol/jingle_session_manager.h +++ b/remoting/protocol/jingle_session_manager.h @@ -97,9 +97,6 @@ class JingleSessionManager const std::vector& relay_hosts, const std::vector& stun_hosts); - // Creates cricket::SessionManager. - void DoStartSessionManager(); - // Creates session description for outgoing session. static cricket::SessionDescription* CreateClientSessionDescription( const CandidateSessionConfig* candidate_config, diff --git a/remoting/webapp/me2mom/client_session.js b/remoting/webapp/me2mom/client_session.js index e8d9b66cf6a22d..50127dd7593961 100644 --- a/remoting/webapp/me2mom/client_session.js +++ b/remoting/webapp/me2mom/client_session.js @@ -188,7 +188,7 @@ remoting.ClientSession.prototype.sendIq_ = function(msg) { var jingleNode = iqNode.firstChild; var serializer = new XMLSerializer(); var parameters = { - 'to': iqNode.getAttribute('to'), + 'to': iqNode.getAttribute('to') || "", 'payload_xml': serializer.serializeToString(jingleNode), 'id': iqNode.getAttribute('id') || '1', 'type': iqNode.getAttribute('type'),