Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_URL_REQUEST_REQUEST_THROTTLER_MANAGER_H_ | |
| 6 #define NET_URL_REQUEST_REQUEST_THROTTLER_MANAGER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/lock.h" | |
| 12 #include "base/scoped_ptr.h" | |
| 13 #include "base/singleton.h" | |
| 14 #include "googleurl/src/gurl.h" | |
| 15 #include "net/url_request/request_throttler_entry.h" | |
| 16 | |
| 17 // Class that registers a request throttler entry for each URL being accessed in | |
| 18 // order to supervise traffic. URL requests for HTTP contents should register | |
| 19 // their URLs in this request throttler manager on each request. | |
|
willchan no longer on Chromium
2010/11/18 06:47:47
This comment is insufficient. It doesn't describe
yzshen
2010/11/19 23:51:36
Done.
| |
| 20 class RequestThrottlerManager { | |
| 21 public: | |
| 22 // Must be called for every request, returns the request throttler entry | |
| 23 // associated with the URL. The caller must inform this entry of some events. | |
| 24 // Please refer to request_throttler_entry_interface.h for further | |
| 25 // informations. | |
| 26 scoped_refptr<RequestThrottlerEntryInterface> RegisterRequestUrl( | |
| 27 const GURL& url); | |
| 28 | |
| 29 // Registers a new entry in this service and overrides the existing entry (if | |
| 30 // any) for the URL. | |
| 31 // It is only used by unit tests. | |
|
willchan no longer on Chromium
2010/11/18 06:47:47
I think I'd prefer that this be named OverrideEntr
yzshen
2010/11/19 23:51:36
Done.
| |
| 32 void OverrideEntry(const GURL& url, | |
| 33 const scoped_refptr<RequestThrottlerEntry>& entry); | |
|
willchan no longer on Chromium
2010/11/17 20:32:34
This should take a raw pointer rather than a const
yzshen
2010/11/19 23:51:36
Done.
| |
| 34 | |
| 35 // Explicitly erases an entry. | |
| 36 // This is useful to remove those entries which have got infinite lifetime and | |
| 37 // thus won't be garbage collected. | |
| 38 // It is only used by unit tests. | |
| 39 void EraseEntry(const GURL& url); | |
|
willchan no longer on Chromium
2010/11/18 06:47:47
Can you name this EraseEntryForTests()? I read th
yzshen
2010/11/19 23:51:36
Done.
| |
| 40 | |
| 41 protected: | |
| 42 RequestThrottlerManager(); | |
| 43 virtual ~RequestThrottlerManager(); | |
|
willchan no longer on Chromium
2010/11/17 20:32:34
Why is the destructor virtual? I don't see virtua
yzshen
2010/11/19 23:51:36
Done.
| |
| 44 | |
| 45 // Method that allows us to transform a URL into an ID that can be used in our | |
| 46 // map. Resulting IDs will be lowercase and be missing both the query string | |
| 47 // and fragment. | |
| 48 std::string GetIdFromUrl(const GURL& url); | |
| 49 | |
| 50 // Method that ensures the map gets cleaned from time to time. The period at | |
| 51 // which garbage collecting happens is adjustable with the | |
| 52 // kRequestBetweenCollecting constant. | |
| 53 void GarbageCollectEntriesIfNecessary(); | |
| 54 // Method that does the actual work of garbage collecting. | |
| 55 void GarbageCollectEntries(); | |
| 56 | |
| 57 // From each URL we generate an ID composed of the host and path | |
| 58 // that allows us to uniquely map an entry to it. | |
| 59 typedef std::map<std::string, scoped_refptr<RequestThrottlerEntry> > | |
|
willchan no longer on Chromium
2010/11/17 20:32:34
http://google-styleguide.googlecode.com/svn/trunk/
yzshen
2010/11/19 23:51:36
Done.
| |
| 60 UrlEntryMap; | |
| 61 | |
| 62 friend struct DefaultSingletonTraits<RequestThrottlerManager>; | |
| 63 | |
| 64 // Map that contains a list of URL ID and their matching | |
| 65 // RequestThrottlerEntry. | |
| 66 UrlEntryMap url_entries_; | |
|
willchan no longer on Chromium
2010/11/17 20:32:34
http://google-styleguide.googlecode.com/svn/trunk/
yzshen
2010/11/19 23:51:36
Done.
| |
| 67 | |
| 68 // Lock to protect those non-static data members. | |
| 69 Lock lock_; | |
| 70 | |
| 71 private: | |
| 72 // Maximum number of entries that we are willing to collect in our map. | |
| 73 static const unsigned int kMaximumNumberOfEntries; | |
| 74 // Number of requests that will be made between garbage collection. | |
| 75 static const unsigned int kRequestsBetweenCollecting; | |
| 76 | |
| 77 // This keeps track of how many requests have been made. Used with | |
| 78 // GarbageCollectEntries. | |
| 79 unsigned int requests_since_last_gc_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(RequestThrottlerManager); | |
|
willchan no longer on Chromium
2010/11/17 20:32:34
Include basictypes.h for this macro.
yzshen
2010/11/19 23:51:36
Done.
| |
| 82 }; | |
| 83 | |
| 84 #endif // NET_URL_REQUEST_REQUEST_THROTTLER_MANAGER_H_ | |
| OLD | NEW |