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

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

Issue 11270027: Add a ResourceScheduler to ResourceDispatcherHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Track background requests Created 8 years 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_RENDERER_HOST_RESOURCE_SCHEDULER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_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/memory/linked_ptr.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "content/common/content_export.h"
17 #include "content/public/browser/global_request_id.h"
18
19 namespace content {
20 class ResourceLoader;
21
22 // There is one ResourceScheduler, which is owned by the ResourceDispatcherHost.
23 //
24 // These are sources of input to the scheduler:
25 // 1. Requests to load, cancel, or finish resources from the
26 // ResourceDispatcherHost.
27 // 2. Notifications of renderer events from the ResourceSchedulerFilter.
28 //
29 // The ResourceScheduler tracks many Clients, which should correlate with tabs.
30 // A client is uniquely identified by its child_id and route_id.
31 //
32 // Each Client may have many Requests in flight. Requests are uniquely
33 // identified within a Client by their request_ids.
34 //
35 // The ResourceDispatcherHost should call ScheduleLoad() when it's ready to
36 // load a request. The returned LoadHandle should be destroyed when the load
37 // finishes or is canceled.
38 //
39 // The scheduling behavior mimicks WebKit's scheduler, which blocks fetching
40 // low priority resources until the first paint has occurred. One exception is
41 // if the client is not fetching anything else, low priority fetching begins
42 // immediately.
43 class CONTENT_EXPORT_PRIVATE ResourceScheduler {
44 public:
45 typedef int64 ClientId;
46 typedef int64 BackgroundRequestId;
47
48 // A LoadHandle is returned to the ResourceDispatcherHost. When the host
49 // deletes the handle, it's automatically removed from ResourceScheduler's
50 // state.
51 class LoadHandle {
52 public:
53 virtual ~LoadHandle() {}
54 virtual linked_ptr<ResourceLoader> loader() = 0;
55 };
56
57 ResourceScheduler();
58 ~ResourceScheduler();
59
60 // Called when the ResourceDispatcherHost is ready to load a resource.
61 // Caller should delete the returned handle when the load completes or is
62 // canceled.
63 scoped_ptr<LoadHandle> ScheduleLoad(int child_id,
64 int route_id,
65 int request_id,
66 const linked_ptr<ResourceLoader>& loader);
willchan no longer on Chromium 2012/12/03 02:30:16 This should take a ResourceLoader* and not increme
James Simonsen 2012/12/05 01:52:45 Done.
67
68 // These events are triggered by ViewHostMsgs.
69
70 // Called when a new client is created.
71 void OnCreate(int child_id, int route_id);
72
73 // Called when a client navigates to a new main document.
74 void OnNavigate(int child_id, int route_id);
75
76 // Called any time a client paints.
77 void OnPaint(int child_id, int route_id);
78
79 // Called when a client is destroyed.
80 void OnDestroy(int child_id, int route_id);
81
82 private:
83 class BackgroundLoadHandle;
84 class ScheduledLoadHandle;
85 struct Client;
86 struct Request;
87
88 typedef std::vector<Request> RequestQueue;
89 typedef std::set<int> RequestIdSet;
90 typedef std::set<BackgroundRequestId> BackgroundRequestSet;
91 typedef std::map<ClientId, Client*> ClientMap;
92
93 struct Request {
94 int request_id;
95 ResourceLoader* loader;
96 };
97
98 struct Client {
99 Client();
willchan no longer on Chromium 2012/12/03 02:30:16 How about declaring the destructor here and defini
James Simonsen 2012/12/05 01:52:45 Done.
100
101 bool has_painted;
102 bool closed;
103 RequestQueue pending_requests;
104 RequestIdSet in_flight_requests;
105 };
106
107 // Called when a ScheduledLoadHandle is destroyed.
108 void RemoveLoad(ClientId client_id, int request_id);
109
110 // Called when a BackgroundLoadHandle is destroyed.
willchan no longer on Chromium 2012/12/03 02:30:16 I think we should kill off this function. I think
James Simonsen 2012/12/05 01:52:45 Done.
111 void RemoveBackgroundLoad(BackgroundRequestId request_id);
112
113 // Kicks off the loader for |request| and adds it to |client|.
114 void StartRequest(Request request, Client* client);
115
116 // Calls StartRequest on all pending requests for |client|.
117 void LoadPendingRequests(Client* client);
118
119 ClientMap client_map_;
120 BackgroundRequestSet background_requests_;
121 };
122
123 } // namespace content
124
125 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_SCHEDULER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698