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

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

Issue 2487001: Request Throttler : Exponential back-off (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Corrected a flaky test due to having 2 implementation of request throttling Created 10 years, 4 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
(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/non_thread_safe.h"
13 #include "base/singleton.h"
14 #include "base/scoped_ptr.h"
15 #include "base/time.h"
16 #include "googleurl/src/gurl.h"
17 #include "net/request_throttler/request_throttler_entry.h"
18
19 class MessageLoop;
20
21 // Class that registers a request throttler entry for each URL being accessed in
22 // order to supervise traffic. URL Http Request should register their URL in
23 // this request throttler manager on each request.
24 class RequestThrottlerManager {
25 public:
26 // Must be called for every request, returns the request throttler entry
27 // associated with the URL. The caller must inform this entry of some events.
28 // Please refer to request_throttler_entry.h for further informations.
29 scoped_refptr<RequestThrottlerEntryInterface> RegisterRequestUrl(
30 const GURL& url);
31
32 // This method is used by higher level modules which can notify this class if
33 // the response they received was malformed. It is useful because
34 // in the case where the response header returned 200 response code but had
35 // a malformed content body we will categorize it as a success and so we
36 // defer this decision to the module that had requested the resource.
37 void NotifyRequestBodyWasMalformed(const GURL& url);
38
39 protected:
40 RequestThrottlerManager();
41 virtual ~RequestThrottlerManager();
42
43 // From each URL we generate an ID composed of the host and path
44 // that allows us to uniquely map an entry to it.
45 typedef std::map<std::string, scoped_refptr<RequestThrottlerEntry> >
46 UrlEntryMap;
47
48 friend struct DefaultSingletonTraits<RequestThrottlerManager>;
49
50 // Map that contains a list of URL ID and their matching
51 // RequestThrottlerEntry.
52 UrlEntryMap url_entries_;
53
54 // Method that allows us to transform an URL into an ID that is useful and
55 // can be used in our map. Resulting IDs will be lowercase and be missing both
56 // the query string and fragment.
57 std::string GetIdFromUrl(const GURL& url);
58
59 // Method that ensures the map gets cleaned from time to time. The period at
60 // which this GarbageCollection happens is adjustable with the
61 // kRequestBetweenCollecting constant.
62 void GarbageCollectEntries();
63
64 private:
65 MessageLoop* current_loop_;
66
67 // Maximum number of entries that we are willing to collect in our map.
68 static const unsigned int kMaximumNumberOfEntries;
69 // Number of requests that will be made between garbage collection.
70 static const unsigned int kRequestsBetweenCollecting;
71
72 // This keeps track of how many request have been made. Used with
73 // GarbageCollectEntries.
74 unsigned int requests_since_last_gc_;
75
76 DISALLOW_COPY_AND_ASSIGN(RequestThrottlerManager);
77 };
78
79 #endif // NET_REQUEST_THROTTLER_REQUEST_THROTTLER_MANAGER_H_
OLDNEW
« no previous file with comments | « net/request_throttler/request_throttler_header_interface.h ('k') | net/request_throttler/request_throttler_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698