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

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 build error in mcs_probe Created 6 years, 1 month 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
« no previous file with comments | « components/timers/rtc_alarm.cc ('k') | google_apis/gcm/engine/heartbeat_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:
24 HeartbeatManager(); 28 explicit HeartbeatManager(scoped_ptr<base::Timer> heartbeat_timer);
25 ~HeartbeatManager(); 29 ~HeartbeatManager();
26 30
27 // Start the heartbeat logic. 31 // Start the heartbeat logic.
28 // |send_heartbeat_callback_| is the callback the HeartbeatManager uses to 32 // |send_heartbeat_callback_| is the callback the HeartbeatManager uses to
29 // send new heartbeats. Only one heartbeat can be outstanding at a time. 33 // send new heartbeats. Only one heartbeat can be outstanding at a time.
30 void Start(const base::Closure& send_heartbeat_callback, 34 void Start(const base::Closure& send_heartbeat_callback,
31 const base::Closure& trigger_reconnect_callback); 35 const base::Closure& trigger_reconnect_callback);
32 36
33 // Stop the timer. Start(..) must be called again to begin sending heartbeats 37 // Stop the timer. Start(..) must be called again to begin sending heartbeats
34 // afterwards. 38 // afterwards.
(...skipping 24 matching lines...) Expand all
59 // Whether the last heartbeat ping sent has been acknowledged or not. 63 // Whether the last heartbeat ping sent has been acknowledged or not.
60 bool waiting_for_ack_; 64 bool waiting_for_ack_;
61 65
62 // The current heartbeat interval. 66 // The current heartbeat interval.
63 int heartbeat_interval_ms_; 67 int heartbeat_interval_ms_;
64 // The most recent server-provided heartbeat interval (0 if none has been 68 // The most recent server-provided heartbeat interval (0 if none has been
65 // provided). 69 // provided).
66 int server_interval_ms_; 70 int server_interval_ms_;
67 71
68 // Timer for triggering heartbeats. 72 // Timer for triggering heartbeats.
69 base::Timer heartbeat_timer_; 73 scoped_ptr<base::Timer> heartbeat_timer_;
70 74
71 // Callbacks for interacting with the the connection. 75 // Callbacks for interacting with the the connection.
72 base::Closure send_heartbeat_callback_; 76 base::Closure send_heartbeat_callback_;
73 base::Closure trigger_reconnect_callback_; 77 base::Closure trigger_reconnect_callback_;
74 78
75 base::WeakPtrFactory<HeartbeatManager> weak_ptr_factory_; 79 base::WeakPtrFactory<HeartbeatManager> weak_ptr_factory_;
76 80
77 DISALLOW_COPY_AND_ASSIGN(HeartbeatManager); 81 DISALLOW_COPY_AND_ASSIGN(HeartbeatManager);
78 }; 82 };
79 83
80 } // namespace gcm 84 } // namespace gcm
81 85
82 #endif // GOOGLE_APIS_GCM_ENGINE_HEARTBEAT_MANAGER_H_ 86 #endif // GOOGLE_APIS_GCM_ENGINE_HEARTBEAT_MANAGER_H_
OLDNEW
« no previous file with comments | « components/timers/rtc_alarm.cc ('k') | google_apis/gcm/engine/heartbeat_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698