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

Side by Side Diff: content/browser/loader/resource_scheduler.h

Issue 11270027: Add a ResourceScheduler to ResourceDispatcherHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Win build Created 7 years, 11 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) 2012 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 CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_
6 #define CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_
7
8 #include <map>
9 #include <set>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/containers/mru_cache.h"
15 #include "base/memory/linked_ptr.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/threading/non_thread_safe.h"
18 #include "content/common/content_export.h"
19 #include "content/public/browser/global_request_id.h"
20
21 namespace net {
22 class URLRequest;
23 }
24
25 namespace content {
26 class ResourceThrottle;
27
28 // There is one ResourceScheduler. All renderer-initiated HTTP requests are
29 // expected to pass through it.
30 //
31 // There are two types of input to the scheduler:
32 // 1. Requests to start, cancel, or finish fetching a resource.
33 // 2. Notifications for renderer events, such as navigation and painting.
34 //
35 // The ResourceScheduler tracks many Clients, which should correlate with tabs.
36 // A client is uniquely identified by its child_id and route_id.
37 //
38 // Each Client may have many Requests in flight. Requests are uniquely
39 // identified within a Client by its ScheduledResourceRequest.
40 //
41 // Users should call ScheduleRequest() to notify this ResourceScheduler of a
42 // new request. The returned ResourceThrottle should be destroyed when the load
43 // finishes or is canceled.
44 //
45 // The scheduler may defer issuing the request via the ResourceThrottle
46 // interface or it may alter the request's priority by calling set_priority() on
47 // the URLRequest.
48 //
49 // The scheduler only tracks the most recently used Clients. If a tab hasn't
50 // navigated or fetched a resource for some time, its state may be forgotten
51 // until its next navigation. In such situations, no request throttling occurs.
52 class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe {
53 public:
54 ResourceScheduler();
55 ~ResourceScheduler();
56
57 // Requests that this ResourceScheduler schedule, and eventually loads, the
58 // specified |url_request|. Caller should delete the returned ResourceThrottle
59 // when the load completes or is canceled.
60 scoped_ptr<ResourceThrottle> ScheduleRequest(
61 int child_id, int route_id, const net::URLRequest& url_request);
62
63 // Called when a client navigates to a new main document.
64 void OnNavigate(int child_id, int route_id);
65
66 // Called the first time a client paints.
67 void OnFirstPaint(int child_id, int route_id);
68
69 private:
70 class ScheduledResourceRequest;
71 friend class ScheduledResourceRequest;
72 struct Client;
73
74 typedef int64 ClientId;
75 typedef base::OwningMRUCache<ClientId, Client*> ClientMap;
76 typedef std::vector<ScheduledResourceRequest*> RequestQueue;
77 typedef std::set<ScheduledResourceRequest*> RequestSet;
78
79 struct Client {
80 Client(ResourceScheduler* scheduler);
81 ~Client();
82
83 bool has_painted;
84 RequestQueue pending_requests;
85 RequestSet in_flight_requests;
86
87 private:
88 ResourceScheduler* scheduler_;
89 };
90
91 // Called when a ScheduledResourceRequest is destroyed.
92 void RemoveRequest(ScheduledResourceRequest* request);
93
94 // Unthrottles the |request| and adds it to |client|.
95 void StartRequest(ScheduledResourceRequest* request, Client* client);
96
97 // Calls StartRequest on all pending requests for |client|.
98 void LoadPendingRequests(Client* client);
99
100 // Called when a Client is evicted from the MRUCache.
101 void RemoveClient(Client* client);
102
103 // Returns the client ID for the given |child_id| and |route_id| combo.
104 ClientId MakeClientId(int child_id, int route_id);
105
106 ClientMap client_map_;
107 RequestSet unowned_requests_;
108 };
109
110 } // namespace content
111
112 #endif // CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698