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

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

Issue 4194001: Implement exponential back-off mechanism and enforce it at the URLRequestHttpJob level. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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.
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.h for further informations.
Jói 2010/11/12 00:12:08 request_throttler_entry.h -> request_throttler_ent
yzshen 2010/11/12 02:05:46 Done.
25 scoped_refptr<RequestThrottlerEntryInterface> RegisterRequestUrl(
26 const GURL& url);
27
28 // This method is used by higher level modules which can notify this class if
Jói 2010/11/12 00:12:08 This comment is not clear enough. Suggest the foll
yzshen 2010/11/12 02:05:46 Thanks a lot!
29 // the response they received was malformed. It is useful because
30 // in the case where the response header returned 200 response code but had
31 // a malformed content body we will categorize it as a success and so we
32 // defer this decision to the module that had requested the resource.
33 void NotifyRequestBodyWasMalformed(const GURL& url);
34
35 // Registers a new entry in this service and overrides the existing entry (if
36 // any) for the URL.
Jói 2010/11/12 00:12:08 if this is primarily for unit testing, we should s
yzshen 2010/11/12 02:05:46 It won't be for unit tests only, since I read the
37 void OverrideEntry(const GURL& url,
38 const scoped_refptr<RequestThrottlerEntry>& entry);
39
40 // Explicitly erases an entry.
41 // This is useful to remove those entries which have got infinite lifetime and
42 // thus won't be garbage collected.
43 void EraseEntry(const GURL& url);
44
45 protected:
46 RequestThrottlerManager();
47 virtual ~RequestThrottlerManager();
48
49 // Method that allows us to transform a URL into an ID that can be used in our
50 // map. Resulting IDs will be lowercase and be missing both the query string
51 // and fragment.
52 std::string GetIdFromUrl(const GURL& url);
53
54 // Method that ensures the map gets cleaned from time to time. The period at
55 // which garbage collecting happens is adjustable with the
56 // kRequestBetweenCollecting constant.
57 void GarbageCollectEntriesIfNecessary();
58 // Method that does the actual work of garbage collecting.
59 void GarbageCollectEntries();
60
61 // From each URL we generate an ID composed of the host and path
62 // that allows us to uniquely map an entry to it.
63 typedef std::map<std::string, scoped_refptr<RequestThrottlerEntry> >
64 UrlEntryMap;
65
66 friend struct DefaultSingletonTraits<RequestThrottlerManager>;
67
68 // Map that contains a list of URL ID and their matching
69 // RequestThrottlerEntry.
70 UrlEntryMap url_entries_;
71
72 // Lock to protect those non-static data members.
73 Lock lock_;
74
75 private:
76 // Maximum number of entries that we are willing to collect in our map.
77 static const unsigned int kMaximumNumberOfEntries;
78 // Number of requests that will be made between garbage collection.
79 static const unsigned int kRequestsBetweenCollecting;
80
81 // This keeps track of how many requests have been made. Used with
82 // GarbageCollectEntries.
83 unsigned int requests_since_last_gc_;
84
85 DISALLOW_COPY_AND_ASSIGN(RequestThrottlerManager);
86 };
87
88 #endif // NET_URL_REQUEST_REQUEST_THROTTLER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698