OLD | NEW |
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 #ifndef NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_H_ |
6 #define NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <queue> | 9 #include <queue> |
10 #include <string> | 10 #include <string> |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // collected. | 86 // collected. |
87 bool IsEntryOutdated() const; | 87 bool IsEntryOutdated() const; |
88 | 88 |
89 // Causes this entry to never reject requests due to back-off. | 89 // Causes this entry to never reject requests due to back-off. |
90 void DisableBackoffThrottling(); | 90 void DisableBackoffThrottling(); |
91 | 91 |
92 // Causes this entry to NULL its manager pointer. | 92 // Causes this entry to NULL its manager pointer. |
93 void DetachManager(); | 93 void DetachManager(); |
94 | 94 |
95 // Implementation of URLRequestThrottlerEntryInterface. | 95 // Implementation of URLRequestThrottlerEntryInterface. |
96 virtual bool ShouldRejectRequest(int load_flags) const OVERRIDE; | 96 virtual bool ShouldRejectRequest(const URLRequest& request) const OVERRIDE; |
97 virtual int64 ReserveSendingTimeForNextRequest( | 97 virtual int64 ReserveSendingTimeForNextRequest( |
98 const base::TimeTicks& earliest_time) OVERRIDE; | 98 const base::TimeTicks& earliest_time) OVERRIDE; |
99 virtual base::TimeTicks GetExponentialBackoffReleaseTime() const OVERRIDE; | 99 virtual base::TimeTicks GetExponentialBackoffReleaseTime() const OVERRIDE; |
100 virtual void UpdateWithResponse( | 100 virtual void UpdateWithResponse( |
101 const std::string& host, | 101 const std::string& host, |
102 const URLRequestThrottlerHeaderInterface* response) OVERRIDE; | 102 const URLRequestThrottlerHeaderInterface* response) OVERRIDE; |
103 virtual void ReceivedContentWasMalformed(int response_code) OVERRIDE; | 103 virtual void ReceivedContentWasMalformed(int response_code) OVERRIDE; |
104 | 104 |
105 protected: | 105 protected: |
106 virtual ~URLRequestThrottlerEntry(); | 106 virtual ~URLRequestThrottlerEntry(); |
107 | 107 |
108 void Initialize(); | 108 void Initialize(); |
109 | 109 |
110 // Returns true if the given response code is considered an error for | 110 // Returns true if the given response code is considered an error for |
111 // throttling purposes. | 111 // throttling purposes. |
112 bool IsConsideredError(int response_code); | 112 bool IsConsideredError(int response_code); |
113 | 113 |
114 // Equivalent to TimeTicks::Now(), virtual to be mockable for testing purpose. | 114 // Equivalent to TimeTicks::Now(), virtual to be mockable for testing purpose. |
115 virtual base::TimeTicks ImplGetTimeNow() const; | 115 virtual base::TimeTicks ImplGetTimeNow() const; |
116 | 116 |
117 // Used internally to handle the opt-out header. | 117 // Used internally to handle the opt-out header. |
118 void HandleThrottlingHeader(const std::string& header_value, | 118 void HandleThrottlingHeader(const std::string& header_value, |
119 const std::string& host); | 119 const std::string& host); |
120 | 120 |
121 // Used internally to keep track of failure->success transitions and | |
122 // generate statistics about them. | |
123 void HandleMetricsTracking(int response_code); | |
124 | |
125 // Retrieves the back-off entry object we're using. Used to enable a | 121 // Retrieves the back-off entry object we're using. Used to enable a |
126 // unit testing seam for dependency injection in tests. | 122 // unit testing seam for dependency injection in tests. |
127 virtual const BackoffEntry* GetBackoffEntry() const; | 123 virtual const BackoffEntry* GetBackoffEntry() const; |
128 virtual BackoffEntry* GetBackoffEntry(); | 124 virtual BackoffEntry* GetBackoffEntry(); |
129 | 125 |
130 // Returns true if |load_flags| contains a flag that indicates an | 126 // Returns true if |load_flags| contains a flag that indicates an |
131 // explicit request by the user to load the resource. We never | 127 // explicit request by the user to load the resource. We never |
132 // throttle requests with such load flags. | 128 // throttle requests with such load flags. |
133 static bool ExplicitUserRequest(const int load_flags); | 129 static bool ExplicitUserRequest(const int load_flags); |
134 | 130 |
(...skipping 22 matching lines...) Expand all Loading... |
157 | 153 |
158 const base::TimeDelta sliding_window_period_; | 154 const base::TimeDelta sliding_window_period_; |
159 const int max_send_threshold_; | 155 const int max_send_threshold_; |
160 | 156 |
161 // True if DisableBackoffThrottling() has been called on this object. | 157 // True if DisableBackoffThrottling() has been called on this object. |
162 bool is_backoff_disabled_; | 158 bool is_backoff_disabled_; |
163 | 159 |
164 // Access it through GetBackoffEntry() to allow a unit test seam. | 160 // Access it through GetBackoffEntry() to allow a unit test seam. |
165 BackoffEntry backoff_entry_; | 161 BackoffEntry backoff_entry_; |
166 | 162 |
167 // The time of the last successful response, plus knowledge of whether | |
168 // the last response was successful or not, let us generate statistics on | |
169 // the length of perceived downtime for a given URL, and the error count | |
170 // when such transitions occur. This is useful for experiments with | |
171 // throttling but will likely become redundant after they are finished. | |
172 // TODO(joi): Remove when the time is right | |
173 base::TimeTicks last_successful_response_time_; | |
174 bool last_response_was_success_; | |
175 | |
176 // Weak back-reference to the manager object managing us. | 163 // Weak back-reference to the manager object managing us. |
177 URLRequestThrottlerManager* manager_; | 164 URLRequestThrottlerManager* manager_; |
178 | 165 |
179 // Canonicalized URL string that this entry is for; used for logging only. | 166 // Canonicalized URL string that this entry is for; used for logging only. |
180 std::string url_id_; | 167 std::string url_id_; |
181 | 168 |
182 BoundNetLog net_log_; | 169 BoundNetLog net_log_; |
183 | 170 |
184 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerEntry); | 171 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerEntry); |
185 }; | 172 }; |
186 | 173 |
187 } // namespace net | 174 } // namespace net |
188 | 175 |
189 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_H_ | 176 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_H_ |
OLD | NEW |