| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 bool is_async) | 171 bool is_async) |
| 172 : client_id_(client_id), | 172 : client_id_(client_id), |
| 173 request_(request), | 173 request_(request), |
| 174 ready_(false), | 174 ready_(false), |
| 175 deferred_(false), | 175 deferred_(false), |
| 176 is_async_(is_async), | 176 is_async_(is_async), |
| 177 attributes_(kAttributeNone), | 177 attributes_(kAttributeNone), |
| 178 scheduler_(scheduler), | 178 scheduler_(scheduler), |
| 179 priority_(priority), | 179 priority_(priority), |
| 180 fifo_ordering_(0), | 180 fifo_ordering_(0), |
| 181 host_port_pair_(net::HostPortPair::FromURL(request->url())), |
| 181 weak_ptr_factory_(this) { | 182 weak_ptr_factory_(this) { |
| 182 DCHECK(!request_->GetUserData(kUserDataKey)); | 183 DCHECK(!request_->GetUserData(kUserDataKey)); |
| 183 request_->SetUserData(kUserDataKey, new UnownedPointer(this)); | 184 request_->SetUserData(kUserDataKey, new UnownedPointer(this)); |
| 184 } | 185 } |
| 185 | 186 |
| 186 ~ScheduledResourceRequest() override { | 187 ~ScheduledResourceRequest() override { |
| 187 request_->RemoveUserData(kUserDataKey); | 188 request_->RemoveUserData(kUserDataKey); |
| 188 scheduler_->RemoveRequest(this); | 189 scheduler_->RemoveRequest(this); |
| 189 } | 190 } |
| 190 | 191 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 uint32_t fifo_ordering() const { return fifo_ordering_; } | 237 uint32_t fifo_ordering() const { return fifo_ordering_; } |
| 237 void set_fifo_ordering(uint32_t fifo_ordering) { | 238 void set_fifo_ordering(uint32_t fifo_ordering) { |
| 238 fifo_ordering_ = fifo_ordering; | 239 fifo_ordering_ = fifo_ordering; |
| 239 } | 240 } |
| 240 RequestAttributes attributes() const { | 241 RequestAttributes attributes() const { |
| 241 return attributes_; | 242 return attributes_; |
| 242 } | 243 } |
| 243 void set_attributes(RequestAttributes attributes) { | 244 void set_attributes(RequestAttributes attributes) { |
| 244 attributes_ = attributes; | 245 attributes_ = attributes; |
| 245 } | 246 } |
| 247 const net::HostPortPair& host_port_pair() const { return host_port_pair_; } |
| 246 | 248 |
| 247 private: | 249 private: |
| 248 class UnownedPointer : public base::SupportsUserData::Data { | 250 class UnownedPointer : public base::SupportsUserData::Data { |
| 249 public: | 251 public: |
| 250 explicit UnownedPointer(ScheduledResourceRequest* pointer) | 252 explicit UnownedPointer(ScheduledResourceRequest* pointer) |
| 251 : pointer_(pointer) {} | 253 : pointer_(pointer) {} |
| 252 | 254 |
| 253 ScheduledResourceRequest* get() const { return pointer_; } | 255 ScheduledResourceRequest* get() const { return pointer_; } |
| 254 | 256 |
| 255 private: | 257 private: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 269 | 271 |
| 270 const ClientId client_id_; | 272 const ClientId client_id_; |
| 271 net::URLRequest* request_; | 273 net::URLRequest* request_; |
| 272 bool ready_; | 274 bool ready_; |
| 273 bool deferred_; | 275 bool deferred_; |
| 274 bool is_async_; | 276 bool is_async_; |
| 275 RequestAttributes attributes_; | 277 RequestAttributes attributes_; |
| 276 ResourceScheduler* scheduler_; | 278 ResourceScheduler* scheduler_; |
| 277 RequestPriorityParams priority_; | 279 RequestPriorityParams priority_; |
| 278 uint32_t fifo_ordering_; | 280 uint32_t fifo_ordering_; |
| 281 // Cached to excessive recomputation in ShouldKeepSearching. |
| 282 const net::HostPortPair host_port_pair_; |
| 279 | 283 |
| 280 base::WeakPtrFactory<ResourceScheduler::ScheduledResourceRequest> | 284 base::WeakPtrFactory<ResourceScheduler::ScheduledResourceRequest> |
| 281 weak_ptr_factory_; | 285 weak_ptr_factory_; |
| 282 | 286 |
| 283 DISALLOW_COPY_AND_ASSIGN(ScheduledResourceRequest); | 287 DISALLOW_COPY_AND_ASSIGN(ScheduledResourceRequest); |
| 284 }; | 288 }; |
| 285 | 289 |
| 286 const void* const ResourceScheduler::ScheduledResourceRequest::kUserDataKey = | 290 const void* const ResourceScheduler::ScheduledResourceRequest::kUserDataKey = |
| 287 &ResourceScheduler::ScheduledResourceRequest::kUserDataKey; | 291 &ResourceScheduler::ScheduledResourceRequest::kUserDataKey; |
| 288 | 292 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 } | 543 } |
| 540 | 544 |
| 541 return attributes; | 545 return attributes; |
| 542 } | 546 } |
| 543 | 547 |
| 544 bool ShouldKeepSearching( | 548 bool ShouldKeepSearching( |
| 545 const net::HostPortPair& active_request_host) const { | 549 const net::HostPortPair& active_request_host) const { |
| 546 size_t same_host_count = 0; | 550 size_t same_host_count = 0; |
| 547 for (RequestSet::const_iterator it = in_flight_requests_.begin(); | 551 for (RequestSet::const_iterator it = in_flight_requests_.begin(); |
| 548 it != in_flight_requests_.end(); ++it) { | 552 it != in_flight_requests_.end(); ++it) { |
| 549 net::HostPortPair host_port_pair = | 553 if (active_request_host.Equals((*it)->host_port_pair())) { |
| 550 net::HostPortPair::FromURL((*it)->url_request()->url()); | |
| 551 if (active_request_host.Equals(host_port_pair)) { | |
| 552 same_host_count++; | 554 same_host_count++; |
| 553 if (same_host_count >= kMaxNumDelayableRequestsPerHostPerClient) | 555 if (same_host_count >= kMaxNumDelayableRequestsPerHostPerClient) |
| 554 return true; | 556 return true; |
| 555 } | 557 } |
| 556 } | 558 } |
| 557 return false; | 559 return false; |
| 558 } | 560 } |
| 559 | 561 |
| 560 void StartRequest(ScheduledResourceRequest* request, | 562 void StartRequest(ScheduledResourceRequest* request, |
| 561 StartMode start_mode) { | 563 StartMode start_mode) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 // Syncronous requests could block the entire render, which could impact | 605 // Syncronous requests could block the entire render, which could impact |
| 604 // user-observable Clients. | 606 // user-observable Clients. |
| 605 if (!request->is_async()) | 607 if (!request->is_async()) |
| 606 return START_REQUEST; | 608 return START_REQUEST; |
| 607 | 609 |
| 608 // TODO(simonjam): This may end up causing disk contention. We should | 610 // TODO(simonjam): This may end up causing disk contention. We should |
| 609 // experiment with throttling if that happens. | 611 // experiment with throttling if that happens. |
| 610 if (!url_request.url().SchemeIsHTTPOrHTTPS()) | 612 if (!url_request.url().SchemeIsHTTPOrHTTPS()) |
| 611 return START_REQUEST; | 613 return START_REQUEST; |
| 612 | 614 |
| 613 net::HostPortPair host_port_pair = | 615 const net::HostPortPair& host_port_pair = request->host_port_pair(); |
| 614 net::HostPortPair::FromURL(url_request.url()); | |
| 615 | 616 |
| 616 if (!priority_requests_delayable_) { | 617 if (!priority_requests_delayable_) { |
| 617 if (using_spdy_proxy_ && url_request.url().SchemeIs(url::kHttpScheme)) | 618 if (using_spdy_proxy_ && url_request.url().SchemeIs(url::kHttpScheme)) |
| 618 return START_REQUEST; | 619 return START_REQUEST; |
| 619 | 620 |
| 620 url::SchemeHostPort scheme_host_port(url_request.url()); | 621 url::SchemeHostPort scheme_host_port(url_request.url()); |
| 621 | 622 |
| 622 net::HttpServerProperties& http_server_properties = | 623 net::HttpServerProperties& http_server_properties = |
| 623 *url_request.context()->http_server_properties(); | 624 *url_request.context()->http_server_properties(); |
| 624 | 625 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 client->ReprioritizeRequest(scheduled_resource_request, old_priority_params, | 915 client->ReprioritizeRequest(scheduled_resource_request, old_priority_params, |
| 915 new_priority_params); | 916 new_priority_params); |
| 916 } | 917 } |
| 917 | 918 |
| 918 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( | 919 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( |
| 919 int child_id, int route_id) { | 920 int child_id, int route_id) { |
| 920 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; | 921 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; |
| 921 } | 922 } |
| 922 | 923 |
| 923 } // namespace content | 924 } // namespace content |
| OLD | NEW |