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" | |
6 | |
5 #include <set> | 7 #include <set> |
6 | 8 |
7 #include "content/browser/loader/resource_scheduler.h" | |
8 | |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "content/common/resource_messages.h" | 15 #include "content/common/resource_messages.h" |
16 #include "content/browser/loader/resource_message_delegate.h" | 16 #include "content/browser/loader/resource_message_delegate.h" |
17 #include "content/public/browser/resource_controller.h" | 17 #include "content/public/browser/resource_controller.h" |
18 #include "content/public/browser/resource_request_info.h" | 18 #include "content/public/browser/resource_request_info.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
30 namespace { | 30 namespace { |
31 | 31 |
32 // Field trial constants | 32 // Field trial constants |
33 const char kThrottleCoalesceFieldTrial[] = "RequestThrottlingAndCoalescing"; | 33 const char kThrottleCoalesceFieldTrial[] = "RequestThrottlingAndCoalescing"; |
34 const char kThrottleCoalesceFieldTrialThrottle[] = "Throttle"; | 34 const char kThrottleCoalesceFieldTrialThrottle[] = "Throttle"; |
35 const char kThrottleCoalesceFieldTrialCoalesce[] = "Coalesce"; | 35 const char kThrottleCoalesceFieldTrialCoalesce[] = "Coalesce"; |
36 | 36 |
37 const char kRequestLimitFieldTrial[] = "OutstandingRequestLimiting"; | 37 const char kRequestLimitFieldTrial[] = "OutstandingRequestLimiting"; |
38 const char kRequestLimitFieldTrialGroupPrefix[] = "Limit"; | 38 const char kRequestLimitFieldTrialGroupPrefix[] = "Limit"; |
39 | 39 |
40 const char kResourcePrioritiesFieldTrial[] = "ResourcePriorities"; | |
41 | |
40 // Post ResourceScheduler histograms of the following forms: | 42 // Post ResourceScheduler histograms of the following forms: |
41 // If |histogram_suffix| is NULL or the empty string: | 43 // If |histogram_suffix| is NULL or the empty string: |
42 // ResourceScheduler.base_name.histogram_name | 44 // ResourceScheduler.base_name.histogram_name |
43 // Else: | 45 // Else: |
44 // ResourceScheduler.base_name.histogram_name.histogram_suffix | 46 // ResourceScheduler.base_name.histogram_name.histogram_suffix |
45 void PostHistogram(const char* base_name, | 47 void PostHistogram(const char* base_name, |
46 const char* histogram_name, | 48 const char* histogram_name, |
47 const char* histogram_suffix, | 49 const char* histogram_suffix, |
48 base::TimeDelta time) { | 50 base::TimeDelta time) { |
49 std::string histogram = | 51 std::string histogram = |
(...skipping 17 matching lines...) Expand all Loading... | |
67 else if (num_clients <= 15) | 69 else if (num_clients <= 15) |
68 return "Max15Clients"; | 70 return "Max15Clients"; |
69 else if (num_clients <= 30) | 71 else if (num_clients <= 30) |
70 return "Max30Clients"; | 72 return "Max30Clients"; |
71 return "Over30Clients"; | 73 return "Over30Clients"; |
72 } | 74 } |
73 | 75 |
74 } // namespace | 76 } // namespace |
75 | 77 |
76 static const size_t kCoalescedTimerPeriod = 5000; | 78 static const size_t kCoalescedTimerPeriod = 5000; |
77 static const size_t kMaxNumDelayableRequestsPerClient = 10; | 79 static const size_t kDefaultMaxNumDelayableRequestsPerClient = 10; |
78 static const size_t kMaxNumDelayableRequestsPerHost = 6; | 80 static const size_t kMaxNumDelayableRequestsPerHost = 6; |
79 static const size_t kMaxNumThrottledRequestsPerClient = 1; | 81 static const size_t kMaxNumThrottledRequestsPerClient = 1; |
82 static const size_t kDefaultMaxNumDelayableWhileLayoutBlocking = 1; | |
83 static const net::RequestPriority | |
84 kDefaultLayoutBlockingPriorityThreshold = net::LOW; | |
80 | 85 |
81 struct ResourceScheduler::RequestPriorityParams { | 86 struct ResourceScheduler::RequestPriorityParams { |
82 RequestPriorityParams() | 87 RequestPriorityParams() |
83 : priority(net::DEFAULT_PRIORITY), | 88 : priority(net::DEFAULT_PRIORITY), |
84 intra_priority(0) { | 89 intra_priority(0) { |
85 } | 90 } |
86 | 91 |
87 RequestPriorityParams(net::RequestPriority priority, int intra_priority) | 92 RequestPriorityParams(net::RequestPriority priority, int intra_priority) |
88 : priority(priority), | 93 : priority(priority), |
89 intra_priority(intra_priority) { | 94 intra_priority(intra_priority) { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 // Each client represents a tab. | 306 // Each client represents a tab. |
302 class ResourceScheduler::Client { | 307 class ResourceScheduler::Client { |
303 public: | 308 public: |
304 explicit Client(ResourceScheduler* scheduler, | 309 explicit Client(ResourceScheduler* scheduler, |
305 bool is_visible, | 310 bool is_visible, |
306 bool is_audible) | 311 bool is_audible) |
307 : is_audible_(is_audible), | 312 : is_audible_(is_audible), |
308 is_visible_(is_visible), | 313 is_visible_(is_visible), |
309 is_loaded_(false), | 314 is_loaded_(false), |
310 is_paused_(false), | 315 is_paused_(false), |
311 has_body_(false), | 316 has_html_body_(false), |
312 using_spdy_proxy_(false), | 317 using_spdy_proxy_(false), |
313 load_started_time_(base::TimeTicks::Now()), | 318 load_started_time_(base::TimeTicks::Now()), |
314 scheduler_(scheduler), | 319 scheduler_(scheduler), |
315 in_flight_delayable_count_(0), | 320 in_flight_delayable_count_(0), |
316 total_layout_blocking_count_(0), | 321 total_layout_blocking_count_(0), |
317 throttle_state_(ResourceScheduler::THROTTLED) {} | 322 throttle_state_(ResourceScheduler::THROTTLED) { |
323 } | |
318 | 324 |
319 ~Client() { | 325 ~Client() { |
320 // Update to default state and pause to ensure the scheduler has a | 326 // Update to default state and pause to ensure the scheduler has a |
321 // correct count of relevant types of clients. | 327 // correct count of relevant types of clients. |
322 is_visible_ = false; | 328 is_visible_ = false; |
323 is_audible_ = false; | 329 is_audible_ = false; |
324 is_paused_ = true; | 330 is_paused_ = true; |
325 UpdateThrottleState(); | 331 UpdateThrottleState(); |
326 } | 332 } |
327 | 333 |
(...skipping 15 matching lines...) Expand all Loading... | |
343 EraseInFlightRequest(request); | 349 EraseInFlightRequest(request); |
344 | 350 |
345 // Removing this request may have freed up another to load. | 351 // Removing this request may have freed up another to load. |
346 LoadAnyStartablePendingRequests(); | 352 LoadAnyStartablePendingRequests(); |
347 } | 353 } |
348 } | 354 } |
349 | 355 |
350 RequestSet StartAndRemoveAllRequests() { | 356 RequestSet StartAndRemoveAllRequests() { |
351 // First start any pending requests so that they will be moved into | 357 // First start any pending requests so that they will be moved into |
352 // in_flight_requests_. This may exceed the limits | 358 // in_flight_requests_. This may exceed the limits |
353 // kMaxNumDelayableRequestsPerClient, kMaxNumDelayableRequestsPerHost and | 359 // kDefaultMaxNumDelayableRequestsPerClient, kMaxNumDelayableRequestsPerHost |
354 // kMaxNumThrottledRequestsPerClient, so this method must not do anything | 360 // and kMaxNumThrottledRequestsPerClient, so this method must not do |
355 // that depends on those limits before calling ClearInFlightRequests() | 361 // anything that depends on those limits before calling |
356 // below. | 362 // ClearInFlightRequests() below. |
357 while (!pending_requests_.IsEmpty()) { | 363 while (!pending_requests_.IsEmpty()) { |
358 ScheduledResourceRequest* request = | 364 ScheduledResourceRequest* request = |
359 *pending_requests_.GetNextHighestIterator(); | 365 *pending_requests_.GetNextHighestIterator(); |
360 pending_requests_.Erase(request); | 366 pending_requests_.Erase(request); |
361 // StartRequest() may modify pending_requests_. TODO(ricea): Does it? | 367 // StartRequest() may modify pending_requests_. TODO(ricea): Does it? |
362 StartRequest(request); | 368 StartRequest(request); |
363 } | 369 } |
364 RequestSet unowned_requests; | 370 RequestSet unowned_requests; |
365 for (RequestSet::iterator it = in_flight_requests_.begin(); | 371 for (RequestSet::iterator it = in_flight_requests_.begin(); |
366 it != in_flight_requests_.end(); ++it) { | 372 it != in_flight_requests_.end(); ++it) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 scheduler_->DecrementActiveClientsLoading(); | 469 scheduler_->DecrementActiveClientsLoading(); |
464 } | 470 } |
465 if (throttle_state_ == COALESCED) { | 471 if (throttle_state_ == COALESCED) { |
466 scheduler_->IncrementCoalescedClients(); | 472 scheduler_->IncrementCoalescedClients(); |
467 } else if (old_throttle_state == COALESCED) { | 473 } else if (old_throttle_state == COALESCED) { |
468 scheduler_->DecrementCoalescedClients(); | 474 scheduler_->DecrementCoalescedClients(); |
469 } | 475 } |
470 } | 476 } |
471 | 477 |
472 void OnNavigate() { | 478 void OnNavigate() { |
473 has_body_ = false; | 479 has_html_body_ = false; |
474 is_loaded_ = false; | 480 is_loaded_ = false; |
475 } | 481 } |
476 | 482 |
477 void OnWillInsertBody() { | 483 void OnWillInsertBody() { |
478 has_body_ = true; | 484 has_html_body_ = true; |
479 LoadAnyStartablePendingRequests(); | 485 LoadAnyStartablePendingRequests(); |
480 } | 486 } |
481 | 487 |
482 void OnReceivedSpdyProxiedHttpResponse() { | 488 void OnReceivedSpdyProxiedHttpResponse() { |
483 if (!using_spdy_proxy_) { | 489 if (!using_spdy_proxy_) { |
484 using_spdy_proxy_ = true; | 490 using_spdy_proxy_ = true; |
485 LoadAnyStartablePendingRequests(); | 491 LoadAnyStartablePendingRequests(); |
486 } | 492 } |
487 } | 493 } |
488 | 494 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
616 request->set_classification(classification); | 622 request->set_classification(classification); |
617 DCHECK_EQ( | 623 DCHECK_EQ( |
618 CountRequestsWithClassification(IN_FLIGHT_DELAYABLE_REQUEST, false), | 624 CountRequestsWithClassification(IN_FLIGHT_DELAYABLE_REQUEST, false), |
619 in_flight_delayable_count_); | 625 in_flight_delayable_count_); |
620 DCHECK_EQ(CountRequestsWithClassification(LAYOUT_BLOCKING_REQUEST, true), | 626 DCHECK_EQ(CountRequestsWithClassification(LAYOUT_BLOCKING_REQUEST, true), |
621 total_layout_blocking_count_); | 627 total_layout_blocking_count_); |
622 } | 628 } |
623 | 629 |
624 RequestClassification ClassifyRequest(ScheduledResourceRequest* request) { | 630 RequestClassification ClassifyRequest(ScheduledResourceRequest* request) { |
625 // If a request is already marked as layout-blocking make sure to keep the | 631 // If a request is already marked as layout-blocking make sure to keep the |
626 // classification across redirects unless the priority was lowered. | 632 // classification across redirects. |
627 if (request->classification() == LAYOUT_BLOCKING_REQUEST && | 633 if (request->classification() == LAYOUT_BLOCKING_REQUEST) |
628 request->url_request()->priority() > net::LOW) { | 634 return LAYOUT_BLOCKING_REQUEST; |
635 | |
636 if (!has_html_body_ && | |
637 request->url_request()->priority() > | |
638 scheduler_->layout_blocking_or_high_priority_threshold()) { | |
629 return LAYOUT_BLOCKING_REQUEST; | 639 return LAYOUT_BLOCKING_REQUEST; |
630 } | 640 } |
631 | 641 |
632 if (!has_body_ && request->url_request()->priority() > net::LOW) | 642 if (request->url_request()->priority() < |
633 return LAYOUT_BLOCKING_REQUEST; | 643 scheduler_->layout_blocking_or_high_priority_threshold()) { |
634 | |
635 if (request->url_request()->priority() < net::LOW) { | |
636 net::HostPortPair host_port_pair = | 644 net::HostPortPair host_port_pair = |
637 net::HostPortPair::FromURL(request->url_request()->url()); | 645 net::HostPortPair::FromURL(request->url_request()->url()); |
638 net::HttpServerProperties& http_server_properties = | 646 net::HttpServerProperties& http_server_properties = |
639 *request->url_request()->context()->http_server_properties(); | 647 *request->url_request()->context()->http_server_properties(); |
640 if (!http_server_properties.SupportsRequestPriority(host_port_pair) && | 648 if (!http_server_properties.SupportsRequestPriority(host_port_pair) && |
641 ContainsKey(in_flight_requests_, request)) { | 649 ContainsKey(in_flight_requests_, request)) { |
642 return IN_FLIGHT_DELAYABLE_REQUEST; | 650 return IN_FLIGHT_DELAYABLE_REQUEST; |
643 } | 651 } |
mmenke
2015/08/13 15:16:07
I'm fine with any of the possible approaches here,
Pat Meenan
2015/08/13 20:56:42
Ok, it resulted in a bunch of changes but I think
| |
644 } | 652 } |
645 return NORMAL_REQUEST; | 653 return NORMAL_REQUEST; |
646 } | 654 } |
647 | 655 |
648 bool ShouldKeepSearching( | 656 bool ShouldKeepSearching( |
649 const net::HostPortPair& active_request_host) const { | 657 const net::HostPortPair& active_request_host) const { |
650 size_t same_host_count = 0; | 658 size_t same_host_count = 0; |
651 for (RequestSet::const_iterator it = in_flight_requests_.begin(); | 659 for (RequestSet::const_iterator it = in_flight_requests_.begin(); |
652 it != in_flight_requests_.end(); ++it) { | 660 it != in_flight_requests_.end(); ++it) { |
653 net::HostPortPair host_port_pair = | 661 net::HostPortPair host_port_pair = |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
762 } | 770 } |
763 | 771 |
764 if (throttle_state_ == THROTTLED && | 772 if (throttle_state_ == THROTTLED && |
765 in_flight_requests_.size() >= kMaxNumThrottledRequestsPerClient) { | 773 in_flight_requests_.size() >= kMaxNumThrottledRequestsPerClient) { |
766 // There may still be request-priority-capable requests that should be | 774 // There may still be request-priority-capable requests that should be |
767 // issued. | 775 // issued. |
768 return DO_NOT_START_REQUEST_AND_KEEP_SEARCHING; | 776 return DO_NOT_START_REQUEST_AND_KEEP_SEARCHING; |
769 } | 777 } |
770 | 778 |
771 // High-priority and layout-blocking requests. | 779 // High-priority and layout-blocking requests. |
772 if (url_request.priority() >= net::LOW) { | 780 if (url_request.priority() >= |
781 scheduler_->layout_blocking_or_high_priority_threshold()) { | |
773 return START_REQUEST; | 782 return START_REQUEST; |
774 } | 783 } |
775 | 784 |
776 if (in_flight_delayable_count_ >= kMaxNumDelayableRequestsPerClient) { | 785 if (in_flight_delayable_count_ >= |
786 scheduler_->max_num_delayable_requests()) { | |
777 return DO_NOT_START_REQUEST_AND_STOP_SEARCHING; | 787 return DO_NOT_START_REQUEST_AND_STOP_SEARCHING; |
778 } | 788 } |
779 | 789 |
780 if (ShouldKeepSearching(host_port_pair)) { | 790 if (ShouldKeepSearching(host_port_pair)) { |
781 // There may be other requests for other hosts we'd allow, | 791 // There may be other requests for other hosts we'd allow, |
782 // so keep checking. | 792 // so keep checking. |
783 return DO_NOT_START_REQUEST_AND_KEEP_SEARCHING; | 793 return DO_NOT_START_REQUEST_AND_KEEP_SEARCHING; |
784 } | 794 } |
785 | 795 |
786 bool have_immediate_requests_in_flight = | 796 // The in-flight requests consist of layout-blocking requests, |
787 in_flight_requests_.size() > in_flight_delayable_count_; | 797 // normal requests and delayable requests. Everything except for |
788 if (have_immediate_requests_in_flight && | 798 // delayable requests is handled above here so this is deciding what to |
789 (!has_body_ || total_layout_blocking_count_ != 0) && | 799 // do with a delayable request while we are in the layout-blocking phase |
790 // Do not allow a low priority request through in parallel if | 800 // of loading. |
791 // we are in a limit field trial. | 801 if (!has_html_body_ || total_layout_blocking_count_ != 0) { |
792 (scheduler_->limit_outstanding_requests() || | 802 size_t non_delayable_requests_in_flight_count = |
793 in_flight_delayable_count_ != 0)) { | 803 in_flight_requests_.size() - in_flight_delayable_count_; |
794 return DO_NOT_START_REQUEST_AND_STOP_SEARCHING; | 804 if (scheduler_->enable_in_flight_layout_blocking_threshold()) { |
805 if (non_delayable_requests_in_flight_count > | |
806 scheduler_->in_flight_layout_blocking_threshold()) { | |
807 // Too many higher priority in-flight requests to allow lower priority | |
808 // requests through. | |
809 return DO_NOT_START_REQUEST_AND_STOP_SEARCHING; | |
810 } | |
811 if (in_flight_requests_.size() > 0 && | |
812 (scheduler_->limit_outstanding_requests() || | |
813 in_flight_delayable_count_ >= | |
814 scheduler_->max_num_delayable_while_layout_blocking())) { | |
815 // Block the request if at least one request is in flight and the | |
816 // number of in-flight delayable requests has hit the configured | |
817 // limit. | |
818 return DO_NOT_START_REQUEST_AND_STOP_SEARCHING; | |
819 } | |
820 } else if (non_delayable_requests_in_flight_count > 0 && | |
821 (scheduler_->limit_outstanding_requests() || | |
822 in_flight_delayable_count_ >= | |
823 scheduler_->max_num_delayable_while_layout_blocking())) { | |
824 // If there are no high-priority requests in flight the floodgates open. | |
825 // If there are high-priority requests in-flight then limit the number | |
826 // of lower-priority requests (or zero if a limit field trial is | |
827 // active). | |
828 return DO_NOT_START_REQUEST_AND_STOP_SEARCHING; | |
829 } | |
795 } | 830 } |
796 | 831 |
797 return START_REQUEST; | 832 return START_REQUEST; |
798 } | 833 } |
799 | 834 |
800 void LoadAnyStartablePendingRequests() { | 835 void LoadAnyStartablePendingRequests() { |
801 // We iterate through all the pending requests, starting with the highest | 836 // We iterate through all the pending requests, starting with the highest |
802 // priority one. For each entry, one of three things can happen: | 837 // priority one. For each entry, one of three things can happen: |
803 // 1) We start the request, remove it from the list, and keep checking. | 838 // 1) We start the request, remove it from the list, and keep checking. |
804 // 2) We do NOT start the request, but ShouldStartRequest() signals us that | 839 // 2) We do NOT start the request, but ShouldStartRequest() signals us that |
(...skipping 26 matching lines...) Expand all Loading... | |
831 DCHECK(query_result == DO_NOT_START_REQUEST_AND_STOP_SEARCHING); | 866 DCHECK(query_result == DO_NOT_START_REQUEST_AND_STOP_SEARCHING); |
832 break; | 867 break; |
833 } | 868 } |
834 } | 869 } |
835 } | 870 } |
836 | 871 |
837 bool is_audible_; | 872 bool is_audible_; |
838 bool is_visible_; | 873 bool is_visible_; |
839 bool is_loaded_; | 874 bool is_loaded_; |
840 bool is_paused_; | 875 bool is_paused_; |
841 bool has_body_; | 876 // Tracks if the main HTML parser has reached the body which marks the end of |
877 // layout-blocking resources. | |
878 bool has_html_body_; | |
842 bool using_spdy_proxy_; | 879 bool using_spdy_proxy_; |
843 RequestQueue pending_requests_; | 880 RequestQueue pending_requests_; |
844 RequestSet in_flight_requests_; | 881 RequestSet in_flight_requests_; |
845 base::TimeTicks load_started_time_; | 882 base::TimeTicks load_started_time_; |
846 // The last time the client switched state between active and background. | 883 // The last time the client switched state between active and background. |
847 base::TimeTicks last_active_switch_time_; | 884 base::TimeTicks last_active_switch_time_; |
848 ResourceScheduler* scheduler_; | 885 ResourceScheduler* scheduler_; |
849 // The number of delayable in-flight requests. | 886 // The number of delayable in-flight requests. |
850 size_t in_flight_delayable_count_; | 887 size_t in_flight_delayable_count_; |
851 // The number of layout-blocking in-flight requests. | 888 // The number of layout-blocking in-flight requests. |
852 size_t total_layout_blocking_count_; | 889 size_t total_layout_blocking_count_; |
853 ResourceScheduler::ClientThrottleState throttle_state_; | 890 ResourceScheduler::ClientThrottleState throttle_state_; |
854 }; | 891 }; |
855 | 892 |
856 ResourceScheduler::ResourceScheduler() | 893 ResourceScheduler::ResourceScheduler() |
857 : should_coalesce_(false), | 894 : should_coalesce_(false), |
858 should_throttle_(false), | 895 should_throttle_(false), |
859 active_clients_loading_(0), | 896 active_clients_loading_(0), |
860 coalesced_clients_(0), | 897 coalesced_clients_(0), |
861 limit_outstanding_requests_(false), | 898 limit_outstanding_requests_(false), |
862 outstanding_request_limit_(0), | 899 outstanding_request_limit_(0), |
900 layout_blocking_or_high_priority_threshold_( | |
901 kDefaultLayoutBlockingPriorityThreshold), | |
902 enable_in_flight_layout_blocking_threshold_(false), | |
903 in_flight_layout_blocking_threshold_(0), | |
904 max_num_delayable_while_layout_blocking_( | |
905 kDefaultMaxNumDelayableWhileLayoutBlocking), | |
906 max_num_delayable_requests_(kDefaultMaxNumDelayableRequestsPerClient), | |
863 coalescing_timer_(new base::Timer(true /* retain_user_task */, | 907 coalescing_timer_(new base::Timer(true /* retain_user_task */, |
864 true /* is_repeating */)) { | 908 true /* is_repeating */)) { |
865 std::string throttling_trial_group = | 909 std::string throttling_trial_group = |
866 base::FieldTrialList::FindFullName(kThrottleCoalesceFieldTrial); | 910 base::FieldTrialList::FindFullName(kThrottleCoalesceFieldTrial); |
867 if (throttling_trial_group == kThrottleCoalesceFieldTrialThrottle) { | 911 if (throttling_trial_group == kThrottleCoalesceFieldTrialThrottle) { |
868 should_throttle_ = true; | 912 should_throttle_ = true; |
869 } else if (throttling_trial_group == kThrottleCoalesceFieldTrialCoalesce) { | 913 } else if (throttling_trial_group == kThrottleCoalesceFieldTrialCoalesce) { |
870 should_coalesce_ = true; | 914 should_coalesce_ = true; |
871 should_throttle_ = true; | 915 should_throttle_ = true; |
872 } | 916 } |
873 | 917 |
874 std::string outstanding_limit_trial_group = | 918 std::string outstanding_limit_trial_group = |
875 base::FieldTrialList::FindFullName(kRequestLimitFieldTrial); | 919 base::FieldTrialList::FindFullName(kRequestLimitFieldTrial); |
876 std::vector<std::string> split_group( | 920 std::vector<std::string> split_group( |
877 base::SplitString(outstanding_limit_trial_group, "=", | 921 base::SplitString(outstanding_limit_trial_group, "=", |
878 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL)); | 922 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL)); |
879 int outstanding_limit = 0; | 923 int outstanding_limit = 0; |
880 if (split_group.size() == 2 && | 924 if (split_group.size() == 2 && |
881 split_group[0] == kRequestLimitFieldTrialGroupPrefix && | 925 split_group[0] == kRequestLimitFieldTrialGroupPrefix && |
882 base::StringToInt(split_group[1], &outstanding_limit) && | 926 base::StringToInt(split_group[1], &outstanding_limit) && |
883 outstanding_limit > 0) { | 927 outstanding_limit > 0) { |
884 limit_outstanding_requests_ = true; | 928 limit_outstanding_requests_ = true; |
885 outstanding_request_limit_ = outstanding_limit; | 929 outstanding_request_limit_ = outstanding_limit; |
886 } | 930 } |
931 | |
932 // Set up the ResourceScheduling field trial options. | |
933 // The field trial parameters are also encoded into the group name since | |
934 // the variations component is not available from here and plumbing the | |
935 // options through the code is overkill for a short experiment. | |
936 // | |
937 // The group name encoding looks like this: | |
938 // <descriptiveName>_ABCDE_E2_F_G | |
939 // A - fetchDeferLateScripts (1 for true, 0 for false) | |
940 // B - fetchIncreaseFontPriority (1 for true, 0 for false) | |
941 // C - fetchIncreaseAsyncScriptPriority (1 for true, 0 for false) | |
942 // D - fetchIncreasePriorities (1 for true, 0 for false) | |
943 // E - fetchEnableLayoutBlockingThreshold (1 for true, 0 for false) | |
944 // E2 - fetchLayoutBlockingThreshold (Numeric) | |
945 // F - fetchMaxNumDelayableWhileLayoutBlocking (Numeric) | |
946 // G - fetchMaxNumDelayableRequests (Numeric) | |
947 std::string resource_priorities_trial_group = | |
948 base::FieldTrialList::FindFullName(kResourcePrioritiesFieldTrial); | |
949 std::vector<std::string> resource_priorities_split_group( | |
950 base::SplitString(resource_priorities_trial_group, "_", | |
951 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL)); | |
952 if (resource_priorities_split_group.size() == 5 && | |
953 resource_priorities_split_group[1].length() == 5) { | |
954 // fetchIncreasePriorities | |
955 if (resource_priorities_split_group[1].at(3) == '1') | |
956 layout_blocking_or_high_priority_threshold_ = net::MEDIUM; | |
957 enable_in_flight_layout_blocking_threshold_ = | |
958 resource_priorities_split_group[1].at(4) == '1'; | |
959 size_t numeric_value = 0; | |
960 if (base::StringToSizeT(resource_priorities_split_group[2], &numeric_value)) | |
961 in_flight_layout_blocking_threshold_ = numeric_value; | |
962 if (base::StringToSizeT(resource_priorities_split_group[3], &numeric_value)) | |
963 max_num_delayable_while_layout_blocking_ = numeric_value; | |
964 if (base::StringToSizeT(resource_priorities_split_group[4], &numeric_value)) | |
965 max_num_delayable_requests_ = numeric_value; | |
966 } | |
887 } | 967 } |
888 | 968 |
889 ResourceScheduler::~ResourceScheduler() { | 969 ResourceScheduler::~ResourceScheduler() { |
890 DCHECK(unowned_requests_.empty()); | 970 DCHECK(unowned_requests_.empty()); |
891 DCHECK(client_map_.empty()); | 971 DCHECK(client_map_.empty()); |
892 } | 972 } |
893 | 973 |
894 void ResourceScheduler::SetThrottleOptionsForTesting(bool should_throttle, | 974 void ResourceScheduler::SetThrottleOptionsForTesting(bool should_throttle, |
895 bool should_coalesce) { | 975 bool should_coalesce) { |
896 should_coalesce_ = should_coalesce; | 976 should_coalesce_ = should_coalesce; |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1202 client->ReprioritizeRequest( | 1282 client->ReprioritizeRequest( |
1203 request, old_priority_params, new_priority_params); | 1283 request, old_priority_params, new_priority_params); |
1204 } | 1284 } |
1205 | 1285 |
1206 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( | 1286 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( |
1207 int child_id, int route_id) { | 1287 int child_id, int route_id) { |
1208 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; | 1288 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; |
1209 } | 1289 } |
1210 | 1290 |
1211 } // namespace content | 1291 } // namespace content |
OLD | NEW |