[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}
This commit is contained in:
@ -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() {
|
||||
|
@ -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_;
|
||||
|
@ -13616,6 +13616,11 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
|
||||
</summary>
|
||||
</histogram>
|
||||
|
||||
<histogram name="GCM.SuspendTime" units="milliseconds">
|
||||
<owner>zea@chromium.org</owner>
|
||||
<summary>Time elapsed from machine suspend until resume.</summary>
|
||||
</histogram>
|
||||
|
||||
<histogram name="GCM.UnregistrationCompleteTime" units="milliseconds">
|
||||
<owner>jianli@chromium.org</owner>
|
||||
<summary>
|
||||
|
Reference in New Issue
Block a user