| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 class AsyncRevalidationManager; | 57 class AsyncRevalidationManager; |
| 58 class LoaderDelegate; | 58 class LoaderDelegate; |
| 59 class NavigationURLLoaderImplCore; | 59 class NavigationURLLoaderImplCore; |
| 60 class NavigationUIData; | 60 class NavigationUIData; |
| 61 class RenderFrameHostImpl; | 61 class RenderFrameHostImpl; |
| 62 class ResourceContext; | 62 class ResourceContext; |
| 63 class ResourceDispatcherHostDelegate; | 63 class ResourceDispatcherHostDelegate; |
| 64 class ResourceHandler; | 64 class ResourceHandler; |
| 65 class ResourceMessageDelegate; | 65 class ResourceMessageDelegate; |
| 66 class ResourceMessageFilter; | 66 class ResourceMessageFilter; |
| 67 class ResourceRequesterInfo; |
| 67 class ResourceRequestInfoImpl; | 68 class ResourceRequestInfoImpl; |
| 68 class ServiceWorkerNavigationHandleCore; | 69 class ServiceWorkerNavigationHandleCore; |
| 69 struct NavigationRequestInfo; | 70 struct NavigationRequestInfo; |
| 70 struct Referrer; | 71 struct Referrer; |
| 71 struct ResourceRequest; | 72 struct ResourceRequest; |
| 72 | 73 |
| 73 namespace mojom { | 74 namespace mojom { |
| 74 class URLLoader; | 75 class URLLoader; |
| 75 } // namespace mojom | 76 } // namespace mojom |
| 76 | 77 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 295 |
| 295 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); | 296 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); |
| 296 | 297 |
| 297 // Called when loading a request with mojo. | 298 // Called when loading a request with mojo. |
| 298 void OnRequestResourceWithMojo( | 299 void OnRequestResourceWithMojo( |
| 299 int routing_id, | 300 int routing_id, |
| 300 int request_id, | 301 int request_id, |
| 301 const ResourceRequest& request, | 302 const ResourceRequest& request, |
| 302 mojom::URLLoaderAssociatedRequest mojo_request, | 303 mojom::URLLoaderAssociatedRequest mojo_request, |
| 303 mojom::URLLoaderClientAssociatedPtr url_loader_client, | 304 mojom::URLLoaderClientAssociatedPtr url_loader_client, |
| 304 ResourceMessageFilter* filter); | 305 std::unique_ptr<ResourceRequesterInfo> requester_info); |
| 305 | 306 |
| 306 void OnSyncLoadWithMojo(int routing_id, | 307 void OnSyncLoadWithMojo(int routing_id, |
| 307 int request_id, | 308 int request_id, |
| 308 const ResourceRequest& request_data, | 309 const ResourceRequest& request_data, |
| 309 ResourceMessageFilter* filter, | 310 std::unique_ptr<ResourceRequesterInfo> requester_info, |
| 310 const SyncLoadResultCallback& result_handler); | 311 const SyncLoadResultCallback& result_handler); |
| 311 | 312 |
| 312 // Helper function for initializing the |request| passed in. By initializing | 313 // Helper function for initializing the |request| passed in. By initializing |
| 313 // we mean setting the |referrer| on the |request|, associating the | 314 // we mean setting the |referrer| on the |request|, associating the |
| 314 // ResourceRequestInfoImpl structure with the |request|, etc. | 315 // ResourceRequestInfoImpl structure with the |request|, etc. |
| 315 // This function should be called for invoking the BeginURLRequest() function | 316 // This function should be called for invoking the BeginURLRequest() function |
| 316 // to initiate a URL request. | 317 // to initiate a URL request. |
| 317 void InitializeURLRequest(net::URLRequest* request, | 318 void InitializeURLRequest(net::URLRequest* request, |
| 318 const Referrer& referrer, | 319 const Referrer& referrer, |
| 319 bool is_download, | 320 bool is_download, |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 std::unique_ptr<LoadInfoList> GetLoadInfoForAllRoutes(); | 513 std::unique_ptr<LoadInfoList> GetLoadInfoForAllRoutes(); |
| 513 | 514 |
| 514 // Checks all pending requests and updates the load info if necessary. | 515 // Checks all pending requests and updates the load info if necessary. |
| 515 void UpdateLoadInfo(); | 516 void UpdateLoadInfo(); |
| 516 | 517 |
| 517 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. | 518 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. |
| 518 void ProcessBlockedRequestsForRoute( | 519 void ProcessBlockedRequestsForRoute( |
| 519 const GlobalFrameRoutingId& global_routing_id, | 520 const GlobalFrameRoutingId& global_routing_id, |
| 520 bool cancel_requests); | 521 bool cancel_requests); |
| 521 | 522 |
| 522 void OnRequestResource(int routing_id, | 523 void OnRequestResource(ResourceMessageFilter* filter, |
| 524 int routing_id, |
| 523 int request_id, | 525 int request_id, |
| 524 const ResourceRequest& request_data); | 526 const ResourceRequest& request_data); |
| 525 | 527 |
| 526 void OnRequestResourceInternal( | 528 void OnRequestResourceInternal( |
| 529 std::unique_ptr<ResourceRequesterInfo> requester_info, |
| 527 int routing_id, | 530 int routing_id, |
| 528 int request_id, | 531 int request_id, |
| 529 const ResourceRequest& request_data, | 532 const ResourceRequest& request_data, |
| 530 mojom::URLLoaderAssociatedRequest mojo_request, | 533 mojom::URLLoaderAssociatedRequest mojo_request, |
| 531 mojom::URLLoaderClientAssociatedPtr url_loader_client); | 534 mojom::URLLoaderClientAssociatedPtr url_loader_client); |
| 532 | 535 |
| 533 void OnSyncLoad(int request_id, | 536 void OnSyncLoad(ResourceMessageFilter* filter, |
| 537 int request_id, |
| 534 const ResourceRequest& request_data, | 538 const ResourceRequest& request_data, |
| 535 IPC::Message* sync_result); | 539 IPC::Message* sync_result); |
| 536 | 540 |
| 537 bool IsRequestIDInUse(const GlobalRequestID& id) const; | 541 bool IsRequestIDInUse(const GlobalRequestID& id) const; |
| 538 | 542 |
| 539 // Update the ResourceRequestInfo and internal maps when a request is | 543 // Update the ResourceRequestInfo and internal maps when a request is |
| 540 // transferred from one process to another. | 544 // transferred from one process to another. |
| 541 void UpdateRequestForTransfer(int child_id, | 545 void UpdateRequestForTransfer( |
| 542 int route_id, | 546 std::unique_ptr<ResourceRequesterInfo> requester_info, |
| 543 int request_id, | 547 int route_id, |
| 544 const ResourceRequest& request_data, | 548 int request_id, |
| 545 LoaderMap::iterator iter); | 549 const ResourceRequest& request_data, |
| 550 LoaderMap::iterator iter); |
| 546 | 551 |
| 547 // If |request_data| is for a request being transferred from another process, | 552 // If |request_data| is for a request being transferred from another process, |
| 548 // then CompleteTransfer method can be used to complete the transfer. | 553 // then CompleteTransfer method can be used to complete the transfer. |
| 549 void CompleteTransfer(int request_id, | 554 void CompleteTransfer(std::unique_ptr<ResourceRequesterInfo> requester_info, |
| 555 int request_id, |
| 550 const ResourceRequest& request_data, | 556 const ResourceRequest& request_data, |
| 551 int route_id); | 557 int route_id); |
| 552 | 558 |
| 553 void BeginRequest( | 559 void BeginRequest( |
| 560 std::unique_ptr<ResourceRequesterInfo> requester_info, |
| 554 int request_id, | 561 int request_id, |
| 555 const ResourceRequest& request_data, | 562 const ResourceRequest& request_data, |
| 556 const SyncLoadResultCallback& sync_result_handler, // only valid for sync | 563 const SyncLoadResultCallback& sync_result_handler, // only valid for sync |
| 557 int route_id, | 564 int route_id, |
| 558 mojom::URLLoaderAssociatedRequest mojo_request, | 565 mojom::URLLoaderAssociatedRequest mojo_request, |
| 559 mojom::URLLoaderClientAssociatedPtr url_loader_client); | 566 mojom::URLLoaderClientAssociatedPtr url_loader_client); |
| 560 | 567 |
| 561 // There are requests which need decisions to be made like the following: | 568 // There are requests which need decisions to be made like the following: |
| 562 // Whether the presence of certain HTTP headers like the Origin header are | 569 // Whether the presence of certain HTTP headers like the Origin header are |
| 563 // valid, etc. These requests may need to be aborted based on these | 570 // valid, etc. These requests may need to be aborted based on these |
| 564 // decisions which could be time consuming. We allow for these decisions | 571 // decisions which could be time consuming. We allow for these decisions |
| 565 // to be made asynchronously. The request proceeds when we hear back from | 572 // to be made asynchronously. The request proceeds when we hear back from |
| 566 // the interceptors about whether to continue or not. | 573 // the interceptors about whether to continue or not. |
| 567 // The |continue_request| parameter in the function indicates whether the | 574 // The |continue_request| parameter in the function indicates whether the |
| 568 // request should be continued or aborted. The |error_code| parameter is set | 575 // request should be continued or aborted. The |error_code| parameter is set |
| 569 // if |continue_request| is false. | 576 // if |continue_request| is false. |
| 570 void ContinuePendingBeginRequest( | 577 void ContinuePendingBeginRequest( |
| 578 std::unique_ptr<ResourceRequesterInfo> requester_info, |
| 571 int request_id, | 579 int request_id, |
| 572 const ResourceRequest& request_data, | 580 const ResourceRequest& request_data, |
| 573 const SyncLoadResultCallback& sync_result_handler, // only valid for sync | 581 const SyncLoadResultCallback& sync_result_handler, // only valid for sync |
| 574 int route_id, | 582 int route_id, |
| 575 const net::HttpRequestHeaders& headers, | 583 const net::HttpRequestHeaders& headers, |
| 576 mojom::URLLoaderAssociatedRequest mojo_request, | 584 mojom::URLLoaderAssociatedRequest mojo_request, |
| 577 mojom::URLLoaderClientAssociatedPtr url_loader_client, | 585 mojom::URLLoaderClientAssociatedPtr url_loader_client, |
| 578 bool continue_request, | 586 bool continue_request, |
| 579 int error_code); | 587 int error_code); |
| 580 | 588 |
| 581 // Creates a ResourceHandler to be used by BeginRequest() for normal resource | 589 // Creates a ResourceHandler to be used by BeginRequest() for normal resource |
| 582 // loading. | 590 // loading. |
| 583 std::unique_ptr<ResourceHandler> CreateResourceHandler( | 591 std::unique_ptr<ResourceHandler> CreateResourceHandler( |
| 592 const ResourceRequesterInfo* requester_info, |
| 584 net::URLRequest* request, | 593 net::URLRequest* request, |
| 585 const ResourceRequest& request_data, | 594 const ResourceRequest& request_data, |
| 586 const SyncLoadResultCallback& sync_result_handler, | 595 const SyncLoadResultCallback& sync_result_handler, |
| 587 int route_id, | 596 int route_id, |
| 588 int process_type, | |
| 589 int child_id, | 597 int child_id, |
| 590 ResourceContext* resource_context, | 598 ResourceContext* resource_context, |
| 591 mojom::URLLoaderAssociatedRequest mojo_request, | 599 mojom::URLLoaderAssociatedRequest mojo_request, |
| 592 mojom::URLLoaderClientAssociatedPtr url_loader_client); | 600 mojom::URLLoaderClientAssociatedPtr url_loader_client); |
| 593 | 601 |
| 594 // Wraps |handler| in the standard resource handlers for normal resource | 602 // Wraps |handler| in the standard resource handlers for normal resource |
| 595 // loading and navigation requests. This adds MimeTypeResourceHandler and | 603 // loading and navigation requests. This adds MimeTypeResourceHandler and |
| 596 // ResourceThrottles. | 604 // ResourceThrottles. |
| 597 std::unique_ptr<ResourceHandler> AddStandardHandlers( | 605 std::unique_ptr<ResourceHandler> AddStandardHandlers( |
| 598 net::URLRequest* request, | 606 net::URLRequest* request, |
| 599 ResourceType resource_type, | 607 ResourceType resource_type, |
| 600 ResourceContext* resource_context, | 608 ResourceContext* resource_context, |
| 601 RequestContextType fetch_request_context_type, | 609 RequestContextType fetch_request_context_type, |
| 602 AppCacheService* appcache_service, | 610 AppCacheService* appcache_service, |
| 603 int child_id, | 611 int child_id, |
| 604 int route_id, | 612 int route_id, |
| 605 std::unique_ptr<ResourceHandler> handler); | 613 std::unique_ptr<ResourceHandler> handler); |
| 606 | 614 |
| 607 void OnCancelRequest(int request_id); | 615 void OnCancelRequest(ResourceMessageFilter* filter, int request_id); |
| 608 void OnReleaseDownloadedFile(int request_id); | 616 void OnReleaseDownloadedFile(ResourceMessageFilter* filter, int request_id); |
| 609 void OnDidChangePriority(int request_id, | 617 void OnDidChangePriority(ResourceMessageFilter* filter, |
| 618 int request_id, |
| 610 net::RequestPriority new_priority, | 619 net::RequestPriority new_priority, |
| 611 int intra_priority_value); | 620 int intra_priority_value); |
| 612 | 621 |
| 613 // Creates ResourceRequestInfoImpl for a download or page save. | 622 // Creates ResourceRequestInfoImpl for a download or page save. |
| 614 // |download| should be true if the request is a file download. | 623 // |download| should be true if the request is a file download. |
| 615 ResourceRequestInfoImpl* CreateRequestInfo( | 624 ResourceRequestInfoImpl* CreateRequestInfo( |
| 616 int child_id, | 625 int child_id, |
| 617 int render_view_route_id, | 626 int render_view_route_id, |
| 618 int render_frame_route_id, | 627 int render_frame_route_id, |
| 619 bool download, | 628 bool download, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 642 ResourceLoader* GetLoader(int child_id, int request_id) const; | 651 ResourceLoader* GetLoader(int child_id, int request_id) const; |
| 643 | 652 |
| 644 // Registers |delegate| to receive resource IPC messages targeted to the | 653 // Registers |delegate| to receive resource IPC messages targeted to the |
| 645 // specified |id|. | 654 // specified |id|. |
| 646 void RegisterResourceMessageDelegate(const GlobalRequestID& id, | 655 void RegisterResourceMessageDelegate(const GlobalRequestID& id, |
| 647 ResourceMessageDelegate* delegate); | 656 ResourceMessageDelegate* delegate); |
| 648 void UnregisterResourceMessageDelegate(const GlobalRequestID& id, | 657 void UnregisterResourceMessageDelegate(const GlobalRequestID& id, |
| 649 ResourceMessageDelegate* delegate); | 658 ResourceMessageDelegate* delegate); |
| 650 | 659 |
| 651 int BuildLoadFlagsForRequest(const ResourceRequest& request_data, | 660 int BuildLoadFlagsForRequest(const ResourceRequest& request_data, |
| 652 int child_id, | |
| 653 bool is_sync_load); | 661 bool is_sync_load); |
| 654 | 662 |
| 655 // Consults the RendererSecurity policy to determine whether the | 663 // Consults the RendererSecurity policy to determine whether the |
| 656 // ResourceDispatcherHostImpl should service this request. A request might | 664 // ResourceDispatcherHostImpl should service this request. A request might |
| 657 // be disallowed if the renderer is not authorized to retrieve the request | 665 // be disallowed if the renderer is not authorized to retrieve the request |
| 658 // URL or if the renderer is attempting to upload an unauthorized file. | 666 // URL or if the renderer is attempting to upload an unauthorized file. |
| 659 bool ShouldServiceRequest(int process_type, | 667 bool ShouldServiceRequest(int child_id, |
| 660 int child_id, | |
| 661 const ResourceRequest& request_data, | 668 const ResourceRequest& request_data, |
| 662 const net::HttpRequestHeaders& headers, | 669 const net::HttpRequestHeaders& headers, |
| 663 ResourceMessageFilter* filter, | 670 ResourceRequesterInfo* requester_info, |
| 664 ResourceContext* resource_context); | 671 ResourceContext* resource_context); |
| 665 | 672 |
| 666 // Notifies the ResourceDispatcherHostDelegate about a download having | 673 // Notifies the ResourceDispatcherHostDelegate about a download having |
| 667 // started. The function returns the |handler| passed in, if the download | 674 // started. The function returns the |handler| passed in, if the download |
| 668 // is not throttled. If the download is to be throttled (Decided by the | 675 // is not throttled. If the download is to be throttled (Decided by the |
| 669 // delegate) the function returns a ThrottlingResourceHandler to handle the | 676 // delegate) the function returns a ThrottlingResourceHandler to handle the |
| 670 // download. | 677 // download. |
| 671 std::unique_ptr<ResourceHandler> HandleDownloadStarted( | 678 std::unique_ptr<ResourceHandler> HandleDownloadStarted( |
| 672 net::URLRequest* request, | 679 net::URLRequest* request, |
| 673 std::unique_ptr<ResourceHandler> handler, | 680 std::unique_ptr<ResourceHandler> handler, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 // The total number of outstanding requests is roughly: | 742 // The total number of outstanding requests is roughly: |
| 736 // (max_outstanding_requests_cost_per_process_ / | 743 // (max_outstanding_requests_cost_per_process_ / |
| 737 // kAvgBytesPerOutstandingRequest) | 744 // kAvgBytesPerOutstandingRequest) |
| 738 int max_outstanding_requests_cost_per_process_; | 745 int max_outstanding_requests_cost_per_process_; |
| 739 | 746 |
| 740 // Time of the last user gesture. Stored so that we can add a load | 747 // Time of the last user gesture. Stored so that we can add a load |
| 741 // flag to requests occurring soon after a gesture to indicate they | 748 // flag to requests occurring soon after a gesture to indicate they |
| 742 // may be because of explicit user action. | 749 // may be because of explicit user action. |
| 743 base::TimeTicks last_user_gesture_time_; | 750 base::TimeTicks last_user_gesture_time_; |
| 744 | 751 |
| 745 // Used during IPC message dispatching so that the handlers can get a pointer | |
| 746 // to the source of the message. | |
| 747 ResourceMessageFilter* filter_; | |
| 748 | |
| 749 ResourceDispatcherHostDelegate* delegate_; | 752 ResourceDispatcherHostDelegate* delegate_; |
| 750 | 753 |
| 751 LoaderDelegate* loader_delegate_; | 754 LoaderDelegate* loader_delegate_; |
| 752 | 755 |
| 753 bool allow_cross_origin_auth_prompt_; | 756 bool allow_cross_origin_auth_prompt_; |
| 754 | 757 |
| 755 // AsyncRevalidationManager is non-NULL if and only if | 758 // AsyncRevalidationManager is non-NULL if and only if |
| 756 // stale-while-revalidate is enabled. | 759 // stale-while-revalidate is enabled. |
| 757 std::unique_ptr<AsyncRevalidationManager> async_revalidation_manager_; | 760 std::unique_ptr<AsyncRevalidationManager> async_revalidation_manager_; |
| 758 | 761 |
| 759 typedef std::map<GlobalRequestID, | 762 typedef std::map<GlobalRequestID, |
| 760 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; | 763 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; |
| 761 DelegateMap delegate_map_; | 764 DelegateMap delegate_map_; |
| 762 | 765 |
| 763 std::unique_ptr<ResourceScheduler> scheduler_; | 766 std::unique_ptr<ResourceScheduler> scheduler_; |
| 764 | 767 |
| 765 // Used to invoke an interceptor for the HTTP header. | 768 // Used to invoke an interceptor for the HTTP header. |
| 766 HeaderInterceptorMap http_header_interceptor_map_; | 769 HeaderInterceptorMap http_header_interceptor_map_; |
| 767 | 770 |
| 768 // Points to the registered download handler intercept. | 771 // Points to the registered download handler intercept. |
| 769 CreateDownloadHandlerIntercept create_download_handler_intercept_; | 772 CreateDownloadHandlerIntercept create_download_handler_intercept_; |
| 770 | 773 |
| 771 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 774 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
| 772 }; | 775 }; |
| 773 | 776 |
| 774 } // namespace content | 777 } // namespace content |
| 775 | 778 |
| 776 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 779 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
| OLD | NEW |