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 | |
8 #include <string> | |
9 | |
10 #include "chrome/browser/sync/notifier/base/sigslotrepeater.h" | |
11 #include "chrome/browser/sync/notifier/base/time.h" | |
12 #include "talk/base/proxyinfo.h" | |
13 #include "talk/base/scoped_ptr.h" | |
14 #include "talk/base/sigslot.h" | |
15 #include "talk/xmpp/xmppengine.h" | |
16 | |
17 namespace buzz { | |
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 | |
31 class AutoReconnect; | |
32 class ConnectionOptions; | |
33 class LoginFailure; | |
34 class LoginSettings; | |
35 class NetworkStatusDetectorTask; | |
36 struct ServerInformation; | |
37 class SingleLoginAttempt; | |
38 class Timer; | |
39 | |
40 // Does the login, keeps it alive (with refreshing cookies and reattempting | |
41 // login when disconnected), figures out what actions to take on the various | |
42 // errors that may occur. | |
43 class Login : public sigslot::has_slots<> { | |
44 public: | |
45 // network_status and firewall may be NULL. | |
46 Login(talk_base::Task* parent, | |
47 const buzz::XmppClientSettings& user_settings, | |
48 const ConnectionOptions& options, | |
49 std::string lang, | |
50 ServerInformation* server_list, | |
51 int server_count, | |
52 NetworkStatusDetectorTask* network_status, | |
53 talk_base::FirewallManager* firewall, | |
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 for | |
61 // 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 if | |
77 // 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 the account (which we | |
85 // use to determine if it is a dasher account or not). | |
86 // | |
87 // After login this may return a more accurate answer, which accounts for | |
88 // open sign-up accounts. | |
89 const std::string& google_host() const; | |
90 | |
91 // Analogous to google_host but for the user account ("fred" in | |
92 // "fred@gmail.com"). | |
93 const std::string& google_user() const; | |
94 | |
95 // Returns the proxy that is being used to connect (or the default proxy | |
96 // information if all attempted connections failed). | |
97 // | |
98 // Do not call until StartConnection has been called. | |
99 const talk_base::ProxyInfo& proxy() const; | |
100 | |
101 int seconds_until_reconnect() const; | |
102 | |
103 // SignalClientStateChange(ConnectionState new_state); | |
104 sigslot::signal1<ConnectionState> SignalClientStateChange; | |
105 | |
106 sigslot::signal1<const LoginFailure&> SignalLoginFailure; | |
107 sigslot::repeater2<const char*, int> SignalLogInput; | |
108 sigslot::repeater2<const char*, int> SignalLogOutput; | |
109 sigslot::repeater1<bool> SignalIdleChange; | |
110 | |
111 // The creator should hook this up to a signal that indicates when the power | |
112 // is being suspended. | |
113 sigslot::repeater1<bool> SignalPowerSuspended; | |
114 | |
115 private: | |
116 void OnRedirect(const std::string& redirect_server, int redirect_port); | |
117 void OnUnexpectedDisconnect(); | |
118 void OnClientStateChange(buzz::XmppEngine::State state); | |
119 void OnLoginFailure(const LoginFailure& failure); | |
120 void OnLogoff(); | |
121 void OnAutoReconnectTimerChange(); | |
122 | |
123 void HandleClientStateChange(ConnectionState new_state); | |
124 void ResetUnexpectedDisconnect(); | |
125 | |
126 void OnNetworkStateDetected(bool was_alive, bool is_alive); | |
127 void OnDisconnectTimeout(); | |
128 | |
129 scoped_ptr<LoginSettings> login_settings_; | |
130 scoped_ptr<AutoReconnect> auto_reconnect_; | |
131 SingleLoginAttempt* single_attempt_; | |
132 bool successful_connection_; | |
133 talk_base::Task* parent_; | |
134 | |
135 ConnectionState state_; | |
136 | |
137 // server redirect information | |
138 time64 redirect_time_ns_; | |
139 std::string redirect_server_; | |
140 int redirect_port_; | |
141 bool unexpected_disconnect_occurred_; | |
142 Timer* reset_unexpected_timer_; | |
143 std::string google_host_; | |
144 std::string google_user_; | |
145 talk_base::ProxyInfo proxy_info_; | |
146 | |
147 Timer* disconnect_timer_; | |
148 | |
149 DISALLOW_COPY_AND_ASSIGN(Login); | |
150 }; | |
151 | |
152 } // namespace notifier | |
153 | |
154 #endif // CHROME_BROWSER_SYNC_NOTIFIER_COMMUNICATOR_LOGIN_H_ | |
OLD | NEW |