Chromium Code Reviews| 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, |
| 97 int load_flags) const OVERRIDE; | |
|
eroman
2012/06/06 04:52:11
Is the load_flags parameter needed anymore? (since
Jói
2012/06/06 13:38:55
You're right, removed.
| |
| 97 virtual int64 ReserveSendingTimeForNextRequest( | 98 virtual int64 ReserveSendingTimeForNextRequest( |
| 98 const base::TimeTicks& earliest_time) OVERRIDE; | 99 const base::TimeTicks& earliest_time) OVERRIDE; |
| 99 virtual base::TimeTicks GetExponentialBackoffReleaseTime() const OVERRIDE; | 100 virtual base::TimeTicks GetExponentialBackoffReleaseTime() const OVERRIDE; |
| 100 virtual void UpdateWithResponse( | 101 virtual void UpdateWithResponse( |
| 101 const std::string& host, | 102 const std::string& host, |
| 102 const URLRequestThrottlerHeaderInterface* response) OVERRIDE; | 103 const URLRequestThrottlerHeaderInterface* response) OVERRIDE; |
| 103 virtual void ReceivedContentWasMalformed(int response_code) OVERRIDE; | 104 virtual void ReceivedContentWasMalformed(int response_code) OVERRIDE; |
| 104 | 105 |
| 105 protected: | 106 protected: |
| 106 virtual ~URLRequestThrottlerEntry(); | 107 virtual ~URLRequestThrottlerEntry(); |
| 107 | 108 |
| 108 void Initialize(); | 109 void Initialize(); |
| 109 | 110 |
| 110 // Returns true if the given response code is considered an error for | 111 // Returns true if the given response code is considered an error for |
| 111 // throttling purposes. | 112 // throttling purposes. |
| 112 bool IsConsideredError(int response_code); | 113 bool IsConsideredError(int response_code); |
| 113 | 114 |
| 114 // Equivalent to TimeTicks::Now(), virtual to be mockable for testing purpose. | 115 // Equivalent to TimeTicks::Now(), virtual to be mockable for testing purpose. |
| 115 virtual base::TimeTicks ImplGetTimeNow() const; | 116 virtual base::TimeTicks ImplGetTimeNow() const; |
| 116 | 117 |
| 117 // Used internally to handle the opt-out header. | 118 // Used internally to handle the opt-out header. |
| 118 void HandleThrottlingHeader(const std::string& header_value, | 119 void HandleThrottlingHeader(const std::string& header_value, |
| 119 const std::string& host); | 120 const std::string& host); |
| 120 | 121 |
| 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 | 122 // Retrieves the back-off entry object we're using. Used to enable a |
| 126 // unit testing seam for dependency injection in tests. | 123 // unit testing seam for dependency injection in tests. |
| 127 virtual const BackoffEntry* GetBackoffEntry() const; | 124 virtual const BackoffEntry* GetBackoffEntry() const; |
| 128 virtual BackoffEntry* GetBackoffEntry(); | 125 virtual BackoffEntry* GetBackoffEntry(); |
| 129 | 126 |
| 130 // Returns true if |load_flags| contains a flag that indicates an | 127 // Returns true if |load_flags| contains a flag that indicates an |
| 131 // explicit request by the user to load the resource. We never | 128 // explicit request by the user to load the resource. We never |
| 132 // throttle requests with such load flags. | 129 // throttle requests with such load flags. |
| 133 static bool ExplicitUserRequest(const int load_flags); | 130 static bool ExplicitUserRequest(const int load_flags); |
| 134 | 131 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 157 | 154 |
| 158 const base::TimeDelta sliding_window_period_; | 155 const base::TimeDelta sliding_window_period_; |
| 159 const int max_send_threshold_; | 156 const int max_send_threshold_; |
| 160 | 157 |
| 161 // True if DisableBackoffThrottling() has been called on this object. | 158 // True if DisableBackoffThrottling() has been called on this object. |
| 162 bool is_backoff_disabled_; | 159 bool is_backoff_disabled_; |
| 163 | 160 |
| 164 // Access it through GetBackoffEntry() to allow a unit test seam. | 161 // Access it through GetBackoffEntry() to allow a unit test seam. |
| 165 BackoffEntry backoff_entry_; | 162 BackoffEntry backoff_entry_; |
| 166 | 163 |
| 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. | 164 // Weak back-reference to the manager object managing us. |
| 177 URLRequestThrottlerManager* manager_; | 165 URLRequestThrottlerManager* manager_; |
| 178 | 166 |
| 179 // Canonicalized URL string that this entry is for; used for logging only. | 167 // Canonicalized URL string that this entry is for; used for logging only. |
| 180 std::string url_id_; | 168 std::string url_id_; |
| 181 | 169 |
| 182 BoundNetLog net_log_; | 170 BoundNetLog net_log_; |
| 183 | 171 |
| 184 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerEntry); | 172 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerEntry); |
| 185 }; | 173 }; |
| 186 | 174 |
| 187 } // namespace net | 175 } // namespace net |
| 188 | 176 |
| 189 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_H_ | 177 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_H_ |
| OLD | NEW |