| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <cstddef> | 6 #include <cstddef> |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "jingle/notifier/communicator/single_login_attempt.h" | 10 #include "jingle/notifier/communicator/single_login_attempt.h" |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "jingle/notifier/base/const_communicator.h" | 14 #include "jingle/notifier/base/const_communicator.h" |
| 15 #include "jingle/notifier/base/gaia_token_pre_xmpp_auth.h" | 15 #include "jingle/notifier/base/gaia_token_pre_xmpp_auth.h" |
| 16 #include "jingle/notifier/communicator/connection_options.h" | 16 #include "jingle/notifier/communicator/connection_options.h" |
| 17 #include "jingle/notifier/communicator/connection_settings.h" | 17 #include "jingle/notifier/communicator/connection_settings.h" |
| 18 #include "jingle/notifier/communicator/login_settings.h" | 18 #include "jingle/notifier/communicator/login_settings.h" |
| 19 #include "jingle/notifier/listener/xml_element_util.h" | 19 #include "jingle/notifier/listener/xml_element_util.h" |
| 20 #include "net/url_request/url_request_context.h" |
| 21 #include "net/url_request/url_request_context_getter.h" |
| 20 #include "talk/xmllite/xmlelement.h" | 22 #include "talk/xmllite/xmlelement.h" |
| 21 #include "talk/xmpp/xmppclient.h" | 23 #include "talk/xmpp/xmppclient.h" |
| 22 #include "talk/xmpp/xmppclientsettings.h" | 24 #include "talk/xmpp/xmppclientsettings.h" |
| 23 #include "talk/xmpp/constants.h" | 25 #include "talk/xmpp/constants.h" |
| 24 | 26 |
| 25 namespace net { | 27 namespace net { |
| 26 class NetLog; | 28 class NetLog; |
| 27 } // namespace net | 29 } // namespace net |
| 28 | 30 |
| 29 namespace notifier { | 31 namespace notifier { |
| 30 | 32 |
| 31 SingleLoginAttempt::SingleLoginAttempt(LoginSettings* login_settings, | 33 SingleLoginAttempt::SingleLoginAttempt(LoginSettings* login_settings, |
| 32 Delegate* delegate) | 34 Delegate* delegate) |
| 33 : login_settings_(login_settings), | 35 : login_settings_(login_settings), |
| 34 delegate_(delegate), | 36 delegate_(delegate), |
| 35 connection_generator_( | 37 connection_generator_( |
| 36 ALLOW_THIS_IN_INITIALIZER_LIST(this), | 38 ALLOW_THIS_IN_INITIALIZER_LIST(this), |
| 37 login_settings_->host_resolver(), | 39 login_settings_->request_context_getter()->GetURLRequestContext()-> |
| 40 host_resolver(), |
| 38 &login_settings_->connection_options(), | 41 &login_settings_->connection_options(), |
| 39 login_settings_->try_ssltcp_first(), | 42 login_settings_->try_ssltcp_first(), |
| 40 login_settings_->servers()) { | 43 login_settings_->servers()) { |
| 44 // DNS resolution will happen at a lower layer (we are using the socket |
| 45 // pools). |
| 46 connection_generator_.SetShouldResolveDNS(false); |
| 41 connection_generator_.StartGenerating(); | 47 connection_generator_.StartGenerating(); |
| 42 } | 48 } |
| 43 | 49 |
| 44 SingleLoginAttempt::~SingleLoginAttempt() {} | 50 SingleLoginAttempt::~SingleLoginAttempt() {} |
| 45 | 51 |
| 46 void SingleLoginAttempt::OnConnect(base::WeakPtr<talk_base::Task> base_task) { | 52 void SingleLoginAttempt::OnConnect(base::WeakPtr<talk_base::Task> base_task) { |
| 47 delegate_->OnConnect(base_task); | 53 delegate_->OnConnect(base_task); |
| 48 } | 54 } |
| 49 | 55 |
| 50 void SingleLoginAttempt::OnError(buzz::XmppEngine::Error error, int subcode, | 56 void SingleLoginAttempt::OnError(buzz::XmppEngine::Error error, int subcode, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 94 } |
| 89 } | 95 } |
| 90 } | 96 } |
| 91 | 97 |
| 92 // Iterate to the next possible connection (still trying to connect). | 98 // Iterate to the next possible connection (still trying to connect). |
| 93 connection_generator_.UseNextConnection(); | 99 connection_generator_.UseNextConnection(); |
| 94 } | 100 } |
| 95 | 101 |
| 96 void SingleLoginAttempt::OnNewSettings( | 102 void SingleLoginAttempt::OnNewSettings( |
| 97 const ConnectionSettings& connection_settings) { | 103 const ConnectionSettings& connection_settings) { |
| 98 // TODO(akalin): Resolve any unresolved IPs, possibly through a | |
| 99 // proxy, instead of skipping them. | |
| 100 if (connection_settings.server().IsUnresolvedIP()) { | |
| 101 connection_generator_.UseNextConnection(); | |
| 102 return; | |
| 103 } | |
| 104 | |
| 105 buzz::XmppClientSettings client_settings = | 104 buzz::XmppClientSettings client_settings = |
| 106 login_settings_->user_settings(); | 105 login_settings_->user_settings(); |
| 107 // Fill in the rest of the client settings. | 106 // Fill in the rest of the client settings. |
| 108 connection_settings.FillXmppClientSettings(&client_settings); | 107 connection_settings.FillXmppClientSettings(&client_settings); |
| 109 | 108 |
| 110 buzz::Jid jid(client_settings.user(), client_settings.host(), | 109 buzz::Jid jid(client_settings.user(), client_settings.host(), |
| 111 buzz::STR_EMPTY); | 110 buzz::STR_EMPTY); |
| 112 buzz::PreXmppAuth* pre_xmpp_auth = | 111 buzz::PreXmppAuth* pre_xmpp_auth = |
| 113 new GaiaTokenPreXmppAuth( | 112 new GaiaTokenPreXmppAuth( |
| 114 jid.Str(), client_settings.auth_cookie(), | 113 jid.Str(), client_settings.auth_cookie(), |
| 115 client_settings.token_service(), | 114 client_settings.token_service(), |
| 116 login_settings_->auth_mechanism()); | 115 login_settings_->auth_mechanism()); |
| 117 xmpp_connection_.reset( | 116 xmpp_connection_.reset( |
| 118 new XmppConnection(client_settings, login_settings_->cert_verifier(), | 117 new XmppConnection(client_settings, |
| 118 login_settings_->request_context_getter(), |
| 119 this, pre_xmpp_auth)); | 119 this, pre_xmpp_auth)); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void SingleLoginAttempt::OnExhaustedSettings( | 122 void SingleLoginAttempt::OnExhaustedSettings( |
| 123 bool successfully_resolved_dns, | 123 bool successfully_resolved_dns, |
| 124 int first_dns_error) { | 124 int first_dns_error) { |
| 125 if (!successfully_resolved_dns) | 125 if (!successfully_resolved_dns) |
| 126 VLOG(1) << "Could not resolve DNS: " << first_dns_error; | 126 VLOG(1) << "Could not resolve DNS: " << first_dns_error; |
| 127 VLOG(1) << "Could not connect to any XMPP server"; | 127 VLOG(1) << "Could not connect to any XMPP server"; |
| 128 delegate_->OnNeedReconnect(); | 128 delegate_->OnNeedReconnect(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 } // namespace notifier | 131 } // namespace notifier |
| OLD | NEW |