| 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 #include "net/url_request/url_request_throttler_manager.h" | 5 #include "net/url_request/url_request_throttler_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "net/base/url_util.h" | 9 #include "net/base/url_util.h" |
| 10 #include "net/log/net_log.h" | 10 #include "net/log/net_log.h" |
| 11 #include "net/log/net_log_event_type.h" |
| 12 #include "net/log/net_log_source_type.h" |
| 11 | 13 |
| 12 namespace net { | 14 namespace net { |
| 13 | 15 |
| 14 const unsigned int URLRequestThrottlerManager::kMaximumNumberOfEntries = 1500; | 16 const unsigned int URLRequestThrottlerManager::kMaximumNumberOfEntries = 1500; |
| 15 const unsigned int URLRequestThrottlerManager::kRequestsBetweenCollecting = 200; | 17 const unsigned int URLRequestThrottlerManager::kRequestsBetweenCollecting = 200; |
| 16 | 18 |
| 17 URLRequestThrottlerManager::URLRequestThrottlerManager() | 19 URLRequestThrottlerManager::URLRequestThrottlerManager() |
| 18 : requests_since_last_gc_(0), | 20 : requests_since_last_gc_(0), |
| 19 enable_thread_checks_(false), | 21 enable_thread_checks_(false), |
| 20 logged_for_localhost_disabled_(false), | 22 logged_for_localhost_disabled_(false), |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 if (entry.get() == NULL) { | 73 if (entry.get() == NULL) { |
| 72 entry = new URLRequestThrottlerEntry(this, url_id); | 74 entry = new URLRequestThrottlerEntry(this, url_id); |
| 73 | 75 |
| 74 // We only disable back-off throttling on an entry that we have | 76 // We only disable back-off throttling on an entry that we have |
| 75 // just constructed. This is to allow unit tests to explicitly override | 77 // just constructed. This is to allow unit tests to explicitly override |
| 76 // the entry for localhost URLs. | 78 // the entry for localhost URLs. |
| 77 std::string host = url.host(); | 79 std::string host = url.host(); |
| 78 if (IsLocalhost(host)) { | 80 if (IsLocalhost(host)) { |
| 79 if (!logged_for_localhost_disabled_ && IsLocalhost(host)) { | 81 if (!logged_for_localhost_disabled_ && IsLocalhost(host)) { |
| 80 logged_for_localhost_disabled_ = true; | 82 logged_for_localhost_disabled_ = true; |
| 81 net_log_.AddEvent(NetLog::TYPE_THROTTLING_DISABLED_FOR_HOST, | 83 net_log_.AddEvent(NetLogEventType::THROTTLING_DISABLED_FOR_HOST, |
| 82 NetLog::StringCallback("host", &host)); | 84 NetLog::StringCallback("host", &host)); |
| 83 } | 85 } |
| 84 | 86 |
| 85 // TODO(joi): Once sliding window is separate from back-off throttling, | 87 // TODO(joi): Once sliding window is separate from back-off throttling, |
| 86 // we can simply return a dummy implementation of | 88 // we can simply return a dummy implementation of |
| 87 // URLRequestThrottlerEntryInterface here that never blocks anything. | 89 // URLRequestThrottlerEntryInterface here that never blocks anything. |
| 88 entry->DisableBackoffThrottling(); | 90 entry->DisableBackoffThrottling(); |
| 89 } | 91 } |
| 90 } | 92 } |
| 91 | 93 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 114 enable_thread_checks_ = enable; | 116 enable_thread_checks_ = enable; |
| 115 } | 117 } |
| 116 | 118 |
| 117 bool URLRequestThrottlerManager::enable_thread_checks() const { | 119 bool URLRequestThrottlerManager::enable_thread_checks() const { |
| 118 return enable_thread_checks_; | 120 return enable_thread_checks_; |
| 119 } | 121 } |
| 120 | 122 |
| 121 void URLRequestThrottlerManager::set_net_log(NetLog* net_log) { | 123 void URLRequestThrottlerManager::set_net_log(NetLog* net_log) { |
| 122 DCHECK(net_log); | 124 DCHECK(net_log); |
| 123 net_log_ = BoundNetLog::Make(net_log, | 125 net_log_ = BoundNetLog::Make(net_log, |
| 124 NetLog::SOURCE_EXPONENTIAL_BACKOFF_THROTTLING); | 126 NetLogSourceType::EXPONENTIAL_BACKOFF_THROTTLING); |
| 125 } | 127 } |
| 126 | 128 |
| 127 NetLog* URLRequestThrottlerManager::net_log() const { | 129 NetLog* URLRequestThrottlerManager::net_log() const { |
| 128 return net_log_.net_log(); | 130 return net_log_.net_log(); |
| 129 } | 131 } |
| 130 | 132 |
| 131 void URLRequestThrottlerManager::OnIPAddressChanged() { | 133 void URLRequestThrottlerManager::OnIPAddressChanged() { |
| 132 OnNetworkChange(); | 134 OnNetworkChange(); |
| 133 } | 135 } |
| 134 | 136 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 void URLRequestThrottlerManager::OnNetworkChange() { | 175 void URLRequestThrottlerManager::OnNetworkChange() { |
| 174 // Remove all entries. Any entries that in-flight requests have a reference | 176 // Remove all entries. Any entries that in-flight requests have a reference |
| 175 // to will live until those requests end, and these entries may be | 177 // to will live until those requests end, and these entries may be |
| 176 // inconsistent with new entries for the same URLs, but since what we | 178 // inconsistent with new entries for the same URLs, but since what we |
| 177 // want is a clean slate for the new connection type, this is OK. | 179 // want is a clean slate for the new connection type, this is OK. |
| 178 url_entries_.clear(); | 180 url_entries_.clear(); |
| 179 requests_since_last_gc_ = 0; | 181 requests_since_last_gc_ = 0; |
| 180 } | 182 } |
| 181 | 183 |
| 182 } // namespace net | 184 } // namespace net |
| OLD | NEW |