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