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

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

Issue 18261003: Cleaning up TODO(joi) entries in //net. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge LKGR. Created 7 years, 5 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
« no previous file with comments | « net/url_request/url_request_throttler_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/strings/string_util.h" 10 #include "base/strings/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),
22 logged_for_localhost_disabled_(false), 21 logged_for_localhost_disabled_(false),
23 registered_from_thread_(base::kInvalidThreadId) { 22 registered_from_thread_(base::kInvalidThreadId) {
24 url_id_replacements_.ClearPassword(); 23 url_id_replacements_.ClearPassword();
25 url_id_replacements_.ClearUsername(); 24 url_id_replacements_.ClearUsername();
26 url_id_replacements_.ClearQuery(); 25 url_id_replacements_.ClearQuery();
27 url_id_replacements_.ClearRef(); 26 url_id_replacements_.ClearRef();
28 27
29 NetworkChangeNotifier::AddIPAddressObserver(this); 28 NetworkChangeNotifier::AddIPAddressObserver(this);
30 NetworkChangeNotifier::AddConnectionTypeObserver(this); 29 NetworkChangeNotifier::AddConnectionTypeObserver(this);
31 } 30 }
(...skipping 11 matching lines...) Expand all
43 } 42 }
44 ++i; 43 ++i;
45 } 44 }
46 45
47 // Delete all entries. 46 // Delete all entries.
48 url_entries_.clear(); 47 url_entries_.clear();
49 } 48 }
50 49
51 scoped_refptr<URLRequestThrottlerEntryInterface> 50 scoped_refptr<URLRequestThrottlerEntryInterface>
52 URLRequestThrottlerManager::RegisterRequestUrl(const GURL &url) { 51 URLRequestThrottlerManager::RegisterRequestUrl(const GURL &url) {
53 DCHECK(!enable_thread_checks_ || CalledOnValidThread()); 52 DCHECK(CalledOnValidThread());
54 53
55 // Normalize the url. 54 // Normalize the url.
56 std::string url_id = GetIdFromUrl(url); 55 std::string url_id = GetIdFromUrl(url);
57 56
58 // Periodically garbage collect old entries. 57 // Periodically garbage collect old entries.
59 GarbageCollectEntriesIfNecessary(); 58 GarbageCollectEntriesIfNecessary();
60 59
61 // Find the entry in the map or create a new NULL entry. 60 // Find the entry in the map or create a new NULL entry.
62 scoped_refptr<URLRequestThrottlerEntry>& entry = url_entries_[url_id]; 61 scoped_refptr<URLRequestThrottlerEntry>& entry = url_entries_[url_id];
63 62
(...skipping 16 matching lines...) Expand all
80 // in AddToOptOutList), this is not a problem. 79 // in AddToOptOutList), this is not a problem.
81 std::string host = url.host(); 80 std::string host = url.host();
82 if (opt_out_hosts_.find(host) != opt_out_hosts_.end() || 81 if (opt_out_hosts_.find(host) != opt_out_hosts_.end() ||
83 IsLocalhost(host)) { 82 IsLocalhost(host)) {
84 if (!logged_for_localhost_disabled_ && IsLocalhost(host)) { 83 if (!logged_for_localhost_disabled_ && IsLocalhost(host)) {
85 logged_for_localhost_disabled_ = true; 84 logged_for_localhost_disabled_ = true;
86 net_log_.AddEvent(NetLog::TYPE_THROTTLING_DISABLED_FOR_HOST, 85 net_log_.AddEvent(NetLog::TYPE_THROTTLING_DISABLED_FOR_HOST,
87 NetLog::StringCallback("host", &host)); 86 NetLog::StringCallback("host", &host));
88 } 87 }
89 88
90 // TODO(joi): Once sliding window is separate from back-off throttling, 89 // If sliding window was separate from back-off throttling, we
91 // we can simply return a dummy implementation of 90 // could simply return a dummy implementation of
92 // URLRequestThrottlerEntryInterface here that never blocks anything (and 91 // URLRequestThrottlerEntryInterface here that never blocks
93 // not keep entries in url_entries_ for opted-out sites). 92 // anything (and not keep entries in url_entries_ for opted-out
93 // sites).
94 entry->DisableBackoffThrottling(); 94 entry->DisableBackoffThrottling();
95 } 95 }
96 } 96 }
97 97
98 return entry; 98 return entry;
99 } 99 }
100 100
101 void URLRequestThrottlerManager::AddToOptOutList(const std::string& host) { 101 void URLRequestThrottlerManager::AddToOptOutList(const std::string& host) {
102 // There is an edge case here that we are not handling, to keep things 102 // There is an edge case here that we are not handling, to keep things
103 // simple. If a host starts adding the opt-out header to its responses 103 // simple. If a host starts adding the opt-out header to its responses
(...skipping 20 matching lines...) Expand all
124 124
125 url_entries_[url_id] = entry; 125 url_entries_[url_id] = entry;
126 } 126 }
127 127
128 void URLRequestThrottlerManager::EraseEntryForTests(const GURL& url) { 128 void URLRequestThrottlerManager::EraseEntryForTests(const GURL& url) {
129 // Normalize the url. 129 // Normalize the url.
130 std::string url_id = GetIdFromUrl(url); 130 std::string url_id = GetIdFromUrl(url);
131 url_entries_.erase(url_id); 131 url_entries_.erase(url_id);
132 } 132 }
133 133
134 void URLRequestThrottlerManager::set_enable_thread_checks(bool enable) {
135 enable_thread_checks_ = enable;
136 }
137
138 bool URLRequestThrottlerManager::enable_thread_checks() const {
139 return enable_thread_checks_;
140 }
141
142 void URLRequestThrottlerManager::set_net_log(NetLog* net_log) { 134 void URLRequestThrottlerManager::set_net_log(NetLog* net_log) {
143 DCHECK(net_log); 135 DCHECK(net_log);
144 net_log_ = BoundNetLog::Make(net_log, 136 net_log_ = BoundNetLog::Make(net_log,
145 NetLog::SOURCE_EXPONENTIAL_BACKOFF_THROTTLING); 137 NetLog::SOURCE_EXPONENTIAL_BACKOFF_THROTTLING);
146 } 138 }
147 139
148 NetLog* URLRequestThrottlerManager::net_log() const { 140 NetLog* URLRequestThrottlerManager::net_log() const {
149 return net_log_.net_log(); 141 return net_log_.net_log();
150 } 142 }
151 143
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 void URLRequestThrottlerManager::OnNetworkChange() { 186 void URLRequestThrottlerManager::OnNetworkChange() {
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
« no previous file with comments | « net/url_request/url_request_throttler_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698