summaryrefslogtreecommitdiffstats
path: root/remoting/jingle_glue
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-06 20:40:50 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-06 20:40:50 +0000
commit3e729c3687149657194dec4cf3d870d54aeafaaf (patch)
tree6c390630ff1b6ffe99392138ad611d40debcbb44 /remoting/jingle_glue
parentd9a92dbc3bdf6bb139ba68cf1f510df45d231517 (diff)
downloadchromium_src-3e729c3687149657194dec4cf3d870d54aeafaaf.zip
chromium_src-3e729c3687149657194dec4cf3d870d54aeafaaf.tar.gz
chromium_src-3e729c3687149657194dec4cf3d870d54aeafaaf.tar.bz2
Revert 99801 - Simplify IqRequest interface.
This is neccessary to make the interface usable with stanzas generated by JingleMessage::ToXml(). BUG=None TEST=Unittests Review URL: http://codereview.chromium.org/7809003 TBR=sergeyu@chromium.org Review URL: http://codereview.chromium.org/7841006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99807 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/jingle_glue')
-rw-r--r--remoting/jingle_glue/iq_request.cc4
-rw-r--r--remoting/jingle_glue/iq_request.h16
-rw-r--r--remoting/jingle_glue/iq_request_unittest.cc3
-rw-r--r--remoting/jingle_glue/javascript_iq_request.cc7
-rw-r--r--remoting/jingle_glue/javascript_iq_request.h3
-rw-r--r--remoting/jingle_glue/jingle_info_request.cc5
-rw-r--r--remoting/jingle_glue/mock_objects.h4
-rw-r--r--remoting/jingle_glue/xmpp_iq_request.cc12
-rw-r--r--remoting/jingle_glue/xmpp_iq_request.h3
9 files changed, 36 insertions, 21 deletions
diff --git a/remoting/jingle_glue/iq_request.cc b/remoting/jingle_glue/iq_request.cc
index 5de2e33..0e93c56 100644
--- a/remoting/jingle_glue/iq_request.cc
+++ b/remoting/jingle_glue/iq_request.cc
@@ -12,11 +12,13 @@ namespace remoting {
// static
buzz::XmlElement* IqRequest::MakeIqStanza(const std::string& type,
const std::string& addressee,
- buzz::XmlElement* iq_body) {
+ buzz::XmlElement* iq_body,
+ const std::string& id) {
buzz::XmlElement* stanza = new buzz::XmlElement(buzz::QN_IQ);
stanza->AddAttr(buzz::QN_TYPE, type);
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/iq_request.h b/remoting/jingle_glue/iq_request.h
index 6fbef97..015d2db 100644
--- a/remoting/jingle_glue/iq_request.h
+++ b/remoting/jingle_glue/iq_request.h
@@ -25,19 +25,23 @@ class IqRequest {
public:
typedef base::Callback<void(const buzz::XmlElement*)> ReplyCallback;
- static buzz::XmlElement* MakeIqStanza(const std::string& type,
- const std::string& addressee,
- buzz::XmlElement* iq_body);
-
IqRequest() {}
virtual ~IqRequest() {}
- // Sends Iq stanza. Takes ownership of |stanza|.
- virtual void SendIq(buzz::XmlElement* stanza) = 0;
+ // Sends stanza of type |type| to |addressee|. |iq_body| contains body of
+ // the stanza. Takes pwnership of |iq_body|.
+ virtual void SendIq(const std::string& type, const std::string& addressee,
+ buzz::XmlElement* iq_body) = 0;
// Sets callback that is called when reply stanza is received.
virtual void set_callback(const ReplyCallback& callback) = 0;
+ protected:
+ static buzz::XmlElement* MakeIqStanza(const std::string& type,
+ const std::string& addressee,
+ buzz::XmlElement* iq_body,
+ const std::string& id);
+
private:
FRIEND_TEST_ALL_PREFIXES(IqRequestTest, MakeIqStanza);
diff --git a/remoting/jingle_glue/iq_request_unittest.cc b/remoting/jingle_glue/iq_request_unittest.cc
index d7eeda6..4b323fb 100644
--- a/remoting/jingle_glue/iq_request_unittest.cc
+++ b/remoting/jingle_glue/iq_request_unittest.cc
@@ -31,8 +31,7 @@ TEST(IqRequestTest, MakeIqStanza) {
buzz::XmlElement* iq_body =
new buzz::XmlElement(buzz::QName(kNamespace, kBodyTag));
scoped_ptr<buzz::XmlElement> stanza(
- IqRequest::MakeIqStanza(kType, kTo, iq_body));
- stanza->AddAttr(buzz::QName("", "id"), kMessageId);
+ IqRequest::MakeIqStanza(kType, kTo, iq_body, kMessageId));
EXPECT_EQ(expected_xml_string, stanza->Str());
}
diff --git a/remoting/jingle_glue/javascript_iq_request.cc b/remoting/jingle_glue/javascript_iq_request.cc
index 62366cf..b08ffe9 100644
--- a/remoting/jingle_glue/javascript_iq_request.cc
+++ b/remoting/jingle_glue/javascript_iq_request.cc
@@ -83,11 +83,12 @@ JavascriptIqRequest::~JavascriptIqRequest() {
registry_->RemoveAllRequests(this);
}
-void JavascriptIqRequest::SendIq(buzz::XmlElement* stanza) {
+void JavascriptIqRequest::SendIq(const std::string& type,
+ const std::string& addressee,
+ buzz::XmlElement* iq_body) {
std::string id = signal_strategy_->GetNextId();
- stanza->AddAttr(buzz::QN_ID, id);
registry_->RegisterRequest(this, id);
- signal_strategy_->SendStanza(stanza);
+ signal_strategy_->SendStanza(MakeIqStanza(type, addressee, iq_body, id));
}
void JavascriptIqRequest::set_callback(const ReplyCallback& callback) {
diff --git a/remoting/jingle_glue/javascript_iq_request.h b/remoting/jingle_glue/javascript_iq_request.h
index f94fc33..d2ff5d9 100644
--- a/remoting/jingle_glue/javascript_iq_request.h
+++ b/remoting/jingle_glue/javascript_iq_request.h
@@ -55,7 +55,8 @@ class JavascriptIqRequest : public IqRequest {
virtual ~JavascriptIqRequest();
// IqRequest interface.
- virtual void SendIq(buzz::XmlElement* iq_body) OVERRIDE;
+ virtual void SendIq(const std::string& type, const std::string& addressee,
+ buzz::XmlElement* iq_body) OVERRIDE;
virtual void set_callback(const ReplyCallback& callback) OVERRIDE;
private:
diff --git a/remoting/jingle_glue/jingle_info_request.cc b/remoting/jingle_glue/jingle_info_request.cc
index 9a5d16d..888c768 100644
--- a/remoting/jingle_glue/jingle_info_request.cc
+++ b/remoting/jingle_glue/jingle_info_request.cc
@@ -34,9 +34,8 @@ JingleInfoRequest::~JingleInfoRequest() {
void JingleInfoRequest::Send(const OnJingleInfoCallback& callback) {
on_jingle_info_cb_ = callback;
- request_->SendIq(IqRequest::MakeIqStanza(
- buzz::STR_GET, buzz::STR_EMPTY,
- new buzz::XmlElement(buzz::QN_JINGLE_INFO_QUERY, true)));
+ request_->SendIq(buzz::STR_GET, buzz::STR_EMPTY,
+ new buzz::XmlElement(buzz::QN_JINGLE_INFO_QUERY, true));
}
void JingleInfoRequest::OnResponse(const buzz::XmlElement* stanza) {
diff --git a/remoting/jingle_glue/mock_objects.h b/remoting/jingle_glue/mock_objects.h
index 5563e22..6c93b0a 100644
--- a/remoting/jingle_glue/mock_objects.h
+++ b/remoting/jingle_glue/mock_objects.h
@@ -27,7 +27,9 @@ class MockIqRequest : public IqRequest {
MockIqRequest();
virtual ~MockIqRequest();
- MOCK_METHOD1(SendIq, void(buzz::XmlElement* stanza));
+ MOCK_METHOD3(SendIq, void(const std::string& type,
+ const std::string& addressee,
+ buzz::XmlElement* iq_body));
MOCK_METHOD1(set_callback, void(const IqRequest::ReplyCallback&));
// Ensure this takes ownership of the pointer, as the real IqRequest object
diff --git a/remoting/jingle_glue/xmpp_iq_request.cc b/remoting/jingle_glue/xmpp_iq_request.cc
index 7e07665..b8057c3 100644
--- a/remoting/jingle_glue/xmpp_iq_request.cc
+++ b/remoting/jingle_glue/xmpp_iq_request.cc
@@ -25,14 +25,20 @@ XmppIqRequest::~XmppIqRequest() {
Unregister();
}
-void XmppIqRequest::SendIq(buzz::XmlElement* stanza) {
+void XmppIqRequest::SendIq(const std::string& type,
+ const std::string& addressee,
+ buzz::XmlElement* iq_body) {
DCHECK_EQ(MessageLoop::current(), message_loop_);
// Unregister the handler if it is already registered.
Unregister();
- stanza->AddAttr(buzz::QN_ID, xmpp_client_->NextId());
- xmpp_client_->engine()->SendIq(stanza, this, &cookie_);
+ DCHECK_GT(type.length(), 0U);
+
+ scoped_ptr<buzz::XmlElement> stanza(MakeIqStanza(type, addressee, iq_body,
+ xmpp_client_->NextId()));
+
+ xmpp_client_->engine()->SendIq(stanza.get(), this, &cookie_);
}
void XmppIqRequest::set_callback(const ReplyCallback& callback) {
diff --git a/remoting/jingle_glue/xmpp_iq_request.h b/remoting/jingle_glue/xmpp_iq_request.h
index 8732c49..ce8d61b 100644
--- a/remoting/jingle_glue/xmpp_iq_request.h
+++ b/remoting/jingle_glue/xmpp_iq_request.h
@@ -24,7 +24,8 @@ class XmppIqRequest : public IqRequest, public buzz::XmppIqHandler {
virtual ~XmppIqRequest();
// IqRequest interface.
- virtual void SendIq(buzz::XmlElement* stanza) OVERRIDE;
+ virtual void SendIq(const std::string& type, const std::string& addressee,
+ buzz::XmlElement* iq_body) OVERRIDE;
virtual void set_callback(const ReplyCallback& callback) OVERRIDE;
// buzz::XmppIqHandler interface.