OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 } // namespace buzz | 26 } // namespace buzz |
27 | 27 |
28 namespace net { | 28 namespace net { |
29 class URLRequestContextGetter; | 29 class URLRequestContextGetter; |
30 } // namespace net | 30 } // namespace net |
31 | 31 |
32 namespace notifier { | 32 namespace notifier { |
33 | 33 |
34 class LoginSettings; | 34 class LoginSettings; |
35 | 35 |
36 // Workaround for MSVS 2005 bug that fails to handle inheritance from a nested | 36 // Does the login, keeps it alive (with refreshing cookies and |
37 // class properly if it comes directly on a base class list. | 37 // reattempting login when disconnected), and figures out what actions |
38 typedef SingleLoginAttempt::Delegate SingleLoginAttemptDelegate; | 38 // to take on the various errors that may occur. |
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 net::NetworkChangeNotifier::IPAddressObserver, | 39 class Login : public net::NetworkChangeNotifier::IPAddressObserver, |
44 public SingleLoginAttemptDelegate { | 40 public SingleLoginAttempt::Delegate { |
45 public: | 41 public: |
46 class Delegate { | 42 class Delegate { |
47 public: | 43 public: |
| 44 // Called when a connection has been successfully established. |
48 virtual void OnConnect( | 45 virtual void OnConnect( |
49 base::WeakPtr<buzz::XmppTaskParentInterface> base_task) = 0; | 46 base::WeakPtr<buzz::XmppTaskParentInterface> base_task) = 0; |
50 virtual void OnDisconnect() = 0; | 47 |
| 48 // Called when there's no connection to the server but we expect |
| 49 // it to come back come back eventually. The connection will be |
| 50 // retried with exponential backoff. |
| 51 virtual void OnTransientDisconnection() = 0; |
| 52 |
| 53 // Called when the current login credentials have been rejected. |
| 54 // The connection will still be retried with exponential backoff; |
| 55 // it's up to the delegate to stop connecting and/or prompt for |
| 56 // new credentials. |
| 57 virtual void OnCredentialsRejected() = 0; |
51 | 58 |
52 protected: | 59 protected: |
53 virtual ~Delegate() {} | 60 virtual ~Delegate(); |
54 }; | 61 }; |
55 | 62 |
56 // Does not take ownership of |delegate|, which must not be NULL. | 63 // Does not take ownership of |delegate|, which must not be NULL. |
57 Login(Delegate* delegate, | 64 Login(Delegate* delegate, |
58 const buzz::XmppClientSettings& user_settings, | 65 const buzz::XmppClientSettings& user_settings, |
59 const scoped_refptr<net::URLRequestContextGetter>& | 66 const scoped_refptr<net::URLRequestContextGetter>& |
60 request_context_getter, | 67 request_context_getter, |
61 const ServerList& servers, | 68 const ServerList& servers, |
62 bool try_ssltcp_first, | 69 bool try_ssltcp_first, |
63 const std::string& auth_mechanism); | 70 const std::string& auth_mechanism); |
64 virtual ~Login(); | 71 virtual ~Login(); |
65 | 72 |
| 73 // Starts connecting (or forces a reconnection if we're backed off). |
66 void StartConnection(); | 74 void StartConnection(); |
67 // The updated settings only take effect the next time StartConnection | 75 |
68 // is called. | 76 // The updated settings take effect only the next time when a |
| 77 // connection is attempted (either via reconnection or a call to |
| 78 // StartConnection()). |
69 void UpdateXmppSettings(const buzz::XmppClientSettings& user_settings); | 79 void UpdateXmppSettings(const buzz::XmppClientSettings& user_settings); |
70 | 80 |
71 // net::NetworkChangeNotifier::IPAddressObserver implementation. | 81 // net::NetworkChangeNotifier::IPAddressObserver implementation. |
72 virtual void OnIPAddressChanged() OVERRIDE; | 82 virtual void OnIPAddressChanged() OVERRIDE; |
73 | 83 |
74 // SingleLoginAttempt::Delegate implementation. | 84 // SingleLoginAttempt::Delegate implementation. |
75 virtual void OnConnect( | 85 virtual void OnConnect( |
76 base::WeakPtr<buzz::XmppTaskParentInterface> base_task) OVERRIDE; | 86 base::WeakPtr<buzz::XmppTaskParentInterface> base_task) OVERRIDE; |
77 virtual void OnNeedReconnect() OVERRIDE; | |
78 virtual void OnRedirect(const ServerInformation& redirect_server) OVERRIDE; | 87 virtual void OnRedirect(const ServerInformation& redirect_server) OVERRIDE; |
| 88 virtual void OnCredentialsRejected() OVERRIDE; |
| 89 virtual void OnSettingsExhausted() OVERRIDE; |
79 | 90 |
80 private: | 91 private: |
81 void OnLogoff(); | 92 void OnLogoff(); |
82 | 93 |
83 // Stops any existing reconnect timer and sets an initial reconnect | 94 // Stops any existing reconnect timer and sets an initial reconnect |
84 // interval. | 95 // interval. |
85 void ResetReconnectState(); | 96 void ResetReconnectState(); |
86 | 97 |
87 // Tries to reconnect in some point in the future. If called | 98 // Tries to reconnect in some point in the future. If called |
88 // repeatedly, will wait longer and longer until reconnecting. | 99 // repeatedly, will wait longer and longer until reconnecting. |
89 void TryReconnect(); | 100 void TryReconnect(); |
90 | 101 |
91 // The actual function (called by |reconnect_timer_|) that does the | 102 // The actual function (called by |reconnect_timer_|) that does the |
92 // reconnection. | 103 // reconnection. |
93 void DoReconnect(); | 104 void DoReconnect(); |
94 | 105 |
95 Delegate* const delegate_; | 106 Delegate* const delegate_; |
96 LoginSettings login_settings_; | 107 LoginSettings login_settings_; |
97 scoped_ptr<SingleLoginAttempt> single_attempt_; | 108 scoped_ptr<SingleLoginAttempt> single_attempt_; |
98 | 109 |
99 // reconnection state. | 110 // reconnection state. |
100 base::TimeDelta reconnect_interval_; | 111 base::TimeDelta reconnect_interval_; |
101 base::OneShotTimer<Login> reconnect_timer_; | 112 base::OneShotTimer<Login> reconnect_timer_; |
102 | 113 |
103 DISALLOW_COPY_AND_ASSIGN(Login); | 114 DISALLOW_COPY_AND_ASSIGN(Login); |
104 }; | 115 }; |
105 | 116 |
106 // Workaround for MSVS 2005 bug that fails to handle inheritance from a nested | |
107 // class properly if it comes directly on a base class list. | |
108 typedef Login::Delegate LoginDelegate; | |
109 | |
110 } // namespace notifier | 117 } // namespace notifier |
111 | 118 |
112 #endif // JINGLE_NOTIFIER_COMMUNICATOR_LOGIN_H_ | 119 #endif // JINGLE_NOTIFIER_COMMUNICATOR_LOGIN_H_ |
OLD | NEW |