Chromium Code Reviews| Index: content/browser/loader/resource_scheduler.h |
| diff --git a/content/browser/loader/resource_scheduler.h b/content/browser/loader/resource_scheduler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6cd6dbfeac5767677be48f25996bb63dd9cfd690 |
| --- /dev/null |
| +++ b/content/browser/loader/resource_scheduler.h |
| @@ -0,0 +1,104 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ |
| +#define CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ |
| + |
| +#include <map> |
| +#include <set> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/compiler_specific.h" |
| +#include "base/memory/linked_ptr.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/threading/non_thread_safe.h" |
| +#include "content/common/content_export.h" |
| +#include "content/public/browser/global_request_id.h" |
| + |
| +namespace net { |
| +class URLRequest; |
| +} |
| + |
| +namespace content { |
| +class ResourceThrottle; |
| + |
| +// 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.
|
| +// |
| +// These are sources of input to the scheduler: |
| +// 1. Requests to load, cancel, or finish resources from the |
| +// ResourceDispatcherHost. |
| +// 2. Notifications of renderer events from the ResourceSchedulerFilter. |
| +// |
| +// The ResourceScheduler tracks many Clients, which should correlate with tabs. |
| +// A client is uniquely identified by its child_id and route_id. |
| +// |
| +// Each Client may have many Requests in flight. Requests are uniquely |
| +// identified within a Client by their request_ids. |
| +// |
| +// The ResourceDispatcherHost should call ScheduleLoad() when it's ready to |
| +// load a request. The returned LoadHandle should be destroyed when the load |
| +// finishes or is canceled. |
| +class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe { |
| + public: |
| + 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.
|
| + |
| + ResourceScheduler(); |
| + ~ResourceScheduler(); |
| + |
| + // Called when the ResourceDispatcherHost is ready to load a resource. |
| + // Caller should delete the returned Throttle when the load completes or is |
| + // canceled. |
| + scoped_ptr<ResourceThrottle> ScheduleRequest( |
| + int child_id, int route_id, const net::URLRequest& url_request); |
| + |
| + // These events are triggered by ViewHostMsgs. |
| + |
| + // Called when a new client is created. |
| + void OnCreate(int child_id, int route_id); |
| + |
| + // Called when a client navigates to a new main document. |
| + void OnNavigate(int child_id, int route_id); |
| + |
| + // Called the first time a client paints. |
| + void OnFirstPaint(int child_id, int route_id); |
| + |
| + // Called when a client is destroyed. |
| + void OnDestroy(int child_id, int route_id); |
| + |
| + private: |
| + class ScheduledResourceRequest; |
| + friend class ScheduledResourceRequest; |
| + struct Client; |
| + |
| + typedef std::vector<ScheduledResourceRequest*> RequestQueue; |
| + typedef std::set<ScheduledResourceRequest*> RequestSet; |
| + typedef std::map<ClientId, Client*> ClientMap; |
| + |
| + struct Client { |
| + Client(); |
| + ~Client(); |
| + |
| + bool has_painted; |
| + bool has_closed; |
| + RequestQueue pending_requests; |
| + RequestSet in_flight_requests; |
| + }; |
| + |
| + // Called when a ScheduledResourceRequest is destroyed. |
| + void RemoveRequest(ScheduledResourceRequest* request); |
| + |
| + // Unthrottles the |request| and adds it to |client|. |
| + void StartRequest(ScheduledResourceRequest* request, Client* client); |
| + |
| + // Calls StartRequest on all pending requests for |client|. |
| + void LoadPendingRequests(Client* client); |
| + |
| + ClientMap client_map_; |
| + RequestSet unowned_requests_; |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ |