| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> |
| 10 #include <string> | 11 #include <string> |
| 11 | 12 |
| 12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 13 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
| 14 #include "base/singleton.h" | 15 #include "base/singleton.h" |
| 15 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
| 16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 17 #include "net/url_request/url_request_throttler_entry.h" | 18 #include "net/url_request/url_request_throttler_entry.h" |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 35 public: | 36 public: |
| 36 static URLRequestThrottlerManager* GetInstance(); | 37 static URLRequestThrottlerManager* GetInstance(); |
| 37 | 38 |
| 38 // Must be called for every request, returns the URL request throttler entry | 39 // Must be called for every request, returns the URL request throttler entry |
| 39 // associated with the URL. The caller must inform this entry of some events. | 40 // associated with the URL. The caller must inform this entry of some events. |
| 40 // Please refer to url_request_throttler_entry_interface.h for further | 41 // Please refer to url_request_throttler_entry_interface.h for further |
| 41 // informations. | 42 // informations. |
| 42 scoped_refptr<URLRequestThrottlerEntryInterface> RegisterRequestUrl( | 43 scoped_refptr<URLRequestThrottlerEntryInterface> RegisterRequestUrl( |
| 43 const GURL& url); | 44 const GURL& url); |
| 44 | 45 |
| 46 // Adds the given host to a list of sites for which exponential back-off |
| 47 // throttling will be disabled. Subdomains are not included, so they |
| 48 // must be added separately. |
| 49 void AddToOptOutList(const std::string& host); |
| 50 |
| 45 // Registers a new entry in this service and overrides the existing entry (if | 51 // Registers a new entry in this service and overrides the existing entry (if |
| 46 // any) for the URL. The service will hold a reference to the entry. | 52 // any) for the URL. The service will hold a reference to the entry. |
| 47 // It is only used by unit tests. | 53 // It is only used by unit tests. |
| 48 void OverrideEntryForTests(const GURL& url, URLRequestThrottlerEntry* entry); | 54 void OverrideEntryForTests(const GURL& url, URLRequestThrottlerEntry* entry); |
| 49 | 55 |
| 50 // Explicitly erases an entry. | 56 // Explicitly erases an entry. |
| 51 // This is useful to remove those entries which have got infinite lifetime and | 57 // This is useful to remove those entries which have got infinite lifetime and |
| 52 // thus won't be garbage collected. | 58 // thus won't be garbage collected. |
| 53 // It is only used by unit tests. | 59 // It is only used by unit tests. |
| 54 void EraseEntryForTests(const GURL& url); | 60 void EraseEntryForTests(const GURL& url); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 int GetNumberOfEntriesForTests() const { return url_entries_.size(); } | 92 int GetNumberOfEntriesForTests() const { return url_entries_.size(); } |
| 87 | 93 |
| 88 private: | 94 private: |
| 89 friend struct DefaultSingletonTraits<URLRequestThrottlerManager>; | 95 friend struct DefaultSingletonTraits<URLRequestThrottlerManager>; |
| 90 | 96 |
| 91 // From each URL we generate an ID composed of the scheme, host, port and path | 97 // From each URL we generate an ID composed of the scheme, host, port and path |
| 92 // that allows us to uniquely map an entry to it. | 98 // that allows us to uniquely map an entry to it. |
| 93 typedef std::map<std::string, scoped_refptr<URLRequestThrottlerEntry> > | 99 typedef std::map<std::string, scoped_refptr<URLRequestThrottlerEntry> > |
| 94 UrlEntryMap; | 100 UrlEntryMap; |
| 95 | 101 |
| 102 // We maintain a set of hosts that have opted out of exponential |
| 103 // back-off throttling. |
| 104 typedef std::set<std::string> OptOutHosts; |
| 105 |
| 96 // Maximum number of entries that we are willing to collect in our map. | 106 // Maximum number of entries that we are willing to collect in our map. |
| 97 static const unsigned int kMaximumNumberOfEntries; | 107 static const unsigned int kMaximumNumberOfEntries; |
| 98 // Number of requests that will be made between garbage collection. | 108 // Number of requests that will be made between garbage collection. |
| 99 static const unsigned int kRequestsBetweenCollecting; | 109 static const unsigned int kRequestsBetweenCollecting; |
| 100 | 110 |
| 101 // Map that contains a list of URL ID and their matching | 111 // Map that contains a list of URL ID and their matching |
| 102 // URLRequestThrottlerEntry. | 112 // URLRequestThrottlerEntry. |
| 103 UrlEntryMap url_entries_; | 113 UrlEntryMap url_entries_; |
| 104 | 114 |
| 115 // Set of hosts that have opted out. |
| 116 OptOutHosts opt_out_hosts_; |
| 117 |
| 105 // This keeps track of how many requests have been made. Used with | 118 // This keeps track of how many requests have been made. Used with |
| 106 // GarbageCollectEntries. | 119 // GarbageCollectEntries. |
| 107 unsigned int requests_since_last_gc_; | 120 unsigned int requests_since_last_gc_; |
| 108 | 121 |
| 109 // Valid after construction. | 122 // Valid after construction. |
| 110 GURL::Replacements url_id_replacements_; | 123 GURL::Replacements url_id_replacements_; |
| 111 | 124 |
| 112 // Whether we would like to reject outgoing HTTP requests during the back-off | 125 // Whether we would like to reject outgoing HTTP requests during the back-off |
| 113 // period. | 126 // period. |
| 114 bool enforce_throttling_; | 127 bool enforce_throttling_; |
| 115 | 128 |
| 116 // Certain tests do not obey the net component's threading policy, so we | 129 // Certain tests do not obey the net component's threading policy, so we |
| 117 // keep track of whether we're being used by tests, and turn off certain | 130 // keep track of whether we're being used by tests, and turn off certain |
| 118 // checks. | 131 // checks. |
| 119 // | 132 // |
| 120 // TODO(joi): See if we can fix the offending unit tests and remove this | 133 // TODO(joi): See if we can fix the offending unit tests and remove this |
| 121 // workaround. | 134 // workaround. |
| 122 bool enable_thread_checks_; | 135 bool enable_thread_checks_; |
| 123 | 136 |
| 124 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerManager); | 137 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerManager); |
| 125 }; | 138 }; |
| 126 | 139 |
| 127 } // namespace net | 140 } // namespace net |
| 128 | 141 |
| 129 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ | 142 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ |
| OLD | NEW |