summaryrefslogtreecommitdiffstats
path: root/remoting
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
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')
-rw-r--r--remoting/host/heartbeat_sender.cc3
-rw-r--r--remoting/host/heartbeat_sender_unittest.cc14
-rw-r--r--remoting/host/register_support_host_request.cc4
-rw-r--r--remoting/host/register_support_host_request_unittest.cc11
-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
13 files changed, 46 insertions, 43 deletions
diff --git a/remoting/host/heartbeat_sender.cc b/remoting/host/heartbeat_sender.cc
index 32ddd49..182c06e 100644
--- a/remoting/host/heartbeat_sender.cc
+++ b/remoting/host/heartbeat_sender.cc
@@ -101,8 +101,7 @@ void HeartbeatSender::DoSendStanza() {
DCHECK_EQ(state_, STARTED);
VLOG(1) << "Sending heartbeat stanza to " << kChromotingBotJid;
- request_->SendIq(IqRequest::MakeIqStanza(
- buzz::STR_SET, kChromotingBotJid, CreateHeartbeatMessage()));
+ request_->SendIq(buzz::STR_SET, kChromotingBotJid, CreateHeartbeatMessage());
}
void HeartbeatSender::ProcessResponse(const XmlElement* response) {
diff --git a/remoting/host/heartbeat_sender_unittest.cc b/remoting/host/heartbeat_sender_unittest.cc
index e7086d9..8818c156 100644
--- a/remoting/host/heartbeat_sender_unittest.cc
+++ b/remoting/host/heartbeat_sender_unittest.cc
@@ -27,7 +27,6 @@ using testing::DoAll;
using testing::Invoke;
using testing::NotNull;
using testing::Return;
-using testing::SaveArg;
namespace remoting {
@@ -51,7 +50,7 @@ class HeartbeatSenderTest : public testing::Test {
};
// Call Start() followed by Stop(), and makes sure an Iq stanza is
-// being sent.
+// being send.
TEST_F(HeartbeatSenderTest, DoSendStanza) {
// |iq_request| is freed by HeartbeatSender.
MockIqRequest* iq_request = new MockIqRequest();
@@ -67,19 +66,12 @@ TEST_F(HeartbeatSenderTest, DoSendStanza) {
EXPECT_CALL(signal_strategy_, CreateIqRequest())
.WillOnce(Return(iq_request));
- XmlElement* sent_iq = NULL;
- EXPECT_CALL(*iq_request, SendIq(NotNull()))
- .WillOnce(SaveArg<0>(&sent_iq));
+ EXPECT_CALL(*iq_request, SendIq(buzz::STR_SET, kChromotingBotJid, NotNull()))
+ .WillOnce(DoAll(DeleteArg<2>(), Return()));
heartbeat_sender->OnSignallingConnected(&signal_strategy_, kTestJid);
message_loop_.RunAllPending();
- scoped_ptr<XmlElement> stanza(sent_iq);
- ASSERT_TRUE(stanza != NULL);
-
- EXPECT_EQ(stanza->Attr(buzz::QName("", "to")), kChromotingBotJid);
- EXPECT_EQ(stanza->Attr(buzz::QName("", "type")), "set");
-
heartbeat_sender->OnSignallingDisconnected();
message_loop_.RunAllPending();
}
diff --git a/remoting/host/register_support_host_request.cc b/remoting/host/register_support_host_request.cc
index 38d3c4a..3c47dab 100644
--- a/remoting/host/register_support_host_request.cc
+++ b/remoting/host/register_support_host_request.cc
@@ -63,8 +63,8 @@ void RegisterSupportHostRequest::OnSignallingConnected(
request_->set_callback(base::Bind(
&RegisterSupportHostRequest::ProcessResponse, base::Unretained(this)));
- request_->SendIq(IqRequest::MakeIqStanza(
- buzz::STR_SET, kChromotingBotJid, CreateRegistrationRequest(jid)));
+ request_->SendIq(buzz::STR_SET, kChromotingBotJid,
+ CreateRegistrationRequest(jid));
}
void RegisterSupportHostRequest::OnSignallingDisconnected() {
diff --git a/remoting/host/register_support_host_request_unittest.cc b/remoting/host/register_support_host_request_unittest.cc
index 85debb9..50c305a 100644
--- a/remoting/host/register_support_host_request_unittest.cc
+++ b/remoting/host/register_support_host_request_unittest.cc
@@ -76,8 +76,8 @@ TEST_F(RegisterSupportHostRequestTest, Send) {
.WillOnce(Return(iq_request));
XmlElement* sent_iq = NULL;
- EXPECT_CALL(*iq_request, SendIq(NotNull()))
- .WillOnce(SaveArg<0>(&sent_iq));
+ EXPECT_CALL(*iq_request, SendIq(buzz::STR_SET, kChromotingBotJid, NotNull()))
+ .WillOnce(SaveArg<2>(&sent_iq));
request->OnSignallingConnected(&signal_strategy_, kTestJid);
message_loop_.RunAllPending();
@@ -86,14 +86,11 @@ TEST_F(RegisterSupportHostRequestTest, Send) {
scoped_ptr<XmlElement> stanza(sent_iq);
ASSERT_TRUE(stanza != NULL);
- EXPECT_EQ(stanza->Attr(buzz::QName("", "to")), kChromotingBotJid);
- EXPECT_EQ(stanza->Attr(buzz::QName("", "type")), "set");
-
EXPECT_EQ(QName(kChromotingXmlNamespace, "register-support-host"),
- stanza->FirstElement()->Name());
+ stanza->Name());
QName signature_tag(kChromotingXmlNamespace, "signature");
- XmlElement* signature = stanza->FirstElement()->FirstNamed(signature_tag);
+ XmlElement* signature = stanza->FirstNamed(signature_tag);
ASSERT_TRUE(signature != NULL);
EXPECT_TRUE(stanza->NextNamed(signature_tag) == NULL);
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.