Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/base/backoff_entry.h" | 5 #include "net/base/backoff_entry.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 // Never reduce previously set release horizon, e.g. due to Retry-After | 127 // Never reduce previously set release horizon, e.g. due to Retry-After |
| 128 // header. | 128 // header. |
| 129 return std::max(ImplGetTimeNow(), exponential_backoff_release_time_); | 129 return std::max(ImplGetTimeNow(), exponential_backoff_release_time_); |
| 130 } | 130 } |
| 131 | 131 |
| 132 // The delay is calculated with this formula: | 132 // The delay is calculated with this formula: |
| 133 // delay = initial_backoff * multiply_factor^( | 133 // delay = initial_backoff * multiply_factor^( |
| 134 // effective_failure_count - 1) * Uniform(1 - jitter_factor, 1] | 134 // effective_failure_count - 1) * Uniform(1 - jitter_factor, 1] |
| 135 double delay = policy_->initial_delay_ms; | 135 double delay = policy_->initial_delay_ms; |
| 136 delay *= pow(policy_->multiply_factor, effective_failure_count - 1); | 136 delay *= pow(policy_->multiply_factor, effective_failure_count - 1); |
| 137 if (isinf(delay)) { | |
| 138 delay = std::max(policy_->maximum_backoff_ms, | |
|
cbentzel
2014/06/14 15:16:07
maximum_backoff_ms is not always set - so it seems
cbentzel
2014/06/14 15:30:47
Actually, we'd reach integral overflow with this a
Ryan Sleevi
2014/06/16 17:20:47
^ base/basictypes.h has kint64max / kint64min
Nicolas Zea
2014/06/16 20:27:25
Switched to doing all overflow checking via Checke
| |
| 139 static_cast<int64>(policy_->initial_delay_ms)); | |
| 140 } | |
| 137 delay -= base::RandDouble() * policy_->jitter_factor * delay; | 141 delay -= base::RandDouble() * policy_->jitter_factor * delay; |
| 138 | 142 |
| 139 const int64 kMaxInt64 = std::numeric_limits<int64>::max(); | 143 const int64 kMaxInt64 = std::numeric_limits<int64>::max(); |
| 140 int64 delay_int = (delay > kMaxInt64) ? | 144 int64 delay_int = (delay > kMaxInt64) ? |
| 141 kMaxInt64 : static_cast<int64>(delay + 0.5); | 145 kMaxInt64 : static_cast<int64>(delay + 0.5); |
| 142 | 146 |
| 143 // Ensure that we do not exceed maximum delay. | 147 // Ensure that we do not exceed maximum delay. |
| 144 if (policy_->maximum_backoff_ms >= 0) | 148 if (policy_->maximum_backoff_ms >= 0) |
| 145 delay_int = std::min(delay_int, policy_->maximum_backoff_ms); | 149 delay_int = std::min(delay_int, policy_->maximum_backoff_ms); |
| 146 | 150 |
| 147 // Never reduce previously set release horizon, e.g. due to Retry-After | 151 // Never reduce previously set release horizon, e.g. due to Retry-After |
| 148 // header. | 152 // header. |
| 149 return std::max( | 153 return std::max( |
| 150 ImplGetTimeNow() + base::TimeDelta::FromMilliseconds(delay_int), | 154 ImplGetTimeNow() + base::TimeDelta::FromMilliseconds(delay_int), |
| 151 exponential_backoff_release_time_); | 155 exponential_backoff_release_time_); |
| 152 } | 156 } |
| 153 | 157 |
| 154 } // namespace net | 158 } // namespace net |
| OLD | NEW |