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

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

Issue 118133003: [GCM] Add heartbeat manager and reconnection logic due to heartbeat failure (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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 GOOGLE_APIS_GCM_ENGINE_HEARTBEAT_MANAGER_H_
6 #define GOOGLE_APIS_GCM_ENGINE_HEARTBEAT_MANAGER_H_
7
8 #include "base/callback.h"
9 #include "base/logging.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/timer/timer.h"
12 #include "google_apis/gcm/base/gcm_export.h"
13
14 namespace mcs_proto {
15 class HeartbeatConfig;
16 }
17
18 namespace gcm {
19
20 // A heartbeat management class, capable of sending and handling heartbeat
21 // receipt/failures and triggering reconnection as necessary.
22 class GCM_EXPORT HeartbeatManager {
23 public:
24 HeartbeatManager();
25 ~HeartbeatManager();
26
27 // Start the heartbeat logic.
28 // |send_heartbeat_callback_| is the callback the HeartbeatManager uses to
29 // send new heartbeats. Only one heartbeat can be outstanding at a time.
30 void Start(const base::Closure& send_heartbeat_callback,
31 const base::Closure& trigger_reconnect_callback);
32
33 // Stop the timer. Start(..) must be called again to begin sending heartbeats
34 // afterwards.
35 void Stop();
36
37 // Reset the heartbeat timer. It is valid to call this even if no heartbeat
38 // is associated with the ack (for example if another signal is used to
39 // determine that the connection is alive).
40 void OnHeartbeatAcked();
41
42 // Updates the current heartbeat interval.
43 void UpdateHeartbeatConfig(const mcs_proto::HeartbeatConfig& config);
44
45 // Returns the next scheduled heartbeat time. If non-null and less than
46 // base::Timeticks::Now(), a heartbeat ack is pending. If null, the heartbeat
47 // manager is stopped.
jianli 2013/12/20 23:10:03 What does it mean if the returned value is non-nul
Nicolas Zea 2013/12/26 22:55:02 That's the time that the heartbeat will be sent. R
48 base::TimeTicks GetNextHeartbeatTime() const;
49
50 protected:
51 // Helper method to send heartbeat on timer trigger.
52 void OnHeartbeatTriggered();
53
54 private:
55 // Restarts the heartbeat timer.
56 void RestartTimer();
57
58 // Whether the last heartbeat ping sent has been acknowledged or not.
59 bool waiting_for_ack_;
60
61 // The current heartbeat interval.
62 base::TimeDelta heartbeat_interval_;
63 // The most recent server-provided heartbeat interval (0 if none has been
64 // provided).
65 int32 server_interval_ms_;
66
67 // Timer for triggering heartbeats.
68 base::Timer heartbeat_timer_;
69
70 // Callbacks for interacting with the the connection.
71 base::Closure send_heartbeat_callback_;
72 base::Closure trigger_reconnect_callback_;
73
74 base::WeakPtrFactory<HeartbeatManager> weak_ptr_factory_;
75
76 DISALLOW_COPY_AND_ASSIGN(HeartbeatManager);
77 };
78
79 } // namespace gcm
80
81 #endif // GOOGLE_APIS_GCM_ENGINE_HEARTBEAT_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698