| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "jingle/notifier/communicator/login.h" | 5 #include "jingle/notifier/communicator/login.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "net/base/host_port_pair.h" | 12 #include "net/base/host_port_pair.h" |
| 13 #include "talk/base/common.h" | 13 #include "talk/base/common.h" |
| 14 #include "talk/base/firewallsocketserver.h" | 14 #include "talk/base/firewallsocketserver.h" |
| 15 #include "talk/base/logging.h" | 15 #include "talk/base/logging.h" |
| 16 #include "talk/base/physicalsocketserver.h" | 16 #include "talk/base/physicalsocketserver.h" |
| 17 #include "talk/base/taskrunner.h" | 17 #include "talk/base/taskrunner.h" |
| 18 #include "talk/xmllite/xmlelement.h" | 18 #include "talk/xmllite/xmlelement.h" |
| 19 #include "talk/xmpp/asyncsocket.h" | 19 #include "talk/xmpp/asyncsocket.h" |
| 20 #include "talk/xmpp/prexmppauth.h" | 20 #include "talk/xmpp/prexmppauth.h" |
| 21 #include "talk/xmpp/xmppclient.h" | 21 #include "talk/xmpp/xmppclient.h" |
| 22 #include "talk/xmpp/xmppclientsettings.h" | 22 #include "talk/xmpp/xmppclientsettings.h" |
| 23 #include "talk/xmpp/xmppengine.h" | 23 #include "talk/xmpp/xmppengine.h" |
| 24 | 24 |
| 25 namespace notifier { | 25 namespace notifier { |
| 26 | 26 |
| 27 // Redirect valid for 5 minutes. | 27 // Redirect valid for 5 minutes. |
| 28 static const int kRedirectTimeoutMinutes = 5; | 28 static const int kRedirectTimeoutMinutes = 5; |
| 29 | 29 |
| 30 Login::Delegate::~Delegate() {} |
| 31 |
| 30 Login::Login(Delegate* delegate, | 32 Login::Login(Delegate* delegate, |
| 31 const buzz::XmppClientSettings& user_settings, | 33 const buzz::XmppClientSettings& user_settings, |
| 32 const scoped_refptr<net::URLRequestContextGetter>& | 34 const scoped_refptr<net::URLRequestContextGetter>& |
| 33 request_context_getter, | 35 request_context_getter, |
| 34 const ServerList& servers, | 36 const ServerList& servers, |
| 35 bool try_ssltcp_first, | 37 bool try_ssltcp_first, |
| 36 const std::string& auth_mechanism) | 38 const std::string& auth_mechanism) |
| 37 : delegate_(delegate), | 39 : delegate_(delegate), |
| 38 login_settings_(user_settings, | 40 login_settings_(user_settings, |
| 39 request_context_getter, | 41 request_context_getter, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 65 void Login::OnNeedReconnect() { | 67 void Login::OnNeedReconnect() { |
| 66 TryReconnect(); | 68 TryReconnect(); |
| 67 } | 69 } |
| 68 | 70 |
| 69 void Login::OnRedirect(const ServerInformation& redirect_server) { | 71 void Login::OnRedirect(const ServerInformation& redirect_server) { |
| 70 login_settings_.SetRedirectServer(redirect_server); | 72 login_settings_.SetRedirectServer(redirect_server); |
| 71 // Drop the current connection, and start the login process again. | 73 // Drop the current connection, and start the login process again. |
| 72 StartConnection(); | 74 StartConnection(); |
| 73 } | 75 } |
| 74 | 76 |
| 77 void Login::OnRejectedCredentials() { |
| 78 delegate_->OnRejectedCredentials(); |
| 79 single_attempt_.reset(); |
| 80 reconnect_timer_.Stop(); |
| 81 } |
| 82 |
| 75 void Login::OnIPAddressChanged() { | 83 void Login::OnIPAddressChanged() { |
| 76 VLOG(1) << "Detected IP address change"; | 84 VLOG(1) << "Detected IP address change"; |
| 77 // Reconnect in 1 to 9 seconds (vary the time a little to try to | 85 // Reconnect in 1 to 9 seconds (vary the time a little to try to |
| 78 // avoid spikey behavior on network hiccups). | 86 // avoid spikey behavior on network hiccups). |
| 79 reconnect_interval_ = base::TimeDelta::FromSeconds(base::RandInt(1, 9)); | 87 reconnect_interval_ = base::TimeDelta::FromSeconds(base::RandInt(1, 9)); |
| 80 TryReconnect(); | 88 TryReconnect(); |
| 81 } | 89 } |
| 82 | 90 |
| 83 void Login::ResetReconnectState() { | 91 void Login::ResetReconnectState() { |
| 84 reconnect_interval_ = | 92 reconnect_interval_ = |
| (...skipping 17 matching lines...) Expand all Loading... |
| 102 const base::TimeDelta kMaxReconnectInterval = | 110 const base::TimeDelta kMaxReconnectInterval = |
| 103 base::TimeDelta::FromMinutes(30); | 111 base::TimeDelta::FromMinutes(30); |
| 104 reconnect_interval_ *= 2; | 112 reconnect_interval_ *= 2; |
| 105 if (reconnect_interval_ > kMaxReconnectInterval) | 113 if (reconnect_interval_ > kMaxReconnectInterval) |
| 106 reconnect_interval_ = kMaxReconnectInterval; | 114 reconnect_interval_ = kMaxReconnectInterval; |
| 107 VLOG(1) << "Reconnecting..."; | 115 VLOG(1) << "Reconnecting..."; |
| 108 StartConnection(); | 116 StartConnection(); |
| 109 } | 117 } |
| 110 | 118 |
| 111 } // namespace notifier | 119 } // namespace notifier |
| OLD | NEW |