diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-06 22:50:13 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-06 22:50:13 +0000 |
commit | 19d963f72826c669179b9fa2c9c11ad40465a701 (patch) | |
tree | 798c0b13524d1fa331e427fd3b64a7e0d3d2798f /remoting/jingle_glue | |
parent | 05932300479fbf56b492155d581c37cd7abea3f0 (diff) | |
download | chromium_src-19d963f72826c669179b9fa2c9c11ad40465a701.zip chromium_src-19d963f72826c669179b9fa2c9c11ad40465a701.tar.gz chromium_src-19d963f72826c669179b9fa2c9c11ad40465a701.tar.bz2 |
Simplify IqRequest interface.
This is neccessary to make the interface usable with stanzas generated
by JingleMessage::ToXml().
BUG=None
TEST=Unittests
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=99801
Review URL: http://codereview.chromium.org/7809003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99851 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/jingle_glue')
-rw-r--r-- | remoting/jingle_glue/iq_request.cc | 4 | ||||
-rw-r--r-- | remoting/jingle_glue/iq_request.h | 16 | ||||
-rw-r--r-- | remoting/jingle_glue/iq_request_unittest.cc | 3 | ||||
-rw-r--r-- | remoting/jingle_glue/javascript_iq_request.cc | 7 | ||||
-rw-r--r-- | remoting/jingle_glue/javascript_iq_request.h | 3 | ||||
-rw-r--r-- | remoting/jingle_glue/jingle_info_request.cc | 5 | ||||
-rw-r--r-- | remoting/jingle_glue/mock_objects.h | 4 | ||||
-rw-r--r-- | remoting/jingle_glue/xmpp_iq_request.cc | 12 | ||||
-rw-r--r-- | remoting/jingle_glue/xmpp_iq_request.h | 3 |
9 files changed, 21 insertions, 36 deletions
diff --git a/remoting/jingle_glue/iq_request.cc b/remoting/jingle_glue/iq_request.cc index 0e93c56..5de2e33 100644 --- a/remoting/jingle_glue/iq_request.cc +++ b/remoting/jingle_glue/iq_request.cc @@ -12,13 +12,11 @@ namespace remoting { // static buzz::XmlElement* IqRequest::MakeIqStanza(const std::string& type, const std::string& addressee, - buzz::XmlElement* iq_body, - const std::string& id) { + buzz::XmlElement* iq_body) { 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 015d2db..6fbef97 100644 --- a/remoting/jingle_glue/iq_request.h +++ b/remoting/jingle_glue/iq_request.h @@ -25,23 +25,19 @@ 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 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; + // Sends Iq stanza. Takes ownership of |stanza|. + virtual void SendIq(buzz::XmlElement* stanza) = 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 4b323fb..d7eeda6 100644 --- a/remoting/jingle_glue/iq_request_unittest.cc +++ b/remoting/jingle_glue/iq_request_unittest.cc @@ -31,7 +31,8 @@ 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, kMessageId)); + IqRequest::MakeIqStanza(kType, kTo, iq_body)); + stanza->AddAttr(buzz::QName("", "id"), 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 b08ffe9..62366cf 100644 --- a/remoting/jingle_glue/javascript_iq_request.cc +++ b/remoting/jingle_glue/javascript_iq_request.cc @@ -83,12 +83,11 @@ JavascriptIqRequest::~JavascriptIqRequest() { registry_->RemoveAllRequests(this); } -void JavascriptIqRequest::SendIq(const std::string& type, - const std::string& addressee, - buzz::XmlElement* iq_body) { +void JavascriptIqRequest::SendIq(buzz::XmlElement* stanza) { std::string id = signal_strategy_->GetNextId(); + stanza->AddAttr(buzz::QN_ID, id); registry_->RegisterRequest(this, id); - signal_strategy_->SendStanza(MakeIqStanza(type, addressee, iq_body, id)); + signal_strategy_->SendStanza(stanza); } 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 d2ff5d9..f94fc33 100644 --- a/remoting/jingle_glue/javascript_iq_request.h +++ b/remoting/jingle_glue/javascript_iq_request.h @@ -55,8 +55,7 @@ class JavascriptIqRequest : public IqRequest { virtual ~JavascriptIqRequest(); // IqRequest interface. - virtual void SendIq(const std::string& type, const std::string& addressee, - buzz::XmlElement* iq_body) OVERRIDE; + virtual void SendIq(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 888c768..9a5d16d 100644 --- a/remoting/jingle_glue/jingle_info_request.cc +++ b/remoting/jingle_glue/jingle_info_request.cc @@ -34,8 +34,9 @@ JingleInfoRequest::~JingleInfoRequest() { 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)); + request_->SendIq(IqRequest::MakeIqStanza( + 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 6c93b0a..5563e22 100644 --- a/remoting/jingle_glue/mock_objects.h +++ b/remoting/jingle_glue/mock_objects.h @@ -27,9 +27,7 @@ class MockIqRequest : public IqRequest { MockIqRequest(); virtual ~MockIqRequest(); - MOCK_METHOD3(SendIq, void(const std::string& type, - const std::string& addressee, - buzz::XmlElement* iq_body)); + MOCK_METHOD1(SendIq, void(buzz::XmlElement* stanza)); 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 b8057c3..7e07665 100644 --- a/remoting/jingle_glue/xmpp_iq_request.cc +++ b/remoting/jingle_glue/xmpp_iq_request.cc @@ -25,20 +25,14 @@ XmppIqRequest::~XmppIqRequest() { Unregister(); } -void XmppIqRequest::SendIq(const std::string& type, - const std::string& addressee, - buzz::XmlElement* iq_body) { +void XmppIqRequest::SendIq(buzz::XmlElement* stanza) { DCHECK_EQ(MessageLoop::current(), message_loop_); // Unregister the handler if it is already registered. Unregister(); - 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_); + stanza->AddAttr(buzz::QN_ID, xmpp_client_->NextId()); + xmpp_client_->engine()->SendIq(stanza, 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 ce8d61b..8732c49 100644 --- a/remoting/jingle_glue/xmpp_iq_request.h +++ b/remoting/jingle_glue/xmpp_iq_request.h @@ -24,8 +24,7 @@ class XmppIqRequest : public IqRequest, public buzz::XmppIqHandler { virtual ~XmppIqRequest(); // IqRequest interface. - virtual void SendIq(const std::string& type, const std::string& addressee, - buzz::XmlElement* iq_body) OVERRIDE; + virtual void SendIq(buzz::XmlElement* stanza) OVERRIDE; virtual void set_callback(const ReplyCallback& callback) OVERRIDE; // buzz::XmppIqHandler interface. |