| 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..dac57bc7693f8db86a7f0c5a34bb34fd97c12e2b
|
| --- /dev/null
|
| +++ b/content/browser/renderer_host/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_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 "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
|
| +// 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_RENDERER_HOST_RESOURCE_SCHEDULER_H_
|
|
|