Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "base/threading/non_thread_safe.h" | |
| 17 #include "content/common/content_export.h" | |
| 18 #include "content/public/browser/global_request_id.h" | |
| 19 | |
| 20 namespace net { | |
| 21 class URLRequest; | |
| 22 } | |
| 23 | |
| 24 namespace content { | |
| 25 class ResourceThrottle; | |
| 26 | |
| 27 // There is one ResourceScheduler, which is owned by the ResourceDispatcherHost. | |
|
darin (slow to review)
2012/12/18 21:09:56
nit: It would be good to de-couple this logically
James Simonsen
2013/01/10 19:47:53
Done.
| |
| 28 // | |
| 29 // These are sources of input to the scheduler: | |
| 30 // 1. Requests to load, cancel, or finish resources from the | |
| 31 // ResourceDispatcherHost. | |
| 32 // 2. Notifications of renderer events from the ResourceSchedulerFilter. | |
| 33 // | |
| 34 // The ResourceScheduler tracks many Clients, which should correlate with tabs. | |
| 35 // A client is uniquely identified by its child_id and route_id. | |
| 36 // | |
| 37 // Each Client may have many Requests in flight. Requests are uniquely | |
| 38 // identified within a Client by their request_ids. | |
| 39 // | |
| 40 // The ResourceDispatcherHost should call ScheduleLoad() when it's ready to | |
| 41 // load a request. The returned LoadHandle should be destroyed when the load | |
| 42 // finishes or is canceled. | |
| 43 class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe { | |
| 44 public: | |
| 45 typedef int64 ClientId; | |
|
darin (slow to review)
2012/12/18 21:09:56
nit: It looks like this typedef can be made privat
James Simonsen
2013/01/10 19:47:53
Done.
| |
| 46 | |
| 47 ResourceScheduler(); | |
| 48 ~ResourceScheduler(); | |
| 49 | |
| 50 // Called when the ResourceDispatcherHost is ready to load a resource. | |
| 51 // Caller should delete the returned Throttle when the load completes or is | |
| 52 // canceled. | |
| 53 scoped_ptr<ResourceThrottle> ScheduleRequest( | |
| 54 int child_id, int route_id, const net::URLRequest& url_request); | |
| 55 | |
| 56 // These events are triggered by ViewHostMsgs. | |
| 57 | |
| 58 // Called when a new client is created. | |
| 59 void OnCreate(int child_id, int route_id); | |
| 60 | |
| 61 // Called when a client navigates to a new main document. | |
| 62 void OnNavigate(int child_id, int route_id); | |
| 63 | |
| 64 // Called the first time a client paints. | |
| 65 void OnFirstPaint(int child_id, int route_id); | |
| 66 | |
| 67 // Called when a client is destroyed. | |
| 68 void OnDestroy(int child_id, int route_id); | |
| 69 | |
| 70 private: | |
| 71 class ScheduledResourceRequest; | |
| 72 friend class ScheduledResourceRequest; | |
| 73 struct Client; | |
| 74 | |
| 75 typedef std::vector<ScheduledResourceRequest*> RequestQueue; | |
| 76 typedef std::set<ScheduledResourceRequest*> RequestSet; | |
| 77 typedef std::map<ClientId, Client*> ClientMap; | |
| 78 | |
| 79 struct Client { | |
| 80 Client(); | |
| 81 ~Client(); | |
| 82 | |
| 83 bool has_painted; | |
| 84 bool has_closed; | |
| 85 RequestQueue pending_requests; | |
| 86 RequestSet in_flight_requests; | |
| 87 }; | |
| 88 | |
| 89 // Called when a ScheduledResourceRequest is destroyed. | |
| 90 void RemoveRequest(ScheduledResourceRequest* request); | |
| 91 | |
| 92 // Unthrottles the |request| and adds it to |client|. | |
| 93 void StartRequest(ScheduledResourceRequest* request, Client* client); | |
| 94 | |
| 95 // Calls StartRequest on all pending requests for |client|. | |
| 96 void LoadPendingRequests(Client* client); | |
| 97 | |
| 98 ClientMap client_map_; | |
| 99 RequestSet unowned_requests_; | |
| 100 }; | |
| 101 | |
| 102 } // namespace content | |
| 103 | |
| 104 #endif // CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ | |
| OLD | NEW |