Chromium Code Reviews| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 net::URLRequest* request_; | 127 net::URLRequest* request_; |
| 128 bool ready_; | 128 bool ready_; |
| 129 bool deferred_; | 129 bool deferred_; |
| 130 ResourceScheduler* scheduler_; | 130 ResourceScheduler* scheduler_; |
| 131 | 131 |
| 132 DISALLOW_COPY_AND_ASSIGN(ScheduledResourceRequest); | 132 DISALLOW_COPY_AND_ASSIGN(ScheduledResourceRequest); |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 // Each client represents a tab. | 135 // Each client represents a tab. |
| 136 struct ResourceScheduler::Client { | 136 struct ResourceScheduler::Client { |
| 137 Client() : has_body(false) {} | 137 Client() : has_body(false), using_spdy_proxy(false) {} |
| 138 ~Client() {} | 138 ~Client() {} |
| 139 | 139 |
| 140 bool has_body; | 140 bool has_body; |
| 141 bool using_spdy_proxy; | |
| 141 RequestQueue pending_requests; | 142 RequestQueue pending_requests; |
| 142 RequestSet in_flight_requests; | 143 RequestSet in_flight_requests; |
| 143 }; | 144 }; |
| 144 | 145 |
| 145 ResourceScheduler::ResourceScheduler() { | 146 ResourceScheduler::ResourceScheduler() { |
| 146 } | 147 } |
| 147 | 148 |
| 148 ResourceScheduler::~ResourceScheduler() { | 149 ResourceScheduler::~ResourceScheduler() { |
| 149 DCHECK(unowned_requests_.empty()); | 150 DCHECK(unowned_requests_.empty()); |
| 150 DCHECK(client_map_.empty()); | 151 DCHECK(client_map_.empty()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 return; | 187 return; |
| 187 } | 188 } |
| 188 | 189 |
| 189 ClientMap::iterator client_it = client_map_.find(request->client_id()); | 190 ClientMap::iterator client_it = client_map_.find(request->client_id()); |
| 190 if (client_it == client_map_.end()) { | 191 if (client_it == client_map_.end()) { |
| 191 return; | 192 return; |
| 192 } | 193 } |
| 193 | 194 |
| 194 Client* client = client_it->second; | 195 Client* client = client_it->second; |
| 195 | 196 |
| 197 if (!client->using_spdy_proxy) { | |
| 198 net::HttpResponseInfo response_info = | |
| 199 request->url_request()->response_info(); | |
| 200 if (response_info.was_fetched_via_spdy && | |
| 201 response_info.was_fetched_via_proxy) { | |
|
James Simonsen
2013/12/02 18:59:31
Is this really the only way to determine it? It se
Pat Meenan
2013/12/02 19:35:51
This is the lowest-impact way I could come up with
| |
| 202 client->using_spdy_proxy = true; | |
| 203 } | |
| 204 } | |
| 205 | |
| 196 if (client->pending_requests.IsQueued(request)) { | 206 if (client->pending_requests.IsQueued(request)) { |
| 197 client->pending_requests.Erase(request); | 207 client->pending_requests.Erase(request); |
| 198 DCHECK(!ContainsKey(client->in_flight_requests, request)); | 208 DCHECK(!ContainsKey(client->in_flight_requests, request)); |
| 199 } else { | 209 } else { |
| 200 size_t erased = client->in_flight_requests.erase(request); | 210 size_t erased = client->in_flight_requests.erase(request); |
| 201 DCHECK(erased); | 211 DCHECK(erased); |
| 202 | 212 |
| 203 // Removing this request may have freed up another to load. | 213 // Removing this request may have freed up another to load. |
| 204 LoadAnyStartablePendingRequests(client); | 214 LoadAnyStartablePendingRequests(client); |
| 205 } | 215 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 ClientId client_id = MakeClientId(child_id, route_id); | 248 ClientId client_id = MakeClientId(child_id, route_id); |
| 239 | 249 |
| 240 ClientMap::iterator it = client_map_.find(client_id); | 250 ClientMap::iterator it = client_map_.find(client_id); |
| 241 if (it == client_map_.end()) { | 251 if (it == client_map_.end()) { |
| 242 // The client was likely deleted shortly before we received this IPC. | 252 // The client was likely deleted shortly before we received this IPC. |
| 243 return; | 253 return; |
| 244 } | 254 } |
| 245 | 255 |
| 246 Client* client = it->second; | 256 Client* client = it->second; |
| 247 client->has_body = false; | 257 client->has_body = false; |
| 258 client->using_spdy_proxy = false; | |
| 248 } | 259 } |
| 249 | 260 |
| 250 void ResourceScheduler::OnWillInsertBody(int child_id, int route_id) { | 261 void ResourceScheduler::OnWillInsertBody(int child_id, int route_id) { |
| 251 DCHECK(CalledOnValidThread()); | 262 DCHECK(CalledOnValidThread()); |
| 252 ClientId client_id = MakeClientId(child_id, route_id); | 263 ClientId client_id = MakeClientId(child_id, route_id); |
| 253 | 264 |
| 254 ClientMap::iterator it = client_map_.find(client_id); | 265 ClientMap::iterator it = client_map_.find(client_id); |
| 255 if (it == client_map_.end()) { | 266 if (it == client_map_.end()) { |
| 256 // The client was likely deleted shortly before we received this IPC. | 267 // The client was likely deleted shortly before we received this IPC. |
| 257 return; | 268 return; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 bool ResourceScheduler::ShouldStartRequest(ScheduledResourceRequest* request, | 359 bool ResourceScheduler::ShouldStartRequest(ScheduledResourceRequest* request, |
| 349 Client* client) const { | 360 Client* client) const { |
| 350 const net::URLRequest& url_request = *request->url_request(); | 361 const net::URLRequest& url_request = *request->url_request(); |
| 351 | 362 |
| 352 // TODO(simonjam): This may end up causing disk contention. We should | 363 // TODO(simonjam): This may end up causing disk contention. We should |
| 353 // experiment with throttling if that happens. | 364 // experiment with throttling if that happens. |
| 354 if (!url_request.url().SchemeIsHTTPOrHTTPS()) { | 365 if (!url_request.url().SchemeIsHTTPOrHTTPS()) { |
| 355 return true; | 366 return true; |
| 356 } | 367 } |
| 357 | 368 |
| 369 if (client->using_spdy_proxy) { | |
| 370 return true; | |
| 371 } | |
| 372 | |
| 358 const net::HttpServerProperties& http_server_properties = | 373 const net::HttpServerProperties& http_server_properties = |
| 359 *url_request.context()->http_server_properties(); | 374 *url_request.context()->http_server_properties(); |
| 360 | 375 |
| 361 // TODO(willchan): We should really improve this algorithm as described in | 376 // TODO(willchan): We should really improve this algorithm as described in |
| 362 // crbug.com/164101. Also, theoretically we should not count a SPDY request | 377 // crbug.com/164101. Also, theoretically we should not count a SPDY request |
| 363 // against the delayable requests limit. | 378 // against the delayable requests limit. |
| 364 bool origin_supports_spdy = http_server_properties.SupportsSpdy( | 379 bool origin_supports_spdy = http_server_properties.SupportsSpdy( |
| 365 net::HostPortPair::FromURL(url_request.url())); | 380 net::HostPortPair::FromURL(url_request.url())); |
| 366 | 381 |
| 367 if (url_request.priority() >= net::LOW || | 382 if (url_request.priority() >= net::LOW || |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 385 | 400 |
| 386 return true; | 401 return true; |
| 387 } | 402 } |
| 388 | 403 |
| 389 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( | 404 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( |
| 390 int child_id, int route_id) { | 405 int child_id, int route_id) { |
| 391 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; | 406 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; |
| 392 } | 407 } |
| 393 | 408 |
| 394 } // namespace content | 409 } // namespace content |
| OLD | NEW |