summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-26 19:40:25 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-26 19:40:25 +0000
commit0570f5622cfe060609a5a3d3700d704558173ca6 (patch)
tree516e5d494352441cd07dfd758e80dcee2e107920 /remoting
parent3a65d92d7c52770a197ba7abe8ea4600e1201a36 (diff)
downloadchromium_src-0570f5622cfe060609a5a3d3700d704558173ca6.zip
chromium_src-0570f5622cfe060609a5a3d3700d704558173ca6.tar.gz
chromium_src-0570f5622cfe060609a5a3d3700d704558173ca6.tar.bz2
Cleanups and bugfixes for JingleInfoRequest.
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
Diffstat (limited to 'remoting')
-rw-r--r--remoting/jingle_glue/iq_request.cc3
-rw-r--r--remoting/jingle_glue/jingle_info_request.cc21
-rw-r--r--remoting/jingle_glue/jingle_info_request.h26
-rw-r--r--remoting/protocol/jingle_session_manager.cc30
-rw-r--r--remoting/protocol/jingle_session_manager.h3
-rw-r--r--remoting/webapp/me2mom/client_session.js2
6 files changed, 29 insertions, 56 deletions
diff --git a/remoting/jingle_glue/iq_request.cc b/remoting/jingle_glue/iq_request.cc
index 3ea2726..0e93c56 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 d8529a6..b8866b5 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<std::string> relay_hosts;
std::vector<talk_base::SocketAddress> 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 fee561f..9a63f82 100644
--- a/remoting/jingle_glue/jingle_info_request.h
+++ b/remoting/jingle_glue/jingle_info_request.h
@@ -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;
@@ -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::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);
};
diff --git a/remoting/protocol/jingle_session_manager.cc b/remoting/protocol/jingle_session_manager.cc
index 077c115..5411c68 100644
--- a/remoting/protocol/jingle_session_manager.cc
+++ b/remoting/protocol/jingle_session_manager.cc
@@ -6,6 +6,7 @@
#include <limits>
+#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 4d7c3c9..58a5cf9 100644
--- a/remoting/protocol/jingle_session_manager.h
+++ b/remoting/protocol/jingle_session_manager.h
@@ -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,
diff --git a/remoting/webapp/me2mom/client_session.js b/remoting/webapp/me2mom/client_session.js
index e8d9b66..50127dd 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'),