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

Unified Diff: net/base/backoff_entry.cc

Issue 1023473003: Allow BackoffEntry to be serialized and deserialized. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweak comments Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: net/base/backoff_entry.cc
diff --git a/net/base/backoff_entry.cc b/net/base/backoff_entry.cc
index bfcc9dd67d6b16f6e1708aad5ff33e5740595d98..a7617b6c6d8aff8f947750a29b07bd3b15565785 100644
--- a/net/base/backoff_entry.cc
+++ b/net/base/backoff_entry.cc
@@ -142,11 +142,25 @@ base::TimeTicks BackoffEntry::CalculateReleaseTime() const {
delay_ms -= base::RandDouble() * policy_->jitter_factor * delay_ms;
// Do overflow checking in microseconds, the internal unit of TimeTicks.
+ base::internal::CheckedNumeric<int64> time_until_release_us = delay_ms + 0.5;
+ time_until_release_us *= base::Time::kMicrosecondsPerMillisecond;
+ base::TimeDelta time_until_release = base::TimeDelta::FromMicroseconds(
+ time_until_release_us.ValueOrDefault(kint64max));
+ base::TimeTicks release_time =
+ TimeUntilReleaseToReleaseTime(time_until_release);
+
+ // Never reduce previously set release horizon, e.g. due to Retry-After
+ // header.
+ return std::max(release_time, exponential_backoff_release_time_);
+}
+
+base::TimeTicks BackoffEntry::TimeUntilReleaseToReleaseTime(
+ base::TimeDelta time_until_release) const {
const int64 kTimeTicksNowUs =
(GetTimeTicksNow() - base::TimeTicks()).InMicroseconds();
+ // Do overflow checking in microseconds, the internal unit of TimeTicks.
base::internal::CheckedNumeric<int64> calculated_release_time_us =
- delay_ms + 0.5;
- calculated_release_time_us *= base::Time::kMicrosecondsPerMillisecond;
+ time_until_release.InMicroseconds();
calculated_release_time_us += kTimeTicksNowUs;
base::internal::CheckedNumeric<int64> maximum_release_time_us = kint64max;
@@ -162,11 +176,7 @@ base::TimeTicks BackoffEntry::CalculateReleaseTime() const {
calculated_release_time_us.ValueOrDefault(kint64max),
maximum_release_time_us.ValueOrDefault(kint64max));
- // Never reduce previously set release horizon, e.g. due to Retry-After
- // header.
- return std::max(
- base::TimeTicks() + base::TimeDelta::FromMicroseconds(release_time_us),
- exponential_backoff_release_time_);
+ return base::TimeTicks() + base::TimeDelta::FromMicroseconds(release_time_us);
}
base::TimeTicks BackoffEntry::GetTimeTicksNow() const {

Powered by Google App Engine
This is Rietveld 408576698