| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "chrome/common/net/notifier/communicator/login.h" | 7 #include "chrome/common/net/notifier/communicator/login.h" |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "chrome/common/net/notifier/communicator/auto_reconnect.h" | 11 #include "chrome/common/net/notifier/communicator/auto_reconnect.h" |
| 12 #include "chrome/common/net/notifier/communicator/connection_options.h" | 12 #include "chrome/common/net/notifier/communicator/connection_options.h" |
| 13 #include "chrome/common/net/notifier/communicator/login_settings.h" | 13 #include "chrome/common/net/notifier/communicator/login_settings.h" |
| 14 #include "chrome/common/net/notifier/communicator/product_info.h" | 14 #include "chrome/common/net/notifier/communicator/product_info.h" |
| 15 #include "chrome/common/net/notifier/communicator/single_login_attempt.h" | 15 #include "chrome/common/net/notifier/communicator/single_login_attempt.h" |
| 16 #include "net/base/host_port_pair.h" | 16 #include "net/base/host_port_pair.h" |
| 17 #include "net/base/network_change_notifier.h" | |
| 18 #include "talk/base/common.h" | 17 #include "talk/base/common.h" |
| 19 #include "talk/base/firewallsocketserver.h" | 18 #include "talk/base/firewallsocketserver.h" |
| 20 #include "talk/base/logging.h" | 19 #include "talk/base/logging.h" |
| 21 #include "talk/base/physicalsocketserver.h" | 20 #include "talk/base/physicalsocketserver.h" |
| 22 #include "talk/base/taskrunner.h" | 21 #include "talk/base/taskrunner.h" |
| 23 #include "talk/xmllite/xmlelement.h" | 22 #include "talk/xmllite/xmlelement.h" |
| 24 #include "talk/xmpp/asyncsocket.h" | 23 #include "talk/xmpp/asyncsocket.h" |
| 25 #include "talk/xmpp/prexmppauth.h" | 24 #include "talk/xmpp/prexmppauth.h" |
| 26 #include "talk/xmpp/xmppclient.h" | 25 #include "talk/xmpp/xmppclient.h" |
| 27 #include "talk/xmpp/xmppclientsettings.h" | 26 #include "talk/xmpp/xmppclientsettings.h" |
| 28 #include "talk/xmpp/xmppengine.h" | 27 #include "talk/xmpp/xmppengine.h" |
| 29 | 28 |
| 30 namespace notifier { | 29 namespace notifier { |
| 31 | 30 |
| 32 // Redirect valid for 5 minutes. | 31 // Redirect valid for 5 minutes. |
| 33 static const int kRedirectTimeoutMinutes = 5; | 32 static const int kRedirectTimeoutMinutes = 5; |
| 34 | 33 |
| 35 // Disconnect if network stays down for more than 10 seconds. | 34 // Disconnect if network stays down for more than 10 seconds. |
| 36 static const int kDisconnectionDelaySecs = 10; | 35 static const int kDisconnectionDelaySecs = 10; |
| 37 | 36 |
| 38 Login::Login(talk_base::TaskParent* parent, | 37 Login::Login(talk_base::TaskParent* parent, |
| 39 const buzz::XmppClientSettings& user_settings, | 38 const buzz::XmppClientSettings& user_settings, |
| 40 const ConnectionOptions& options, | 39 const ConnectionOptions& options, |
| 41 std::string lang, | 40 std::string lang, |
| 42 net::HostResolver* host_resolver, | 41 net::HostResolver* host_resolver, |
| 43 ServerInformation* server_list, | 42 ServerInformation* server_list, |
| 44 int server_count, | 43 int server_count, |
| 45 net::NetworkChangeNotifier* network_change_notifier, | |
| 46 talk_base::FirewallManager* firewall, | 44 talk_base::FirewallManager* firewall, |
| 47 bool proxy_only, | 45 bool proxy_only, |
| 48 bool previous_login_successful) | 46 bool previous_login_successful) |
| 49 : parent_(parent), | 47 : parent_(parent), |
| 50 login_settings_(new LoginSettings(user_settings, | 48 login_settings_(new LoginSettings(user_settings, |
| 51 options, | 49 options, |
| 52 lang, | 50 lang, |
| 53 host_resolver, | 51 host_resolver, |
| 54 server_list, | 52 server_list, |
| 55 server_count, | 53 server_count, |
| 56 firewall, | 54 firewall, |
| 57 proxy_only)), | 55 proxy_only)), |
| 58 network_change_notifier_(network_change_notifier), | |
| 59 single_attempt_(NULL), | 56 single_attempt_(NULL), |
| 60 successful_connection_(previous_login_successful), | 57 successful_connection_(previous_login_successful), |
| 61 state_(STATE_OPENING), | 58 state_(STATE_OPENING), |
| 62 redirect_port_(0), | 59 redirect_port_(0), |
| 63 unexpected_disconnect_occurred_(false), | 60 unexpected_disconnect_occurred_(false), |
| 64 google_host_(user_settings.host()), | 61 google_host_(user_settings.host()), |
| 65 google_user_(user_settings.user()) { | 62 google_user_(user_settings.user()) { |
| 66 DCHECK(network_change_notifier_); | |
| 67 // Hook up all the signals and observers. | 63 // Hook up all the signals and observers. |
| 68 network_change_notifier_->AddObserver(this); | 64 net::NetworkChangeNotifier::AddObserver(this); |
| 69 auto_reconnect_.SignalStartConnection.connect(this, | 65 auto_reconnect_.SignalStartConnection.connect(this, |
| 70 &Login::StartConnection); | 66 &Login::StartConnection); |
| 71 auto_reconnect_.SignalTimerStartStop.connect( | 67 auto_reconnect_.SignalTimerStartStop.connect( |
| 72 this, | 68 this, |
| 73 &Login::OnAutoReconnectTimerChange); | 69 &Login::OnAutoReconnectTimerChange); |
| 74 SignalClientStateChange.connect(&auto_reconnect_, | 70 SignalClientStateChange.connect(&auto_reconnect_, |
| 75 &AutoReconnect::OnClientStateChange); | 71 &AutoReconnect::OnClientStateChange); |
| 76 SignalIdleChange.connect(&auto_reconnect_, | 72 SignalIdleChange.connect(&auto_reconnect_, |
| 77 &AutoReconnect::set_idle); | 73 &AutoReconnect::set_idle); |
| 78 SignalPowerSuspended.connect(&auto_reconnect_, | 74 SignalPowerSuspended.connect(&auto_reconnect_, |
| 79 &AutoReconnect::OnPowerSuspend); | 75 &AutoReconnect::OnPowerSuspend); |
| 80 | 76 |
| 81 // Then check the initial state of the connection. | 77 // Then check the initial state of the connection. |
| 82 CheckConnection(); | 78 CheckConnection(); |
| 83 } | 79 } |
| 84 | 80 |
| 85 // Defined so that the destructors are executed here (and the corresponding | 81 // Defined so that the destructors are executed here (and the corresponding |
| 86 // classes don't need to be included in the header file). | 82 // classes don't need to be included in the header file). |
| 87 Login::~Login() { | 83 Login::~Login() { |
| 88 if (single_attempt_) { | 84 if (single_attempt_) { |
| 89 single_attempt_->Abort(); | 85 single_attempt_->Abort(); |
| 90 single_attempt_ = NULL; | 86 single_attempt_ = NULL; |
| 91 } | 87 } |
| 92 network_change_notifier_->RemoveObserver(this); | 88 net::NetworkChangeNotifier::RemoveObserver(this); |
| 93 } | 89 } |
| 94 | 90 |
| 95 void Login::StartConnection() { | 91 void Login::StartConnection() { |
| 96 // If there is a server redirect, use it. | 92 // If there is a server redirect, use it. |
| 97 if (base::Time::Now() < | 93 if (base::Time::Now() < |
| 98 (redirect_time_ + | 94 (redirect_time_ + |
| 99 base::TimeDelta::FromMinutes(kRedirectTimeoutMinutes))) { | 95 base::TimeDelta::FromMinutes(kRedirectTimeoutMinutes))) { |
| 100 // Override server/port with redirect values. | 96 // Override server/port with redirect values. |
| 101 DCHECK_NE(redirect_port_, 0); | 97 DCHECK_NE(redirect_port_, 0); |
| 102 net::HostPortPair server_override(redirect_server_, redirect_port_); | 98 net::HostPortPair server_override(redirect_server_, redirect_port_); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 335 |
| 340 if (single_attempt_) { | 336 if (single_attempt_) { |
| 341 single_attempt_->Abort(); | 337 single_attempt_->Abort(); |
| 342 single_attempt_ = NULL; | 338 single_attempt_ = NULL; |
| 343 } | 339 } |
| 344 | 340 |
| 345 StartConnection(); | 341 StartConnection(); |
| 346 } | 342 } |
| 347 | 343 |
| 348 } // namespace notifier | 344 } // namespace notifier |
| OLD | NEW |