| 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 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 bool is_async) | 220 bool is_async) |
| 221 : client_id_(client_id), | 221 : client_id_(client_id), |
| 222 request_(request), | 222 request_(request), |
| 223 ready_(false), | 223 ready_(false), |
| 224 deferred_(false), | 224 deferred_(false), |
| 225 is_async_(is_async), | 225 is_async_(is_async), |
| 226 attributes_(kAttributeNone), | 226 attributes_(kAttributeNone), |
| 227 scheduler_(scheduler), | 227 scheduler_(scheduler), |
| 228 priority_(priority), | 228 priority_(priority), |
| 229 fifo_ordering_(0), | 229 fifo_ordering_(0), |
| 230 peak_delayable_requests_in_flight_(0u), |
| 230 host_port_pair_(net::HostPortPair::FromURL(request->url())), | 231 host_port_pair_(net::HostPortPair::FromURL(request->url())), |
| 231 weak_ptr_factory_(this) { | 232 weak_ptr_factory_(this) { |
| 232 DCHECK(!request_->GetUserData(kUserDataKey)); | 233 DCHECK(!request_->GetUserData(kUserDataKey)); |
| 233 request_->SetUserData(kUserDataKey, base::MakeUnique<UnownedPointer>(this)); | 234 request_->SetUserData(kUserDataKey, base::MakeUnique<UnownedPointer>(this)); |
| 234 } | 235 } |
| 235 | 236 |
| 236 ~ScheduledResourceRequest() override { | 237 ~ScheduledResourceRequest() override { |
| 238 if ((attributes_ & kAttributeLayoutBlocking) == kAttributeLayoutBlocking) { |
| 239 UMA_HISTOGRAM_COUNTS_100( |
| 240 "ResourceScheduler.PeakDelayableRequestsInFlight.LayoutBlocking", |
| 241 peak_delayable_requests_in_flight_); |
| 242 } |
| 243 if (!((attributes_ & kAttributeDelayable) == kAttributeDelayable)) { |
| 244 UMA_HISTOGRAM_COUNTS_100( |
| 245 "ResourceScheduler.PeakDelayableRequestsInFlight.NonDelayable", |
| 246 peak_delayable_requests_in_flight_); |
| 247 } |
| 237 request_->RemoveUserData(kUserDataKey); | 248 request_->RemoveUserData(kUserDataKey); |
| 238 scheduler_->RemoveRequest(this); | 249 scheduler_->RemoveRequest(this); |
| 239 } | 250 } |
| 240 | 251 |
| 241 static ScheduledResourceRequest* ForRequest(net::URLRequest* request) { | 252 static ScheduledResourceRequest* ForRequest(net::URLRequest* request) { |
| 242 UnownedPointer* pointer = | 253 UnownedPointer* pointer = |
| 243 static_cast<UnownedPointer*>(request->GetUserData(kUserDataKey)); | 254 static_cast<UnownedPointer*>(request->GetUserData(kUserDataKey)); |
| 244 return pointer ? pointer->get() : nullptr; | 255 return pointer ? pointer->get() : nullptr; |
| 245 } | 256 } |
| 246 | 257 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 267 START_SYNC)); | 278 START_SYNC)); |
| 268 return; | 279 return; |
| 269 } | 280 } |
| 270 deferred_ = false; | 281 deferred_ = false; |
| 271 Resume(); | 282 Resume(); |
| 272 } | 283 } |
| 273 | 284 |
| 274 ready_ = true; | 285 ready_ = true; |
| 275 } | 286 } |
| 276 | 287 |
| 288 void UpdateDelayableRequestsInFlight(size_t delayable_requests_in_flight) { |
| 289 peak_delayable_requests_in_flight_ = std::max( |
| 290 peak_delayable_requests_in_flight_, delayable_requests_in_flight); |
| 291 } |
| 292 |
| 277 void set_request_priority_params(const RequestPriorityParams& priority) { | 293 void set_request_priority_params(const RequestPriorityParams& priority) { |
| 278 priority_ = priority; | 294 priority_ = priority; |
| 279 } | 295 } |
| 280 const RequestPriorityParams& get_request_priority_params() const { | 296 const RequestPriorityParams& get_request_priority_params() const { |
| 281 return priority_; | 297 return priority_; |
| 282 } | 298 } |
| 283 const ClientId& client_id() const { return client_id_; } | 299 const ClientId& client_id() const { return client_id_; } |
| 284 net::URLRequest* url_request() { return request_; } | 300 net::URLRequest* url_request() { return request_; } |
| 285 const net::URLRequest* url_request() const { return request_; } | 301 const net::URLRequest* url_request() const { return request_; } |
| 286 bool is_async() const { return is_async_; } | 302 bool is_async() const { return is_async_; } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 337 |
| 322 const ClientId client_id_; | 338 const ClientId client_id_; |
| 323 net::URLRequest* request_; | 339 net::URLRequest* request_; |
| 324 bool ready_; | 340 bool ready_; |
| 325 bool deferred_; | 341 bool deferred_; |
| 326 bool is_async_; | 342 bool is_async_; |
| 327 RequestAttributes attributes_; | 343 RequestAttributes attributes_; |
| 328 ResourceScheduler* scheduler_; | 344 ResourceScheduler* scheduler_; |
| 329 RequestPriorityParams priority_; | 345 RequestPriorityParams priority_; |
| 330 uint32_t fifo_ordering_; | 346 uint32_t fifo_ordering_; |
| 347 |
| 348 // Maximum number of delayable requests in-flight when |this| was in-flight. |
| 349 size_t peak_delayable_requests_in_flight_; |
| 331 // Cached to excessive recomputation in ShouldKeepSearching. | 350 // Cached to excessive recomputation in ShouldKeepSearching. |
| 332 const net::HostPortPair host_port_pair_; | 351 const net::HostPortPair host_port_pair_; |
| 333 | 352 |
| 334 base::WeakPtrFactory<ResourceScheduler::ScheduledResourceRequest> | 353 base::WeakPtrFactory<ResourceScheduler::ScheduledResourceRequest> |
| 335 weak_ptr_factory_; | 354 weak_ptr_factory_; |
| 336 | 355 |
| 337 DISALLOW_COPY_AND_ASSIGN(ScheduledResourceRequest); | 356 DISALLOW_COPY_AND_ASSIGN(ScheduledResourceRequest); |
| 338 }; | 357 }; |
| 339 | 358 |
| 340 const void* const ResourceScheduler::ScheduledResourceRequest::kUserDataKey = | 359 const void* const ResourceScheduler::ScheduledResourceRequest::kUserDataKey = |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 } | 506 } |
| 488 | 507 |
| 489 private: | 508 private: |
| 490 enum ShouldStartReqResult { | 509 enum ShouldStartReqResult { |
| 491 DO_NOT_START_REQUEST_AND_STOP_SEARCHING, | 510 DO_NOT_START_REQUEST_AND_STOP_SEARCHING, |
| 492 DO_NOT_START_REQUEST_AND_KEEP_SEARCHING, | 511 DO_NOT_START_REQUEST_AND_KEEP_SEARCHING, |
| 493 START_REQUEST, | 512 START_REQUEST, |
| 494 YIELD_SCHEDULER | 513 YIELD_SCHEDULER |
| 495 }; | 514 }; |
| 496 | 515 |
| 516 // Records the metrics related to number of requests in flight. |
| 517 void RecordRequestCountMetrics() const { |
| 518 UMA_HISTOGRAM_COUNTS_100("ResourceScheduler.RequestsCount.All", |
| 519 in_flight_requests_.size()); |
| 520 UMA_HISTOGRAM_COUNTS_100("ResourceScheduler.RequestsCount.Delayable", |
| 521 in_flight_delayable_count_); |
| 522 UMA_HISTOGRAM_COUNTS_100( |
| 523 "ResourceScheduler.RequestsCount.NonDelayable", |
| 524 in_flight_requests_.size() - in_flight_delayable_count_); |
| 525 UMA_HISTOGRAM_COUNTS_100( |
| 526 "ResourceScheduler.RequestsCount.TotalLayoutBlocking", |
| 527 total_layout_blocking_count_); |
| 528 } |
| 529 |
| 497 void InsertInFlightRequest(ScheduledResourceRequest* request) { | 530 void InsertInFlightRequest(ScheduledResourceRequest* request) { |
| 498 in_flight_requests_.insert(request); | 531 in_flight_requests_.insert(request); |
| 499 SetRequestAttributes(request, DetermineRequestAttributes(request)); | 532 SetRequestAttributes(request, DetermineRequestAttributes(request)); |
| 533 RecordRequestCountMetrics(); |
| 534 |
| 535 if (RequestAttributesAreSet(request->attributes(), kAttributeDelayable)) { |
| 536 // Notify all in-flight with the new count of in-flight delayable |
| 537 // requests. |
| 538 for (RequestSet::const_iterator it = in_flight_requests_.begin(); |
| 539 it != in_flight_requests_.end(); ++it) { |
| 540 (*it)->UpdateDelayableRequestsInFlight(in_flight_delayable_count_); |
| 541 } |
| 542 } |
| 543 |
| 544 if (RequestAttributesAreSet(request->attributes(), |
| 545 kAttributeLayoutBlocking) || |
| 546 !RequestAttributesAreSet(request->attributes(), kAttributeDelayable)) { |
| 547 // |request| is either a layout blocking or a non-delayable request. |
| 548 request->UpdateDelayableRequestsInFlight(in_flight_delayable_count_); |
| 549 } |
| 500 } | 550 } |
| 501 | 551 |
| 502 void EraseInFlightRequest(ScheduledResourceRequest* request) { | 552 void EraseInFlightRequest(ScheduledResourceRequest* request) { |
| 503 size_t erased = in_flight_requests_.erase(request); | 553 size_t erased = in_flight_requests_.erase(request); |
| 504 DCHECK_EQ(1u, erased); | 554 DCHECK_EQ(1u, erased); |
| 505 // Clear any special state that we were tracking for this request. | 555 // Clear any special state that we were tracking for this request. |
| 506 SetRequestAttributes(request, kAttributeNone); | 556 SetRequestAttributes(request, kAttributeNone); |
| 507 } | 557 } |
| 508 | 558 |
| 509 void ClearInFlightRequests() { | 559 void ClearInFlightRequests() { |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 } | 1144 } |
| 1095 ReprioritizeRequest(request, new_priority, current_intra_priority); | 1145 ReprioritizeRequest(request, new_priority, current_intra_priority); |
| 1096 } | 1146 } |
| 1097 | 1147 |
| 1098 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( | 1148 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( |
| 1099 int child_id, int route_id) { | 1149 int child_id, int route_id) { |
| 1100 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; | 1150 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; |
| 1101 } | 1151 } |
| 1102 | 1152 |
| 1103 } // namespace content | 1153 } // namespace content |
| OLD | NEW |