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..1e48696e4550e7315ab0f275734c1df39246e303 |
| --- /dev/null |
| +++ b/content/browser/loader/resource_scheduler.h |
| @@ -0,0 +1,131 @@ |
| +// 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 "content/common/content_export.h" |
| +#include "content/public/browser/global_request_id.h" |
| + |
| +namespace net { |
| +class URLRequest; |
| +} |
| + |
| +namespace content { |
| + |
| +// There is one ResourceScheduler, which is owned by the ResourceDispatcherHost. |
| +// |
| +// 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. |
| +// |
| +// The scheduling behavior mimicks WebKit's scheduler, which blocks fetching |
|
willchan no longer on Chromium
2012/12/13 06:30:43
Let's kill off this comment. We're going to diverg
James Simonsen
2012/12/14 20:23:23
Done.
|
| +// low priority resources until the first paint has occurred. One exception is |
| +// if the client is not fetching anything else, low priority fetching begins |
| +// immediately. |
| +class CONTENT_EXPORT ResourceScheduler { |
| + public: |
| + typedef int64 ClientId; |
| + typedef int64 SchedulerId; |
| + |
| + // A LoadHandle is returned to the ResourceLoader. When the loader deletes the |
| + // handle, it's automatically removed from ResourceScheduler's state. |
| + class LoadHandle { |
| + public: |
| + virtual ~LoadHandle() {} |
| + }; |
| + |
| + // ResourceScheduler's interface back to the ResourceLoader. Allows |
| + // ResourceScheduler to initiate loads and read information about the request. |
| + class Loadable { |
| + public: |
| + virtual ~Loadable() {} |
| + virtual void StartRequest() = 0; |
| + virtual const net::URLRequest* url_request() = 0; |
| + }; |
| + |
| + ResourceScheduler(); |
| + ~ResourceScheduler(); |
| + |
| + // Called when the ResourceDispatcherHost is ready to load a resource. |
| + // Caller should delete the returned handle when the load completes or is |
| + // canceled. |
| + scoped_ptr<LoadHandle> ScheduleLoad(int child_id, |
| + int route_id, |
| + Loadable* loadable); |
| + |
| + // 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 any time a client paints. |
| + void OnPaint(int child_id, int route_id); |
| + |
| + // Called when a client is destroyed. |
| + void OnDestroy(int child_id, int route_id); |
| + |
| + private: |
| + friend class LoadHandleImpl; |
| + struct Client; |
| + struct Request; |
| + |
| + typedef std::vector<Request> RequestQueue; |
| + typedef std::set<SchedulerId> SchedulerIdSet; |
| + typedef std::map<ClientId, Client*> ClientMap; |
| + |
| + struct Request { |
| + SchedulerId scheduler_id; |
| + Loadable* loadable; |
| + }; |
| + |
| + struct Client { |
| + Client(); |
| + ~Client(); |
| + |
| + bool has_painted; |
| + bool has_closed; |
| + RequestQueue pending_requests; |
| + SchedulerIdSet in_flight_requests; |
| + }; |
| + |
| + // Called when a LoadHandle is destroyed. |
| + void RemoveLoad(SchedulerId scheduler_id, ClientId client_id); |
| + |
| + // Kicks off the loader for |request| and adds it to |client|. |
| + void StartRequest(Request request, Client* client); |
| + |
| + // Calls StartRequest on all pending requests for |client|. |
| + void LoadPendingRequests(Client* client); |
| + |
| + ClientMap client_map_; |
| + SchedulerId next_scheduler_id_; |
| + SchedulerIdSet unowned_requests_; |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ |