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

Unified Diff: google_apis/gcm/engine/heartbeat_manager.cc

Issue 1357053003: [GCM] Be more aggressive about triggering heartbeats when waking from sleep (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Self review Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « google_apis/gcm/engine/heartbeat_manager.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: google_apis/gcm/engine/heartbeat_manager.cc
diff --git a/google_apis/gcm/engine/heartbeat_manager.cc b/google_apis/gcm/engine/heartbeat_manager.cc
index 293f41667ebdff12ea102960606b01806959d807..98759123f0132c44b112d7b08f031544859beea9 100644
--- a/google_apis/gcm/engine/heartbeat_manager.cc
+++ b/google_apis/gcm/engine/heartbeat_manager.cc
@@ -25,6 +25,8 @@ const int kWifiHeartbeatDefaultMs = 1000 * 60 * 15; // 15 minutes.
const int kHeartbeatAckDefaultMs = 1000 * 60 * 1; // 1 minute.
// Minimum allowed client default heartbeat interval.
const int kMinClientHeartbeatIntervalMs = 1000 * 60 * 2; // 2 minutes.
+// Minimum time spent sleeping before we force a new heartbeat.
+const int kMinSuspendTimeMs = 1000 * 10; // 10 seconds.
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// The period at which to check if the heartbeat time has passed. Used to
@@ -118,8 +120,23 @@ void HeartbeatManager::UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer) {
heartbeat_timer_->Start(FROM_HERE, remaining_delay, timer_task);
}
+void HeartbeatManager::OnSuspend() {
+ // The system is going to sleep. Record the time, so on resume we know how
+ // much time the machine was suspended.
+ suspend_time_ = base::Time::Now();
+}
+
void HeartbeatManager::OnResume() {
- CheckForMissedHeartbeat();
+ // The system just resumed from sleep. It's likely that the connection to
+ // MCS was silently lost during that time, even if a heartbeat is not yet
+ // due. Force a heartbeat to detect if the connection is still good.
+ base::TimeDelta elapsed = base::Time::Now() - suspend_time_;
+ UMA_HISTOGRAM_LONG_TIMES("GCM.SuspendTime", elapsed);
+
+ // Make sure a minimum amount of time has passed before forcing a heartbeat to
+ // avoid any tight loop scenarios.
+ if (elapsed > base::TimeDelta::FromMilliseconds(kMinSuspendTimeMs))
+ OnHeartbeatTriggered();
}
void HeartbeatManager::OnHeartbeatTriggered() {
« no previous file with comments | « google_apis/gcm/engine/heartbeat_manager.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698