| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_REQUEST_THROTTLER_REQUEST_THROTTLER_ENTRY_H_ |
| 6 #define NET_REQUEST_THROTTLER_REQUEST_THROTTLER_ENTRY_H_ |
| 7 |
| 8 #include "net/request_throttler/request_throttler_entry_interface.h" |
| 9 |
| 10 #include <string> |
| 11 |
| 12 #include "base/ref_counted.h" |
| 13 #include "base/time.h" |
| 14 |
| 15 // Represents an entry of the Request Throttler Manager. |
| 16 class RequestThrottlerEntry : public RequestThrottlerEntryInterface { |
| 17 public: |
| 18 // Additional constant to adjust back-off. |
| 19 static const int kAdditionalConstantMs; |
| 20 |
| 21 // Time after which the entry is considered outdated. |
| 22 static const int kEntryLifetimeSec; |
| 23 |
| 24 // Fuzzing percentage. ex: 10% will spread requests randomly |
| 25 // between 90%-100% of the calculated time. |
| 26 static const double kJitterFactor; |
| 27 |
| 28 // Initial delay. |
| 29 static const int kInitialBackoffMs; |
| 30 |
| 31 // Maximum amount of time we are willing to delay our request. |
| 32 static const int kMaximumBackoffMs; |
| 33 |
| 34 // Factor by which the waiting time will be multiplied. |
| 35 static const double kMultiplyFactor; |
| 36 |
| 37 // Name of the header that servers can use to ask clients to delay their next |
| 38 // request. ex: "X-Retry-After" |
| 39 static const char kRetryHeaderName[]; |
| 40 |
| 41 RequestThrottlerEntry(); |
| 42 |
| 43 ////// Implementation of the Request throttler Interface. /////// |
| 44 |
| 45 // This method needs to be called prior to every request; if it returns |
| 46 // false, the calling module must cancel its current request. |
| 47 virtual bool IsRequestAllowed() const; |
| 48 |
| 49 // This method needs to be called each time a response is received. |
| 50 virtual void UpdateWithResponse( |
| 51 const RequestThrottlerHeaderInterface* response); |
| 52 |
| 53 ////////// Specific method of Request throttler Entry //////////////// |
| 54 |
| 55 // Used by the manager, returns if the entry needs to be garbage collected. |
| 56 bool IsEntryOutdated() const; |
| 57 |
| 58 // Used by the manager, enables the manager to flag the last successful |
| 59 // request as a failure. |
| 60 void ReceivedContentWasMalformed(); |
| 61 |
| 62 protected: |
| 63 |
| 64 // This struct is used to save the state of the entry each time we are updated |
| 65 // with a response header so we can regenerate it if we are informed that one |
| 66 // of our bodies was malformed. |
| 67 struct OldValues { |
| 68 base::TimeTicks release_time; |
| 69 int number_of_failed_requests; |
| 70 }; |
| 71 |
| 72 virtual ~RequestThrottlerEntry(); |
| 73 |
| 74 // Calculates when we should start sending requests again. Follows a failure |
| 75 // response. |
| 76 base::TimeTicks CalculateReleaseTime(); |
| 77 |
| 78 // Equivalent to TimeTicks::Now(), virtual to be mockable for testing purpose. |
| 79 virtual base::TimeTicks GetTimeNow() const; |
| 80 |
| 81 // Is used internally to increase release time following a retry-after header. |
| 82 void HandleCustomRetryAfter(const std::string& header_value); |
| 83 |
| 84 // Saves the state of the object to be able to regenerate it. |
| 85 // Must be informed of the state of the response. |
| 86 void SaveState(); |
| 87 |
| 88 // This contains the timestamp at which we are allowed to start sending |
| 89 // requests again. |
| 90 base::TimeTicks release_time_; |
| 91 |
| 92 // Number of times we were delayed. |
| 93 int num_times_delayed_; |
| 94 |
| 95 // Are we currently managing this request. |
| 96 bool is_managed_; |
| 97 |
| 98 OldValues old_values_; |
| 99 |
| 100 private: |
| 101 DISALLOW_COPY_AND_ASSIGN(RequestThrottlerEntry); |
| 102 }; |
| 103 |
| 104 #endif // NET_REQUEST_THROTTLER_REQUEST_THROTTLER_ENTRY_H_ |
| OLD | NEW |