OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_COMMUNICATOR_LOGIN_H_ |
| 6 #define CHROME_BROWSER_SYNC_NOTIFIER_COMMUNICATOR_LOGIN_H_ |
| 7 #include <string> |
| 8 |
| 9 #include "chrome/browser/sync/notifier/base/time.h" |
| 10 #include "chrome/browser/sync/notifier/gaia_auth/sigslotrepeater.h" |
| 11 #include "talk/base/proxyinfo.h" |
| 12 #include "talk/base/scoped_ptr.h" |
| 13 #include "talk/base/sigslot.h" |
| 14 #include "talk/xmpp/xmppengine.h" |
| 15 |
| 16 namespace buzz { |
| 17 class CaptchaChallenge; |
| 18 class XmppClient; |
| 19 class XmppEngine; |
| 20 class XmppClientSettings; |
| 21 } // namespace buzz |
| 22 |
| 23 namespace talk_base { |
| 24 class FirewallManager; |
| 25 struct ProxyInfo; |
| 26 class Task; |
| 27 } // namespace talk_base |
| 28 |
| 29 namespace notifier { |
| 30 class AutoReconnect; |
| 31 class ConnectionOptions; |
| 32 class LoginFailure; |
| 33 class LoginSettings; |
| 34 class NetworkStatusDetectorTask; |
| 35 struct ServerInformation; |
| 36 class SingleLoginAttempt; |
| 37 class Timer; |
| 38 |
| 39 // Does the login, keeps it alive (with refreshing cookies |
| 40 // and reattempting login when disconnected), figures out |
| 41 // what actions to take on the various errors that may occur. |
| 42 class Login : public sigslot::has_slots<> { |
| 43 public: |
| 44 // network_status and firewall may be NULL |
| 45 Login(talk_base::Task* parent, |
| 46 const buzz::XmppClientSettings& user_settings, |
| 47 const ConnectionOptions& options, |
| 48 std::string lang, |
| 49 ServerInformation* server_list, |
| 50 int server_count, |
| 51 NetworkStatusDetectorTask* network_status, |
| 52 talk_base::FirewallManager* firewall, |
| 53 bool no_gaia_auth, |
| 54 bool proxy_only, |
| 55 bool previous_login_successful); |
| 56 ~Login(); |
| 57 |
| 58 enum ConnectionState { |
| 59 STATE_CLOSED, |
| 60 // Same as the closed state but indicates that a countdown is happening |
| 61 // for auto-retrying the connection. |
| 62 STATE_RETRYING, |
| 63 STATE_OPENING, |
| 64 STATE_OPENED, |
| 65 }; |
| 66 |
| 67 ConnectionState connection_state() const { |
| 68 return state_; |
| 69 } |
| 70 |
| 71 void StartConnection(); |
| 72 void UseNextConnection(); |
| 73 void UseCurrentConnection(); |
| 74 buzz::XmppClient* xmpp_client(); |
| 75 |
| 76 // Start the auto-reconnect. It may not do the auto-reconnect |
| 77 // if auto-reconnect is turned off. |
| 78 void DoAutoReconnect(); |
| 79 |
| 80 const LoginSettings& login_settings() const { |
| 81 return *(login_settings_.get()); |
| 82 } |
| 83 |
| 84 // Returns the best guess at the host responsible for |
| 85 // the account (which we use to determine if it is |
| 86 // a dasher account or not). |
| 87 // |
| 88 // After login this may return a more accurate answer, |
| 89 // which accounts for open sign-up accounts. |
| 90 const std::string& google_host() const; |
| 91 |
| 92 // Analogous to google_host but for the user account. |
| 93 // ("fred" in "fred@gmail.com") |
| 94 const std::string& google_user() const; |
| 95 |
| 96 // Returns the proxy that is being used to connect (or |
| 97 // the default proxy information if all attempted |
| 98 // connections failed). |
| 99 // |
| 100 // Do not call until StartConnection has been called. |
| 101 const talk_base::ProxyInfo& proxy() const; |
| 102 |
| 103 int seconds_until_reconnect() const; |
| 104 |
| 105 // SignalClientStateChange(ConnectionState new_state); |
| 106 sigslot::signal1<ConnectionState> SignalClientStateChange; |
| 107 |
| 108 sigslot::signal1<const LoginFailure&> SignalLoginFailure; |
| 109 sigslot::repeater2<const char*, int> SignalLogInput; |
| 110 sigslot::repeater2<const char*, int> SignalLogOutput; |
| 111 sigslot::repeater1<bool> SignalIdleChange; |
| 112 |
| 113 // The creator should hook this up to a signal that indicates when the power |
| 114 // is being suspended. |
| 115 sigslot::repeater1<bool> SignalPowerSuspended; |
| 116 |
| 117 private: |
| 118 void OnRedirect(const std::string& redirect_server, int redirect_port); |
| 119 void OnUnexpectedDisconnect(); |
| 120 void OnClientStateChange(buzz::XmppEngine::State state); |
| 121 void OnLoginFailure(const LoginFailure& failure); |
| 122 void OnLogoff(); |
| 123 void OnAutoReconnectTimerChange(); |
| 124 |
| 125 void HandleClientStateChange(ConnectionState new_state); |
| 126 void ResetUnexpectedDisconnect(); |
| 127 |
| 128 void OnNetworkStateDetected(bool was_alive, bool is_alive); |
| 129 void OnDisconnectTimeout(); |
| 130 |
| 131 scoped_ptr<LoginSettings> login_settings_; |
| 132 scoped_ptr<AutoReconnect> auto_reconnect_; |
| 133 SingleLoginAttempt* single_attempt_; |
| 134 bool successful_connection_; |
| 135 talk_base::Task* parent_; |
| 136 |
| 137 ConnectionState state_; |
| 138 |
| 139 // server redirect information |
| 140 time64 redirect_time_ns_; |
| 141 std::string redirect_server_; |
| 142 int redirect_port_; |
| 143 bool unexpected_disconnect_occurred_; |
| 144 Timer* reset_unexpected_timer_; |
| 145 std::string google_host_; |
| 146 std::string google_user_; |
| 147 talk_base::ProxyInfo proxy_info_; |
| 148 |
| 149 Timer* disconnect_timer_; |
| 150 |
| 151 DISALLOW_COPY_AND_ASSIGN(Login); |
| 152 }; |
| 153 } // namespace notifier |
| 154 |
| 155 #endif // CHROME_BROWSER_SYNC_NOTIFIER_COMMUNICATOR_LOGIN_H_ |
OLD | NEW |