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

Side by Side Diff: remoting/host/register_support_host_request.cc

Issue 8432009: Refactor IqRequest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years, 1 month 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
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/host/register_support_host_request.h" 5 #include "remoting/host/register_support_host_request.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "remoting/base/constants.h" 12 #include "remoting/base/constants.h"
13 #include "remoting/host/host_config.h" 13 #include "remoting/host/host_config.h"
14 #include "remoting/jingle_glue/iq_request.h" 14 #include "remoting/jingle_glue/iq_sender.h"
15 #include "remoting/jingle_glue/jingle_thread.h" 15 #include "remoting/jingle_glue/jingle_thread.h"
16 #include "remoting/jingle_glue/signal_strategy.h" 16 #include "remoting/jingle_glue/signal_strategy.h"
17 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" 17 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
18 #include "third_party/libjingle/source/talk/xmpp/constants.h" 18 #include "third_party/libjingle/source/talk/xmpp/constants.h"
19 19
20 using buzz::QName; 20 using buzz::QName;
21 using buzz::XmlElement; 21 using buzz::XmlElement;
22 22
23 namespace remoting { 23 namespace remoting {
24 24
(...skipping 27 matching lines...) Expand all
52 return true; 52 return true;
53 } 53 }
54 54
55 void RegisterSupportHostRequest::OnSignallingConnected( 55 void RegisterSupportHostRequest::OnSignallingConnected(
56 SignalStrategy* signal_strategy, 56 SignalStrategy* signal_strategy,
57 const std::string& jid) { 57 const std::string& jid) {
58 DCHECK(!callback_.is_null()); 58 DCHECK(!callback_.is_null());
59 59
60 message_loop_ = MessageLoop::current(); 60 message_loop_ = MessageLoop::current();
61 61
62 request_.reset(signal_strategy->CreateIqRequest()); 62 iq_sender_.reset(new IqSender(signal_strategy));
63 request_->set_callback(base::Bind( 63 request_.reset(iq_sender_->SendIq(
64 &RegisterSupportHostRequest::ProcessResponse, base::Unretained(this))); 64 IqSender::MakeIqStanza(buzz::STR_SET, kChromotingBotJid,
65 65 CreateRegistrationRequest(jid)),
66 request_->SendIq(IqRequest::MakeIqStanza( 66 base::Bind(&RegisterSupportHostRequest::ProcessResponse,
67 buzz::STR_SET, kChromotingBotJid, CreateRegistrationRequest(jid))); 67 base::Unretained(this))));
68 } 68 }
69 69
70 void RegisterSupportHostRequest::OnSignallingDisconnected() { 70 void RegisterSupportHostRequest::OnSignallingDisconnected() {
71 if (!message_loop_) { 71 if (!message_loop_) {
72 // We will reach here with |message_loop_| NULL if the Host's 72 // We will reach here with |message_loop_| NULL if the Host's
73 // XMPP connection attempt fails. 73 // XMPP connection attempt fails.
74 CHECK(!callback_.is_null()); 74 CHECK(!callback_.is_null());
75 DCHECK(!request_.get()); 75 DCHECK(!request_.get());
76 callback_.Run(false, std::string(), base::TimeDelta()); 76 callback_.Run(false, std::string(), base::TimeDelta());
77 return; 77 return;
78 } 78 }
79 DCHECK_EQ(message_loop_, MessageLoop::current()); 79 DCHECK_EQ(message_loop_, MessageLoop::current());
80 request_.reset(); 80 request_.reset();
81 iq_sender_.reset();
81 } 82 }
82 83
83 // Ignore any notifications other than signalling 84 // Ignore any notifications other than signalling
84 // connected/disconnected events. 85 // connected/disconnected events.
85 void RegisterSupportHostRequest::OnAccessDenied() { } 86 void RegisterSupportHostRequest::OnAccessDenied() { }
86 void RegisterSupportHostRequest::OnClientAuthenticated( 87 void RegisterSupportHostRequest::OnClientAuthenticated(
87 const std::string& jid) { } 88 const std::string& jid) { }
88 void RegisterSupportHostRequest::OnClientDisconnected( 89 void RegisterSupportHostRequest::OnClientDisconnected(
89 const std::string& jid) { } 90 const std::string& jid) { }
90 void RegisterSupportHostRequest::OnShutdown() { } 91 void RegisterSupportHostRequest::OnShutdown() { }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 std::string* support_id, 123 std::string* support_id,
123 base::TimeDelta* lifetime) { 124 base::TimeDelta* lifetime) {
124 std::string type = response->Attr(buzz::QN_TYPE); 125 std::string type = response->Attr(buzz::QN_TYPE);
125 if (type == buzz::STR_ERROR) { 126 if (type == buzz::STR_ERROR) {
126 LOG(ERROR) << "Received error in response to heartbeat: " 127 LOG(ERROR) << "Received error in response to heartbeat: "
127 << response->Str(); 128 << response->Str();
128 return false; 129 return false;
129 } 130 }
130 131
131 // This method must only be called for error or result stanzas. 132 // This method must only be called for error or result stanzas.
132 DCHECK_EQ(buzz::STR_RESULT, type); 133 if (type != buzz::STR_RESULT) {
134 LOG(ERROR) << "Received unexpect stanza of type \"" << type << "\"";
135 return false;
136 }
133 137
134 const XmlElement* result_element = response->FirstNamed(QName( 138 const XmlElement* result_element = response->FirstNamed(QName(
135 kChromotingXmlNamespace, kRegisterQueryResultTag)); 139 kChromotingXmlNamespace, kRegisterQueryResultTag));
136 if (!result_element) { 140 if (!result_element) {
137 LOG(ERROR) << "<" << kRegisterQueryResultTag 141 LOG(ERROR) << "<" << kRegisterQueryResultTag
138 << "> is missing in the host registration response: " 142 << "> is missing in the host registration response: "
139 << response->Str(); 143 << response->Str();
140 return false; 144 return false;
141 } 145 }
142 146
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 180
177 void RegisterSupportHostRequest::ProcessResponse(const XmlElement* response) { 181 void RegisterSupportHostRequest::ProcessResponse(const XmlElement* response) {
178 DCHECK_EQ(message_loop_, MessageLoop::current()); 182 DCHECK_EQ(message_loop_, MessageLoop::current());
179 std::string support_id; 183 std::string support_id;
180 base::TimeDelta lifetime; 184 base::TimeDelta lifetime;
181 bool success = ParseResponse(response, &support_id, &lifetime); 185 bool success = ParseResponse(response, &support_id, &lifetime);
182 callback_.Run(success, support_id, lifetime); 186 callback_.Run(success, support_id, lifetime);
183 } 187 }
184 188
185 } // namespace remoting 189 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698