OLD | NEW |
---|---|
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 #include <set> | |
6 | |
5 #include "content/browser/loader/resource_scheduler.h" | 7 #include "content/browser/loader/resource_scheduler.h" |
6 | 8 |
7 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
8 #include "content/common/resource_messages.h" | 10 #include "content/common/resource_messages.h" |
9 #include "content/browser/loader/resource_message_delegate.h" | 11 #include "content/browser/loader/resource_message_delegate.h" |
10 #include "content/public/browser/resource_controller.h" | 12 #include "content/public/browser/resource_controller.h" |
11 #include "content/public/browser/resource_request_info.h" | 13 #include "content/public/browser/resource_request_info.h" |
12 #include "content/public/browser/resource_throttle.h" | 14 #include "content/public/browser/resource_throttle.h" |
13 #include "ipc/ipc_message_macros.h" | 15 #include "ipc/ipc_message_macros.h" |
14 #include "net/base/host_port_pair.h" | 16 #include "net/base/host_port_pair.h" |
15 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
16 #include "net/base/request_priority.h" | 18 #include "net/base/request_priority.h" |
17 #include "net/http/http_server_properties.h" | 19 #include "net/http/http_server_properties.h" |
18 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
19 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
20 | 22 |
21 namespace content { | 23 namespace content { |
22 | 24 |
23 static const size_t kMaxNumDelayableRequestsPerClient = 10; | 25 static const size_t kMaxNumDelayableRequestsPerClient = 10; |
24 static const size_t kMaxNumDelayableRequestsPerHost = 6; | 26 static const size_t kMaxNumDelayableRequestsPerHost = 6; |
25 | 27 |
26 // A thin wrapper around net::PriorityQueue that deals with | 28 |
27 // ScheduledResourceRequests instead of PriorityQueue::Pointers. | 29 struct ResourceScheduler::RequestPriorityParams { |
30 RequestPriorityParams() | |
31 : priority(net::DEFAULT_PRIORITY), | |
32 intra_priority(0) | |
darin (slow to review)
2014/03/24 18:23:33
nit: opening "{" on previous line
shatch
2014/03/24 21:08:44
Done.
| |
33 { | |
34 } | |
35 | |
36 RequestPriorityParams(net::RequestPriority priority, int intra_priority) | |
37 : priority(priority), | |
38 intra_priority(intra_priority) { | |
39 } | |
40 | |
41 bool operator==(const RequestPriorityParams& other) const { | |
42 return (priority == other.priority) && | |
43 (intra_priority == other.intra_priority); | |
44 } | |
45 | |
46 bool operator!=(const RequestPriorityParams& other) const { | |
47 return (priority != other.priority) || | |
darin (slow to review)
2014/03/24 18:23:33
nit: Implement in terms of operator== ? e.g.: ret
shatch
2014/03/24 21:08:44
Done.
| |
48 (intra_priority != other.intra_priority); | |
49 } | |
50 | |
51 bool GetSortingValue(const RequestPriorityParams& other) const { | |
darin (slow to review)
2014/03/24 18:23:33
nit: maybe call this function GreaterThan (or inve
shatch
2014/03/24 21:08:44
Done.
| |
52 if (priority != other.priority) | |
53 return priority > other.priority; | |
54 return intra_priority > other.intra_priority; | |
55 } | |
56 | |
57 net::RequestPriority priority; | |
58 int intra_priority; | |
59 }; | |
60 | |
28 class ResourceScheduler::RequestQueue { | 61 class ResourceScheduler::RequestQueue { |
29 private: | 62 public: |
30 typedef net::PriorityQueue<ScheduledResourceRequest*> NetQueue; | 63 typedef std::multiset<ScheduledResourceRequest*, ScheduledResourceSorter> |
64 NetQueue; | |
31 | 65 |
32 public: | 66 RequestQueue() : fifo_ordering_ids_(0) {} |
33 class Iterator { | |
34 public: | |
35 Iterator(NetQueue* queue) : queue_(queue) { | |
36 DCHECK(queue != NULL); | |
37 current_pointer_ = queue_->FirstMax(); | |
38 } | |
39 | |
40 Iterator& operator++() { | |
41 current_pointer_ = queue_->GetNextTowardsLastMin(current_pointer_); | |
42 return *this; | |
43 } | |
44 | |
45 Iterator operator++(int) { | |
46 Iterator result(*this); | |
47 ++(*this); | |
48 return result; | |
49 } | |
50 | |
51 ScheduledResourceRequest* value() { | |
52 return current_pointer_.value(); | |
53 } | |
54 | |
55 bool is_null() { | |
56 return current_pointer_.is_null(); | |
57 } | |
58 | |
59 private: | |
60 NetQueue* queue_; | |
61 NetQueue::Pointer current_pointer_; | |
62 }; | |
63 | |
64 RequestQueue() : queue_(net::NUM_PRIORITIES) {} | |
65 ~RequestQueue() {} | 67 ~RequestQueue() {} |
66 | 68 |
67 // Adds |request| to the queue with given |priority|. | 69 // Adds |request| to the queue with given |priority|. |
68 void Insert(ScheduledResourceRequest* request, | 70 void Insert(ScheduledResourceRequest* request); |
69 net::RequestPriority priority) { | |
70 DCHECK(!ContainsKey(pointers_, request)); | |
71 NetQueue::Pointer pointer = queue_.Insert(request, priority); | |
72 pointers_[request] = pointer; | |
73 } | |
74 | 71 |
75 // Removes |request| from the queue. | 72 // Removes |request| from the queue. |
76 void Erase(ScheduledResourceRequest* request) { | 73 void Erase(ScheduledResourceRequest* request) { |
77 PointerMap::iterator it = pointers_.find(request); | 74 PointerMap::iterator it = pointers_.find(request); |
78 DCHECK(it != pointers_.end()); | 75 DCHECK(it != pointers_.end()); |
79 if (it == pointers_.end()) | 76 if (it == pointers_.end()) |
80 return; | 77 return; |
81 queue_.Erase(it->second); | 78 queue_.erase(it->second); |
82 pointers_.erase(it); | 79 pointers_.erase(it); |
83 } | 80 } |
84 | 81 |
85 // Returns the highest priority request that's queued, or NULL if none are. | 82 NetQueue::iterator GetNextHighestIterator() { |
86 ScheduledResourceRequest* FirstMax() { | 83 return queue_.begin(); |
87 return queue_.FirstMax().value(); | |
88 } | 84 } |
89 | 85 |
90 Iterator GetNextHighestIterator() { | 86 NetQueue::iterator End() { |
91 return Iterator(&queue_); | 87 return queue_.end(); |
92 } | 88 } |
93 | 89 |
94 // Returns true if |request| is queued. | 90 // Returns true if |request| is queued. |
95 bool IsQueued(ScheduledResourceRequest* request) const { | 91 bool IsQueued(ScheduledResourceRequest* request) const { |
96 return ContainsKey(pointers_, request); | 92 return ContainsKey(pointers_, request); |
97 } | 93 } |
98 | 94 |
99 // Returns true if no requests are queued. | 95 // Returns true if no requests are queued. |
100 bool IsEmpty() const { return queue_.size() == 0; } | 96 bool IsEmpty() const { return queue_.size() == 0; } |
101 | 97 |
102 private: | 98 private: |
103 typedef std::map<ScheduledResourceRequest*, NetQueue::Pointer> PointerMap; | 99 typedef std::map<ScheduledResourceRequest*, NetQueue::iterator> PointerMap; |
100 | |
101 uint32 MakeFifoOrderingId() { | |
102 fifo_ordering_ids_ += 1; | |
103 return fifo_ordering_ids_; | |
104 } | |
105 | |
106 // Used to create an ordering ID for scheduled resources so that resources | |
107 // with same priority/intra_priority stay in fifo order. | |
108 uint32 fifo_ordering_ids_; | |
104 | 109 |
105 NetQueue queue_; | 110 NetQueue queue_; |
106 PointerMap pointers_; | 111 PointerMap pointers_; |
107 }; | 112 }; |
108 | 113 |
109 // This is the handle we return to the ResourceDispatcherHostImpl so it can | 114 // This is the handle we return to the ResourceDispatcherHostImpl so it can |
110 // interact with the request. | 115 // interact with the request. |
111 class ResourceScheduler::ScheduledResourceRequest | 116 class ResourceScheduler::ScheduledResourceRequest |
112 : public ResourceMessageDelegate, | 117 : public ResourceMessageDelegate, |
113 public ResourceThrottle { | 118 public ResourceThrottle { |
114 public: | 119 public: |
115 ScheduledResourceRequest(const ClientId& client_id, | 120 ScheduledResourceRequest(const ClientId& client_id, |
116 net::URLRequest* request, | 121 net::URLRequest* request, |
117 ResourceScheduler* scheduler) | 122 ResourceScheduler* scheduler, |
123 const RequestPriorityParams& priority) | |
118 : ResourceMessageDelegate(request), | 124 : ResourceMessageDelegate(request), |
119 client_id_(client_id), | 125 client_id_(client_id), |
120 request_(request), | 126 request_(request), |
121 ready_(false), | 127 ready_(false), |
122 deferred_(false), | 128 deferred_(false), |
123 scheduler_(scheduler) { | 129 scheduler_(scheduler), |
130 priority_(priority), | |
131 fifo_ordering_(0) { | |
124 TRACE_EVENT_ASYNC_BEGIN1("net", "URLRequest", request_, | 132 TRACE_EVENT_ASYNC_BEGIN1("net", "URLRequest", request_, |
125 "url", request->url().spec()); | 133 "url", request->url().spec()); |
126 } | 134 } |
127 | 135 |
128 virtual ~ScheduledResourceRequest() { | 136 virtual ~ScheduledResourceRequest() { |
129 scheduler_->RemoveRequest(this); | 137 scheduler_->RemoveRequest(this); |
130 } | 138 } |
131 | 139 |
132 void Start() { | 140 void Start() { |
133 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request_, "Queued"); | 141 TRACE_EVENT_ASYNC_STEP_PAST0("net", "URLRequest", request_, "Queued"); |
134 ready_ = true; | 142 ready_ = true; |
135 if (deferred_ && request_->status().is_success()) { | 143 if (deferred_ && request_->status().is_success()) { |
136 deferred_ = false; | 144 deferred_ = false; |
137 controller()->Resume(); | 145 controller()->Resume(); |
138 } | 146 } |
139 } | 147 } |
140 | 148 |
149 void set_request_priority_params(const RequestPriorityParams& priority) { | |
150 priority_ = priority; | |
151 } | |
152 const RequestPriorityParams& get_request_priority_params() const { | |
153 return priority_; | |
154 } | |
141 const ClientId& client_id() const { return client_id_; } | 155 const ClientId& client_id() const { return client_id_; } |
142 net::URLRequest* url_request() { return request_; } | 156 net::URLRequest* url_request() { return request_; } |
143 const net::URLRequest* url_request() const { return request_; } | 157 const net::URLRequest* url_request() const { return request_; } |
158 uint32 fifo_ordering() const { return fifo_ordering_; } | |
159 void set_fifo_ordering(uint32 fifo_ordering) { | |
160 fifo_ordering_ = fifo_ordering; | |
161 } | |
144 | 162 |
145 private: | 163 private: |
146 // ResourceMessageDelegate interface: | 164 // ResourceMessageDelegate interface: |
147 virtual bool OnMessageReceived(const IPC::Message& message, | 165 virtual bool OnMessageReceived(const IPC::Message& message, |
148 bool* message_was_ok) OVERRIDE { | 166 bool* message_was_ok) OVERRIDE { |
149 bool handled = true; | 167 bool handled = true; |
150 IPC_BEGIN_MESSAGE_MAP_EX(ScheduledResourceRequest, message, *message_was_ok) | 168 IPC_BEGIN_MESSAGE_MAP_EX(ScheduledResourceRequest, message, *message_was_ok) |
151 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, DidChangePriority) | 169 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, DidChangePriority) |
152 IPC_MESSAGE_UNHANDLED(handled = false) | 170 IPC_MESSAGE_UNHANDLED(handled = false) |
153 IPC_END_MESSAGE_MAP_EX() | 171 IPC_END_MESSAGE_MAP_EX() |
154 return handled; | 172 return handled; |
155 } | 173 } |
156 | 174 |
157 // ResourceThrottle interface: | 175 // ResourceThrottle interface: |
158 virtual void WillStartRequest(bool* defer) OVERRIDE { | 176 virtual void WillStartRequest(bool* defer) OVERRIDE { |
159 deferred_ = *defer = !ready_; | 177 deferred_ = *defer = !ready_; |
160 } | 178 } |
161 | 179 |
162 virtual const char* GetNameForLogging() const OVERRIDE { | 180 virtual const char* GetNameForLogging() const OVERRIDE { |
163 return "ResourceScheduler"; | 181 return "ResourceScheduler"; |
164 } | 182 } |
165 | 183 |
166 void DidChangePriority(int request_id, net::RequestPriority new_priority) { | 184 void DidChangePriority(int request_id, net::RequestPriority new_priority, |
167 scheduler_->ReprioritizeRequest(this, new_priority); | 185 int intra_priority_value) { |
186 scheduler_->ReprioritizeRequest(this, new_priority, intra_priority_value); | |
168 } | 187 } |
169 | 188 |
170 ClientId client_id_; | 189 ClientId client_id_; |
171 net::URLRequest* request_; | 190 net::URLRequest* request_; |
172 bool ready_; | 191 bool ready_; |
173 bool deferred_; | 192 bool deferred_; |
174 ResourceScheduler* scheduler_; | 193 ResourceScheduler* scheduler_; |
194 RequestPriorityParams priority_; | |
195 uint32 fifo_ordering_; | |
175 | 196 |
176 DISALLOW_COPY_AND_ASSIGN(ScheduledResourceRequest); | 197 DISALLOW_COPY_AND_ASSIGN(ScheduledResourceRequest); |
177 }; | 198 }; |
178 | 199 |
200 bool ResourceScheduler::ScheduledResourceSorter::operator()( | |
201 const ScheduledResourceRequest* a, | |
202 const ScheduledResourceRequest* b) const { | |
203 // Want the set to be ordered first by decreasing priority, then by | |
204 // decreasing intra_priority. | |
205 // ie. with (priority, intra_priority) | |
206 // [(1, 0), (1, 0), (0, 100), (0, 0)] | |
207 if (a->get_request_priority_params() != b->get_request_priority_params()) | |
208 return a->get_request_priority_params().GetSortingValue( | |
209 b->get_request_priority_params()); | |
210 | |
211 // If priority/intra_priority is the same, fall back to fifo ordering. | |
212 // std::multiset doesn't guarantee this until c++11. | |
213 return a->fifo_ordering() < b->fifo_ordering(); | |
214 } | |
215 | |
216 void ResourceScheduler::RequestQueue::Insert( | |
217 ScheduledResourceRequest* request) { | |
218 DCHECK(!ContainsKey(pointers_, request)); | |
219 request->set_fifo_ordering(MakeFifoOrderingId()); | |
220 pointers_[request] = queue_.insert(request); | |
221 } | |
222 | |
179 // Each client represents a tab. | 223 // Each client represents a tab. |
180 struct ResourceScheduler::Client { | 224 struct ResourceScheduler::Client { |
181 Client() : has_body(false), using_spdy_proxy(false) {} | 225 Client() : has_body(false), using_spdy_proxy(false) {} |
182 ~Client() {} | 226 ~Client() {} |
183 | 227 |
184 bool has_body; | 228 bool has_body; |
185 bool using_spdy_proxy; | 229 bool using_spdy_proxy; |
186 RequestQueue pending_requests; | 230 RequestQueue pending_requests; |
187 RequestSet in_flight_requests; | 231 RequestSet in_flight_requests; |
188 }; | 232 }; |
189 | 233 |
190 ResourceScheduler::ResourceScheduler() { | 234 ResourceScheduler::ResourceScheduler() { |
191 } | 235 } |
192 | 236 |
193 ResourceScheduler::~ResourceScheduler() { | 237 ResourceScheduler::~ResourceScheduler() { |
194 DCHECK(unowned_requests_.empty()); | 238 DCHECK(unowned_requests_.empty()); |
195 DCHECK(client_map_.empty()); | 239 DCHECK(client_map_.empty()); |
196 } | 240 } |
197 | 241 |
198 scoped_ptr<ResourceThrottle> ResourceScheduler::ScheduleRequest( | 242 scoped_ptr<ResourceThrottle> ResourceScheduler::ScheduleRequest( |
199 int child_id, | 243 int child_id, |
200 int route_id, | 244 int route_id, |
201 net::URLRequest* url_request) { | 245 net::URLRequest* url_request) { |
202 DCHECK(CalledOnValidThread()); | 246 DCHECK(CalledOnValidThread()); |
203 ClientId client_id = MakeClientId(child_id, route_id); | 247 ClientId client_id = MakeClientId(child_id, route_id); |
204 scoped_ptr<ScheduledResourceRequest> request( | 248 scoped_ptr<ScheduledResourceRequest> request( |
205 new ScheduledResourceRequest(client_id, url_request, this)); | 249 new ScheduledResourceRequest(client_id, url_request, this, |
250 RequestPriorityParams(url_request->priority(), 0))); | |
206 | 251 |
207 ClientMap::iterator it = client_map_.find(client_id); | 252 ClientMap::iterator it = client_map_.find(client_id); |
208 if (it == client_map_.end()) { | 253 if (it == client_map_.end()) { |
209 // There are several ways this could happen: | 254 // There are several ways this could happen: |
210 // 1. <a ping> requests don't have a route_id. | 255 // 1. <a ping> requests don't have a route_id. |
211 // 2. Most unittests don't send the IPCs needed to register Clients. | 256 // 2. Most unittests don't send the IPCs needed to register Clients. |
212 // 3. The tab is closed while a RequestResource IPC is in flight. | 257 // 3. The tab is closed while a RequestResource IPC is in flight. |
213 unowned_requests_.insert(request.get()); | 258 unowned_requests_.insert(request.get()); |
214 request->Start(); | 259 request->Start(); |
215 return request.PassAs<ResourceThrottle>(); | 260 return request.PassAs<ResourceThrottle>(); |
216 } | 261 } |
217 | 262 |
218 Client* client = it->second; | 263 Client* client = it->second; |
219 if (ShouldStartRequest(request.get(), client) == START_REQUEST) { | 264 if (ShouldStartRequest(request.get(), client) == START_REQUEST) { |
220 StartRequest(request.get(), client); | 265 StartRequest(request.get(), client); |
221 } else { | 266 } else { |
222 client->pending_requests.Insert(request.get(), url_request->priority()); | 267 client->pending_requests.Insert(request.get()); |
223 } | 268 } |
224 return request.PassAs<ResourceThrottle>(); | 269 return request.PassAs<ResourceThrottle>(); |
225 } | 270 } |
226 | 271 |
227 void ResourceScheduler::RemoveRequest(ScheduledResourceRequest* request) { | 272 void ResourceScheduler::RemoveRequest(ScheduledResourceRequest* request) { |
228 DCHECK(CalledOnValidThread()); | 273 DCHECK(CalledOnValidThread()); |
229 if (ContainsKey(unowned_requests_, request)) { | 274 if (ContainsKey(unowned_requests_, request)) { |
230 unowned_requests_.erase(request); | 275 unowned_requests_.erase(request); |
231 return; | 276 return; |
232 } | 277 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 } | 374 } |
330 } | 375 } |
331 | 376 |
332 void ResourceScheduler::StartRequest(ScheduledResourceRequest* request, | 377 void ResourceScheduler::StartRequest(ScheduledResourceRequest* request, |
333 Client* client) { | 378 Client* client) { |
334 client->in_flight_requests.insert(request); | 379 client->in_flight_requests.insert(request); |
335 request->Start(); | 380 request->Start(); |
336 } | 381 } |
337 | 382 |
338 void ResourceScheduler::ReprioritizeRequest(ScheduledResourceRequest* request, | 383 void ResourceScheduler::ReprioritizeRequest(ScheduledResourceRequest* request, |
339 net::RequestPriority new_priority) { | 384 net::RequestPriority new_priority, |
385 int new_intra_priority_value) { | |
340 if (request->url_request()->load_flags() & net::LOAD_IGNORE_LIMITS) { | 386 if (request->url_request()->load_flags() & net::LOAD_IGNORE_LIMITS) { |
341 // We should not be re-prioritizing requests with the | 387 // We should not be re-prioritizing requests with the |
342 // IGNORE_LIMITS flag. | 388 // IGNORE_LIMITS flag. |
343 NOTREACHED(); | 389 NOTREACHED(); |
344 return; | 390 return; |
345 } | 391 } |
346 net::RequestPriority old_priority = request->url_request()->priority(); | 392 |
347 DCHECK_NE(new_priority, old_priority); | 393 RequestPriorityParams new_priority_params(new_priority, |
348 request->url_request()->SetPriority(new_priority); | 394 new_intra_priority_value); |
395 RequestPriorityParams old_priority_params = | |
396 request->get_request_priority_params(); | |
397 | |
398 DCHECK(old_priority_params != new_priority_params); | |
399 | |
400 request->url_request()->SetPriority(new_priority_params.priority); | |
401 request->set_request_priority_params(new_priority_params); | |
349 ClientMap::iterator client_it = client_map_.find(request->client_id()); | 402 ClientMap::iterator client_it = client_map_.find(request->client_id()); |
350 if (client_it == client_map_.end()) { | 403 if (client_it == client_map_.end()) { |
351 // The client was likely deleted shortly before we received this IPC. | 404 // The client was likely deleted shortly before we received this IPC. |
352 return; | 405 return; |
353 } | 406 } |
354 | 407 |
408 if (old_priority_params == new_priority_params) | |
409 return; | |
410 | |
355 Client *client = client_it->second; | 411 Client *client = client_it->second; |
356 if (!client->pending_requests.IsQueued(request)) { | 412 if (!client->pending_requests.IsQueued(request)) { |
357 DCHECK(ContainsKey(client->in_flight_requests, request)); | 413 DCHECK(ContainsKey(client->in_flight_requests, request)); |
358 // Request has already started. | 414 // Request has already started. |
359 return; | 415 return; |
360 } | 416 } |
361 | 417 |
362 client->pending_requests.Erase(request); | 418 client->pending_requests.Erase(request); |
363 client->pending_requests.Insert(request, | 419 client->pending_requests.Insert(request); |
364 request->url_request()->priority()); | |
365 | 420 |
366 if (new_priority > old_priority) { | 421 if (new_priority_params.priority > old_priority_params.priority) { |
367 // Check if this request is now able to load at its new priority. | 422 // Check if this request is now able to load at its new priority. |
368 LoadAnyStartablePendingRequests(client); | 423 LoadAnyStartablePendingRequests(client); |
369 } | 424 } |
370 } | 425 } |
371 | 426 |
372 void ResourceScheduler::LoadAnyStartablePendingRequests(Client* client) { | 427 void ResourceScheduler::LoadAnyStartablePendingRequests(Client* client) { |
373 // We iterate through all the pending requests, starting with the highest | 428 // We iterate through all the pending requests, starting with the highest |
374 // priority one. For each entry, one of three things can happen: | 429 // priority one. For each entry, one of three things can happen: |
375 // 1) We start the request, remove it from the list, and keep checking. | 430 // 1) We start the request, remove it from the list, and keep checking. |
376 // 2) We do NOT start the request, but ShouldStartRequest() signals us that | 431 // 2) We do NOT start the request, but ShouldStartRequest() signals us that |
377 // there may be room for other requests, so we keep checking and leave | 432 // there may be room for other requests, so we keep checking and leave |
378 // the previous request still in the list. | 433 // the previous request still in the list. |
379 // 3) We do not start the request, same as above, but StartRequest() tells | 434 // 3) We do not start the request, same as above, but StartRequest() tells |
380 // us there's no point in checking any further requests. | 435 // us there's no point in checking any further requests. |
381 | 436 RequestQueue::NetQueue::iterator request_iter = |
382 RequestQueue::Iterator request_iter = | |
383 client->pending_requests.GetNextHighestIterator(); | 437 client->pending_requests.GetNextHighestIterator(); |
384 | 438 while (request_iter != client->pending_requests.End()) { |
385 while (!request_iter.is_null()) { | 439 ScheduledResourceRequest* request = *request_iter; |
386 ScheduledResourceRequest* request = request_iter.value(); | |
387 ShouldStartReqResult query_result = ShouldStartRequest(request, client); | 440 ShouldStartReqResult query_result = ShouldStartRequest(request, client); |
388 | 441 |
389 if (query_result == START_REQUEST) { | 442 if (query_result == START_REQUEST) { |
390 client->pending_requests.Erase(request); | 443 client->pending_requests.Erase(request); |
391 StartRequest(request, client); | 444 StartRequest(request, client); |
392 | 445 |
393 // StartRequest can modify the pending list, so we (re)start evaluation | 446 // StartRequest can modify the pending list, so we (re)start evaluation |
394 // from the currently highest priority request. Avoid copying a singular | 447 // from the currently highest priority request. Avoid copying a singular |
395 // iterator, which would trigger undefined behavior. | 448 // iterator, which would trigger undefined behavior. |
396 if (client->pending_requests.GetNextHighestIterator().is_null()) | 449 if (client->pending_requests.GetNextHighestIterator() == |
450 client->pending_requests.End()) | |
397 break; | 451 break; |
398 request_iter = client->pending_requests.GetNextHighestIterator(); | 452 request_iter = client->pending_requests.GetNextHighestIterator(); |
399 } else if (query_result == DO_NOT_START_REQUEST_AND_KEEP_SEARCHING) { | 453 } else if (query_result == DO_NOT_START_REQUEST_AND_KEEP_SEARCHING) { |
400 ++request_iter; | 454 ++request_iter; |
401 continue; | 455 continue; |
402 } else { | 456 } else { |
403 DCHECK(query_result == DO_NOT_START_REQUEST_AND_STOP_SEARCHING); | 457 DCHECK(query_result == DO_NOT_START_REQUEST_AND_STOP_SEARCHING); |
404 break; | 458 break; |
405 } | 459 } |
406 } | 460 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 | 568 |
515 return START_REQUEST; | 569 return START_REQUEST; |
516 } | 570 } |
517 | 571 |
518 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( | 572 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( |
519 int child_id, int route_id) { | 573 int child_id, int route_id) { |
520 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; | 574 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; |
521 } | 575 } |
522 | 576 |
523 } // namespace content | 577 } // namespace content |
OLD | NEW |