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

Side by Side 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: DCHECK that there isn't an existing ScheduledResourceRequest attached to the URLRequest. 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ 5 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_
6 #define CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ 6 #define CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
(...skipping 26 matching lines...) Expand all
37 // thread is considered the authority on renderer lifetime, which means some 37 // thread is considered the authority on renderer lifetime, which means some
38 // IPCs may be meaningless if they arrive after the UI thread signals a renderer 38 // IPCs may be meaningless if they arrive after the UI thread signals a renderer
39 // has been deleted. 39 // has been deleted.
40 // 40 //
41 // The ResourceScheduler tracks many Clients, which should correlate with tabs. 41 // The ResourceScheduler tracks many Clients, which should correlate with tabs.
42 // A client is uniquely identified by its child_id and route_id. 42 // A client is uniquely identified by its child_id and route_id.
43 // 43 //
44 // Each Client may have many Requests in flight. Requests are uniquely 44 // Each Client may have many Requests in flight. Requests are uniquely
45 // identified within a Client by its ScheduledResourceRequest. 45 // identified within a Client by its ScheduledResourceRequest.
46 // 46 //
47 // Users should call ScheduleRequest() to notify this ResourceScheduler of a 47 // Users should call ScheduleRequest() to notify this ResourceScheduler of a new
48 // new request. The returned ResourceThrottle should be destroyed when the load 48 // request. The returned ResourceThrottle should be destroyed when the load
49 // finishes or is canceled. 49 // finishes or is canceled, before the net::URLRequest.
50 // 50 //
51 // The scheduler may defer issuing the request via the ResourceThrottle 51 // The scheduler may defer issuing the request via the ResourceThrottle
52 // interface or it may alter the request's priority by calling set_priority() on 52 // interface or it may alter the request's priority by calling set_priority() on
53 // the URLRequest. 53 // the URLRequest.
54 class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe { 54 class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe {
55 public: 55 public:
56 enum ClientThrottleState { 56 enum ClientThrottleState {
57 // TODO(aiolos): Add logic to ShouldStartRequest for PAUSED Clients to only 57 // TODO(aiolos): Add logic to ShouldStartRequest for PAUSED Clients to only
58 // issue synchronous requests. 58 // issue synchronous requests.
59 // TODO(aiolos): Add max number of THROTTLED Clients, and logic to set 59 // TODO(aiolos): Add max number of THROTTLED Clients, and logic to set
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // TODO(aiolos): Remove when throttling and coalescing have landed 97 // TODO(aiolos): Remove when throttling and coalescing have landed
98 void SetThrottleOptionsForTesting(bool should_throttle, bool should_coalesce); 98 void SetThrottleOptionsForTesting(bool should_throttle, bool should_coalesce);
99 99
100 bool should_coalesce() const { return should_coalesce_; } 100 bool should_coalesce() const { return should_coalesce_; }
101 bool should_throttle() const { return should_throttle_; } 101 bool should_throttle() const { return should_throttle_; }
102 102
103 ClientThrottleState GetClientStateForTesting(int child_id, int route_id); 103 ClientThrottleState GetClientStateForTesting(int child_id, int route_id);
104 104
105 // Requests that this ResourceScheduler schedule, and eventually loads, the 105 // Requests that this ResourceScheduler schedule, and eventually loads, the
106 // specified |url_request|. Caller should delete the returned ResourceThrottle 106 // specified |url_request|. Caller should delete the returned ResourceThrottle
107 // when the load completes or is canceled. 107 // when the load completes or is canceled, before |url_request| is deleted.
108 scoped_ptr<ResourceThrottle> ScheduleRequest( 108 scoped_ptr<ResourceThrottle> ScheduleRequest(int child_id,
109 int child_id, int route_id, net::URLRequest* url_request); 109 int route_id,
110 bool is_async,
111 net::URLRequest* url_request);
110 112
111 // Signals from the UI thread, posted as tasks on the IO thread: 113 // Signals from the UI thread, posted as tasks on the IO thread:
112 114
113 // Called when a renderer is created. 115 // Called when a renderer is created.
114 void OnClientCreated(int child_id, 116 void OnClientCreated(int child_id,
115 int route_id, 117 int route_id,
116 bool is_visible, 118 bool is_visible,
117 bool is_audible); 119 bool is_audible);
118 120
119 // Called when a renderer is destroyed. 121 // Called when a renderer is destroyed.
(...skipping 26 matching lines...) Expand all
146 // Client functions: 148 // Client functions:
147 149
148 // Called to check if all user observable tabs have completed loading. 150 // Called to check if all user observable tabs have completed loading.
149 bool active_clients_loaded() const { return active_clients_loading_ == 0; } 151 bool active_clients_loaded() const { return active_clients_loading_ == 0; }
150 152
151 bool IsClientVisibleForTesting(int child_id, int route_id); 153 bool IsClientVisibleForTesting(int child_id, int route_id);
152 154
153 // Returns true if at least one client is currently loading. 155 // Returns true if at least one client is currently loading.
154 bool HasLoadingClients() const; 156 bool HasLoadingClients() const;
155 157
158 // Update the priority for |request|. Modifies request->priority(), and may
159 // start the request loading if it wasn't already started.
160 void ReprioritizeRequest(net::URLRequest* request,
161 net::RequestPriority new_priority,
162 int intra_priority_value);
163
156 private: 164 private:
157 // Returns true if limiting of outstanding requests is enabled. 165 // Returns true if limiting of outstanding requests is enabled.
158 bool limit_outstanding_requests() const { 166 bool limit_outstanding_requests() const {
159 return limit_outstanding_requests_; 167 return limit_outstanding_requests_;
160 } 168 }
161 169
162 // Returns the outstanding request limit. Only valid if 170 // Returns the outstanding request limit. Only valid if
163 // |IsLimitingOutstandingRequests()|. 171 // |IsLimitingOutstandingRequests()|.
164 size_t outstanding_request_limit() const { 172 size_t outstanding_request_limit() const {
165 return outstanding_request_limit_; 173 return outstanding_request_limit_;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 void DecrementCoalescedClients(); 216 void DecrementCoalescedClients();
209 217
210 void LoadCoalescedRequests(); 218 void LoadCoalescedRequests();
211 219
212 size_t CountCoalescedClients() const; 220 size_t CountCoalescedClients() const;
213 221
214 // Returns UNKNOWN if the corresponding client is not found, else returns 222 // Returns UNKNOWN if the corresponding client is not found, else returns
215 // whether the client is ACTIVE (user-observable) or BACKGROUND. 223 // whether the client is ACTIVE (user-observable) or BACKGROUND.
216 ClientState GetClientState(ClientId client_id) const; 224 ClientState GetClientState(ClientId client_id) const;
217 225
218 // Update the queue position for |request|, possibly causing it to start
219 // loading.
220 //
221 // Queues are maintained for each priority level. When |request| is
222 // reprioritized, it will move to the end of the queue for that priority
223 // level.
224 void ReprioritizeRequest(ScheduledResourceRequest* request,
225 net::RequestPriority new_priority,
226 int intra_priority_value);
227
228 // Returns the client ID for the given |child_id| and |route_id| combo. 226 // Returns the client ID for the given |child_id| and |route_id| combo.
229 ClientId MakeClientId(int child_id, int route_id); 227 ClientId MakeClientId(int child_id, int route_id);
230 228
231 // Returns the client for the given |child_id| and |route_id| combo. 229 // Returns the client for the given |child_id| and |route_id| combo.
232 Client* GetClient(int child_id, int route_id); 230 Client* GetClient(int child_id, int route_id);
233 231
234 bool should_coalesce_; 232 bool should_coalesce_;
235 bool should_throttle_; 233 bool should_throttle_;
236 ClientMap client_map_; 234 ClientMap client_map_;
237 size_t active_clients_loading_; 235 size_t active_clients_loading_;
238 size_t coalesced_clients_; 236 size_t coalesced_clients_;
239 bool limit_outstanding_requests_; 237 bool limit_outstanding_requests_;
240 size_t outstanding_request_limit_; 238 size_t outstanding_request_limit_;
241 // This is a repeating timer to initiate requests on COALESCED Clients. 239 // This is a repeating timer to initiate requests on COALESCED Clients.
242 scoped_ptr<base::Timer> coalescing_timer_; 240 scoped_ptr<base::Timer> coalescing_timer_;
243 RequestSet unowned_requests_; 241 RequestSet unowned_requests_;
242
243 DISALLOW_COPY_AND_ASSIGN(ResourceScheduler);
244 }; 244 };
245 245
246 } // namespace content 246 } // namespace content
247 247
248 #endif // CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ 248 #endif // CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_unittest.cc ('k') | content/browser/loader/resource_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698