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

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

Issue 10440119: Introduce a delegate to avoid hardcoding "chrome-extension" in net/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review nit and merge to LKGR for commit. Created 8 years, 6 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 enforce_throttling_(true),
22 enable_thread_checks_(false), 21 enable_thread_checks_(false),
23 logged_for_localhost_disabled_(false), 22 logged_for_localhost_disabled_(false),
24 registered_from_thread_(base::kInvalidThreadId) { 23 registered_from_thread_(base::kInvalidThreadId) {
25 url_id_replacements_.ClearPassword(); 24 url_id_replacements_.ClearPassword();
26 url_id_replacements_.ClearUsername(); 25 url_id_replacements_.ClearUsername();
27 url_id_replacements_.ClearQuery(); 26 url_id_replacements_.ClearQuery();
28 url_id_replacements_.ClearRef(); 27 url_id_replacements_.ClearRef();
29 28
30 NetworkChangeNotifier::AddIPAddressObserver(this); 29 NetworkChangeNotifier::AddIPAddressObserver(this);
31 NetworkChangeNotifier::AddConnectionTypeObserver(this); 30 NetworkChangeNotifier::AddConnectionTypeObserver(this);
32 } 31 }
33 32
34 URLRequestThrottlerManager::~URLRequestThrottlerManager() { 33 URLRequestThrottlerManager::~URLRequestThrottlerManager() {
35 NetworkChangeNotifier::RemoveIPAddressObserver(this); 34 NetworkChangeNotifier::RemoveIPAddressObserver(this);
36 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); 35 NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
37 36
38 // Since, for now, the manager object might conceivably go away before 37 // Since the manager object might conceivably go away before the
39 // the entries, detach the entries' back-pointer to the manager. 38 // 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(); 39 UrlEntryMap::iterator i = url_entries_.begin();
43 while (i != url_entries_.end()) { 40 while (i != url_entries_.end()) {
44 if (i->second != NULL) { 41 if (i->second != NULL) {
45 i->second->DetachManager(); 42 i->second->DetachManager();
46 } 43 }
47 ++i; 44 ++i;
48 } 45 }
49 46
50 // Delete all entries. 47 // Delete all entries.
51 url_entries_.clear(); 48 url_entries_.clear();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 134 }
138 135
139 void URLRequestThrottlerManager::set_enable_thread_checks(bool enable) { 136 void URLRequestThrottlerManager::set_enable_thread_checks(bool enable) {
140 enable_thread_checks_ = enable; 137 enable_thread_checks_ = enable;
141 } 138 }
142 139
143 bool URLRequestThrottlerManager::enable_thread_checks() const { 140 bool URLRequestThrottlerManager::enable_thread_checks() const {
144 return enable_thread_checks_; 141 return enable_thread_checks_;
145 } 142 }
146 143
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) { 144 void URLRequestThrottlerManager::set_net_log(NetLog* net_log) {
156 DCHECK(net_log); 145 DCHECK(net_log);
157 net_log_ = BoundNetLog::Make(net_log, 146 net_log_ = BoundNetLog::Make(net_log,
158 NetLog::SOURCE_EXPONENTIAL_BACKOFF_THROTTLING); 147 NetLog::SOURCE_EXPONENTIAL_BACKOFF_THROTTLING);
159 } 148 }
160 149
161 NetLog* URLRequestThrottlerManager::net_log() const { 150 NetLog* URLRequestThrottlerManager::net_log() const {
162 return net_log_.net_log(); 151 return net_log_.net_log();
163 } 152 }
164 153
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 void URLRequestThrottlerManager::OnNetworkChange() { 196 void URLRequestThrottlerManager::OnNetworkChange() {
208 // Remove all entries. Any entries that in-flight requests have a reference 197 // 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 198 // 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 199 // 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. 200 // want is a clean slate for the new connection type, this is OK.
212 url_entries_.clear(); 201 url_entries_.clear();
213 requests_since_last_gc_ = 0; 202 requests_since_last_gc_ = 0;
214 } 203 }
215 204
216 } // namespace net 205 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_throttler_manager.h ('k') | net/url_request/url_request_throttler_simulation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698