Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(744)

Side by Side Diff: net/url_request/url_request_throttler_manager.cc

Issue 11620007: Switch from OnIPAddressChanged and OnConnectionTypeChange to OnNetworkChanged Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 : requests_since_last_gc_(0), 20 : requests_since_last_gc_(0),
21 enable_thread_checks_(false), 21 enable_thread_checks_(false),
22 logged_for_localhost_disabled_(false), 22 logged_for_localhost_disabled_(false),
23 registered_from_thread_(base::kInvalidThreadId) { 23 registered_from_thread_(base::kInvalidThreadId) {
24 url_id_replacements_.ClearPassword(); 24 url_id_replacements_.ClearPassword();
25 url_id_replacements_.ClearUsername(); 25 url_id_replacements_.ClearUsername();
26 url_id_replacements_.ClearQuery(); 26 url_id_replacements_.ClearQuery();
27 url_id_replacements_.ClearRef(); 27 url_id_replacements_.ClearRef();
28 28
29 NetworkChangeNotifier::AddIPAddressObserver(this); 29 NetworkChangeNotifier::AddNetworkChangeObserver(this);
30 NetworkChangeNotifier::AddConnectionTypeObserver(this);
31 } 30 }
32 31
33 URLRequestThrottlerManager::~URLRequestThrottlerManager() { 32 URLRequestThrottlerManager::~URLRequestThrottlerManager() {
34 NetworkChangeNotifier::RemoveIPAddressObserver(this); 33 NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
35 NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
36 34
37 // Since the manager object might conceivably go away before the 35 // Since the manager object might conceivably go away before the
38 // entries, detach the entries' back-pointer to the manager. 36 // entries, detach the entries' back-pointer to the manager.
39 UrlEntryMap::iterator i = url_entries_.begin(); 37 UrlEntryMap::iterator i = url_entries_.begin();
40 while (i != url_entries_.end()) { 38 while (i != url_entries_.end()) {
41 if (i->second != NULL) { 39 if (i->second != NULL) {
42 i->second->DetachManager(); 40 i->second->DetachManager();
43 } 41 }
44 ++i; 42 ++i;
45 } 43 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 void URLRequestThrottlerManager::set_net_log(NetLog* net_log) { 140 void URLRequestThrottlerManager::set_net_log(NetLog* net_log) {
143 DCHECK(net_log); 141 DCHECK(net_log);
144 net_log_ = BoundNetLog::Make(net_log, 142 net_log_ = BoundNetLog::Make(net_log,
145 NetLog::SOURCE_EXPONENTIAL_BACKOFF_THROTTLING); 143 NetLog::SOURCE_EXPONENTIAL_BACKOFF_THROTTLING);
146 } 144 }
147 145
148 NetLog* URLRequestThrottlerManager::net_log() const { 146 NetLog* URLRequestThrottlerManager::net_log() const {
149 return net_log_.net_log(); 147 return net_log_.net_log();
150 } 148 }
151 149
152 void URLRequestThrottlerManager::OnIPAddressChanged() {
153 OnNetworkChange();
154 }
155
156 void URLRequestThrottlerManager::OnConnectionTypeChanged(
157 NetworkChangeNotifier::ConnectionType type) {
158 OnNetworkChange();
159 }
160
161 std::string URLRequestThrottlerManager::GetIdFromUrl(const GURL& url) const { 150 std::string URLRequestThrottlerManager::GetIdFromUrl(const GURL& url) const {
162 if (!url.is_valid()) 151 if (!url.is_valid())
163 return url.possibly_invalid_spec(); 152 return url.possibly_invalid_spec();
164 153
165 GURL id = url.ReplaceComponents(url_id_replacements_); 154 GURL id = url.ReplaceComponents(url_id_replacements_);
166 return StringToLowerASCII(id.spec()).c_str(); 155 return StringToLowerASCII(id.spec()).c_str();
167 } 156 }
168 157
169 void URLRequestThrottlerManager::GarbageCollectEntriesIfNecessary() { 158 void URLRequestThrottlerManager::GarbageCollectEntriesIfNecessary() {
170 requests_since_last_gc_++; 159 requests_since_last_gc_++;
(...skipping 13 matching lines...) Expand all
184 ++i; 173 ++i;
185 } 174 }
186 } 175 }
187 176
188 // In case something broke we want to make sure not to grow indefinitely. 177 // In case something broke we want to make sure not to grow indefinitely.
189 while (url_entries_.size() > kMaximumNumberOfEntries) { 178 while (url_entries_.size() > kMaximumNumberOfEntries) {
190 url_entries_.erase(url_entries_.begin()); 179 url_entries_.erase(url_entries_.begin());
191 } 180 }
192 } 181 }
193 182
194 void URLRequestThrottlerManager::OnNetworkChange() { 183 void URLRequestThrottlerManager::OnNetworkChanged(
184 NetworkChangeNotifier::ConnectionType type) {
185 if (type != NetworkChangeNotifier::CONNECTION_NONE)
186 return;
195 // Remove all entries. Any entries that in-flight requests have a reference 187 // Remove all entries. Any entries that in-flight requests have a reference
196 // to will live until those requests end, and these entries may be 188 // to will live until those requests end, and these entries may be
197 // inconsistent with new entries for the same URLs, but since what we 189 // inconsistent with new entries for the same URLs, but since what we
198 // want is a clean slate for the new connection type, this is OK. 190 // want is a clean slate for the new connection type, this is OK.
199 url_entries_.clear(); 191 url_entries_.clear();
200 requests_since_last_gc_ = 0; 192 requests_since_last_gc_ = 0;
201 } 193 }
202 194
203 } // namespace net 195 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698