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_SINGLE_LOGIN_ATTEMPT_H_ |
| 6 #define CHROME_BROWSER_SYNC_NOTIFIER_COMMUNICATOR_SINGLE_LOGIN_ATTEMPT_H_ |
| 7 #include <string> |
| 8 |
| 9 #include "chrome/browser/sync/notifier/communicator/login.h" |
| 10 #include "talk/base/scoped_ptr.h" |
| 11 #include "talk/base/sigslot.h" |
| 12 #include "talk/base/task.h" |
| 13 #include "talk/xmpp/xmppengine.h" |
| 14 |
| 15 namespace buzz { |
| 16 class AsyncSocket; |
| 17 class CaptchaChallenge; |
| 18 class PreXmppAuth; |
| 19 class XmppClient; |
| 20 class XmppClientSettings; |
| 21 class XmppClientSettings; |
| 22 } |
| 23 |
| 24 namespace talk_base { |
| 25 class FirewallManager; |
| 26 struct ProxyInfo; |
| 27 class SignalThread; |
| 28 class Task; |
| 29 } |
| 30 |
| 31 namespace notifier { |
| 32 class ConnectionSettings; |
| 33 class LoginFailure; |
| 34 class LoginSettings; |
| 35 struct ServerInformation; |
| 36 class XmppConnectionGenerator; |
| 37 |
| 38 // Handles all of the aspects of a single login attempt |
| 39 // (across multiple ip addresses) and maintainence. By containing |
| 40 // this within one class, when another login attempt is made, |
| 41 // this class will be disposed and all of the signalling for the |
| 42 // previous login attempt will be cleaned up immediately. |
| 43 // |
| 44 // This is a task to allow for cleaning this up when a signal |
| 45 // is being fired. Technically, delete this during the firing of |
| 46 // a signal could work but it is fragile. |
| 47 class SingleLoginAttempt : public talk_base::Task, public sigslot::has_slots<> { |
| 48 public: |
| 49 SingleLoginAttempt(talk_base::Task* parent, |
| 50 LoginSettings* login_settings, |
| 51 bool successful_connection); |
| 52 ~SingleLoginAttempt(); |
| 53 virtual int ProcessStart(); |
| 54 void UseNextConnection(); |
| 55 void UseCurrentConnection(); |
| 56 |
| 57 buzz::XmppClient* xmpp_client() { |
| 58 return client_; |
| 59 } |
| 60 |
| 61 // Returns the proxy that is being used to connect (or |
| 62 // the default proxy information if all attempted |
| 63 // connections failed). |
| 64 const talk_base::ProxyInfo& proxy() const; |
| 65 |
| 66 // Typically handled by creating a new SingleLoginAttempt |
| 67 // and doing StartConnection |
| 68 sigslot::signal0<> SignalUnexpectedDisconnect; |
| 69 |
| 70 // Typically handled by setting storing the redirect for 5 seconds, |
| 71 // and setting it into LoginSettings, then creating a new SingleLoginAttempt, |
| 72 // and doing StartConnection. |
| 73 // |
| 74 // SignalRedirect(const std::string& redirect_server, int redirect_port); |
| 75 sigslot::signal2<const std::string&, int> SignalRedirect; |
| 76 |
| 77 sigslot::signal0<> SignalNeedAutoReconnect; |
| 78 |
| 79 // SignalClientStateChange(buzz::XmppEngine::State new_state); |
| 80 sigslot::signal1<buzz::XmppEngine::State> SignalClientStateChange; |
| 81 |
| 82 // See the LoginFailure for how to handle this. |
| 83 sigslot::signal1<const LoginFailure&> SignalLoginFailure; |
| 84 |
| 85 // Sent when there is a graceful log-off (state goes to closed |
| 86 // with no error) |
| 87 sigslot::signal0<> SignalLogoff; |
| 88 |
| 89 sigslot::repeater2<const char*, int> SignalLogInput; |
| 90 sigslot::repeater2<const char*, int> SignalLogOutput; |
| 91 |
| 92 protected: |
| 93 virtual void Stop(); |
| 94 |
| 95 private: |
| 96 void DoLogin(const ConnectionSettings& connection_settings); |
| 97 buzz::AsyncSocket* CreateSocket(const buzz::XmppClientSettings& xcs); |
| 98 buzz::PreXmppAuth* CreatePreXmppAuth(const buzz::XmppClientSettings& xcs); |
| 99 |
| 100 // cleans up any xmpp client state to get ready for a new one |
| 101 void ClearClient(); |
| 102 |
| 103 void HandleConnectionError( |
| 104 buzz::XmppEngine::Error code, |
| 105 int subcode, |
| 106 const buzz::XmlElement* stream_error, |
| 107 const buzz::CaptchaChallenge& captcha_challenge); |
| 108 void HandleConnectionPasswordError( |
| 109 const buzz::CaptchaChallenge& captcha_challenge); |
| 110 |
| 111 void DiagnoseConnectionError(); |
| 112 void OnHttpTestDone(talk_base::SignalThread* thread); |
| 113 |
| 114 void OnAuthenticationError(); |
| 115 void OnCertificateExpired(); |
| 116 void OnFreshAuthCookie(const std::string& auth_cookie); |
| 117 void OnClientStateChange(buzz::XmppEngine::State state); |
| 118 void OnClientStateChangeClosed(buzz::XmppEngine::State previous_state); |
| 119 void OnAttemptedAllConnections(bool successfully_resolved_dns, |
| 120 int first_dns_error); |
| 121 |
| 122 bool auto_reconnect() const; |
| 123 |
| 124 buzz::XmppEngine::State state_; |
| 125 buzz::XmppEngine::Error code_; |
| 126 int subcode_; |
| 127 bool need_authentication_; |
| 128 bool certificate_expired_; |
| 129 bool cookie_refreshed_; |
| 130 bool successful_connection_; |
| 131 LoginSettings* login_settings_; |
| 132 buzz::XmppClient* client_; |
| 133 scoped_ptr<XmppConnectionGenerator> connection_generator_; |
| 134 |
| 135 DISALLOW_COPY_AND_ASSIGN(SingleLoginAttempt); |
| 136 }; |
| 137 } // namespace notifier |
| 138 |
| 139 #endif // CHROME_BROWSER_SYNC_NOTIFIER_COMMUNICATOR_SINGLE_LOGIN_ATTEMPT_H_ |
OLD | NEW |