| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // This file implements backoff in the suggest system so that we don't | 5 // This file implements backoff in the suggest system so that we don't |
| 6 // DOS the Suggest servers when using URLFetcher. | 6 // DOS the Suggest servers when using URLFetcher. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_URL_FETCHER_PROTECT_H__ | 8 #ifndef CHROME_BROWSER_URL_FETCHER_PROTECT_H__ |
| 9 #define CHROME_BROWSER_URL_FETCHER_PROTECT_H__ | 9 #define CHROME_BROWSER_URL_FETCHER_PROTECT_H__ |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 int UpdateBackoff(EventType event_type); | 57 int UpdateBackoff(EventType event_type); |
| 58 | 58 |
| 59 // Returns the max retries allowed. | 59 // Returns the max retries allowed. |
| 60 int max_retries() const { | 60 int max_retries() const { |
| 61 return max_retries_; | 61 return max_retries_; |
| 62 } | 62 } |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 // When a request comes, calculate the release time for it. | 65 // When a request comes, calculate the release time for it. |
| 66 // Returns the backoff time before sending. | 66 // Returns the backoff time before sending. |
| 67 TimeDelta AntiOverload(); | 67 base::TimeDelta AntiOverload(); |
| 68 // Resets backoff when service is ok. | 68 // Resets backoff when service is ok. |
| 69 // Returns the backoff time before sending. | 69 // Returns the backoff time before sending. |
| 70 TimeDelta ResetBackoff(); | 70 base::TimeDelta ResetBackoff(); |
| 71 // Calculates new backoff when encountering a failure. | 71 // Calculates new backoff when encountering a failure. |
| 72 // Returns the backoff time before sending. | 72 // Returns the backoff time before sending. |
| 73 TimeDelta IncreaseBackoff(); | 73 base::TimeDelta IncreaseBackoff(); |
| 74 | 74 |
| 75 // Default parameters. Time is in milliseconds. | 75 // Default parameters. Time is in milliseconds. |
| 76 static const int kDefaultSlidingWindowPeriod; | 76 static const int kDefaultSlidingWindowPeriod; |
| 77 static const int kDefaultMaxSendThreshold; | 77 static const int kDefaultMaxSendThreshold; |
| 78 static const int kDefaultMaxRetries; | 78 static const int kDefaultMaxRetries; |
| 79 static const int kDefaultInitialTimeout; | 79 static const int kDefaultInitialTimeout; |
| 80 static const double kDefaultMultiplier; | 80 static const double kDefaultMultiplier; |
| 81 static const int kDefaultConstantFactor; | 81 static const int kDefaultConstantFactor; |
| 82 static const int kDefaultMaximumTimeout; | 82 static const int kDefaultMaximumTimeout; |
| 83 | 83 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 94 // factor by which to multiply on exponential backoff (e.g., 2.0) | 94 // factor by which to multiply on exponential backoff (e.g., 2.0) |
| 95 double multiplier_; | 95 double multiplier_; |
| 96 // constant time term to add to each attempt | 96 // constant time term to add to each attempt |
| 97 int constant_factor_; | 97 int constant_factor_; |
| 98 // maximum amount of time between requests | 98 // maximum amount of time between requests |
| 99 int maximum_timeout_; | 99 int maximum_timeout_; |
| 100 | 100 |
| 101 // current exponential backoff period | 101 // current exponential backoff period |
| 102 int timeout_period_; | 102 int timeout_period_; |
| 103 // time that protection is scheduled to end | 103 // time that protection is scheduled to end |
| 104 TimeTicks release_time_; | 104 base::TimeTicks release_time_; |
| 105 | 105 |
| 106 // Sets up a lock to ensure thread safe. | 106 // Sets up a lock to ensure thread safe. |
| 107 Lock lock_; | 107 Lock lock_; |
| 108 | 108 |
| 109 // A list of the recent send events. We ues them to decide whether | 109 // A list of the recent send events. We ues them to decide whether |
| 110 // there are too many requests sent in sliding window. | 110 // there are too many requests sent in sliding window. |
| 111 std::queue<TimeTicks> send_log_; | 111 std::queue<base::TimeTicks> send_log_; |
| 112 | 112 |
| 113 DISALLOW_COPY_AND_ASSIGN(URLFetcherProtectEntry); | 113 DISALLOW_COPY_AND_ASSIGN(URLFetcherProtectEntry); |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 | 116 |
| 117 // This singleton class is used to manage all protect entries. | 117 // This singleton class is used to manage all protect entries. |
| 118 // Now we use the host name as service id. | 118 // Now we use the host name as service id. |
| 119 class URLFetcherProtectManager { | 119 class URLFetcherProtectManager { |
| 120 public: | 120 public: |
| 121 ~URLFetcherProtectManager(); | 121 ~URLFetcherProtectManager(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 136 typedef std::map<const std::string, URLFetcherProtectEntry*> ProtectService; | 136 typedef std::map<const std::string, URLFetcherProtectEntry*> ProtectService; |
| 137 | 137 |
| 138 static Lock lock_; | 138 static Lock lock_; |
| 139 static scoped_ptr<URLFetcherProtectManager> protect_manager_; | 139 static scoped_ptr<URLFetcherProtectManager> protect_manager_; |
| 140 ProtectService services_; | 140 ProtectService services_; |
| 141 | 141 |
| 142 DISALLOW_COPY_AND_ASSIGN(URLFetcherProtectManager); | 142 DISALLOW_COPY_AND_ASSIGN(URLFetcherProtectManager); |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 #endif // CHROME_BROWSER_URL_FETCHER_PROTECT_H__ | 145 #endif // CHROME_BROWSER_URL_FETCHER_PROTECT_H__ |
| OLD | NEW |