| 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/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "net/base/net_log.h" | 11 #include "net/base/net_log.h" |
| 12 #include "net/base/net_util.h" | 12 #include "net/base/net_util.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 const unsigned int URLRequestThrottlerManager::kMaximumNumberOfEntries = 1500; | 16 const unsigned int URLRequestThrottlerManager::kMaximumNumberOfEntries = 1500; |
| 17 const unsigned int URLRequestThrottlerManager::kRequestsBetweenCollecting = 200; | 17 const unsigned int URLRequestThrottlerManager::kRequestsBetweenCollecting = 200; |
| 18 | 18 |
| 19 URLRequestThrottlerManager::URLRequestThrottlerManager() | 19 URLRequestThrottlerManager::URLRequestThrottlerManager( |
| 20 URLRequestThrottlerManagerDelegate* delegate) |
| 20 : requests_since_last_gc_(0), | 21 : requests_since_last_gc_(0), |
| 21 enforce_throttling_(true), | |
| 22 enable_thread_checks_(false), | 22 enable_thread_checks_(false), |
| 23 logged_for_localhost_disabled_(false), | 23 logged_for_localhost_disabled_(false), |
| 24 registered_from_thread_(base::kInvalidThreadId) { | 24 registered_from_thread_(base::kInvalidThreadId), |
| 25 delegate_(delegate) { |
| 25 url_id_replacements_.ClearPassword(); | 26 url_id_replacements_.ClearPassword(); |
| 26 url_id_replacements_.ClearUsername(); | 27 url_id_replacements_.ClearUsername(); |
| 27 url_id_replacements_.ClearQuery(); | 28 url_id_replacements_.ClearQuery(); |
| 28 url_id_replacements_.ClearRef(); | 29 url_id_replacements_.ClearRef(); |
| 29 | 30 |
| 30 NetworkChangeNotifier::AddIPAddressObserver(this); | 31 NetworkChangeNotifier::AddIPAddressObserver(this); |
| 31 NetworkChangeNotifier::AddConnectionTypeObserver(this); | 32 NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 32 } | 33 } |
| 33 | 34 |
| 34 URLRequestThrottlerManager::~URLRequestThrottlerManager() { | 35 URLRequestThrottlerManager::~URLRequestThrottlerManager() { |
| 35 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 36 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 36 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 37 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 37 | 38 |
| 38 // Since, for now, the manager object might conceivably go away before | 39 // Since the manager object might conceivably go away before the |
| 39 // the entries, detach the entries' back-pointer to the manager. | 40 // entries, detach the entries' back-pointer to the manager. |
| 40 // | |
| 41 // TODO(joi): Revisit whether to make entries non-refcounted. | |
| 42 UrlEntryMap::iterator i = url_entries_.begin(); | 41 UrlEntryMap::iterator i = url_entries_.begin(); |
| 43 while (i != url_entries_.end()) { | 42 while (i != url_entries_.end()) { |
| 44 if (i->second != NULL) { | 43 if (i->second != NULL) { |
| 45 i->second->DetachManager(); | 44 i->second->DetachManager(); |
| 46 } | 45 } |
| 47 ++i; | 46 ++i; |
| 48 } | 47 } |
| 49 | 48 |
| 50 // Delete all entries. | 49 // Delete all entries. |
| 51 url_entries_.clear(); | 50 url_entries_.clear(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 } | 136 } |
| 138 | 137 |
| 139 void URLRequestThrottlerManager::set_enable_thread_checks(bool enable) { | 138 void URLRequestThrottlerManager::set_enable_thread_checks(bool enable) { |
| 140 enable_thread_checks_ = enable; | 139 enable_thread_checks_ = enable; |
| 141 } | 140 } |
| 142 | 141 |
| 143 bool URLRequestThrottlerManager::enable_thread_checks() const { | 142 bool URLRequestThrottlerManager::enable_thread_checks() const { |
| 144 return enable_thread_checks_; | 143 return enable_thread_checks_; |
| 145 } | 144 } |
| 146 | 145 |
| 147 void URLRequestThrottlerManager::set_enforce_throttling(bool enforce) { | |
| 148 enforce_throttling_ = enforce; | |
| 149 } | |
| 150 | |
| 151 bool URLRequestThrottlerManager::enforce_throttling() { | |
| 152 return enforce_throttling_; | |
| 153 } | |
| 154 | |
| 155 void URLRequestThrottlerManager::set_net_log(NetLog* net_log) { | 146 void URLRequestThrottlerManager::set_net_log(NetLog* net_log) { |
| 156 DCHECK(net_log); | 147 DCHECK(net_log); |
| 157 net_log_ = BoundNetLog::Make(net_log, | 148 net_log_ = BoundNetLog::Make(net_log, |
| 158 NetLog::SOURCE_EXPONENTIAL_BACKOFF_THROTTLING); | 149 NetLog::SOURCE_EXPONENTIAL_BACKOFF_THROTTLING); |
| 159 } | 150 } |
| 160 | 151 |
| 161 NetLog* URLRequestThrottlerManager::net_log() const { | 152 NetLog* URLRequestThrottlerManager::net_log() const { |
| 162 return net_log_.net_log(); | 153 return net_log_.net_log(); |
| 163 } | 154 } |
| 164 | 155 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 void URLRequestThrottlerManager::OnNetworkChange() { | 198 void URLRequestThrottlerManager::OnNetworkChange() { |
| 208 // Remove all entries. Any entries that in-flight requests have a reference | 199 // Remove all entries. Any entries that in-flight requests have a reference |
| 209 // to will live until those requests end, and these entries may be | 200 // to will live until those requests end, and these entries may be |
| 210 // inconsistent with new entries for the same URLs, but since what we | 201 // inconsistent with new entries for the same URLs, but since what we |
| 211 // want is a clean slate for the new connection type, this is OK. | 202 // want is a clean slate for the new connection type, this is OK. |
| 212 url_entries_.clear(); | 203 url_entries_.clear(); |
| 213 requests_since_last_gc_ = 0; | 204 requests_since_last_gc_ = 0; |
| 214 } | 205 } |
| 215 | 206 |
| 216 } // namespace net | 207 } // namespace net |
| OLD | NEW |