| OLD | NEW |
| 1 // Copyright (c) 2010 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 #ifndef JINGLE_NOTIFIER_COMMUNICATOR_LOGIN_H_ | 5 #ifndef JINGLE_NOTIFIER_COMMUNICATOR_LOGIN_H_ |
| 6 #define JINGLE_NOTIFIER_COMMUNICATOR_LOGIN_H_ | 6 #define JINGLE_NOTIFIER_COMMUNICATOR_LOGIN_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "base/timer.h" | 12 #include "base/timer.h" |
| 13 #include "base/weak_ptr.h" | 13 #include "base/weak_ptr.h" |
| 14 #include "jingle/notifier/communicator/single_login_attempt.h" |
| 14 #include "net/base/network_change_notifier.h" | 15 #include "net/base/network_change_notifier.h" |
| 15 #include "talk/base/proxyinfo.h" | |
| 16 #include "talk/base/sigslot.h" | |
| 17 #include "talk/xmpp/xmppengine.h" | 16 #include "talk/xmpp/xmppengine.h" |
| 18 | 17 |
| 19 namespace buzz { | 18 namespace buzz { |
| 20 class XmppClient; | 19 class XmppClient; |
| 21 class XmppEngine; | 20 class XmppEngine; |
| 22 class XmppClientSettings; | 21 class XmppClientSettings; |
| 23 } // namespace buzz | 22 } // namespace buzz |
| 24 | 23 |
| 25 namespace net { | 24 namespace net { |
| 26 class HostResolver; | 25 class HostResolver; |
| 27 } // namespace net | 26 } // namespace net |
| 28 | 27 |
| 29 namespace talk_base { | 28 namespace talk_base { |
| 30 class Task; | 29 class Task; |
| 31 class TaskParent; | 30 class TaskParent; |
| 32 } // namespace talk_base | 31 } // namespace talk_base |
| 33 | 32 |
| 34 namespace notifier { | 33 namespace notifier { |
| 35 | 34 |
| 36 class ConnectionOptions; | 35 class ConnectionOptions; |
| 37 class LoginSettings; | 36 class LoginSettings; |
| 38 struct ServerInformation; | 37 struct ServerInformation; |
| 39 class SingleLoginAttempt; | |
| 40 | 38 |
| 41 // Does the login, keeps it alive (with refreshing cookies and reattempting | 39 // Does the login, keeps it alive (with refreshing cookies and reattempting |
| 42 // login when disconnected), figures out what actions to take on the various | 40 // login when disconnected), figures out what actions to take on the various |
| 43 // errors that may occur. | 41 // errors that may occur. |
| 44 class Login : public net::NetworkChangeNotifier::Observer, | 42 class Login : public net::NetworkChangeNotifier::Observer, |
| 45 public sigslot::has_slots<> { | 43 public SingleLoginAttempt::Delegate { |
| 46 public: | 44 public: |
| 47 // firewall may be NULL. | 45 class Delegate { |
| 48 Login(const buzz::XmppClientSettings& user_settings, | 46 public: |
| 47 virtual ~Delegate() {} |
| 48 |
| 49 virtual void OnConnect(base::WeakPtr<talk_base::Task> base_task) = 0; |
| 50 virtual void OnDisconnect() = 0; |
| 51 }; |
| 52 |
| 53 // Does not take ownership of |delegate|, |host_resolver|, or |
| 54 // |server_list|, none of which may be NULL. |
| 55 Login(Delegate* delegate, |
| 56 const buzz::XmppClientSettings& user_settings, |
| 49 const ConnectionOptions& options, | 57 const ConnectionOptions& options, |
| 50 net::HostResolver* host_resolver, | 58 net::HostResolver* host_resolver, |
| 51 ServerInformation* server_list, | 59 ServerInformation* server_list, |
| 52 int server_count, | 60 int server_count, |
| 53 bool try_ssltcp_first); | 61 bool try_ssltcp_first); |
| 54 virtual ~Login(); | 62 virtual ~Login(); |
| 55 | 63 |
| 56 void StartConnection(); | 64 void StartConnection(); |
| 57 | 65 |
| 58 // net::NetworkChangeNotifier::Observer implementation. | 66 // net::NetworkChangeNotifier::Observer implementation. |
| 59 virtual void OnIPAddressChanged(); | 67 virtual void OnIPAddressChanged(); |
| 60 | 68 |
| 61 sigslot::signal1<base::WeakPtr<talk_base::Task> > SignalConnect; | 69 // SingleLoginAttempt::Delegate implementation. |
| 62 sigslot::signal0<> SignalDisconnect; | 70 virtual void OnConnect(base::WeakPtr<talk_base::Task> base_task); |
| 71 virtual void OnNeedReconnect(); |
| 72 virtual void OnRedirect(const std::string& redirect_server, |
| 73 int redirect_port); |
| 63 | 74 |
| 64 private: | 75 private: |
| 65 void OnLogoff(); | 76 void OnLogoff(); |
| 66 void OnRedirect(const std::string& redirect_server, int redirect_port); | |
| 67 void OnConnect(base::WeakPtr<talk_base::Task> parent); | |
| 68 | 77 |
| 69 // Stops any existing reconnect timer and sets an initial reconnect | 78 // Stops any existing reconnect timer and sets an initial reconnect |
| 70 // interval. | 79 // interval. |
| 71 void ResetReconnectState(); | 80 void ResetReconnectState(); |
| 72 | 81 |
| 73 // Tries to reconnect in some point in the future. If called | 82 // Tries to reconnect in some point in the future. If called |
| 74 // repeatedly, will wait longer and longer until reconnecting. | 83 // repeatedly, will wait longer and longer until reconnecting. |
| 75 void TryReconnect(); | 84 void TryReconnect(); |
| 76 | 85 |
| 77 // The actual function (called by |reconnect_timer_|) that does the | 86 // The actual function (called by |reconnect_timer_|) that does the |
| 78 // reconnection. | 87 // reconnection. |
| 79 void DoReconnect(); | 88 void DoReconnect(); |
| 80 | 89 |
| 81 talk_base::TaskParent* parent_; | 90 Delegate* delegate_; |
| 82 scoped_ptr<LoginSettings> login_settings_; | 91 scoped_ptr<LoginSettings> login_settings_; |
| 83 scoped_ptr<SingleLoginAttempt> single_attempt_; | 92 scoped_ptr<SingleLoginAttempt> single_attempt_; |
| 84 | 93 |
| 85 // reconnection state. | 94 // reconnection state. |
| 86 base::TimeDelta reconnect_interval_; | 95 base::TimeDelta reconnect_interval_; |
| 87 base::OneShotTimer<Login> reconnect_timer_; | 96 base::OneShotTimer<Login> reconnect_timer_; |
| 88 | 97 |
| 89 // server redirect information | 98 // server redirect information |
| 90 base::Time redirect_time_; | 99 base::Time redirect_time_; |
| 91 std::string redirect_server_; | 100 std::string redirect_server_; |
| 92 int redirect_port_; | 101 int redirect_port_; |
| 93 | 102 |
| 94 DISALLOW_COPY_AND_ASSIGN(Login); | 103 DISALLOW_COPY_AND_ASSIGN(Login); |
| 95 }; | 104 }; |
| 96 | 105 |
| 97 } // namespace notifier | 106 } // namespace notifier |
| 98 | 107 |
| 99 #endif // JINGLE_NOTIFIER_COMMUNICATOR_LOGIN_H_ | 108 #endif // JINGLE_NOTIFIER_COMMUNICATOR_LOGIN_H_ |
| OLD | NEW |