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

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

Issue 1758573004: [GCM] Fixing the client interval interaction with heartbeat ack (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | google_apis/gcm/engine/heartbeat_manager_unittest.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 #include "google_apis/gcm/engine/heartbeat_manager.h" 5 #include "google_apis/gcm/engine/heartbeat_manager.h"
6 6
7 #include <limits>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/callback.h" 10 #include "base/callback.h"
10 #include "base/location.h" 11 #include "base/location.h"
11 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
12 #include "base/power_monitor/power_monitor.h" 13 #include "base/power_monitor/power_monitor.h"
13 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 ResetConnection(ConnectionFactory::HEARTBEAT_FAILURE); 160 ResetConnection(ConnectionFactory::HEARTBEAT_FAILURE);
160 return; 161 return;
161 } 162 }
162 163
163 waiting_for_ack_ = true; 164 waiting_for_ack_ = true;
164 RestartTimer(); 165 RestartTimer();
165 send_heartbeat_callback_.Run(); 166 send_heartbeat_callback_.Run();
166 } 167 }
167 168
168 void HeartbeatManager::RestartTimer() { 169 void HeartbeatManager::RestartTimer() {
170 int interval_ms = std::numeric_limits<int>::max();
Nicolas Zea 2016/03/03 00:19:43 Why not initialize to heartbeat_interval_ms_?
fgorski 2016/03/03 17:10:35 Done.
169 if (!waiting_for_ack_) { 171 if (!waiting_for_ack_) {
170 // Recalculate the timer interval based network type. 172 // Recalculate the timer interval based network type.
Nicolas Zea 2016/03/03 00:19:43 nit: based network type -> based on network type
fgorski 2016/03/03 17:10:35 Done.
171 // Server interval takes precedence over client interval, even if the latter 173 // Server interval takes precedence over client interval, even if the latter
172 // is less. 174 // is less.
173 if (server_interval_ms_ != 0) { 175 if (server_interval_ms_ != 0) {
174 // If a server interval is set, it overrides any local one. 176 // If a server interval is set, it overrides any local one.
175 heartbeat_interval_ms_ = server_interval_ms_; 177 heartbeat_interval_ms_ = server_interval_ms_;
Nicolas Zea 2016/03/03 00:19:43 It seems like at this point heartbeat_interval_ms_
fgorski 2016/03/03 17:10:35 We are not able to do calculation in respective me
176 } else if (HasClientHeartbeatInterval()) { 178 } else if (HasClientHeartbeatInterval()) {
177 // Client interval might have been adjusted up, which should only take 179 // Client interval might have been adjusted up, which should only take
178 // effect during a reconnection. 180 // effect during a reconnection.
179 if (client_interval_ms_ < heartbeat_interval_ms_ || 181 if (client_interval_ms_ <= heartbeat_interval_ms_ ||
180 heartbeat_interval_ms_ == 0) { 182 heartbeat_interval_ms_ == 0) {
181 heartbeat_interval_ms_ = client_interval_ms_; 183 heartbeat_interval_ms_ = client_interval_ms_;
182 } 184 }
183 } else { 185 } else {
184 heartbeat_interval_ms_ = GetDefaultHeartbeatInterval(); 186 heartbeat_interval_ms_ = GetDefaultHeartbeatInterval();
185 } 187 }
188 interval_ms = heartbeat_interval_ms_;
186 DVLOG(1) << "Sending next heartbeat in " 189 DVLOG(1) << "Sending next heartbeat in "
187 << heartbeat_interval_ms_ << " ms."; 190 << interval_ms << " ms.";
188 } else { 191 } else {
189 heartbeat_interval_ms_ = kHeartbeatAckDefaultMs; 192 // Not updating the value of heartbeat_interval_ms_ when waitign for ack.
sjoe 2016/03/02 23:46:08 waitign -> waiting
fgorski 2016/03/03 17:10:35 Done.
193 interval_ms = kHeartbeatAckDefaultMs;
190 DVLOG(1) << "Resetting timer for ack with " 194 DVLOG(1) << "Resetting timer for ack with "
191 << heartbeat_interval_ms_ << " ms interval."; 195 << interval_ms << " ms interval.";
192 } 196 }
193 197
194 heartbeat_expected_time_ = 198 heartbeat_expected_time_ =
195 base::Time::Now() + 199 base::Time::Now() + base::TimeDelta::FromMilliseconds(interval_ms);
196 base::TimeDelta::FromMilliseconds(heartbeat_interval_ms_);
197 heartbeat_timer_->Start(FROM_HERE, 200 heartbeat_timer_->Start(FROM_HERE,
198 base::TimeDelta::FromMilliseconds( 201 base::TimeDelta::FromMilliseconds(
199 heartbeat_interval_ms_), 202 interval_ms),
200 base::Bind(&HeartbeatManager::OnHeartbeatTriggered, 203 base::Bind(&HeartbeatManager::OnHeartbeatTriggered,
201 weak_ptr_factory_.GetWeakPtr())); 204 weak_ptr_factory_.GetWeakPtr()));
202 205
203 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 206 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
204 // Windows, Mac, Android, iOS, and Chrome OS all provide a way to be notified 207 // Windows, Mac, Android, iOS, and Chrome OS all provide a way to be notified
205 // when the system is suspending or resuming. The only one that does not is 208 // when the system is suspending or resuming. The only one that does not is
206 // Linux so we need to poll to check for missed heartbeats. 209 // Linux so we need to poll to check for missed heartbeats.
207 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 210 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
208 FROM_HERE, 211 FROM_HERE,
209 base::Bind(&HeartbeatManager::CheckForMissedHeartbeat, 212 base::Bind(&HeartbeatManager::CheckForMissedHeartbeat,
210 weak_ptr_factory_.GetWeakPtr()), 213 weak_ptr_factory_.GetWeakPtr()),
211 base::TimeDelta::FromMilliseconds(kHeartbeatMissedCheckMs)); 214 base::TimeDelta::FromMilliseconds(kHeartbeatMissedCheckMs));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 interval <= max_heartbeat_interval; 289 interval <= max_heartbeat_interval;
287 } 290 }
288 291
289 void HeartbeatManager::ResetConnection( 292 void HeartbeatManager::ResetConnection(
290 ConnectionFactory::ConnectionResetReason reason) { 293 ConnectionFactory::ConnectionResetReason reason) {
291 Stop(); 294 Stop();
292 trigger_reconnect_callback_.Run(reason); 295 trigger_reconnect_callback_.Run(reason);
293 } 296 }
294 297
295 } // namespace gcm 298 } // namespace gcm
OLDNEW
« no previous file with comments | « no previous file | google_apis/gcm/engine/heartbeat_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698