Skip to content

Commit

Permalink
Cleanups and bugfixes for JingleInfoRequest.
Browse files Browse the repository at this point in the history
BUG=None
TEST=JinlgeInfoRequest can fetch jingle info on both host and client

Review URL: http://codereview.chromium.org/7495041

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94149 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sergeyu@chromium.org committed Jul 26, 2011
1 parent 3a65d92 commit 0570f56
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 56 deletions.
3 changes: 2 additions & 1 deletion remoting/jingle_glue/iq_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 3 additions & 18 deletions remoting/jingle_glue/jingle_info_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> relay_hosts;
std::vector<talk_base::SocketAddress> stun_hosts;
Expand Down Expand Up @@ -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
26 changes: 10 additions & 16 deletions remoting/jingle_glue/jingle_info_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <vector>

#include "base/basictypes.h"
#include "base/callback_old.h"
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"

class Task;
Expand All @@ -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.
Expand All @@ -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::string&, const std::vector<std::string>&,
const std::vector<talk_base::SocketAddress>&>::Type
OnJingleInfoCallback;
typedef base::Callback<void (
const std::string&, const std::vector<std::string>&,
const std::vector<talk_base::SocketAddress>&)> 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<IqRequest> request_;
scoped_ptr<OnJingleInfoCallback> on_jingle_info_cb_;
scoped_ptr<Task> done_cb_;
OnJingleInfoCallback on_jingle_info_cb_;

DISALLOW_COPY_AND_ASSIGN(JingleInfoRequest);
};
Expand Down
30 changes: 13 additions & 17 deletions remoting/protocol/jingle_session_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <limits>

#include "base/bind.h"
#include "base/message_loop.h"
#include "base/string_util.h"
#include "base/task.h"
Expand Down Expand Up @@ -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.
Expand All @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions remoting/protocol/jingle_session_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ class JingleSessionManager
const std::vector<std::string>& relay_hosts,
const std::vector<talk_base::SocketAddress>& stun_hosts);

// Creates cricket::SessionManager.
void DoStartSessionManager();

// Creates session description for outgoing session.
static cricket::SessionDescription* CreateClientSessionDescription(
const CandidateSessionConfig* candidate_config,
Expand Down
2 changes: 1 addition & 1 deletion remoting/webapp/me2mom/client_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit 0570f56

Please sign in to comment.