Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Unified Diff: content/browser/loader/resource_scheduler.h

Issue 1285863003: ResourceScheduler: remove dependency on ResourceRequestInfo and request_id (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Changes suggested by davidben@ Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/loader/resource_scheduler.h
diff --git a/content/browser/loader/resource_scheduler.h b/content/browser/loader/resource_scheduler.h
index 60cf0cd69f8c10360b3c3f43babb2a61744e7443..2d5d986203030ab1836d18b13909d2a7069ad39c 100644
--- a/content/browser/loader/resource_scheduler.h
+++ b/content/browser/loader/resource_scheduler.h
@@ -14,6 +14,7 @@
#include "base/threading/non_thread_safe.h"
#include "base/timer/timer.h"
#include "content/common/content_export.h"
+#include "content/public/browser/resource_throttle.h"
#include "net/base/priority_queue.h"
#include "net/base/request_priority.h"
@@ -23,7 +24,6 @@ class URLRequest;
}
namespace content {
-class ResourceThrottle;
// There is one ResourceScheduler. All renderer-initiated HTTP requests are
// expected to pass through it.
@@ -44,9 +44,9 @@ class ResourceThrottle;
// Each Client may have many Requests in flight. Requests are uniquely
// identified within a Client by its ScheduledResourceRequest.
//
-// Users should call ScheduleRequest() to notify this ResourceScheduler of a
-// new request. The returned ResourceThrottle should be destroyed when the load
-// finishes or is canceled.
+// Users should call ScheduleRequest() to notify this ResourceScheduler of a new
+// request. The returned ScheduledResourceRequest should be destroyed when the
+// load finishes or is canceled, before the net::URLRequest.
//
// The scheduler may defer issuing the request via the ResourceThrottle
// interface or it may alter the request's priority by calling set_priority() on
@@ -86,6 +86,25 @@ class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe {
LAYOUT_BLOCKING_REQUEST,
};
+ // Handle for a scheduled request. On creation, it will attach itself to the
+ // net::URLRequest it is associated with. On destruction, it will detach
+ // itself. It must be destroyed before the associated URLRequest.
+ class ScheduledResourceRequest : public ResourceThrottle {
+ public:
+ ScheduledResourceRequest();
+ ~ScheduledResourceRequest() override;
+
+ virtual void ChangePriority(net::RequestPriority new_priority,
+ int intra_priority_value) = 0;
+
+ // If there currently exists a ScheduledResourceRequest-implementing object
+ // for |request|, then return it. Otherwise returns nullptr.
+ static ScheduledResourceRequest* ForRequest(net::URLRequest* request);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ScheduledResourceRequest);
+ };
+
ResourceScheduler();
~ResourceScheduler();
@@ -103,10 +122,13 @@ class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe {
ClientThrottleState GetClientStateForTesting(int child_id, int route_id);
// Requests that this ResourceScheduler schedule, and eventually loads, the
- // specified |url_request|. Caller should delete the returned ResourceThrottle
- // when the load completes or is canceled.
- scoped_ptr<ResourceThrottle> ScheduleRequest(
- int child_id, int route_id, net::URLRequest* url_request);
+ // specified |url_request|. Caller should delete the returned
+ // ScheduledResourceRequest when the load completes or is canceled.
+ scoped_ptr<ScheduledResourceRequest> ScheduleRequest(
+ int child_id,
+ int route_id,
+ bool is_async,
+ net::URLRequest* url_request);
// Signals from the UI thread, posted as tasks on the IO thread:
@@ -154,6 +176,8 @@ class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe {
bool HasLoadingClients() const;
private:
+ friend class ScheduledResourceRequest;
+
// Returns true if limiting of outstanding requests is enabled.
bool limit_outstanding_requests() const {
return limit_outstanding_requests_;
@@ -175,20 +199,20 @@ class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe {
};
class RequestQueue;
- class ScheduledResourceRequest;
+ class ScheduledResourceRequestImpl;
struct RequestPriorityParams;
struct ScheduledResourceSorter {
- bool operator()(const ScheduledResourceRequest* a,
- const ScheduledResourceRequest* b) const;
+ bool operator()(const ScheduledResourceRequestImpl* a,
+ const ScheduledResourceRequestImpl* b) const;
};
class Client;
typedef int64 ClientId;
typedef std::map<ClientId, Client*> ClientMap;
- typedef std::set<ScheduledResourceRequest*> RequestSet;
+ typedef std::set<ScheduledResourceRequestImpl*> RequestSet;
- // Called when a ScheduledResourceRequest is destroyed.
- void RemoveRequest(ScheduledResourceRequest* request);
+ // Called when a ScheduledResourceRequestImpl is destroyed.
+ void RemoveRequest(ScheduledResourceRequestImpl* request);
// These calls may update the ThrottleState of all clients, and have the
// potential to be re-entrant.
@@ -221,7 +245,7 @@ class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe {
// 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,
+ void ReprioritizeRequest(ScheduledResourceRequestImpl* request,
net::RequestPriority new_priority,
int intra_priority_value);
@@ -241,6 +265,8 @@ class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe {
// This is a repeating timer to initiate requests on COALESCED Clients.
scoped_ptr<base::Timer> coalescing_timer_;
RequestSet unowned_requests_;
+
+ DISALLOW_COPY_AND_ASSIGN(ResourceScheduler);
};
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698