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

Side by Side Diff: net/request_throttler/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_REQUEST_THROTTLER_REQUEST_THROTTLER_MANAGER_H_
6 #define NET_REQUEST_THROTTLER_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/request_throttler/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.
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
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 // Returns the interval between now and the time after which requests to |url|
36 // are allowed, in milliseconds. The return value is always positive or 0.
37 // Returning 0 means that currently requests to |url| are allowed.
38 int64 GetBackoffDelayInMilliseconds(const GURL& url);
39
40 // Registers a new entry in this service and overrides the existing entry (if
41 // any) for the URL.
42 // It is only used by unit tests.
43 void OverrideEntry(const GURL& url,
44 const scoped_refptr<RequestThrottlerEntry>& entry);
45
46 // Clears all existing entries.
47 // It is only used by unit tests.
48 void ClearAllEntries();
49
50 // Disables throttling except for those URLs with which OverrideEntry are
51 // called.
52 // It is only used by unit tests.
53 void DisableThrottlingByDefault();
54
55 protected:
56 RequestThrottlerManager();
57 virtual ~RequestThrottlerManager();
58
59 // Method that allows us to transform a URL into an ID that can be used in our
60 // map. Resulting IDs will be lowercase and be missing both the query string
61 // and fragment.
62 std::string GetIdFromUrl(const GURL& url);
63
64 // Method that ensures the map gets cleaned from time to time. The period at
65 // which garbage collecting happens is adjustable with the
66 // kRequestBetweenCollecting constant.
67 void GarbageCollectEntriesIfNecessary();
68 // Method that does the actual work of garbage collecting.
69 void GarbageCollectEntries();
70
71 // From each URL we generate an ID composed of the host and path
72 // that allows us to uniquely map an entry to it.
73 typedef std::map<std::string, scoped_refptr<RequestThrottlerEntry> >
74 UrlEntryMap;
75
76 friend struct DefaultSingletonTraits<RequestThrottlerManager>;
77
78 // Map that contains a list of URL ID and their matching
79 // RequestThrottlerEntry.
80 UrlEntryMap url_entries_;
81
82 // Lock to protect those non-static data members.
83 Lock lock_;
84
85 private:
86 // Maximum number of entries that we are willing to collect in our map.
87 static const unsigned int kMaximumNumberOfEntries;
88 // Number of requests that will be made between garbage collection.
89 static const unsigned int kRequestsBetweenCollecting;
90
91 // This keeps track of how many requests have been made. Used with
92 // GarbageCollectEntries.
93 unsigned int requests_since_last_gc_;
94
95 // Whether throttling is disabled by default.
96 bool no_throttling_by_default_;
97
98 DISALLOW_COPY_AND_ASSIGN(RequestThrottlerManager);
99 };
100
101 #endif // NET_REQUEST_THROTTLER_REQUEST_THROTTLER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698