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

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: Remove all linked_ptrs 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_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/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 net {
20 class URLRequest;
21 }
22
23 namespace content {
24
25 // There is one ResourceScheduler, which is owned by the ResourceDispatcherHost.
26 //
27 // These are sources of input to the scheduler:
28 // 1. Requests to load, cancel, or finish resources from the
29 // ResourceDispatcherHost.
30 // 2. Notifications of renderer events from the ResourceSchedulerFilter.
31 //
32 // The ResourceScheduler tracks many Clients, which should correlate with tabs.
33 // A client is uniquely identified by its child_id and route_id.
34 //
35 // Each Client may have many Requests in flight. Requests are uniquely
36 // identified within a Client by their request_ids.
37 //
38 // The ResourceDispatcherHost should call ScheduleLoad() when it's ready to
39 // load a request. The returned LoadHandle should be destroyed when the load
40 // finishes or is canceled.
41 class CONTENT_EXPORT ResourceScheduler {
42 public:
43 typedef int64 ClientId;
44 typedef int64 SchedulerId;
45
46 // A LoadHandle is returned to the ResourceLoader. When the loader deletes the
47 // handle, it's automatically removed from ResourceScheduler's state.
48 class LoadHandle {
49 public:
50 virtual ~LoadHandle() {}
51 };
52
53 // ResourceScheduler's interface back to the ResourceLoader. Allows
54 // ResourceScheduler to initiate loads and read information about the request.
55 class Loadable {
56 public:
57 virtual ~Loadable() {}
58 virtual void StartRequest() = 0;
59 virtual const net::URLRequest& url_request() = 0;
darin (slow to review) 2012/12/14 22:16:28 virtual functions should never use unix_hacker_sty
60 };
61
62 ResourceScheduler();
63 ~ResourceScheduler();
64
65 // Called when the ResourceDispatcherHost is ready to load a resource.
66 // Caller should delete the returned handle when the load completes or is
67 // canceled.
68 scoped_ptr<LoadHandle> ScheduleLoad(int child_id,
69 int route_id,
70 Loadable* loadable);
71
72 // These events are triggered by ViewHostMsgs.
73
74 // Called when a new client is created.
75 void OnCreate(int child_id, int route_id);
darin (slow to review) 2012/12/14 22:16:28 OnCreate and OnDestroy do not really seem to corre
James Simonsen 2012/12/15 02:58:57 OnCreate is tied to an event now. And OnDestroy is
76
77 // Called when a client navigates to a new main document.
78 void OnNavigate(int child_id, int route_id);
79
80 // Called any time a client paints.
81 void OnPaint(int child_id, int route_id);
82
83 // Called when a client is destroyed.
84 void OnDestroy(int child_id, int route_id);
85
86 private:
87 friend class LoadHandleImpl;
88 struct Client;
89 struct Request;
90
91 typedef std::vector<Request> RequestQueue;
92 typedef std::set<SchedulerId> SchedulerIdSet;
93 typedef std::map<ClientId, Client*> ClientMap;
94
95 struct Request {
96 SchedulerId scheduler_id;
97 Loadable* loadable;
98 };
99
100 struct Client {
101 Client();
102 ~Client();
103
104 bool has_painted;
105 bool has_closed;
106 RequestQueue pending_requests;
107 SchedulerIdSet in_flight_requests;
108 };
109
110 // Called when a LoadHandle is destroyed.
111 void RemoveLoad(SchedulerId scheduler_id, ClientId client_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 SchedulerId next_scheduler_id_;
121 SchedulerIdSet unowned_requests_;
122 };
123
124 } // namespace content
125
126 #endif // CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698