Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 // in order to supervise traffic. URL requests for HTTP contents should | 27 // in order to supervise traffic. URL requests for HTTP contents should |
| 28 // register their URLs in this manager on each request. | 28 // register their URLs in this manager on each request. |
| 29 // | 29 // |
| 30 // URLRequestThrottlerManager maintains a map of URL IDs to URL request | 30 // URLRequestThrottlerManager maintains a map of URL IDs to URL request |
| 31 // throttler entries. It creates URL request throttler entries when new URLs | 31 // throttler entries. It creates URL request throttler entries when new URLs |
| 32 // are registered, and does garbage collection from time to time in order to | 32 // are registered, and does garbage collection from time to time in order to |
| 33 // clean out outdated entries. URL ID consists of lowercased scheme, host, port | 33 // clean out outdated entries. URL ID consists of lowercased scheme, host, port |
| 34 // and path. All URLs converted to the same ID will share the same entry. | 34 // and path. All URLs converted to the same ID will share the same entry. |
| 35 class NET_EXPORT URLRequestThrottlerManager | 35 class NET_EXPORT URLRequestThrottlerManager |
| 36 : NON_EXPORTED_BASE(public base::NonThreadSafe), | 36 : NON_EXPORTED_BASE(public base::NonThreadSafe), |
| 37 public NetworkChangeNotifier::IPAddressObserver, | 37 public NetworkChangeNotifier::NetworkChangeObserver { |
| 38 public NetworkChangeNotifier::ConnectionTypeObserver { | |
| 39 public: | 38 public: |
| 40 URLRequestThrottlerManager(); | 39 URLRequestThrottlerManager(); |
| 41 virtual ~URLRequestThrottlerManager(); | 40 virtual ~URLRequestThrottlerManager(); |
| 42 | 41 |
| 43 // Must be called for every request, returns the URL request throttler entry | 42 // Must be called for every request, returns the URL request throttler entry |
| 44 // associated with the URL. The caller must inform this entry of some events. | 43 // associated with the URL. The caller must inform this entry of some events. |
| 45 // Please refer to url_request_throttler_entry_interface.h for further | 44 // Please refer to url_request_throttler_entry_interface.h for further |
| 46 // informations. | 45 // informations. |
| 47 scoped_refptr<URLRequestThrottlerEntryInterface> RegisterRequestUrl( | 46 scoped_refptr<URLRequestThrottlerEntryInterface> RegisterRequestUrl( |
| 48 const GURL& url); | 47 const GURL& url); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 70 bool enable_thread_checks() const; | 69 bool enable_thread_checks() const; |
| 71 | 70 |
| 72 // Whether throttling is enabled or not. | 71 // Whether throttling is enabled or not. |
| 73 void set_enforce_throttling(bool enforce); | 72 void set_enforce_throttling(bool enforce); |
| 74 bool enforce_throttling(); | 73 bool enforce_throttling(); |
| 75 | 74 |
| 76 // Sets the NetLog instance to use. | 75 // Sets the NetLog instance to use. |
| 77 void set_net_log(NetLog* net_log); | 76 void set_net_log(NetLog* net_log); |
| 78 NetLog* net_log() const; | 77 NetLog* net_log() const; |
| 79 | 78 |
| 80 // IPAddressObserver interface. | 79 // NetworkChangeNotifier::NetworkChangeObserver interface. |
| 81 virtual void OnIPAddressChanged() OVERRIDE; | 80 // When we switch from online to offline or change IP addresses, we |
| 82 | 81 // clear all back-off history. This is a precaution in case the change in |
| 83 // ConnectionTypeObserver interface. | 82 // online state now lets us communicate without error with servers that |
| 84 virtual void OnConnectionTypeChanged( | 83 // we were previously getting 500 or 503 responses from (perhaps the |
| 84 // responses are from a badly-written proxy that should have returned a | |
| 85 // 502 or 504 because it's upstream connection was down or it had no route | |
| 86 // to the server). | |
| 87 virtual void OnNetworkChanged( | |
|
szym
2013/01/20 06:52:08
You should keep the orders of declarations and def
| |
| 85 NetworkChangeNotifier::ConnectionType type) OVERRIDE; | 88 NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 86 | 89 |
| 87 // Method that allows us to transform a URL into an ID that can be used in our | 90 // Method that allows us to transform a URL into an ID that can be used in our |
| 88 // map. Resulting IDs will be lowercase and consist of the scheme, host, port | 91 // map. Resulting IDs will be lowercase and consist of the scheme, host, port |
| 89 // and path (without query string, fragment, etc.). | 92 // and path (without query string, fragment, etc.). |
| 90 // If the URL is invalid, the invalid spec will be returned, without any | 93 // If the URL is invalid, the invalid spec will be returned, without any |
| 91 // transformation. | 94 // transformation. |
| 92 std::string GetIdFromUrl(const GURL& url) const; | 95 std::string GetIdFromUrl(const GURL& url) const; |
| 93 | 96 |
| 94 // Method that ensures the map gets cleaned from time to time. The period at | 97 // Method that ensures the map gets cleaned from time to time. The period at |
| 95 // which garbage collecting happens is adjustable with the | 98 // which garbage collecting happens is adjustable with the |
| 96 // kRequestBetweenCollecting constant. | 99 // kRequestBetweenCollecting constant. |
| 97 void GarbageCollectEntriesIfNecessary(); | 100 void GarbageCollectEntriesIfNecessary(); |
| 98 | 101 |
| 99 // Method that does the actual work of garbage collecting. | 102 // Method that does the actual work of garbage collecting. |
| 100 void GarbageCollectEntries(); | 103 void GarbageCollectEntries(); |
| 101 | 104 |
| 102 // When we switch from online to offline or change IP addresses, we | |
| 103 // clear all back-off history. This is a precaution in case the change in | |
| 104 // online state now lets us communicate without error with servers that | |
| 105 // we were previously getting 500 or 503 responses from (perhaps the | |
| 106 // responses are from a badly-written proxy that should have returned a | |
| 107 // 502 or 504 because it's upstream connection was down or it had no route | |
| 108 // to the server). | |
| 109 void OnNetworkChange(); | |
| 110 | |
| 111 // Used by tests. | 105 // Used by tests. |
| 112 int GetNumberOfEntriesForTests() const { return url_entries_.size(); } | 106 int GetNumberOfEntriesForTests() const { return url_entries_.size(); } |
| 113 | 107 |
| 114 private: | 108 private: |
| 115 // From each URL we generate an ID composed of the scheme, host, port and path | 109 // From each URL we generate an ID composed of the scheme, host, port and path |
| 116 // that allows us to uniquely map an entry to it. | 110 // that allows us to uniquely map an entry to it. |
| 117 typedef std::map<std::string, scoped_refptr<URLRequestThrottlerEntry> > | 111 typedef std::map<std::string, scoped_refptr<URLRequestThrottlerEntry> > |
| 118 UrlEntryMap; | 112 UrlEntryMap; |
| 119 | 113 |
| 120 // We maintain a set of hosts that have opted out of exponential | 114 // We maintain a set of hosts that have opted out of exponential |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 | 151 |
| 158 // Valid once we've registered for network notifications. | 152 // Valid once we've registered for network notifications. |
| 159 base::PlatformThreadId registered_from_thread_; | 153 base::PlatformThreadId registered_from_thread_; |
| 160 | 154 |
| 161 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerManager); | 155 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerManager); |
| 162 }; | 156 }; |
| 163 | 157 |
| 164 } // namespace net | 158 } // namespace net |
| 165 | 159 |
| 166 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ | 160 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ |
| OLD | NEW |