| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 net::URLRequest* request_; | 171 net::URLRequest* request_; |
| 172 bool ready_; | 172 bool ready_; |
| 173 bool deferred_; | 173 bool deferred_; |
| 174 ResourceScheduler* scheduler_; | 174 ResourceScheduler* scheduler_; |
| 175 | 175 |
| 176 DISALLOW_COPY_AND_ASSIGN(ScheduledResourceRequest); | 176 DISALLOW_COPY_AND_ASSIGN(ScheduledResourceRequest); |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 // Each client represents a tab. | 179 // Each client represents a tab. |
| 180 struct ResourceScheduler::Client { | 180 struct ResourceScheduler::Client { |
| 181 Client() : has_body(false) {} | 181 Client() : has_body(false), using_spdy_proxy(false) {} |
| 182 ~Client() {} | 182 ~Client() {} |
| 183 | 183 |
| 184 bool has_body; | 184 bool has_body; |
| 185 bool using_spdy_proxy; |
| 185 RequestQueue pending_requests; | 186 RequestQueue pending_requests; |
| 186 RequestSet in_flight_requests; | 187 RequestSet in_flight_requests; |
| 187 }; | 188 }; |
| 188 | 189 |
| 189 ResourceScheduler::ResourceScheduler() { | 190 ResourceScheduler::ResourceScheduler() { |
| 190 } | 191 } |
| 191 | 192 |
| 192 ResourceScheduler::~ResourceScheduler() { | 193 ResourceScheduler::~ResourceScheduler() { |
| 193 DCHECK(unowned_requests_.empty()); | 194 DCHECK(unowned_requests_.empty()); |
| 194 DCHECK(client_map_.empty()); | 195 DCHECK(client_map_.empty()); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 DCHECK(CalledOnValidThread()); | 299 DCHECK(CalledOnValidThread()); |
| 299 ClientId client_id = MakeClientId(child_id, route_id); | 300 ClientId client_id = MakeClientId(child_id, route_id); |
| 300 | 301 |
| 301 ClientMap::iterator it = client_map_.find(client_id); | 302 ClientMap::iterator it = client_map_.find(client_id); |
| 302 if (it == client_map_.end()) { | 303 if (it == client_map_.end()) { |
| 303 // The client was likely deleted shortly before we received this IPC. | 304 // The client was likely deleted shortly before we received this IPC. |
| 304 return; | 305 return; |
| 305 } | 306 } |
| 306 | 307 |
| 307 Client* client = it->second; | 308 Client* client = it->second; |
| 308 client->has_body = false; | 309 client->has_body = true; |
| 309 if (!client->has_body) { | 310 LoadAnyStartablePendingRequests(client); |
| 310 client->has_body = true; | 311 } |
| 312 |
| 313 void ResourceScheduler::OnReceivedSpdyProxiedHttpResponse( |
| 314 int child_id, |
| 315 int route_id) { |
| 316 DCHECK(CalledOnValidThread()); |
| 317 ClientId client_id = MakeClientId(child_id, route_id); |
| 318 |
| 319 ClientMap::iterator client_it = client_map_.find(client_id); |
| 320 if (client_it == client_map_.end()) { |
| 321 return; |
| 322 } |
| 323 |
| 324 Client* client = client_it->second; |
| 325 |
| 326 if (!client->using_spdy_proxy) { |
| 327 client->using_spdy_proxy = true; |
| 311 LoadAnyStartablePendingRequests(client); | 328 LoadAnyStartablePendingRequests(client); |
| 312 } | 329 } |
| 313 } | 330 } |
| 314 | 331 |
| 315 void ResourceScheduler::StartRequest(ScheduledResourceRequest* request, | 332 void ResourceScheduler::StartRequest(ScheduledResourceRequest* request, |
| 316 Client* client) { | 333 Client* client) { |
| 317 client->in_flight_requests.insert(request); | 334 client->in_flight_requests.insert(request); |
| 318 request->Start(); | 335 request->Start(); |
| 319 } | 336 } |
| 320 | 337 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 ScheduledResourceRequest* request, | 461 ScheduledResourceRequest* request, |
| 445 Client* client) const { | 462 Client* client) const { |
| 446 const net::URLRequest& url_request = *request->url_request(); | 463 const net::URLRequest& url_request = *request->url_request(); |
| 447 | 464 |
| 448 // TODO(simonjam): This may end up causing disk contention. We should | 465 // TODO(simonjam): This may end up causing disk contention. We should |
| 449 // experiment with throttling if that happens. | 466 // experiment with throttling if that happens. |
| 450 if (!url_request.url().SchemeIsHTTPOrHTTPS()) { | 467 if (!url_request.url().SchemeIsHTTPOrHTTPS()) { |
| 451 return START_REQUEST; | 468 return START_REQUEST; |
| 452 } | 469 } |
| 453 | 470 |
| 471 if (client->using_spdy_proxy && url_request.url().SchemeIs("http")) { |
| 472 return START_REQUEST; |
| 473 } |
| 474 |
| 454 const net::HttpServerProperties& http_server_properties = | 475 const net::HttpServerProperties& http_server_properties = |
| 455 *url_request.context()->http_server_properties(); | 476 *url_request.context()->http_server_properties(); |
| 456 | 477 |
| 457 if (url_request.priority() >= net::LOW || | 478 if (url_request.priority() >= net::LOW || |
| 458 !ResourceRequestInfo::ForRequest(&url_request)->IsAsync()) { | 479 !ResourceRequestInfo::ForRequest(&url_request)->IsAsync()) { |
| 459 return START_REQUEST; | 480 return START_REQUEST; |
| 460 } | 481 } |
| 461 | 482 |
| 462 net::HostPortPair host_port_pair = | 483 net::HostPortPair host_port_pair = |
| 463 net::HostPortPair::FromURL(url_request.url()); | 484 net::HostPortPair::FromURL(url_request.url()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 493 | 514 |
| 494 return START_REQUEST; | 515 return START_REQUEST; |
| 495 } | 516 } |
| 496 | 517 |
| 497 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( | 518 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( |
| 498 int child_id, int route_id) { | 519 int child_id, int route_id) { |
| 499 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; | 520 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; |
| 500 } | 521 } |
| 501 | 522 |
| 502 } // namespace content | 523 } // namespace content |
| OLD | NEW |