Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.h

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

Powered by Google App Engine
This is Rietveld 408576698