| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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_MANAGER_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ |
| 6 #define NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 // any) for the URL. The service will hold a reference to the entry. | 42 // any) for the URL. The service will hold a reference to the entry. |
| 43 // It is only used by unit tests. | 43 // It is only used by unit tests. |
| 44 void OverrideEntryForTests(const GURL& url, URLRequestThrottlerEntry* entry); | 44 void OverrideEntryForTests(const GURL& url, URLRequestThrottlerEntry* entry); |
| 45 | 45 |
| 46 // Explicitly erases an entry. | 46 // Explicitly erases an entry. |
| 47 // This is useful to remove those entries which have got infinite lifetime and | 47 // This is useful to remove those entries which have got infinite lifetime and |
| 48 // thus won't be garbage collected. | 48 // thus won't be garbage collected. |
| 49 // It is only used by unit tests. | 49 // It is only used by unit tests. |
| 50 void EraseEntryForTests(const GURL& url); | 50 void EraseEntryForTests(const GURL& url); |
| 51 | 51 |
| 52 void set_enforce_throttling(bool enforce_throttling) { |
| 53 enforce_throttling_ = enforce_throttling; |
| 54 } |
| 55 |
| 56 bool enforce_throttling() const { return enforce_throttling_; } |
| 57 |
| 52 protected: | 58 protected: |
| 53 URLRequestThrottlerManager(); | 59 URLRequestThrottlerManager(); |
| 54 ~URLRequestThrottlerManager(); | 60 ~URLRequestThrottlerManager(); |
| 55 | 61 |
| 56 // Method that allows us to transform a URL into an ID that can be used in our | 62 // Method that allows us to transform a URL into an ID that can be used in our |
| 57 // map. Resulting IDs will be lowercase and consist of the scheme, host, port | 63 // map. Resulting IDs will be lowercase and consist of the scheme, host, port |
| 58 // and path (without query string, fragment, etc.). | 64 // and path (without query string, fragment, etc.). |
| 59 // If the URL is invalid, the invalid spec will be returned, without any | 65 // If the URL is invalid, the invalid spec will be returned, without any |
| 60 // transformation. | 66 // transformation. |
| 61 std::string GetIdFromUrl(const GURL& url) const; | 67 std::string GetIdFromUrl(const GURL& url) const; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 86 // Map that contains a list of URL ID and their matching | 92 // Map that contains a list of URL ID and their matching |
| 87 // URLRequestThrottlerEntry. | 93 // URLRequestThrottlerEntry. |
| 88 UrlEntryMap url_entries_; | 94 UrlEntryMap url_entries_; |
| 89 | 95 |
| 90 // This keeps track of how many requests have been made. Used with | 96 // This keeps track of how many requests have been made. Used with |
| 91 // GarbageCollectEntries. | 97 // GarbageCollectEntries. |
| 92 unsigned int requests_since_last_gc_; | 98 unsigned int requests_since_last_gc_; |
| 93 | 99 |
| 94 mutable scoped_ptr<GURL::Replacements> url_id_replacements_; | 100 mutable scoped_ptr<GURL::Replacements> url_id_replacements_; |
| 95 | 101 |
| 102 // Whether we would like to reject outgoing HTTP requests during the back-off |
| 103 // period. |
| 104 bool enforce_throttling_; |
| 105 |
| 96 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerManager); | 106 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerManager); |
| 97 }; | 107 }; |
| 98 | 108 |
| 99 } // namespace net | 109 } // namespace net |
| 100 | 110 |
| 101 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ | 111 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ |
| OLD | NEW |