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 |
| index fa53c5b318f291d1d68a6054f4353d20958552b1..4bd61529784d19f4d6725a08dd1bedd6b6ea44f9 100644 |
| --- a/content/browser/loader/resource_scheduler.h |
| +++ b/content/browser/loader/resource_scheduler.h |
| @@ -7,7 +7,6 @@ |
| #include <map> |
| #include <set> |
| -#include <vector> |
| #include "base/basictypes.h" |
| #include "base/compiler_specific.h" |
| @@ -16,6 +15,8 @@ |
| #include "base/threading/non_thread_safe.h" |
| #include "content/common/content_export.h" |
| #include "content/public/browser/global_request_id.h" |
|
willchan no longer on Chromium
2013/03/19 23:08:32
delete (maybe you need to move to .cc?)?
James Simonsen
2013/03/20 00:32:04
Done.
|
| +#include "net/base/priority_queue.h" |
| +#include "net/base/request_priority.h" |
| namespace net { |
| class URLRequest; |
| @@ -32,6 +33,11 @@ class ResourceThrottle; |
| // 2. Notifications for renderer events, such as new tabs, navigation and |
| // painting. |
| // |
| +// These input come from different threads, so they may not be in sync. The UI |
| +// thread is considered the authority on renderer lifetime, which means some |
| +// IPCs may be meaningless if they arrive after the UI thread signals a renderer |
| +// has been deleted. |
| +// |
| // The ResourceScheduler tracks many Clients, which should correlate with tabs. |
| // A client is uniquely identified by its child_id and route_id. |
| // |
| @@ -56,12 +62,16 @@ class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe { |
| scoped_ptr<ResourceThrottle> ScheduleRequest( |
| int child_id, int route_id, net::URLRequest* url_request); |
| + // Signals from the UI thread, posted as tasks on the IO thread: |
| + |
| // Called when a renderer is created. |
| void OnClientCreated(int child_id, int route_id); |
| // Called when a renderer is destroyed. |
| void OnClientDeleted(int child_id, int route_id); |
| + // Signals from IPC messages directly from the renderers: |
| + |
| // Called when a client navigates to a new main document. |
| void OnNavigate(int child_id, int route_id); |
| @@ -70,32 +80,41 @@ class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe { |
| void OnWillInsertBody(int child_id, int route_id); |
| private: |
| + class RequestQueue; |
| class ScheduledResourceRequest; |
| - friend class ScheduledResourceRequest; |
| struct Client; |
| typedef int64 ClientId; |
| typedef std::map<ClientId, Client*> ClientMap; |
| - typedef std::vector<ScheduledResourceRequest*> RequestQueue; |
| typedef std::set<ScheduledResourceRequest*> RequestSet; |
| - struct Client { |
| - Client(); |
| - ~Client(); |
| - |
| - bool has_body; |
| - 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); |
| + // Update the queue position for |request|, possibly causing it to start |
| + // loading. |
| + // |
| + // Queues are maintained for each priority level. When |request| is |
| + // reprioritized, it will move to the end of the queue for that priority |
| + // level. |
| + void ReprioritizeRequest(ScheduledResourceRequest* request, |
| + net::RequestPriority new_priority); |
| + |
| + // Attempts to load any pending requests in |client|, based on the |
| + // results of ShouldStartRequest(). |
| + void LoadAnyStartablePendingRequests(Client* client); |
| + |
| + // Returns the number of requests with priority < LOW that are currently in |
| + // flight. |
| + size_t GetNumDelayableRequestsInFlight(Client* client) const; |
| + |
| + // Returns true if the request should start. This is the core scheduling |
| + // algorithm. |
| + bool ShouldStartRequest(ScheduledResourceRequest* request, |
| + Client* client) const; |
| // Returns the client ID for the given |child_id| and |route_id| combo. |
| ClientId MakeClientId(int child_id, int route_id); |