| 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 "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 class ResourceThrottle; |
| 25 |
| 26 // There is one ResourceScheduler, which is owned by the ResourceDispatcherHost. |
| 27 // |
| 28 // These are sources of input to the scheduler: |
| 29 // 1. Requests to load, cancel, or finish resources from the |
| 30 // ResourceDispatcherHost. |
| 31 // 2. Notifications of renderer events from the ResourceSchedulerFilter. |
| 32 // |
| 33 // The ResourceScheduler tracks many Clients, which should correlate with tabs. |
| 34 // A client is uniquely identified by its child_id and route_id. |
| 35 // |
| 36 // Each Client may have many Requests in flight. Requests are uniquely |
| 37 // identified within a Client by their request_ids. |
| 38 // |
| 39 // The ResourceDispatcherHost should call ScheduleLoad() when it's ready to |
| 40 // load a request. The returned LoadHandle should be destroyed when the load |
| 41 // finishes or is canceled. |
| 42 class CONTENT_EXPORT ResourceScheduler { |
| 43 public: |
| 44 typedef int64 ClientId; |
| 45 |
| 46 ResourceScheduler(); |
| 47 ~ResourceScheduler(); |
| 48 |
| 49 // Called when the ResourceDispatcherHost is ready to load a resource. |
| 50 // Caller should delete the returned Throttle when the load completes or is |
| 51 // canceled. |
| 52 scoped_ptr<ResourceThrottle> ScheduleRequest( |
| 53 int child_id, int route_id, const net::URLRequest& url_request); |
| 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 the first time a client paints. |
| 64 void OnFirstPaint(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 class ScheduledResourceThrottle; |
| 71 friend class ScheduledResourceThrottle; |
| 72 struct Client; |
| 73 |
| 74 typedef std::vector<ScheduledResourceThrottle*> RequestQueue; |
| 75 typedef std::set<ScheduledResourceThrottle*> RequestSet; |
| 76 typedef std::map<ClientId, Client*> ClientMap; |
| 77 |
| 78 struct Client { |
| 79 Client(); |
| 80 ~Client(); |
| 81 |
| 82 bool has_painted; |
| 83 bool has_closed; |
| 84 RequestQueue pending_requests; |
| 85 RequestSet in_flight_requests; |
| 86 }; |
| 87 |
| 88 // Called when a ScheduledResourceThrottle is destroyed. |
| 89 void RemoveRequest(ScheduledResourceThrottle* request); |
| 90 |
| 91 // Unthrottles the |request| and adds it to |client|. |
| 92 void StartRequest(ScheduledResourceThrottle* request, Client* client); |
| 93 |
| 94 // Calls StartRequest on all pending requests for |client|. |
| 95 void LoadPendingRequests(Client* client); |
| 96 |
| 97 ClientMap client_map_; |
| 98 RequestSet unowned_requests_; |
| 99 }; |
| 100 |
| 101 } // namespace content |
| 102 |
| 103 #endif // CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ |
| OLD | NEW |