OLD | NEW |
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 Loading... |
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 buzz::STR_SET, kChromotingBotJid, CreateRegistrationRequest(jid), |
65 | 65 base::Bind(&RegisterSupportHostRequest::ProcessResponse, |
66 request_->SendIq(IqRequest::MakeIqStanza( | 66 base::Unretained(this)))); |
67 buzz::STR_SET, kChromotingBotJid, CreateRegistrationRequest(jid))); | |
68 } | 67 } |
69 | 68 |
70 void RegisterSupportHostRequest::OnSignallingDisconnected() { | 69 void RegisterSupportHostRequest::OnSignallingDisconnected() { |
71 if (!message_loop_) { | 70 if (!message_loop_) { |
72 // We will reach here with |message_loop_| NULL if the Host's | 71 // We will reach here with |message_loop_| NULL if the Host's |
73 // XMPP connection attempt fails. | 72 // XMPP connection attempt fails. |
74 CHECK(!callback_.is_null()); | 73 CHECK(!callback_.is_null()); |
75 DCHECK(!request_.get()); | 74 DCHECK(!request_.get()); |
76 callback_.Run(false, std::string(), base::TimeDelta()); | 75 callback_.Run(false, std::string(), base::TimeDelta()); |
77 return; | 76 return; |
78 } | 77 } |
79 DCHECK_EQ(message_loop_, MessageLoop::current()); | 78 DCHECK_EQ(message_loop_, MessageLoop::current()); |
80 request_.reset(); | 79 request_.reset(); |
| 80 iq_sender_.reset(); |
81 } | 81 } |
82 | 82 |
83 // Ignore any notifications other than signalling | 83 // Ignore any notifications other than signalling |
84 // connected/disconnected events. | 84 // connected/disconnected events. |
85 void RegisterSupportHostRequest::OnAccessDenied() { } | 85 void RegisterSupportHostRequest::OnAccessDenied() { } |
86 void RegisterSupportHostRequest::OnClientAuthenticated( | 86 void RegisterSupportHostRequest::OnClientAuthenticated( |
87 const std::string& jid) { } | 87 const std::string& jid) { } |
88 void RegisterSupportHostRequest::OnClientDisconnected( | 88 void RegisterSupportHostRequest::OnClientDisconnected( |
89 const std::string& jid) { } | 89 const std::string& jid) { } |
90 void RegisterSupportHostRequest::OnShutdown() { } | 90 void RegisterSupportHostRequest::OnShutdown() { } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 std::string* support_id, | 122 std::string* support_id, |
123 base::TimeDelta* lifetime) { | 123 base::TimeDelta* lifetime) { |
124 std::string type = response->Attr(buzz::QN_TYPE); | 124 std::string type = response->Attr(buzz::QN_TYPE); |
125 if (type == buzz::STR_ERROR) { | 125 if (type == buzz::STR_ERROR) { |
126 LOG(ERROR) << "Received error in response to heartbeat: " | 126 LOG(ERROR) << "Received error in response to heartbeat: " |
127 << response->Str(); | 127 << response->Str(); |
128 return false; | 128 return false; |
129 } | 129 } |
130 | 130 |
131 // This method must only be called for error or result stanzas. | 131 // This method must only be called for error or result stanzas. |
132 DCHECK_EQ(std::string(buzz::STR_RESULT), type); | 132 if (type != buzz::STR_RESULT) { |
| 133 LOG(ERROR) << "Received unexpect stanza of type \"" << type << "\""; |
| 134 return false; |
| 135 } |
133 | 136 |
134 const XmlElement* result_element = response->FirstNamed(QName( | 137 const XmlElement* result_element = response->FirstNamed(QName( |
135 kChromotingXmlNamespace, kRegisterQueryResultTag)); | 138 kChromotingXmlNamespace, kRegisterQueryResultTag)); |
136 if (!result_element) { | 139 if (!result_element) { |
137 LOG(ERROR) << "<" << kRegisterQueryResultTag | 140 LOG(ERROR) << "<" << kRegisterQueryResultTag |
138 << "> is missing in the host registration response: " | 141 << "> is missing in the host registration response: " |
139 << response->Str(); | 142 << response->Str(); |
140 return false; | 143 return false; |
141 } | 144 } |
142 | 145 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 179 |
177 void RegisterSupportHostRequest::ProcessResponse(const XmlElement* response) { | 180 void RegisterSupportHostRequest::ProcessResponse(const XmlElement* response) { |
178 DCHECK_EQ(message_loop_, MessageLoop::current()); | 181 DCHECK_EQ(message_loop_, MessageLoop::current()); |
179 std::string support_id; | 182 std::string support_id; |
180 base::TimeDelta lifetime; | 183 base::TimeDelta lifetime; |
181 bool success = ParseResponse(response, &support_id, &lifetime); | 184 bool success = ParseResponse(response, &support_id, &lifetime); |
182 callback_.Run(success, support_id, lifetime); | 185 callback_.Run(success, support_id, lifetime); |
183 } | 186 } |
184 | 187 |
185 } // namespace remoting | 188 } // namespace remoting |
OLD | NEW |