Chromium Code Reviews| Index: content/browser/renderer_host/resource_scheduler.h |
| diff --git a/content/browser/renderer_host/resource_scheduler.h b/content/browser/renderer_host/resource_scheduler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1cd32dde9f58c6ea1757a7bdcf438c457be060a5 |
| --- /dev/null |
| +++ b/content/browser/renderer_host/resource_scheduler.h |
| @@ -0,0 +1,101 @@ |
| +// 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_RENDERER_HOST_RESOURCE_SCHEDULER_H_ |
| +#define CONTENT_BROWSER_RENDERER_HOST_RESOURCE_SCHEDULER_H_ |
| + |
| +#include <map> |
| +#include <set> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/compiler_specific.h" |
| +#include "content/common/content_export.h" |
| +#include "content/public/browser/global_request_id.h" |
| + |
| +namespace content { |
| +class ResourceLoader; |
| + |
| +// 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 scheduling behavior mimicks WebKit's scheduler, which blocks fetching |
| +// 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. |
| +// |
| +// 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.
|
| +class CONTENT_EXPORT ResourceScheduler { |
| + public: |
| + ResourceScheduler(); |
| + ~ResourceScheduler(); |
| + |
| + // Called when the ResourceDispatcherHost is ready to load a resource. |
| + void ScheduleLoad(int child_id, |
| + int route_id, |
| + int request_id, |
| + ResourceLoader* loader); |
| + |
| + // Called when the ResourceDispatcherHost is done loading a resource. |
| + void RemoveLoad(int child_id, |
| + int route_id, |
| + int request_id); |
| + |
| + // 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: |
| + struct Client; |
| + struct Request; |
| + |
| + typedef std::vector<Request> RequestQueue; |
| + typedef std::set<int> RequestIdSet; |
| + typedef std::map<int64, Client*> ClientMap; |
| + |
| + struct Request { |
| + int request_id; |
| + ResourceLoader* loader; |
| + }; |
| + |
| + struct Client { |
| + Client(); |
| + |
| + bool has_painted; |
| + RequestQueue pending_requests; |
| + RequestIdSet in_flight_requests; |
| + }; |
| + |
| + // 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_; |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_SCHEDULER_H_ |