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