Chromium Code Reviews| Index: net/request_throttler/request_throttler_entry.h |
| =================================================================== |
| --- net/request_throttler/request_throttler_entry.h (revision 0) |
| +++ net/request_throttler/request_throttler_entry.h (revision 0) |
| @@ -0,0 +1,142 @@ |
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef NET_REQUEST_THROTTLER_REQUEST_THROTTLER_ENTRY_H_ |
| +#define NET_REQUEST_THROTTLER_REQUEST_THROTTLER_ENTRY_H_ |
| + |
| +#include "net/request_throttler/request_throttler_entry_interface.h" |
| + |
| +#include <queue> |
| +#include <string> |
| + |
| +#include "base/lock.h" |
| + |
| +// Represents an entry of the Request Throttler Manager. |
| +class RequestThrottlerEntry : public RequestThrottlerEntryInterface { |
| + public: |
| + // Sliding window period. |
| + static const int kDefaultSlidingWindowPeriodMs; |
| + |
| + // Maximum number of requests allowed in sliding window period. |
| + static const int kDefaultMaxSendThreshold; |
| + |
| + // Initial delay. |
| + static const int kDefaultInitialBackoffMs; |
| + |
| + // Additional constant to adjust back-off. |
| + static const int kDefaultAdditionalConstantMs; |
| + |
| + // Factor by which the waiting time will be multiplied. |
| + static const double kDefaultMultiplyFactor; |
| + |
| + // Fuzzing percentage. ex: 10% will spread requests randomly |
| + // between 90%-100% of the calculated time. |
| + static const double kDefaultJitterFactor; |
| + |
| + // Maximum amount of time we are willing to delay our request. |
| + static const int kDefaultMaximumBackoffMs; |
| + |
| + // Time after which the entry is considered outdated. |
| + static const int kDefaultEntryLifetimeMs; |
| + |
| + // Name of the header that servers can use to ask clients to delay their next |
| + // request. ex: "X-Retry-After" |
|
Jói
2010/11/12 00:12:08
Suggest removing the example name.
yzshen
2010/11/12 02:05:46
Done.
|
| + static const char kRetryHeaderName[]; |
| + |
| + RequestThrottlerEntry(); |
| + |
| + // It is used by unit tests. |
| + RequestThrottlerEntry(int sliding_window_period_ms, |
| + int max_send_threshold, |
| + int initial_backoff_ms, |
| + int additional_constant_ms, |
| + double multiply_factor, |
| + double jitter_factor, |
| + int maximum_backoff_ms, |
| + int entry_lifetime_ms); |
| + |
| + ////// Implementation of RequestThrottlerEntryInterface /////// |
| + |
| + // This method needs to be called prior to every request; if it returns |
| + // false, the calling module must cancel its current request. |
| + virtual bool IsRequestAllowed() const; |
| + |
| + // This method needs to be called each time a response is received. |
| + virtual void UpdateWithResponse( |
| + const RequestThrottlerHeaderInterface* response); |
| + |
| + // This method needs to be called each time when a request is actually sent. |
| + void NotifyRequestStart(); |
| + |
| + ////////// Specific methods of RequestThrottlerEntry //////////////// |
| + |
| + // Used by the manager, returns if the entry needs to be garbage collected. |
| + bool IsEntryOutdated() const; |
| + |
| + // Used by the manager, enables the manager to flag the last successful |
| + // request as a failure. |
| + void ReceivedContentWasMalformed(); |
| + |
| + base::TimeTicks release_time() const; |
| + |
| + protected: |
| + // This struct is used to save the state of the entry each time we are updated |
| + // with a response header so we can regenerate it if we are informed that one |
| + // of our bodies was malformed. |
| + struct OldValues { |
| + base::TimeTicks release_time; |
| + int number_of_failed_requests; |
| + }; |
| + |
| + virtual ~RequestThrottlerEntry(); |
| + |
| + void Initialize(); |
| + |
| + // Calculates when we should start sending requests again. Follows a failure |
| + // response. |
| + base::TimeTicks CalculateReleaseTime(); |
| + |
| + // Equivalent to TimeTicks::Now(), virtual to be mockable for testing purpose. |
| + virtual base::TimeTicks GetTimeNow() const; |
| + |
| + // Used internally to increase release time following a retry-after header. |
| + void HandleCustomRetryAfter(const std::string& header_value); |
| + |
| + // Saves the state of the object to be able to regenerate it. |
| + // Must be informed of the state of the response. |
| + void SaveState(); |
| + |
| + // This contains the timestamp at which we are allowed to start sending |
| + // requests again. |
| + base::TimeTicks release_time_; |
| + |
| + // Number of times we were delayed. |
| + int num_times_delayed_; |
| + |
| + // Are we currently managing this request. |
| + bool is_managed_; |
| + |
| + OldValues old_values_; |
| + |
| + // A list of the recent send events. We use them to decide whether there are |
|
joi
2010/11/09 20:07:17
I haven't looked in detail yet, but if I understan
yzshen
2010/11/09 22:32:22
Yes, that is how it works.
|
| + // too many requests sent in sliding window. |
| + std::queue<base::TimeTicks> send_log_; |
| + |
| + const int sliding_window_period_ms_; |
| + const int max_send_threshold_; |
| + const int initial_backoff_ms_; |
| + const int additional_constant_ms_; |
| + const double multiply_factor_; |
| + const double jitter_factor_; |
| + const int maximum_backoff_ms_; |
| + const int entry_lifetime_ms_; |
| + |
| + // Lock to protect the non-static data members. |
| + mutable Lock lock_; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(RequestThrottlerEntry); |
| +}; |
| + |
| +#endif // NET_REQUEST_THROTTLER_REQUEST_THROTTLER_ENTRY_H_ |
| Property changes on: net\request_throttler\request_throttler_entry.h |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |