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

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

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 #ifndef NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ 5 #ifndef NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_
6 #define NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ 6 #define NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set>
10 #include <string> 11 #include <string>
11 12
12 #include "base/basictypes.h" 13 #include "base/basictypes.h"
13 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
14 #include "base/singleton.h" 15 #include "base/singleton.h"
15 #include "base/threading/non_thread_safe.h" 16 #include "base/threading/non_thread_safe.h"
16 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
17 #include "net/url_request/url_request_throttler_entry.h" 18 #include "net/url_request/url_request_throttler_entry.h"
18 19
19 namespace net { 20 namespace net {
(...skipping 15 matching lines...) Expand all
35 public: 36 public:
36 static URLRequestThrottlerManager* GetInstance(); 37 static URLRequestThrottlerManager* GetInstance();
37 38
38 // Must be called for every request, returns the URL request throttler entry 39 // Must be called for every request, returns the URL request throttler entry
39 // associated with the URL. The caller must inform this entry of some events. 40 // associated with the URL. The caller must inform this entry of some events.
40 // Please refer to url_request_throttler_entry_interface.h for further 41 // Please refer to url_request_throttler_entry_interface.h for further
41 // informations. 42 // informations.
42 scoped_refptr<URLRequestThrottlerEntryInterface> RegisterRequestUrl( 43 scoped_refptr<URLRequestThrottlerEntryInterface> RegisterRequestUrl(
43 const GURL& url); 44 const GURL& url);
44 45
46 // Adds the given host to a list of sites for which exponential back-off
47 // throttling will be disabled. Subdomains are not included, so they
48 // must be added separately.
49 void AddToOptOutList(const std::string& host);
50
45 // Registers a new entry in this service and overrides the existing entry (if 51 // Registers a new entry in this service and overrides the existing entry (if
46 // any) for the URL. The service will hold a reference to the entry. 52 // any) for the URL. The service will hold a reference to the entry.
47 // It is only used by unit tests. 53 // It is only used by unit tests.
48 void OverrideEntryForTests(const GURL& url, URLRequestThrottlerEntry* entry); 54 void OverrideEntryForTests(const GURL& url, URLRequestThrottlerEntry* entry);
49 55
50 // Explicitly erases an entry. 56 // Explicitly erases an entry.
51 // This is useful to remove those entries which have got infinite lifetime and 57 // This is useful to remove those entries which have got infinite lifetime and
52 // thus won't be garbage collected. 58 // thus won't be garbage collected.
53 // It is only used by unit tests. 59 // It is only used by unit tests.
54 void EraseEntryForTests(const GURL& url); 60 void EraseEntryForTests(const GURL& url);
(...skipping 28 matching lines...) Expand all
83 int GetNumberOfEntriesForTests() const { return url_entries_.size(); } 89 int GetNumberOfEntriesForTests() const { return url_entries_.size(); }
84 90
85 private: 91 private:
86 friend struct DefaultSingletonTraits<URLRequestThrottlerManager>; 92 friend struct DefaultSingletonTraits<URLRequestThrottlerManager>;
87 93
88 // From each URL we generate an ID composed of the scheme, host, port and path 94 // From each URL we generate an ID composed of the scheme, host, port and path
89 // that allows us to uniquely map an entry to it. 95 // that allows us to uniquely map an entry to it.
90 typedef std::map<std::string, scoped_refptr<URLRequestThrottlerEntry> > 96 typedef std::map<std::string, scoped_refptr<URLRequestThrottlerEntry> >
91 UrlEntryMap; 97 UrlEntryMap;
92 98
99 // We maintain a set of hosts that have opted out of exponential
100 // back-off throttling.
101 typedef std::set<std::string> OptOutHosts;
102
93 // Maximum number of entries that we are willing to collect in our map. 103 // Maximum number of entries that we are willing to collect in our map.
94 static const unsigned int kMaximumNumberOfEntries; 104 static const unsigned int kMaximumNumberOfEntries;
95 // Number of requests that will be made between garbage collection. 105 // Number of requests that will be made between garbage collection.
96 static const unsigned int kRequestsBetweenCollecting; 106 static const unsigned int kRequestsBetweenCollecting;
97 107
98 // Map that contains a list of URL ID and their matching 108 // Map that contains a list of URL ID and their matching
99 // URLRequestThrottlerEntry. 109 // URLRequestThrottlerEntry.
100 UrlEntryMap url_entries_; 110 UrlEntryMap url_entries_;
101 111
112 // Set of hosts that have opted out.
113 OptOutHosts opt_out_hosts_;
114
102 // This keeps track of how many requests have been made. Used with 115 // This keeps track of how many requests have been made. Used with
103 // GarbageCollectEntries. 116 // GarbageCollectEntries.
104 unsigned int requests_since_last_gc_; 117 unsigned int requests_since_last_gc_;
105 118
106 // Valid after construction. 119 // Valid after construction.
107 GURL::Replacements url_id_replacements_; 120 GURL::Replacements url_id_replacements_;
108 121
109 // Whether we would like to reject outgoing HTTP requests during the back-off 122 // Whether we would like to reject outgoing HTTP requests during the back-off
110 // period. 123 // period.
111 bool enforce_throttling_; 124 bool enforce_throttling_;
112 125
113 // Certain tests do not obey the net component's threading policy, so we 126 // Certain tests do not obey the net component's threading policy, so we
114 // keep track of whether we're being used by tests, and turn off certain 127 // keep track of whether we're being used by tests, and turn off certain
115 // checks. 128 // checks.
116 // 129 //
117 // TODO(joi): See if we can fix the offending unit tests and remove this 130 // TODO(joi): See if we can fix the offending unit tests and remove this
118 // workaround. 131 // workaround.
119 bool being_tested_; 132 bool being_tested_;
120 133
121 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerManager); 134 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerManager);
122 }; 135 };
123 136
124 } // namespace net 137 } // namespace net
125 138
126 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ 139 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698