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 // This is the browser side of the resource dispatcher, it receives requests | 5 // This is the browser side of the resource dispatcher, it receives requests |
6 // from the child process (i.e. [Renderer, Plugin, Worker]ProcessHost), and | 6 // from the child process (i.e. [Renderer, Plugin, Worker]ProcessHost), and |
7 // dispatches them to URLRequests. It then forwards the messages from the | 7 // dispatches them to URLRequests. It then forwards the messages from the |
8 // URLRequests back to the correct process for handling. | 8 // URLRequests back to the correct process for handling. |
9 // | 9 // |
10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 int count, | 450 int count, |
451 const ResourceRequestInfoImpl& info); | 451 const ResourceRequestInfoImpl& info); |
452 | 452 |
453 // Called when an in flight request allocates or releases a shared memory | 453 // Called when an in flight request allocates or releases a shared memory |
454 // buffer. |count| indicates whether the request is issuing or finishing. | 454 // buffer. |count| indicates whether the request is issuing or finishing. |
455 // |count| must be 1 or -1. | 455 // |count| must be 1 or -1. |
456 OustandingRequestsStats IncrementOutstandingRequestsCount( | 456 OustandingRequestsStats IncrementOutstandingRequestsCount( |
457 int count, | 457 int count, |
458 ResourceRequestInfoImpl* info); | 458 ResourceRequestInfoImpl* info); |
459 | 459 |
| 460 // Called from IncrementOutstandingRequestsCount to update the per-tab |
| 461 // request stats in |outstanding_requests_per_tab_map_|. |
| 462 // TODO(ksakamoto): This is just for temporary metrics collection for the |
| 463 // Loading Dispatcher v0 (crbug.com/723233), and will be removed soon. |
| 464 void IncrementOutstandingRequestsPerTab(int count, |
| 465 const ResourceRequestInfoImpl& info); |
| 466 |
460 // Estimate how much heap space |request| will consume to run. | 467 // Estimate how much heap space |request| will consume to run. |
461 static int CalculateApproximateMemoryCost(net::URLRequest* request); | 468 static int CalculateApproximateMemoryCost(net::URLRequest* request); |
462 | 469 |
463 // Force cancels any pending requests for the given route id. This method | 470 // Force cancels any pending requests for the given route id. This method |
464 // acts like CancelRequestsForProcess when the |route_id| member of | 471 // acts like CancelRequestsForProcess when the |route_id| member of |
465 // |routing_id| is MSG_ROUTING_NONE. | 472 // |routing_id| is MSG_ROUTING_NONE. |
466 void CancelRequestsForRoute(const GlobalFrameRoutingId& global_routing_id); | 473 void CancelRequestsForRoute(const GlobalFrameRoutingId& global_routing_id); |
467 | 474 |
468 // The list of all requests that we have pending. This list is not really | 475 // The list of all requests that we have pending. This list is not really |
469 // optimized, and assumes that we have relatively few requests pending at once | 476 // optimized, and assumes that we have relatively few requests pending at once |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 // WebContents. | 513 // WebContents. |
507 static std::unique_ptr<LoadInfoMap> PickMoreInterestingLoadInfos( | 514 static std::unique_ptr<LoadInfoMap> PickMoreInterestingLoadInfos( |
508 std::unique_ptr<LoadInfoList> infos); | 515 std::unique_ptr<LoadInfoList> infos); |
509 | 516 |
510 // Gets all the LoadInfos for each pending request. | 517 // Gets all the LoadInfos for each pending request. |
511 std::unique_ptr<LoadInfoList> GetLoadInfoForAllRoutes(); | 518 std::unique_ptr<LoadInfoList> GetLoadInfoForAllRoutes(); |
512 | 519 |
513 // Checks all pending requests and updates the load info if necessary. | 520 // Checks all pending requests and updates the load info if necessary. |
514 void UpdateLoadInfo(); | 521 void UpdateLoadInfo(); |
515 | 522 |
| 523 // Records statistics about outstanding requests since the last call, and |
| 524 // reset the stats. |
| 525 void RecordOutstandingRequestsStats(); |
| 526 |
516 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. | 527 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. |
517 void ProcessBlockedRequestsForRoute( | 528 void ProcessBlockedRequestsForRoute( |
518 const GlobalFrameRoutingId& global_routing_id, | 529 const GlobalFrameRoutingId& global_routing_id, |
519 bool cancel_requests); | 530 bool cancel_requests); |
520 | 531 |
521 void OnRequestResource(ResourceRequesterInfo* requester_info, | 532 void OnRequestResource(ResourceRequesterInfo* requester_info, |
522 int routing_id, | 533 int routing_id, |
523 int request_id, | 534 int request_id, |
524 const ResourceRequest& request_data); | 535 const ResourceRequest& request_data); |
525 | 536 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 // is not throttled. If the download is to be throttled (Decided by the | 699 // is not throttled. If the download is to be throttled (Decided by the |
689 // delegate) the function returns a ThrottlingResourceHandler to handle the | 700 // delegate) the function returns a ThrottlingResourceHandler to handle the |
690 // download. | 701 // download. |
691 std::unique_ptr<ResourceHandler> HandleDownloadStarted( | 702 std::unique_ptr<ResourceHandler> HandleDownloadStarted( |
692 net::URLRequest* request, | 703 net::URLRequest* request, |
693 std::unique_ptr<ResourceHandler> handler, | 704 std::unique_ptr<ResourceHandler> handler, |
694 bool is_content_initiated, | 705 bool is_content_initiated, |
695 bool must_download, | 706 bool must_download, |
696 bool is_new_request); | 707 bool is_new_request); |
697 | 708 |
| 709 // Returns true if there are two or more tabs that are not network 2-quiet |
| 710 // (i.e. have at least three outstanding requests). |
| 711 bool HasRequestsFromMultipleActiveTabs(); |
| 712 |
698 LoaderMap pending_loaders_; | 713 LoaderMap pending_loaders_; |
699 | 714 |
700 // Collection of temp files downloaded for child processes via | 715 // Collection of temp files downloaded for child processes via |
701 // the download_to_file mechanism. We avoid deleting them until | 716 // the download_to_file mechanism. We avoid deleting them until |
702 // the client no longer needs them. | 717 // the client no longer needs them. |
703 typedef std::map<int, scoped_refptr<storage::ShareableFileReference> > | 718 typedef std::map<int, scoped_refptr<storage::ShareableFileReference> > |
704 DeletableFilesMap; // key is request id | 719 DeletableFilesMap; // key is request id |
705 typedef std::map<int, DeletableFilesMap> | 720 typedef std::map<int, DeletableFilesMap> |
706 RegisteredTempFiles; // key is child process id | 721 RegisteredTempFiles; // key is child process id |
707 RegisteredTempFiles registered_temp_files_; | 722 RegisteredTempFiles registered_temp_files_; |
708 | 723 |
709 // A timer that periodically calls UpdateLoadInfo while pending_loaders_ is | 724 // A timer that periodically calls UpdateLoadInfo while pending_loaders_ is |
710 // not empty and at least one RenderViewHost is loading. | 725 // not empty and at least one RenderViewHost is loading. |
711 std::unique_ptr<base::RepeatingTimer> update_load_states_timer_; | 726 std::unique_ptr<base::RepeatingTimer> update_load_states_timer_; |
712 | 727 |
| 728 // A timer that periodically calls RecordOutstandingRequestsStats. |
| 729 std::unique_ptr<base::RepeatingTimer> |
| 730 record_outstanding_requests_stats_timer_; |
| 731 |
713 // Request ID for browser initiated requests. request_ids generated by | 732 // Request ID for browser initiated requests. request_ids generated by |
714 // child processes are counted up from 0, while browser created requests | 733 // child processes are counted up from 0, while browser created requests |
715 // start at -2 and go down from there. (We need to start at -2 because -1 is | 734 // start at -2 and go down from there. (We need to start at -2 because -1 is |
716 // used as a special value all over the resource_dispatcher_host for | 735 // used as a special value all over the resource_dispatcher_host for |
717 // uninitialized variables.) This way, we no longer have the unlikely (but | 736 // uninitialized variables.) This way, we no longer have the unlikely (but |
718 // observed in the real world!) event where we have two requests with the same | 737 // observed in the real world!) event where we have two requests with the same |
719 // request_id_. | 738 // request_id_. |
720 int request_id_; | 739 int request_id_; |
721 | 740 |
722 // True if the resource dispatcher host has been shut down. | 741 // True if the resource dispatcher host has been shut down. |
723 bool is_shutdown_; | 742 bool is_shutdown_; |
724 | 743 |
725 using BlockedLoadersList = std::vector<std::unique_ptr<ResourceLoader>>; | 744 using BlockedLoadersList = std::vector<std::unique_ptr<ResourceLoader>>; |
726 using BlockedLoadersMap = | 745 using BlockedLoadersMap = |
727 std::map<GlobalFrameRoutingId, std::unique_ptr<BlockedLoadersList>>; | 746 std::map<GlobalFrameRoutingId, std::unique_ptr<BlockedLoadersList>>; |
728 BlockedLoadersMap blocked_loaders_map_; | 747 BlockedLoadersMap blocked_loaders_map_; |
729 | 748 |
730 // Maps the child_ids to the approximate number of bytes | 749 // Maps the child_ids to the approximate number of bytes |
731 // being used to service its resource requests. No entry implies 0 cost. | 750 // being used to service its resource requests. No entry implies 0 cost. |
732 typedef std::map<int, OustandingRequestsStats> OutstandingRequestsStatsMap; | 751 typedef std::map<int, OustandingRequestsStats> OutstandingRequestsStatsMap; |
733 OutstandingRequestsStatsMap outstanding_requests_stats_map_; | 752 OutstandingRequestsStatsMap outstanding_requests_stats_map_; |
734 | 753 |
| 754 // Maps (child_id, route_id) to the number of outstanding requests. |
| 755 // Used only when OOPIF is not enabled, since in OOPIF modes routing_id |
| 756 // doesn't represent tabs. |
| 757 // TODO(ksakamoto): This is just for temporary metrics collection for the |
| 758 // Loading Dispatcher v0 (crbug.com/723233), and will be removed soon. |
| 759 typedef std::map<std::pair<int, int>, int> OutstandingRequestsPerTabMap; |
| 760 OutstandingRequestsPerTabMap outstanding_requests_per_tab_map_; |
| 761 |
735 // |num_in_flight_requests_| is the total number of requests currently issued | 762 // |num_in_flight_requests_| is the total number of requests currently issued |
736 // summed across all renderers. | 763 // summed across all renderers. |
737 int num_in_flight_requests_; | 764 int num_in_flight_requests_; |
738 | 765 |
739 // |max_num_in_flight_requests_| is the upper bound on how many requests | 766 // |max_num_in_flight_requests_| is the upper bound on how many requests |
740 // can be in flight at once. It's based on the maximum number of file | 767 // can be in flight at once. It's based on the maximum number of file |
741 // descriptors open per process. We need a global limit for the browser | 768 // descriptors open per process. We need a global limit for the browser |
742 // process. | 769 // process. |
743 int max_num_in_flight_requests_; | 770 int max_num_in_flight_requests_; |
744 | 771 |
(...skipping 11 matching lines...) Expand all Loading... |
756 // (max_outstanding_requests_cost_per_process_ / | 783 // (max_outstanding_requests_cost_per_process_ / |
757 // kAvgBytesPerOutstandingRequest) | 784 // kAvgBytesPerOutstandingRequest) |
758 int max_outstanding_requests_cost_per_process_; | 785 int max_outstanding_requests_cost_per_process_; |
759 | 786 |
760 // Largest number of outstanding requests seen so far across all processes. | 787 // Largest number of outstanding requests seen so far across all processes. |
761 int largest_outstanding_request_count_seen_; | 788 int largest_outstanding_request_count_seen_; |
762 | 789 |
763 // Largest number of outstanding requests seen so far in any single process. | 790 // Largest number of outstanding requests seen so far in any single process. |
764 int largest_outstanding_request_per_process_count_seen_; | 791 int largest_outstanding_request_per_process_count_seen_; |
765 | 792 |
| 793 // Largest number of outstanding requests seen since the last call to |
| 794 // RecordOutstandingRequestsStats. |
| 795 int peak_outstanding_request_count_ = 0; |
| 796 |
| 797 // Largest number of outstanding requests seen while there are outstanding |
| 798 // requests from two or more tabs, since the last call to |
| 799 // RecordOutstandingRequestsStats. |
| 800 int peak_outstanding_request_count_multitab_ = 0; |
| 801 |
766 // Time of the last user gesture. Stored so that we can add a load | 802 // Time of the last user gesture. Stored so that we can add a load |
767 // flag to requests occurring soon after a gesture to indicate they | 803 // flag to requests occurring soon after a gesture to indicate they |
768 // may be because of explicit user action. | 804 // may be because of explicit user action. |
769 base::TimeTicks last_user_gesture_time_; | 805 base::TimeTicks last_user_gesture_time_; |
770 | 806 |
771 ResourceDispatcherHostDelegate* delegate_; | 807 ResourceDispatcherHostDelegate* delegate_; |
772 | 808 |
773 LoaderDelegate* loader_delegate_; | 809 LoaderDelegate* loader_delegate_; |
774 | 810 |
775 bool allow_cross_origin_auth_prompt_; | 811 bool allow_cross_origin_auth_prompt_; |
(...skipping 18 matching lines...) Expand all Loading... |
794 | 830 |
795 // Whether experimental web platform features are enabled. | 831 // Whether experimental web platform features are enabled. |
796 bool experimental_web_features_enabled_; | 832 bool experimental_web_features_enabled_; |
797 | 833 |
798 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 834 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
799 }; | 835 }; |
800 | 836 |
801 } // namespace content | 837 } // namespace content |
802 | 838 |
803 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 839 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
OLD | NEW |