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

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: Address mmenke's final review nits Created 5 years, 7 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
« no previous file with comments | « net/base/backoff_entry.h ('k') | net/base/backoff_entry_serializer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/backoff_entry.cc
diff --git a/net/base/backoff_entry.cc b/net/base/backoff_entry.cc
index bfcc9dd67d6b16f6e1708aad5ff33e5740595d98..870d6a15631001f696b1abab361d0c3efcf127cc 100644
--- a/net/base/backoff_entry.cc
+++ b/net/base/backoff_entry.cc
@@ -142,11 +142,24 @@ 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> backoff_duration_us = delay_ms + 0.5;
+ backoff_duration_us *= base::Time::kMicrosecondsPerMillisecond;
+ base::TimeDelta backoff_duration = base::TimeDelta::FromMicroseconds(
+ backoff_duration_us.ValueOrDefault(kint64max));
+ base::TimeTicks release_time = BackoffDurationToReleaseTime(backoff_duration);
+
+ // 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::BackoffDurationToReleaseTime(
+ base::TimeDelta backoff_duration) 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;
+ backoff_duration.InMicroseconds();
calculated_release_time_us += kTimeTicksNowUs;
base::internal::CheckedNumeric<int64> maximum_release_time_us = kint64max;
@@ -162,11 +175,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 {
« no previous file with comments | « net/base/backoff_entry.h ('k') | net/base/backoff_entry_serializer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698