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