| 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 "content/browser/loader/resource_scheduler.h" | 5 #include "content/browser/loader/resource_scheduler.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "content/common/resource_messages.h" | 8 #include "content/common/resource_messages.h" |
| 9 #include "content/browser/loader/resource_message_delegate.h" | 9 #include "content/browser/loader/resource_message_delegate.h" |
| 10 #include "content/public/browser/resource_controller.h" | 10 #include "content/public/browser/resource_controller.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 // 3. The tab is closed while a RequestResource IPC is in flight. | 167 // 3. The tab is closed while a RequestResource IPC is in flight. |
| 168 unowned_requests_.insert(request.get()); | 168 unowned_requests_.insert(request.get()); |
| 169 request->Start(); | 169 request->Start(); |
| 170 return request.PassAs<ResourceThrottle>(); | 170 return request.PassAs<ResourceThrottle>(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 Client* client = it->second; | 173 Client* client = it->second; |
| 174 if (ShouldStartRequest(request.get(), client)) { | 174 if (ShouldStartRequest(request.get(), client)) { |
| 175 StartRequest(request.get(), client); | 175 StartRequest(request.get(), client); |
| 176 } else { | 176 } else { |
| 177 client->pending_requests.Insert(request.get(), url_request->priority()); | 177 client->pending_requests.Insert(request.get(), url_request->GetPriority()); |
| 178 } | 178 } |
| 179 return request.PassAs<ResourceThrottle>(); | 179 return request.PassAs<ResourceThrottle>(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void ResourceScheduler::RemoveRequest(ScheduledResourceRequest* request) { | 182 void ResourceScheduler::RemoveRequest(ScheduledResourceRequest* request) { |
| 183 DCHECK(CalledOnValidThread()); | 183 DCHECK(CalledOnValidThread()); |
| 184 if (ContainsKey(unowned_requests_, request)) { | 184 if (ContainsKey(unowned_requests_, request)) { |
| 185 unowned_requests_.erase(request); | 185 unowned_requests_.erase(request); |
| 186 return; | 186 return; |
| 187 } | 187 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 266 } |
| 267 | 267 |
| 268 void ResourceScheduler::StartRequest(ScheduledResourceRequest* request, | 268 void ResourceScheduler::StartRequest(ScheduledResourceRequest* request, |
| 269 Client* client) { | 269 Client* client) { |
| 270 client->in_flight_requests.insert(request); | 270 client->in_flight_requests.insert(request); |
| 271 request->Start(); | 271 request->Start(); |
| 272 } | 272 } |
| 273 | 273 |
| 274 void ResourceScheduler::ReprioritizeRequest(ScheduledResourceRequest* request, | 274 void ResourceScheduler::ReprioritizeRequest(ScheduledResourceRequest* request, |
| 275 net::RequestPriority new_priority) { | 275 net::RequestPriority new_priority) { |
| 276 net::RequestPriority old_priority = request->url_request()->priority(); | 276 net::RequestPriority old_priority = request->url_request()->GetPriority(); |
| 277 DCHECK_NE(new_priority, old_priority); | 277 DCHECK_NE(new_priority, old_priority); |
| 278 request->url_request()->SetPriority(new_priority); | 278 request->url_request()->SetPriority(new_priority); |
| 279 ClientMap::iterator client_it = client_map_.find(request->client_id()); | 279 ClientMap::iterator client_it = client_map_.find(request->client_id()); |
| 280 if (client_it == client_map_.end()) { | 280 if (client_it == client_map_.end()) { |
| 281 // The client was likely deleted shortly before we received this IPC. | 281 // The client was likely deleted shortly before we received this IPC. |
| 282 return; | 282 return; |
| 283 } | 283 } |
| 284 | 284 |
| 285 Client *client = client_it->second; | 285 Client *client = client_it->second; |
| 286 if (!client->pending_requests.IsQueued(request)) { | 286 if (!client->pending_requests.IsQueued(request)) { |
| 287 DCHECK(ContainsKey(client->in_flight_requests, request)); | 287 DCHECK(ContainsKey(client->in_flight_requests, request)); |
| 288 // Request has already started. | 288 // Request has already started. |
| 289 return; | 289 return; |
| 290 } | 290 } |
| 291 | 291 |
| 292 client->pending_requests.Erase(request); | 292 client->pending_requests.Erase(request); |
| 293 client->pending_requests.Insert(request, request->url_request()->priority()); | 293 client->pending_requests.Insert(request, |
| 294 request->url_request()->GetPriority()); |
| 294 | 295 |
| 295 if (new_priority > old_priority) { | 296 if (new_priority > old_priority) { |
| 296 // Check if this request is now able to load at its new priority. | 297 // Check if this request is now able to load at its new priority. |
| 297 LoadAnyStartablePendingRequests(client); | 298 LoadAnyStartablePendingRequests(client); |
| 298 } | 299 } |
| 299 } | 300 } |
| 300 | 301 |
| 301 void ResourceScheduler::LoadAnyStartablePendingRequests(Client* client) { | 302 void ResourceScheduler::LoadAnyStartablePendingRequests(Client* client) { |
| 302 while (!client->pending_requests.IsEmpty()) { | 303 while (!client->pending_requests.IsEmpty()) { |
| 303 ScheduledResourceRequest* request = client->pending_requests.FirstMax(); | 304 ScheduledResourceRequest* request = client->pending_requests.FirstMax(); |
| 304 if (ShouldStartRequest(request, client)) { | 305 if (ShouldStartRequest(request, client)) { |
| 305 client->pending_requests.Erase(request); | 306 client->pending_requests.Erase(request); |
| 306 StartRequest(request, client); | 307 StartRequest(request, client); |
| 307 } else { | 308 } else { |
| 308 break; | 309 break; |
| 309 } | 310 } |
| 310 } | 311 } |
| 311 } | 312 } |
| 312 | 313 |
| 313 size_t ResourceScheduler::GetNumDelayableRequestsInFlight( | 314 size_t ResourceScheduler::GetNumDelayableRequestsInFlight( |
| 314 Client* client) const { | 315 Client* client) const { |
| 315 size_t count = 0; | 316 size_t count = 0; |
| 316 for (RequestSet::iterator it = client->in_flight_requests.begin(); | 317 for (RequestSet::iterator it = client->in_flight_requests.begin(); |
| 317 it != client->in_flight_requests.end(); ++it) { | 318 it != client->in_flight_requests.end(); ++it) { |
| 318 if ((*it)->url_request()->priority() < net::LOW) { | 319 if ((*it)->url_request()->GetPriority() < net::LOW) { |
| 319 const net::HttpServerProperties& http_server_properties = | 320 const net::HttpServerProperties& http_server_properties = |
| 320 *(*it)->url_request()->context()->http_server_properties(); | 321 *(*it)->url_request()->context()->http_server_properties(); |
| 321 if (!http_server_properties.SupportsSpdy( | 322 if (!http_server_properties.SupportsSpdy( |
| 322 net::HostPortPair::FromURL((*it)->url_request()->url()))) { | 323 net::HostPortPair::FromURL((*it)->url_request()->url()))) { |
| 323 ++count; | 324 ++count; |
| 324 } | 325 } |
| 325 } | 326 } |
| 326 } | 327 } |
| 327 return count; | 328 return count; |
| 328 } | 329 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 357 | 358 |
| 358 const net::HttpServerProperties& http_server_properties = | 359 const net::HttpServerProperties& http_server_properties = |
| 359 *url_request.context()->http_server_properties(); | 360 *url_request.context()->http_server_properties(); |
| 360 | 361 |
| 361 // TODO(willchan): We should really improve this algorithm as described in | 362 // TODO(willchan): We should really improve this algorithm as described in |
| 362 // crbug.com/164101. Also, theoretically we should not count a SPDY request | 363 // crbug.com/164101. Also, theoretically we should not count a SPDY request |
| 363 // against the delayable requests limit. | 364 // against the delayable requests limit. |
| 364 bool origin_supports_spdy = http_server_properties.SupportsSpdy( | 365 bool origin_supports_spdy = http_server_properties.SupportsSpdy( |
| 365 net::HostPortPair::FromURL(url_request.url())); | 366 net::HostPortPair::FromURL(url_request.url())); |
| 366 | 367 |
| 367 if (url_request.priority() >= net::LOW || | 368 if (url_request.GetPriority() >= net::LOW || |
| 368 !ResourceRequestInfo::ForRequest(&url_request)->IsAsync() || | 369 !ResourceRequestInfo::ForRequest(&url_request)->IsAsync() || |
| 369 origin_supports_spdy) { | 370 origin_supports_spdy) { |
| 370 return true; | 371 return true; |
| 371 } | 372 } |
| 372 | 373 |
| 373 size_t num_delayable_requests_in_flight = | 374 size_t num_delayable_requests_in_flight = |
| 374 GetNumDelayableRequestsInFlight(client); | 375 GetNumDelayableRequestsInFlight(client); |
| 375 if (num_delayable_requests_in_flight >= kMaxNumDelayableRequestsPerClient) { | 376 if (num_delayable_requests_in_flight >= kMaxNumDelayableRequestsPerClient) { |
| 376 return false; | 377 return false; |
| 377 } | 378 } |
| 378 | 379 |
| 379 bool have_immediate_requests_in_flight = | 380 bool have_immediate_requests_in_flight = |
| 380 client->in_flight_requests.size() > num_delayable_requests_in_flight; | 381 client->in_flight_requests.size() > num_delayable_requests_in_flight; |
| 381 if (have_immediate_requests_in_flight && !client->has_body && | 382 if (have_immediate_requests_in_flight && !client->has_body && |
| 382 num_delayable_requests_in_flight != 0) { | 383 num_delayable_requests_in_flight != 0) { |
| 383 return false; | 384 return false; |
| 384 } | 385 } |
| 385 | 386 |
| 386 return true; | 387 return true; |
| 387 } | 388 } |
| 388 | 389 |
| 389 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( | 390 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( |
| 390 int child_id, int route_id) { | 391 int child_id, int route_id) { |
| 391 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; | 392 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; |
| 392 } | 393 } |
| 393 | 394 |
| 394 } // namespace content | 395 } // namespace content |
| OLD | NEW |