| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 enforce_throttling_(true), | 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 url_id_replacements_.ClearPassword(); | 25 url_id_replacements_.ClearPassword(); |
| 26 url_id_replacements_.ClearUsername(); | 26 url_id_replacements_.ClearUsername(); |
| 27 url_id_replacements_.ClearQuery(); | 27 url_id_replacements_.ClearQuery(); |
| 28 url_id_replacements_.ClearRef(); | 28 url_id_replacements_.ClearRef(); |
| 29 | 29 |
| 30 NetworkChangeNotifier::AddIPAddressObserver(this); | 30 NetworkChangeNotifier::AddIPAddressObserver(this); |
| 31 NetworkChangeNotifier::AddOnlineStateObserver(this); | 31 NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 32 } | 32 } |
| 33 | 33 |
| 34 URLRequestThrottlerManager::~URLRequestThrottlerManager() { | 34 URLRequestThrottlerManager::~URLRequestThrottlerManager() { |
| 35 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 35 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 36 NetworkChangeNotifier::RemoveOnlineStateObserver(this); | 36 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 37 | 37 |
| 38 // Since, for now, the manager object might conceivably go away before | 38 // Since, for now, the manager object might conceivably go away before |
| 39 // the entries, detach the entries' back-pointer to the manager. | 39 // the entries, detach the entries' back-pointer to the manager. |
| 40 // | 40 // |
| 41 // TODO(joi): Revisit whether to make entries non-refcounted. | 41 // TODO(joi): Revisit whether to make entries non-refcounted. |
| 42 UrlEntryMap::iterator i = url_entries_.begin(); | 42 UrlEntryMap::iterator i = url_entries_.begin(); |
| 43 while (i != url_entries_.end()) { | 43 while (i != url_entries_.end()) { |
| 44 if (i->second != NULL) { | 44 if (i->second != NULL) { |
| 45 i->second->DetachManager(); | 45 i->second->DetachManager(); |
| 46 } | 46 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 159 } |
| 160 | 160 |
| 161 NetLog* URLRequestThrottlerManager::net_log() const { | 161 NetLog* URLRequestThrottlerManager::net_log() const { |
| 162 return net_log_.net_log(); | 162 return net_log_.net_log(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void URLRequestThrottlerManager::OnIPAddressChanged() { | 165 void URLRequestThrottlerManager::OnIPAddressChanged() { |
| 166 OnNetworkChange(); | 166 OnNetworkChange(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void URLRequestThrottlerManager::OnOnlineStateChanged(bool online) { | 169 void URLRequestThrottlerManager::OnConnectionTypeChanged( |
| 170 NetworkChangeNotifier::ConnectionType type) { |
| 170 OnNetworkChange(); | 171 OnNetworkChange(); |
| 171 } | 172 } |
| 172 | 173 |
| 173 std::string URLRequestThrottlerManager::GetIdFromUrl(const GURL& url) const { | 174 std::string URLRequestThrottlerManager::GetIdFromUrl(const GURL& url) const { |
| 174 if (!url.is_valid()) | 175 if (!url.is_valid()) |
| 175 return url.possibly_invalid_spec(); | 176 return url.possibly_invalid_spec(); |
| 176 | 177 |
| 177 GURL id = url.ReplaceComponents(url_id_replacements_); | 178 GURL id = url.ReplaceComponents(url_id_replacements_); |
| 178 return StringToLowerASCII(id.spec()).c_str(); | 179 return StringToLowerASCII(id.spec()).c_str(); |
| 179 } | 180 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 200 // In case something broke we want to make sure not to grow indefinitely. | 201 // In case something broke we want to make sure not to grow indefinitely. |
| 201 while (url_entries_.size() > kMaximumNumberOfEntries) { | 202 while (url_entries_.size() > kMaximumNumberOfEntries) { |
| 202 url_entries_.erase(url_entries_.begin()); | 203 url_entries_.erase(url_entries_.begin()); |
| 203 } | 204 } |
| 204 } | 205 } |
| 205 | 206 |
| 206 void URLRequestThrottlerManager::OnNetworkChange() { | 207 void URLRequestThrottlerManager::OnNetworkChange() { |
| 207 // Remove all entries. Any entries that in-flight requests have a reference | 208 // Remove all entries. Any entries that in-flight requests have a reference |
| 208 // to will live until those requests end, and these entries may be | 209 // to will live until those requests end, and these entries may be |
| 209 // inconsistent with new entries for the same URLs, but since what we | 210 // inconsistent with new entries for the same URLs, but since what we |
| 210 // want is a clean slate for the new connection state, this is OK. | 211 // want is a clean slate for the new connection type, this is OK. |
| 211 url_entries_.clear(); | 212 url_entries_.clear(); |
| 212 requests_since_last_gc_ = 0; | 213 requests_since_last_gc_ = 0; |
| 213 } | 214 } |
| 214 | 215 |
| 215 } // namespace net | 216 } // namespace net |
| OLD | NEW |