diff options
author | zea <zea@chromium.org> | 2015-09-22 14:12:41 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-22 21:36:44 +0000 |
commit | 62052fe23d2c58db7c63f9e2db1b98ec0f140b9b (patch) | |
tree | cb875a4c71458c6b04f86a946a6636c06e1a526e /google_apis | |
parent | 84d1b1f25526e2d19dd14d0ae0cba858b3211401 (diff) | |
download | chromium_src-62052fe23d2c58db7c63f9e2db1b98ec0f140b9b.zip chromium_src-62052fe23d2c58db7c63f9e2db1b98ec0f140b9b.tar.gz chromium_src-62052fe23d2c58db7c63f9e2db1b98ec0f140b9b.tar.bz2 |
[GCM] Be more aggressive about triggering heartbeats when waking from sleep
As long as ten seconds has elapsed since the machine went to sleep, we'll now
force a heartbeat on resume.
BUG=526910
Review URL: https://codereview.chromium.org/1357053003
Cr-Commit-Position: refs/heads/master@{#350226}
Diffstat (limited to 'google_apis')
-rw-r--r-- | google_apis/gcm/engine/heartbeat_manager.cc | 19 | ||||
-rw-r--r-- | google_apis/gcm/engine/heartbeat_manager.h | 4 |
2 files changed, 22 insertions, 1 deletions
diff --git a/google_apis/gcm/engine/heartbeat_manager.cc b/google_apis/gcm/engine/heartbeat_manager.cc index 293f416..9875912 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() { diff --git a/google_apis/gcm/engine/heartbeat_manager.h b/google_apis/gcm/engine/heartbeat_manager.h index a6d47ea..83a25cf 100644 --- a/google_apis/gcm/engine/heartbeat_manager.h +++ b/google_apis/gcm/engine/heartbeat_manager.h @@ -61,6 +61,7 @@ class GCM_EXPORT HeartbeatManager : public base::PowerObserver { void UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer); // base::PowerObserver override. + void OnSuspend() override; void OnResume() override; // Maximum and minimum of the custom client interval that can be requested, @@ -114,6 +115,9 @@ class GCM_EXPORT HeartbeatManager : public base::PowerObserver { // Timer for triggering heartbeats. scoped_ptr<base::Timer> heartbeat_timer_; + // Time at which the machine was last suspended. + base::Time suspend_time_; + // Callbacks for interacting with the the connection. base::Closure send_heartbeat_callback_; ReconnectCallback trigger_reconnect_callback_; |