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

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

Issue 641943002: components: Introduce AlarmTimer class and use it for GCM heartbeat (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix gyp files Created 6 years, 2 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/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
11 #include "base/timer/timer.h"
12 #include "google_apis/gcm/base/gcm_export.h" 12 #include "google_apis/gcm/base/gcm_export.h"
13 13
14 namespace base {
15 class Timer;
16 }
17
14 namespace mcs_proto { 18 namespace mcs_proto {
15 class HeartbeatConfig; 19 class HeartbeatConfig;
16 } 20 }
17 21
18 namespace gcm { 22 namespace gcm {
19 23
20 // A heartbeat management class, capable of sending and handling heartbeat 24 // A heartbeat management class, capable of sending and handling heartbeat
21 // receipt/failures and triggering reconnection as necessary. 25 // receipt/failures and triggering reconnection as necessary.
22 class GCM_EXPORT HeartbeatManager { 26 class GCM_EXPORT HeartbeatManager {
23 public: 27 public:
(...skipping 17 matching lines...) Expand all
41 45
42 // Updates the current heartbeat interval. 46 // Updates the current heartbeat interval.
43 void UpdateHeartbeatConfig(const mcs_proto::HeartbeatConfig& config); 47 void UpdateHeartbeatConfig(const mcs_proto::HeartbeatConfig& config);
44 48
45 // Returns the next scheduled heartbeat time. A null time means 49 // Returns the next scheduled heartbeat time. A null time means
46 // no heartbeat is pending. If non-null and less than the 50 // no heartbeat is pending. If non-null and less than the
47 // current time (in ticks), the heartbeat has been triggered and an ack is 51 // current time (in ticks), the heartbeat has been triggered and an ack is
48 // pending. 52 // pending.
49 base::TimeTicks GetNextHeartbeatTime() const; 53 base::TimeTicks GetNextHeartbeatTime() const;
50 54
55 // Sets the Timer that will be used for heartbeat messages. Can only be
56 // called before the first time Start() is called.
57 void SetHeartbeatTimer(scoped_ptr<base::Timer> timer);
Nicolas Zea 2014/10/22 17:32:16 Why not just pass it in at construction time?
Chirantan Ekbote 2014/10/22 18:47:14 I originally tried that. But to pass it in at con
Nicolas Zea 2014/10/23 17:49:02 IMO its worse to have the possibility of someone c
Chirantan Ekbote 2014/10/23 23:53:30 Done.
58
51 protected: 59 protected:
52 // Helper method to send heartbeat on timer trigger. 60 // Helper method to send heartbeat on timer trigger.
53 void OnHeartbeatTriggered(); 61 void OnHeartbeatTriggered();
54 62
55 private: 63 private:
56 // Restarts the heartbeat timer. 64 // Restarts the heartbeat timer.
57 void RestartTimer(); 65 void RestartTimer();
58 66
67 // Whether the HeartbeatManager has started sending heartbeats.
68 bool started_;
69
59 // Whether the last heartbeat ping sent has been acknowledged or not. 70 // Whether the last heartbeat ping sent has been acknowledged or not.
60 bool waiting_for_ack_; 71 bool waiting_for_ack_;
61 72
62 // The current heartbeat interval. 73 // The current heartbeat interval.
63 int heartbeat_interval_ms_; 74 int heartbeat_interval_ms_;
64 // The most recent server-provided heartbeat interval (0 if none has been 75 // The most recent server-provided heartbeat interval (0 if none has been
65 // provided). 76 // provided).
66 int server_interval_ms_; 77 int server_interval_ms_;
67 78
68 // Timer for triggering heartbeats. 79 // Timer for triggering heartbeats.
69 base::Timer heartbeat_timer_; 80 scoped_ptr<base::Timer> heartbeat_timer_;
70 81
71 // Callbacks for interacting with the the connection. 82 // Callbacks for interacting with the the connection.
72 base::Closure send_heartbeat_callback_; 83 base::Closure send_heartbeat_callback_;
73 base::Closure trigger_reconnect_callback_; 84 base::Closure trigger_reconnect_callback_;
74 85
75 base::WeakPtrFactory<HeartbeatManager> weak_ptr_factory_; 86 base::WeakPtrFactory<HeartbeatManager> weak_ptr_factory_;
76 87
77 DISALLOW_COPY_AND_ASSIGN(HeartbeatManager); 88 DISALLOW_COPY_AND_ASSIGN(HeartbeatManager);
78 }; 89 };
79 90
80 } // namespace gcm 91 } // namespace gcm
81 92
82 #endif // GOOGLE_APIS_GCM_ENGINE_HEARTBEAT_MANAGER_H_ 93 #endif // GOOGLE_APIS_GCM_ENGINE_HEARTBEAT_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698