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

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

Issue 6711046: Add an opt-out header for HTTP throttling. Never throttle for localhost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update copyright years. Created 9 years, 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/string_util.h" 8 #include "base/string_util.h"
9 #include "net/base/net_util.h"
9 10
10 namespace net { 11 namespace net {
11 12
12 const unsigned int URLRequestThrottlerManager::kMaximumNumberOfEntries = 1500; 13 const unsigned int URLRequestThrottlerManager::kMaximumNumberOfEntries = 1500;
13 const unsigned int URLRequestThrottlerManager::kRequestsBetweenCollecting = 200; 14 const unsigned int URLRequestThrottlerManager::kRequestsBetweenCollecting = 200;
14 15
15 URLRequestThrottlerManager* URLRequestThrottlerManager::GetInstance() { 16 URLRequestThrottlerManager* URLRequestThrottlerManager::GetInstance() {
16 return Singleton<URLRequestThrottlerManager>::get(); 17 return Singleton<URLRequestThrottlerManager>::get();
17 } 18 }
18 19
19 scoped_refptr<URLRequestThrottlerEntryInterface> 20 scoped_refptr<URLRequestThrottlerEntryInterface>
20 URLRequestThrottlerManager::RegisterRequestUrl(const GURL &url) { 21 URLRequestThrottlerManager::RegisterRequestUrl(const GURL &url) {
21 DCHECK(being_tested_ || CalledOnValidThread()); 22 DCHECK(being_tested_ || CalledOnValidThread());
22 23
23 // Normalize the url. 24 // Normalize the url.
24 std::string url_id = GetIdFromUrl(url); 25 std::string url_id = GetIdFromUrl(url);
25 26
26 // Periodically garbage collect old entries. 27 // Periodically garbage collect old entries.
27 GarbageCollectEntriesIfNecessary(); 28 GarbageCollectEntriesIfNecessary();
28 29
29 // Find the entry in the map or create it. 30 // Find the entry in the map or create it.
30 scoped_refptr<URLRequestThrottlerEntry>& entry = url_entries_[url_id]; 31 scoped_refptr<URLRequestThrottlerEntry>& entry = url_entries_[url_id];
31 if (entry.get() == NULL) 32 if (entry.get() == NULL)
32 entry = new URLRequestThrottlerEntry(); 33 entry = new URLRequestThrottlerEntry(this);
34
35 std::string host = url.host();
36 if (opt_out_hosts_.find(host) != opt_out_hosts_.end() || IsLocalhost(host)) {
yzshen1 2011/03/18 22:49:51 [Don't have a strong opinion. Just to make sure yo
Jói 2011/03/23 23:38:24 I'm doing this on request of the web developers in
37 // TODO(joi): Once sliding window is separate from back-off throttling,
38 // we can simply return a dummy implementation of
39 // URLRequestThrottlerEntryInterface here that never blocks anything (and
40 // not keep entries in url_entries_ for opted-out sites).
yzshen1 2011/03/18 22:49:51 We might still need to keep track of back-off peri
Jói 2011/03/23 23:38:24 Right, I think as per the comment I added on URLRe
41 entry->DisableBackoffThrottling();
42 }
33 43
34 return entry; 44 return entry;
35 } 45 }
36 46
47 void URLRequestThrottlerManager::AddToOptOutList(const std::string& host) {
48 // There is an edge case here that we are not handling, to keep things
49 // simple. If a host starts adding the opt-out header to its responses
50 // after there are already one or more entries in url_entries_ for that
51 // host, the pre-existing entries may still perform back-off throttling.
52 // In practice, this would almost never occur.
53 opt_out_hosts_.insert(host);
54 }
55
37 void URLRequestThrottlerManager::OverrideEntryForTests( 56 void URLRequestThrottlerManager::OverrideEntryForTests(
38 const GURL& url, 57 const GURL& url,
39 URLRequestThrottlerEntry* entry) { 58 URLRequestThrottlerEntry* entry) {
40 // Normalize the url. 59 // Normalize the url.
41 std::string url_id = GetIdFromUrl(url); 60 std::string url_id = GetIdFromUrl(url);
42 61
43 // Periodically garbage collect old entries. 62 // Periodically garbage collect old entries.
44 GarbageCollectEntriesIfNecessary(); 63 GarbageCollectEntriesIfNecessary();
45 64
46 url_entries_[url_id] = entry; 65 url_entries_[url_id] = entry;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 140 }
122 } 141 }
123 142
124 // In case something broke we want to make sure not to grow indefinitely. 143 // In case something broke we want to make sure not to grow indefinitely.
125 while (url_entries_.size() > kMaximumNumberOfEntries) { 144 while (url_entries_.size() > kMaximumNumberOfEntries) {
126 url_entries_.erase(url_entries_.begin()); 145 url_entries_.erase(url_entries_.begin());
127 } 146 }
128 } 147 }
129 148
130 } // namespace net 149 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698