| 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 "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 // |
| 42 // The scheduling behavior mimicks WebKit's scheduler, which blocks fetching |
| 43 // low priority resources until the first paint has occurred. One exception is |
| 44 // if the client is not fetching anything else, low priority fetching begins |
| 45 // immediately. |
| 46 class CONTENT_EXPORT ResourceScheduler { |
| 47 public: |
| 48 typedef int64 ClientId; |
| 49 typedef int64 SchedulerId; |
| 50 |
| 51 // A LoadHandle is returned to the ResourceLoader. When the loader deletes the |
| 52 // handle, it's automatically removed from ResourceScheduler's state. |
| 53 class LoadHandle { |
| 54 public: |
| 55 virtual ~LoadHandle() {} |
| 56 }; |
| 57 |
| 58 // ResourceScheduler's interface back to the ResourceLoader. Allows |
| 59 // ResourceScheduler to initiate loads and read information about the request. |
| 60 class Loadable { |
| 61 public: |
| 62 virtual ~Loadable() {} |
| 63 virtual void StartRequest() = 0; |
| 64 virtual const net::URLRequest* url_request() = 0; |
| 65 }; |
| 66 |
| 67 ResourceScheduler(); |
| 68 ~ResourceScheduler(); |
| 69 |
| 70 // Called when the ResourceDispatcherHost is ready to load a resource. |
| 71 // Caller should delete the returned handle when the load completes or is |
| 72 // canceled. |
| 73 scoped_ptr<LoadHandle> ScheduleLoad(int child_id, |
| 74 int route_id, |
| 75 Loadable* loadable); |
| 76 |
| 77 // These events are triggered by ViewHostMsgs. |
| 78 |
| 79 // Called when a new client is created. |
| 80 void OnCreate(int child_id, int route_id); |
| 81 |
| 82 // Called when a client navigates to a new main document. |
| 83 void OnNavigate(int child_id, int route_id); |
| 84 |
| 85 // Called any time a client paints. |
| 86 void OnPaint(int child_id, int route_id); |
| 87 |
| 88 // Called when a client is destroyed. |
| 89 void OnDestroy(int child_id, int route_id); |
| 90 |
| 91 private: |
| 92 friend class LoadHandleImpl; |
| 93 struct Client; |
| 94 struct Request; |
| 95 |
| 96 typedef std::vector<Request> RequestQueue; |
| 97 typedef std::set<SchedulerId> SchedulerIdSet; |
| 98 typedef std::map<ClientId, Client*> ClientMap; |
| 99 |
| 100 struct Request { |
| 101 SchedulerId scheduler_id; |
| 102 Loadable* loadable; |
| 103 }; |
| 104 |
| 105 struct Client { |
| 106 Client(); |
| 107 ~Client(); |
| 108 |
| 109 bool has_painted; |
| 110 bool has_closed; |
| 111 RequestQueue pending_requests; |
| 112 SchedulerIdSet in_flight_requests; |
| 113 }; |
| 114 |
| 115 // Called when a LoadHandle is destroyed. |
| 116 void RemoveLoad(SchedulerId scheduler_id, ClientId client_id); |
| 117 |
| 118 // Kicks off the loader for |request| and adds it to |client|. |
| 119 void StartRequest(Request request, Client* client); |
| 120 |
| 121 // Calls StartRequest on all pending requests for |client|. |
| 122 void LoadPendingRequests(Client* client); |
| 123 |
| 124 ClientMap client_map_; |
| 125 SchedulerId next_scheduler_id_; |
| 126 SchedulerIdSet unowned_requests_; |
| 127 }; |
| 128 |
| 129 } // namespace content |
| 130 |
| 131 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_SCHEDULER_H_ |
| OLD | NEW |