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