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 JINGLE_NOTIFIER_COMMUNICATOR_AUTO_RECONNECT_H_ | |
6 #define JINGLE_NOTIFIER_COMMUNICATOR_AUTO_RECONNECT_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/time.h" | |
11 #include "base/timer.h" | |
12 #include "jingle/notifier/communicator/login_connection_state.h" | |
13 #include "talk/base/sigslot.h" | |
14 | |
15 namespace notifier { | |
16 | |
17 class AutoReconnect : public sigslot::has_slots<> { | |
18 public: | |
19 AutoReconnect(); | |
20 void StartReconnectTimer(); | |
21 void StopReconnectTimer(); | |
22 void OnClientStateChange(LoginConnectionState state); | |
23 | |
24 void NetworkStateChanged(bool is_alive); | |
25 | |
26 // Callback when power is suspended. | |
27 void OnPowerSuspend(bool suspended); | |
28 | |
29 void set_idle(bool idle) { | |
30 is_idle_ = idle; | |
31 } | |
32 | |
33 // Returns true if the auto-retry is to be done (pending a countdown). | |
34 bool is_retrying() const { | |
35 return reconnect_timer_started_; | |
36 } | |
37 | |
38 sigslot::signal0<> SignalTimerStartStop; | |
39 sigslot::signal0<> SignalStartConnection; | |
40 | |
41 private: | |
42 void StartReconnectTimerWithInterval(base::TimeDelta interval); | |
43 void DoReconnect(); | |
44 void ResetState(); | |
45 void SetupReconnectInterval(); | |
46 void StopDelayedResetTimer(); | |
47 | |
48 base::TimeDelta reconnect_interval_; | |
49 bool reconnect_timer_started_; | |
50 base::OneShotTimer<AutoReconnect> reconnect_timer_; | |
51 base::OneShotTimer<AutoReconnect> delayed_reset_timer_; | |
52 | |
53 bool is_idle_; | |
54 DISALLOW_COPY_AND_ASSIGN(AutoReconnect); | |
55 }; | |
56 | |
57 // Wait 2 seconds until after we actually connect to reset reconnect related | |
58 // items. | |
59 // | |
60 // The reason for this delay is to avoid the situation in which buzz is trying | |
61 // to block the client due to abuse and the client responses by going into | |
62 // rapid reconnect mode, which makes the problem more severe. | |
63 extern const int kResetReconnectInfoDelaySec; | |
64 | |
65 } // namespace notifier | |
66 | |
67 #endif // JINGLE_NOTIFIER_COMMUNICATOR_AUTO_RECONNECT_H_ | |
OLD | NEW |