Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: remoting/jingle_glue/xmpp_iq_request.cc

Issue 7841006: Revert 99801 - Simplify IqRequest interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/jingle_glue/xmpp_iq_request.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/jingle_glue/xmpp_iq_request.h" 5 #include "remoting/jingle_glue/xmpp_iq_request.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "third_party/libjingle/source/talk/xmpp/constants.h" 9 #include "third_party/libjingle/source/talk/xmpp/constants.h"
10 #include "third_party/libjingle/source/talk/xmpp/xmppclient.h" 10 #include "third_party/libjingle/source/talk/xmpp/xmppclient.h"
11 11
12 namespace remoting { 12 namespace remoting {
13 13
14 XmppIqRequest::XmppIqRequest(MessageLoop* message_loop, 14 XmppIqRequest::XmppIqRequest(MessageLoop* message_loop,
15 buzz::XmppClient* xmpp_client) 15 buzz::XmppClient* xmpp_client)
16 : message_loop_(message_loop), 16 : message_loop_(message_loop),
17 xmpp_client_(xmpp_client), 17 xmpp_client_(xmpp_client),
18 cookie_(NULL) { 18 cookie_(NULL) {
19 DCHECK(xmpp_client_); 19 DCHECK(xmpp_client_);
20 DCHECK_EQ(MessageLoop::current(), message_loop_); 20 DCHECK_EQ(MessageLoop::current(), message_loop_);
21 } 21 }
22 22
23 XmppIqRequest::~XmppIqRequest() { 23 XmppIqRequest::~XmppIqRequest() {
24 DCHECK_EQ(MessageLoop::current(), message_loop_); 24 DCHECK_EQ(MessageLoop::current(), message_loop_);
25 Unregister(); 25 Unregister();
26 } 26 }
27 27
28 void XmppIqRequest::SendIq(buzz::XmlElement* stanza) { 28 void XmppIqRequest::SendIq(const std::string& type,
29 const std::string& addressee,
30 buzz::XmlElement* iq_body) {
29 DCHECK_EQ(MessageLoop::current(), message_loop_); 31 DCHECK_EQ(MessageLoop::current(), message_loop_);
30 32
31 // Unregister the handler if it is already registered. 33 // Unregister the handler if it is already registered.
32 Unregister(); 34 Unregister();
33 35
34 stanza->AddAttr(buzz::QN_ID, xmpp_client_->NextId()); 36 DCHECK_GT(type.length(), 0U);
35 xmpp_client_->engine()->SendIq(stanza, this, &cookie_); 37
38 scoped_ptr<buzz::XmlElement> stanza(MakeIqStanza(type, addressee, iq_body,
39 xmpp_client_->NextId()));
40
41 xmpp_client_->engine()->SendIq(stanza.get(), this, &cookie_);
36 } 42 }
37 43
38 void XmppIqRequest::set_callback(const ReplyCallback& callback) { 44 void XmppIqRequest::set_callback(const ReplyCallback& callback) {
39 callback_ = callback; 45 callback_ = callback;
40 } 46 }
41 47
42 void XmppIqRequest::Unregister() { 48 void XmppIqRequest::Unregister() {
43 if (cookie_) { 49 if (cookie_) {
44 // No need to unregister the handler if the client has been destroyed. 50 // No need to unregister the handler if the client has been destroyed.
45 if (xmpp_client_) { 51 if (xmpp_client_) {
46 xmpp_client_->engine()->RemoveIqHandler(cookie_, NULL); 52 xmpp_client_->engine()->RemoveIqHandler(cookie_, NULL);
47 } 53 }
48 cookie_ = NULL; 54 cookie_ = NULL;
49 } 55 }
50 } 56 }
51 57
52 void XmppIqRequest::IqResponse(buzz::XmppIqCookie cookie, 58 void XmppIqRequest::IqResponse(buzz::XmppIqCookie cookie,
53 const buzz::XmlElement* stanza) { 59 const buzz::XmlElement* stanza) {
54 if (!callback_.is_null()) { 60 if (!callback_.is_null()) {
55 callback_.Run(stanza); 61 callback_.Run(stanza);
56 callback_.Reset(); 62 callback_.Reset();
57 } 63 }
58 } 64 }
59 65
60 } // namespace remoting 66 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/jingle_glue/xmpp_iq_request.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698