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

Side by Side Diff: net/base/backoff_entry.cc

Issue 2390653002: Allow backoff entry serialization if clock is null. (Closed)
Patch Set: feedback Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « net/base/backoff_entry.h ('k') | net/base/backoff_entry_serializer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 void BackoffEntry::Reset() { 108 void BackoffEntry::Reset() {
109 failure_count_ = 0; 109 failure_count_ = 0;
110 // For legacy reasons, we reset exponential_backoff_release_time_ to the 110 // For legacy reasons, we reset exponential_backoff_release_time_ to the
111 // uninitialized state. It would also be reasonable to reset it to 111 // uninitialized state. It would also be reasonable to reset it to
112 // GetTimeTicksNow(). The effects are the same, i.e. ShouldRejectRequest() 112 // GetTimeTicksNow(). The effects are the same, i.e. ShouldRejectRequest()
113 // will return false right after Reset(). 113 // will return false right after Reset().
114 exponential_backoff_release_time_ = base::TimeTicks(); 114 exponential_backoff_release_time_ = base::TimeTicks();
115 } 115 }
116 116
117 base::TimeTicks BackoffEntry::GetTimeTicksNow() const {
118 return clock_ ? clock_->NowTicks() : base::TimeTicks::Now();
119 }
120
117 base::TimeTicks BackoffEntry::CalculateReleaseTime() const { 121 base::TimeTicks BackoffEntry::CalculateReleaseTime() const {
118 int effective_failure_count = 122 int effective_failure_count =
119 std::max(0, failure_count_ - policy_->num_errors_to_ignore); 123 std::max(0, failure_count_ - policy_->num_errors_to_ignore);
120 124
121 // If always_use_initial_delay is true, it's equivalent to 125 // If always_use_initial_delay is true, it's equivalent to
122 // the effective_failure_count always being one greater than when it's false. 126 // the effective_failure_count always being one greater than when it's false.
123 if (policy_->always_use_initial_delay) 127 if (policy_->always_use_initial_delay)
124 ++effective_failure_count; 128 ++effective_failure_count;
125 129
126 if (effective_failure_count == 0) { 130 if (effective_failure_count == 0) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // Decide between maximum release time and calculated release time, accounting 176 // Decide between maximum release time and calculated release time, accounting
173 // for overflow with both. 177 // for overflow with both.
174 int64_t release_time_us = std::min(calculated_release_time_us.ValueOrDefault( 178 int64_t release_time_us = std::min(calculated_release_time_us.ValueOrDefault(
175 std::numeric_limits<int64_t>::max()), 179 std::numeric_limits<int64_t>::max()),
176 maximum_release_time_us.ValueOrDefault( 180 maximum_release_time_us.ValueOrDefault(
177 std::numeric_limits<int64_t>::max())); 181 std::numeric_limits<int64_t>::max()));
178 182
179 return base::TimeTicks() + base::TimeDelta::FromMicroseconds(release_time_us); 183 return base::TimeTicks() + base::TimeDelta::FromMicroseconds(release_time_us);
180 } 184 }
181 185
182 base::TimeTicks BackoffEntry::GetTimeTicksNow() const {
183 return clock_ ? clock_->NowTicks() : base::TimeTicks::Now();
184 }
185
186 } // namespace net 186 } // namespace net
OLDNEW
« no previous file with comments | « net/base/backoff_entry.h ('k') | net/base/backoff_entry_serializer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698