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_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 "content/common/content_export.h" | |
| 15 #include "content/public/browser/global_request_id.h" | |
| 16 | |
| 17 namespace content { | |
| 18 class ResourceLoader; | |
| 19 | |
| 20 // There is one ResourceScheduler, which is owned by the ResourceDispatcherHost. | |
| 21 // | |
| 22 // These are sources of input to the scheduler: | |
| 23 // 1. Requests to load, cancel, or finish resources from the | |
| 24 // ResourceDispatcherHost. | |
| 25 // 2. Notifications of renderer events from the ResourceSchedulerFilter. | |
| 26 // | |
| 27 // The ResourceScheduler tracks many Clients, which should correlate with tabs. | |
| 28 // A client is uniquely identified by its child_id and route_id. | |
| 29 // | |
| 30 // Each Client may have many Requests in flight. Requests are uniquely | |
| 31 // identified within a Client by their request_ids. | |
| 32 // | |
| 33 // The scheduling behavior mimicks WebKit's scheduler, which blocks fetching | |
| 34 // low priority resources until the first paint has occurred. One exception is | |
| 35 // if the client is not fetching anything else, low priority fetching begins | |
| 36 // immediately. | |
| 37 // | |
| 38 // TODO(simonjam): This'd be CONTENT_EXPORT_PRIVATE if we had such a thing. | |
|
willchan no longer on Chromium
2012/10/25 19:44:49
Why don't we have this? Aren't we trying to write
James Simonsen
2012/11/17 02:56:15
Done.
| |
| 39 class CONTENT_EXPORT ResourceScheduler { | |
| 40 public: | |
| 41 ResourceScheduler(); | |
| 42 ~ResourceScheduler(); | |
| 43 | |
| 44 // Called when the ResourceDispatcherHost is ready to load a resource. | |
| 45 void ScheduleLoad(int child_id, | |
| 46 int route_id, | |
| 47 int request_id, | |
| 48 ResourceLoader* loader); | |
| 49 | |
| 50 // Called when the ResourceDispatcherHost is done loading a resource. | |
| 51 void RemoveLoad(int child_id, | |
| 52 int route_id, | |
| 53 int request_id); | |
| 54 | |
| 55 // These events are triggered by ViewHostMsgs. | |
| 56 | |
| 57 // Called when a new client is created. | |
| 58 void OnCreate(int child_id, int route_id); | |
| 59 | |
| 60 // Called when a client navigates to a new main document. | |
| 61 void OnNavigate(int child_id, int route_id); | |
| 62 | |
| 63 // Called any time a client paints. | |
| 64 void OnPaint(int child_id, int route_id); | |
| 65 | |
| 66 // Called when a client is destroyed. | |
| 67 void OnDestroy(int child_id, int route_id); | |
| 68 | |
| 69 private: | |
| 70 struct Client; | |
| 71 struct Request; | |
| 72 | |
| 73 typedef std::vector<Request> RequestQueue; | |
| 74 typedef std::set<int> RequestIdSet; | |
| 75 typedef std::map<int64, Client*> ClientMap; | |
| 76 | |
| 77 struct Request { | |
| 78 int request_id; | |
| 79 ResourceLoader* loader; | |
| 80 }; | |
| 81 | |
| 82 struct Client { | |
| 83 Client(); | |
| 84 | |
| 85 bool has_painted; | |
| 86 RequestQueue pending_requests; | |
| 87 RequestIdSet in_flight_requests; | |
| 88 }; | |
| 89 | |
| 90 // Kicks off the loader for |request| and adds it to |client|. | |
| 91 void StartRequest(Request request, Client* client); | |
| 92 | |
| 93 // Calls StartRequest on all pending requests for |client|. | |
| 94 void LoadPendingRequests(Client* client); | |
| 95 | |
| 96 ClientMap client_map_; | |
| 97 }; | |
| 98 | |
| 99 } // namespace content | |
| 100 | |
| 101 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_SCHEDULER_H_ | |
| OLD | NEW |