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

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

Issue 7809003: Simplify IqRequest interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix windows 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(const std::string& type, 28 void XmppIqRequest::SendIq(buzz::XmlElement* stanza) {
29 const std::string& addressee,
30 buzz::XmlElement* iq_body) {
31 DCHECK_EQ(MessageLoop::current(), message_loop_); 29 DCHECK_EQ(MessageLoop::current(), message_loop_);
32 30
33 // Unregister the handler if it is already registered. 31 // Unregister the handler if it is already registered.
34 Unregister(); 32 Unregister();
35 33
36 DCHECK_GT(type.length(), 0U); 34 stanza->AddAttr(buzz::QN_ID, xmpp_client_->NextId());
37 35 xmpp_client_->engine()->SendIq(stanza, this, &cookie_);
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_);
42 } 36 }
43 37
44 void XmppIqRequest::set_callback(const ReplyCallback& callback) { 38 void XmppIqRequest::set_callback(const ReplyCallback& callback) {
45 callback_ = callback; 39 callback_ = callback;
46 } 40 }
47 41
48 void XmppIqRequest::Unregister() { 42 void XmppIqRequest::Unregister() {
49 if (cookie_) { 43 if (cookie_) {
50 // No need to unregister the handler if the client has been destroyed. 44 // No need to unregister the handler if the client has been destroyed.
51 if (xmpp_client_) { 45 if (xmpp_client_) {
52 xmpp_client_->engine()->RemoveIqHandler(cookie_, NULL); 46 xmpp_client_->engine()->RemoveIqHandler(cookie_, NULL);
53 } 47 }
54 cookie_ = NULL; 48 cookie_ = NULL;
55 } 49 }
56 } 50 }
57 51
58 void XmppIqRequest::IqResponse(buzz::XmppIqCookie cookie, 52 void XmppIqRequest::IqResponse(buzz::XmppIqCookie cookie,
59 const buzz::XmlElement* stanza) { 53 const buzz::XmlElement* stanza) {
60 if (!callback_.is_null()) { 54 if (!callback_.is_null()) {
61 callback_.Run(stanza); 55 callback_.Run(stanza);
62 callback_.Reset(); 56 callback_.Reset();
63 } 57 }
64 } 58 }
65 59
66 } // namespace remoting 60 } // 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