diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-24 00:11:59 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-24 00:11:59 +0000 |
commit | 106816845b891a0cf3d82fdc65b4f80ccb067ee7 (patch) | |
tree | 259ace7fc53c9594f3ef79f17934341f72186a52 | |
parent | 3ae7d212612dbbef97e9c2a1f7d649534533066e (diff) | |
download | chromium_src-106816845b891a0cf3d82fdc65b4f80ccb067ee7.zip chromium_src-106816845b891a0cf3d82fdc65b4f80ccb067ee7.tar.gz chromium_src-106816845b891a0cf3d82fdc65b4f80ccb067ee7.tar.bz2 |
Minor fixes to BackoffEntry.
1. maximum_backoff_ms and entry_lifetime_ms now are int64.
2. Protection from integer overflow when calculating delay.
Review URL: https://chromiumcodereview.appspot.com/9838069
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128617 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/base/backoff_entry.cc | 10 | ||||
-rw-r--r-- | net/base/backoff_entry.h | 7 |
2 files changed, 11 insertions, 6 deletions
diff --git a/net/base/backoff_entry.cc b/net/base/backoff_entry.cc index 5fcaed9..683bebf 100644 --- a/net/base/backoff_entry.cc +++ b/net/base/backoff_entry.cc @@ -6,6 +6,7 @@ #include <algorithm> #include <cmath> +#include <limits> #include "base/logging.h" #include "base/rand_util.h" @@ -121,10 +122,13 @@ base::TimeTicks BackoffEntry::CalculateReleaseTime() const { delay *= pow(policy_->multiply_factor, effective_failure_count - 1); delay -= base::RandDouble() * policy_->jitter_factor * delay; + const int64 kMaxInt64 = std::numeric_limits<int64>::max(); + int64 delay_int = (delay > kMaxInt64) ? + kMaxInt64 : static_cast<int64>(delay + 0.5); + // Ensure that we do not exceed maximum delay. - int64 delay_int = static_cast<int64>(delay + 0.5); - delay_int = std::min(delay_int, - static_cast<int64>(policy_->maximum_backoff_ms)); + if (policy_->maximum_backoff_ms >= 0) + delay_int = std::min(delay_int, policy_->maximum_backoff_ms); // Never reduce previously set release horizon, e.g. due to Retry-After // header. diff --git a/net/base/backoff_entry.h b/net/base/backoff_entry.h index e964670..ce280a4 100644 --- a/net/base/backoff_entry.h +++ b/net/base/backoff_entry.h @@ -36,12 +36,13 @@ class NET_EXPORT_PRIVATE BackoffEntry // between 90%-100% of the calculated time. double jitter_factor; - // Maximum amount of time we are willing to delay our request. - int maximum_backoff_ms; + // Maximum amount of time we are willing to delay our request, -1 + // for no maximum. + int64 maximum_backoff_ms; // Time to keep an entry from being discarded even when it // has no significant state, -1 to never discard. - int entry_lifetime_ms; + int64 entry_lifetime_ms; }; // Lifetime of policy must enclose lifetime of BackoffEntry. The |