Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(789)

Side by Side Diff: google_apis/gcm/engine/heartbeat_manager.h

Issue 989803002: Use base::PowerObserver to check for missed heartbeats (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 GOOGLE_APIS_GCM_ENGINE_HEARTBEAT_MANAGER_H_ 5 #ifndef GOOGLE_APIS_GCM_ENGINE_HEARTBEAT_MANAGER_H_
6 #define GOOGLE_APIS_GCM_ENGINE_HEARTBEAT_MANAGER_H_ 6 #define GOOGLE_APIS_GCM_ENGINE_HEARTBEAT_MANAGER_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/power_monitor/power_observer.h"
12 #include "google_apis/gcm/base/gcm_export.h" 13 #include "google_apis/gcm/base/gcm_export.h"
13 14
14 namespace base { 15 namespace base {
15 class Timer; 16 class Timer;
16 } 17 }
17 18
18 namespace mcs_proto { 19 namespace mcs_proto {
19 class HeartbeatConfig; 20 class HeartbeatConfig;
20 } 21 }
21 22
22 namespace gcm { 23 namespace gcm {
23 24
24 // A heartbeat management class, capable of sending and handling heartbeat 25 // A heartbeat management class, capable of sending and handling heartbeat
25 // receipt/failures and triggering reconnection as necessary. 26 // receipt/failures and triggering reconnection as necessary.
26 class GCM_EXPORT HeartbeatManager { 27 class GCM_EXPORT HeartbeatManager : public base::PowerObserver {
27 public: 28 public:
28 HeartbeatManager(); 29 HeartbeatManager();
29 ~HeartbeatManager(); 30 ~HeartbeatManager() override;
30 31
31 // Start the heartbeat logic. 32 // Start the heartbeat logic.
32 // |send_heartbeat_callback_| is the callback the HeartbeatManager uses to 33 // |send_heartbeat_callback_| is the callback the HeartbeatManager uses to
33 // send new heartbeats. Only one heartbeat can be outstanding at a time. 34 // send new heartbeats. Only one heartbeat can be outstanding at a time.
34 void Start(const base::Closure& send_heartbeat_callback, 35 void Start(const base::Closure& send_heartbeat_callback,
35 const base::Closure& trigger_reconnect_callback); 36 const base::Closure& trigger_reconnect_callback);
36 37
37 // Stop the timer. Start(..) must be called again to begin sending heartbeats 38 // Stop the timer. Start(..) must be called again to begin sending heartbeats
38 // afterwards. 39 // afterwards.
39 void Stop(); 40 void Stop();
40 41
41 // Reset the heartbeat timer. It is valid to call this even if no heartbeat 42 // Reset the heartbeat timer. It is valid to call this even if no heartbeat
42 // is associated with the ack (for example if another signal is used to 43 // is associated with the ack (for example if another signal is used to
43 // determine that the connection is alive). 44 // determine that the connection is alive).
44 void OnHeartbeatAcked(); 45 void OnHeartbeatAcked();
45 46
46 // Updates the current heartbeat interval. 47 // Updates the current heartbeat interval.
47 void UpdateHeartbeatConfig(const mcs_proto::HeartbeatConfig& config); 48 void UpdateHeartbeatConfig(const mcs_proto::HeartbeatConfig& config);
48 49
49 // Returns the next scheduled heartbeat time. A null time means 50 // Returns the next scheduled heartbeat time. A null time means
50 // no heartbeat is pending. If non-null and less than the 51 // no heartbeat is pending. If non-null and less than the
51 // current time (in ticks), the heartbeat has been triggered and an ack is 52 // current time (in ticks), the heartbeat has been triggered and an ack is
52 // pending. 53 // pending.
53 base::TimeTicks GetNextHeartbeatTime() const; 54 base::TimeTicks GetNextHeartbeatTime() const;
54 55
55 // Updates the timer used for scheduling heartbeats. 56 // Updates the timer used for scheduling heartbeats.
56 void UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer); 57 void UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer);
57 58
59 // base::PowerObserver override.
60 void OnResume() override;
61
58 protected: 62 protected:
59 // Helper method to send heartbeat on timer trigger. 63 // Helper method to send heartbeat on timer trigger.
60 void OnHeartbeatTriggered(); 64 void OnHeartbeatTriggered();
61 65
62 // Periodic check to see if the heartbeat has been missed due to some system 66 // Periodic check to see if the heartbeat has been missed due to some system
63 // issue (e.g. the machine was suspended and the timer did not account for 67 // issue (e.g. the machine was suspended and the timer did not account for
64 // that). 68 // that).
65 void CheckForMissedHeartbeat(); 69 void CheckForMissedHeartbeat();
66 70
67 private: 71 private:
(...skipping 21 matching lines...) Expand all
89 base::Closure trigger_reconnect_callback_; 93 base::Closure trigger_reconnect_callback_;
90 94
91 base::WeakPtrFactory<HeartbeatManager> weak_ptr_factory_; 95 base::WeakPtrFactory<HeartbeatManager> weak_ptr_factory_;
92 96
93 DISALLOW_COPY_AND_ASSIGN(HeartbeatManager); 97 DISALLOW_COPY_AND_ASSIGN(HeartbeatManager);
94 }; 98 };
95 99
96 } // namespace gcm 100 } // namespace gcm
97 101
98 #endif // GOOGLE_APIS_GCM_ENGINE_HEARTBEAT_MANAGER_H_ 102 #endif // GOOGLE_APIS_GCM_ENGINE_HEARTBEAT_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | google_apis/gcm/engine/heartbeat_manager.cc » ('j') | google_apis/gcm/engine/heartbeat_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698