OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef NET_BASE_BACKOFF_ITEM_H_ | 5 #ifndef NET_BASE_BACKOFF_ITEM_H_ |
6 #define NET_BASE_BACKOFF_ITEM_H_ | 6 #define NET_BASE_BACKOFF_ITEM_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/threading/non_thread_safe.h" | 9 #include "base/threading/non_thread_safe.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 | 62 |
63 // Causes this object reject requests until the specified absolute time. | 63 // Causes this object reject requests until the specified absolute time. |
64 // This can be used to e.g. implement support for a Retry-After header. | 64 // This can be used to e.g. implement support for a Retry-After header. |
65 void SetCustomReleaseTime(const base::TimeTicks& release_time); | 65 void SetCustomReleaseTime(const base::TimeTicks& release_time); |
66 | 66 |
67 // Returns true if this object has no significant state (i.e. you could | 67 // Returns true if this object has no significant state (i.e. you could |
68 // just as well start with a fresh BackoffEntry object), and hasn't | 68 // just as well start with a fresh BackoffEntry object), and hasn't |
69 // had for Policy::entry_lifetime_ms_. | 69 // had for Policy::entry_lifetime_ms_. |
70 bool CanDiscard() const; | 70 bool CanDiscard() const; |
71 | 71 |
72 // Resets this entry to a fresh (as if just constructed) state. | |
73 void Reset(); | |
74 | |
75 // Returns the failure count for this entry. | |
76 int failure_count() const; | |
wtc
2011/05/25 23:12:06
Nit: define this getter inline?
Jói
2011/05/26 14:53:42
Done.
| |
77 | |
72 protected: | 78 protected: |
73 // Equivalent to TimeTicks::Now(), virtual so unit tests can override. | 79 // Equivalent to TimeTicks::Now(), virtual so unit tests can override. |
74 // TODO(joi): Switch to constructor-time dependency injection? | 80 virtual base::TimeTicks ImplGetTimeNow() const; |
wtc
2011/05/25 23:12:06
Nit: we usually put "Impl" at the end, so "GetTime
Jói
2011/05/26 14:53:42
I've been using Impl at the front for methods inte
| |
75 virtual base::TimeTicks GetTimeNow() const; | |
76 | 81 |
77 private: | 82 private: |
78 // Calculates when requests should again be allowed through. | 83 // Calculates when requests should again be allowed through. |
79 base::TimeTicks CalculateReleaseTime() const; | 84 base::TimeTicks CalculateReleaseTime() const; |
80 | 85 |
81 // Timestamp calculated by the exponential back-off algorithm at which we are | 86 // Timestamp calculated by the exponential back-off algorithm at which we are |
82 // allowed to start sending requests again. | 87 // allowed to start sending requests again. |
83 base::TimeTicks exponential_backoff_release_time_; | 88 base::TimeTicks exponential_backoff_release_time_; |
84 | 89 |
85 // Counts request errors; reset on success. | 90 // Counts request errors; reset on success. |
86 int failure_count_; | 91 int failure_count_; |
87 | 92 |
88 const Policy* const policy_; | 93 const Policy* const policy_; |
89 | 94 |
90 DISALLOW_COPY_AND_ASSIGN(BackoffEntry); | 95 DISALLOW_COPY_AND_ASSIGN(BackoffEntry); |
91 }; | 96 }; |
92 | 97 |
93 } // namespace net | 98 } // namespace net |
94 | 99 |
95 #endif // NET_BASE_BACKOFF_ITEM_H_ | 100 #endif // NET_BASE_BACKOFF_ITEM_H_ |
OLD | NEW |