OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/signaling/xmpp_signal_strategy.h" | 5 #include "remoting/signaling/xmpp_signal_strategy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 XmppSignalStrategy::XmppServerConfig::XmppServerConfig() {} | 46 XmppSignalStrategy::XmppServerConfig::XmppServerConfig() {} |
47 XmppSignalStrategy::XmppServerConfig::~XmppServerConfig() {} | 47 XmppSignalStrategy::XmppServerConfig::~XmppServerConfig() {} |
48 | 48 |
49 XmppSignalStrategy::XmppSignalStrategy( | 49 XmppSignalStrategy::XmppSignalStrategy( |
50 net::ClientSocketFactory* socket_factory, | 50 net::ClientSocketFactory* socket_factory, |
51 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 51 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
52 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config) | 52 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config) |
53 : socket_factory_(socket_factory), | 53 : socket_factory_(socket_factory), |
54 request_context_getter_(request_context_getter), | 54 request_context_getter_(request_context_getter), |
55 resource_name_(kDefaultResourceName), | 55 resource_name_(kDefaultResourceName), |
56 xmpp_client_(NULL), | 56 xmpp_client_(nullptr), |
57 xmpp_server_config_(xmpp_server_config), | 57 xmpp_server_config_(xmpp_server_config), |
58 state_(DISCONNECTED), | 58 state_(DISCONNECTED), |
59 error_(OK) { | 59 error_(OK) { |
60 #if defined(NDEBUG) | 60 #if defined(NDEBUG) |
61 CHECK(xmpp_server_config_.use_tls); | 61 CHECK(xmpp_server_config_.use_tls); |
62 #endif | 62 #endif |
63 } | 63 } |
64 | 64 |
65 XmppSignalStrategy::~XmppSignalStrategy() { | 65 XmppSignalStrategy::~XmppSignalStrategy() { |
66 Disconnect(); | 66 Disconnect(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 } | 131 } |
132 | 132 |
133 void XmppSignalStrategy::Disconnect() { | 133 void XmppSignalStrategy::Disconnect() { |
134 DCHECK(CalledOnValidThread()); | 134 DCHECK(CalledOnValidThread()); |
135 | 135 |
136 if (xmpp_client_) { | 136 if (xmpp_client_) { |
137 xmpp_client_->engine()->RemoveStanzaHandler(this); | 137 xmpp_client_->engine()->RemoveStanzaHandler(this); |
138 | 138 |
139 xmpp_client_->Disconnect(); | 139 xmpp_client_->Disconnect(); |
140 | 140 |
141 // |xmpp_client_| should be set to NULL in OnConnectionStateChanged() | 141 // |xmpp_client_| should be set to nullptr in OnConnectionStateChanged() |
142 // in response to Disconnect() call above. | 142 // in response to Disconnect() call above. |
143 DCHECK(xmpp_client_ == NULL); | 143 DCHECK(xmpp_client_ == nullptr); |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 SignalStrategy::State XmppSignalStrategy::GetState() const { | 147 SignalStrategy::State XmppSignalStrategy::GetState() const { |
148 DCHECK(CalledOnValidThread()); | 148 DCHECK(CalledOnValidThread()); |
149 return state_; | 149 return state_; |
150 } | 150 } |
151 | 151 |
152 SignalStrategy::Error XmppSignalStrategy::GetError() const { | 152 SignalStrategy::Error XmppSignalStrategy::GetError() const { |
153 DCHECK(CalledOnValidThread()); | 153 DCHECK(CalledOnValidThread()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 // what Id we return. | 188 // what Id we return. |
189 return std::string(); | 189 return std::string(); |
190 } | 190 } |
191 return xmpp_client_->NextId(); | 191 return xmpp_client_->NextId(); |
192 } | 192 } |
193 | 193 |
194 bool XmppSignalStrategy::HandleStanza(const buzz::XmlElement* stanza) { | 194 bool XmppSignalStrategy::HandleStanza(const buzz::XmlElement* stanza) { |
195 DCHECK(CalledOnValidThread()); | 195 DCHECK(CalledOnValidThread()); |
196 ObserverListBase<Listener>::Iterator it(listeners_); | 196 ObserverListBase<Listener>::Iterator it(listeners_); |
197 Listener* listener; | 197 Listener* listener; |
198 while ((listener = it.GetNext()) != NULL) { | 198 while ((listener = it.GetNext()) != nullptr) { |
199 if (listener->OnSignalStrategyIncomingStanza(stanza)) | 199 if (listener->OnSignalStrategyIncomingStanza(stanza)) |
200 return true; | 200 return true; |
201 } | 201 } |
202 return false; | 202 return false; |
203 } | 203 } |
204 | 204 |
205 void XmppSignalStrategy::SetAuthInfo(const std::string& username, | 205 void XmppSignalStrategy::SetAuthInfo(const std::string& username, |
206 const std::string& auth_token, | 206 const std::string& auth_token, |
207 const std::string& auth_service) { | 207 const std::string& auth_service) { |
208 DCHECK(CalledOnValidThread()); | 208 DCHECK(CalledOnValidThread()); |
(...skipping 20 matching lines...) Expand all Loading... |
229 // Make sure we dump errors to the log. | 229 // Make sure we dump errors to the log. |
230 int subcode; | 230 int subcode; |
231 buzz::XmppEngine::Error error = xmpp_client_->GetError(&subcode); | 231 buzz::XmppEngine::Error error = xmpp_client_->GetError(&subcode); |
232 VLOG(0) << "XMPP connection was closed: error=" << error | 232 VLOG(0) << "XMPP connection was closed: error=" << error |
233 << ", subcode=" << subcode; | 233 << ", subcode=" << subcode; |
234 | 234 |
235 keep_alive_timer_.Stop(); | 235 keep_alive_timer_.Stop(); |
236 | 236 |
237 // Client is destroyed by the TaskRunner after the client is | 237 // Client is destroyed by the TaskRunner after the client is |
238 // closed. Reset the pointer so we don't try to use it later. | 238 // closed. Reset the pointer so we don't try to use it later. |
239 xmpp_client_ = NULL; | 239 xmpp_client_ = nullptr; |
240 | 240 |
241 switch (error) { | 241 switch (error) { |
242 case buzz::XmppEngine::ERROR_UNAUTHORIZED: | 242 case buzz::XmppEngine::ERROR_UNAUTHORIZED: |
243 case buzz::XmppEngine::ERROR_AUTH: | 243 case buzz::XmppEngine::ERROR_AUTH: |
244 case buzz::XmppEngine::ERROR_MISSING_USERNAME: | 244 case buzz::XmppEngine::ERROR_MISSING_USERNAME: |
245 error_ = AUTHENTICATION_FAILED; | 245 error_ = AUTHENTICATION_FAILED; |
246 break; | 246 break; |
247 | 247 |
248 default: | 248 default: |
249 error_ = NETWORK_ERROR; | 249 error_ = NETWORK_ERROR; |
(...skipping 22 matching lines...) Expand all Loading... |
272 std::string mechanism = notifier::kDefaultGaiaAuthMechanism; | 272 std::string mechanism = notifier::kDefaultGaiaAuthMechanism; |
273 if (settings.token_service() == "oauth2") { | 273 if (settings.token_service() == "oauth2") { |
274 mechanism = "X-OAUTH2"; | 274 mechanism = "X-OAUTH2"; |
275 } | 275 } |
276 | 276 |
277 return new notifier::GaiaTokenPreXmppAuth( | 277 return new notifier::GaiaTokenPreXmppAuth( |
278 jid.Str(), settings.auth_token(), settings.token_service(), mechanism); | 278 jid.Str(), settings.auth_token(), settings.token_service(), mechanism); |
279 } | 279 } |
280 | 280 |
281 } // namespace remoting | 281 } // namespace remoting |
OLD | NEW |