OLD | NEW |
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 "components/gcm_driver/gcm_channel_status_syncer.h" | 5 #include "components/gcm_driver/gcm_channel_status_syncer.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
9 #include "base/location.h" | 11 #include "base/location.h" |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
12 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
13 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
14 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
15 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
16 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 request_->Start(); | 206 request_->Start(); |
205 } | 207 } |
206 | 208 |
207 base::TimeDelta GCMChannelStatusSyncer::GetRequestDelayInterval() const { | 209 base::TimeDelta GCMChannelStatusSyncer::GetRequestDelayInterval() const { |
208 // No delay during testing. | 210 // No delay during testing. |
209 if (delay_removed_for_testing_) | 211 if (delay_removed_for_testing_) |
210 return base::TimeDelta(); | 212 return base::TimeDelta(); |
211 | 213 |
212 // Make sure that checking with server occurs at polling interval, regardless | 214 // Make sure that checking with server occurs at polling interval, regardless |
213 // whether the browser restarts. | 215 // whether the browser restarts. |
214 int64 delay_seconds = poll_interval_seconds_ - | 216 int64_t delay_seconds = poll_interval_seconds_ - |
215 (base::Time::Now() - last_check_time_).InSeconds(); | 217 (base::Time::Now() - last_check_time_).InSeconds(); |
216 if (delay_seconds < 0) | 218 if (delay_seconds < 0) |
217 delay_seconds = 0; | 219 delay_seconds = 0; |
218 | 220 |
219 if (last_check_time_.is_null()) { | 221 if (last_check_time_.is_null()) { |
220 // For the first-time request, add a small delay to avoid sending request at | 222 // For the first-time request, add a small delay to avoid sending request at |
221 // browser startup time. | 223 // browser startup time. |
222 DCHECK(!delay_seconds); | 224 DCHECK(!delay_seconds); |
223 delay_seconds = kFirstTimeDelaySeconds; | 225 delay_seconds = kFirstTimeDelaySeconds; |
224 } else { | 226 } else { |
225 // Otherwise, add a fuzzing variation to the delay. | 227 // Otherwise, add a fuzzing variation to the delay. |
226 // The fuzzing variation is off when the custom interval is used. | 228 // The fuzzing variation is off when the custom interval is used. |
227 if (!custom_poll_interval_use_count_) | 229 if (!custom_poll_interval_use_count_) |
228 delay_seconds += base::RandInt(0, kGCMChannelRequestTimeJitterSeconds); | 230 delay_seconds += base::RandInt(0, kGCMChannelRequestTimeJitterSeconds); |
229 } | 231 } |
230 | 232 |
231 return base::TimeDelta::FromSeconds(delay_seconds); | 233 return base::TimeDelta::FromSeconds(delay_seconds); |
232 } | 234 } |
233 | 235 |
234 } // namespace gcm | 236 } // namespace gcm |
OLD | NEW |