| 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 13 matching lines...) Expand all Loading... |
| 24 #include "base/observer_list.h" | 24 #include "base/observer_list.h" |
| 25 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 26 #include "base/timer/timer.h" | 26 #include "base/timer/timer.h" |
| 27 #include "content/browser/download/download_resource_handler.h" | 27 #include "content/browser/download/download_resource_handler.h" |
| 28 #include "content/browser/download/save_types.h" | 28 #include "content/browser/download/save_types.h" |
| 29 #include "content/browser/loader/global_routing_id.h" | 29 #include "content/browser/loader/global_routing_id.h" |
| 30 #include "content/browser/loader/resource_loader.h" | 30 #include "content/browser/loader/resource_loader.h" |
| 31 #include "content/browser/loader/resource_loader_delegate.h" | 31 #include "content/browser/loader/resource_loader_delegate.h" |
| 32 #include "content/browser/loader/resource_scheduler.h" | 32 #include "content/browser/loader/resource_scheduler.h" |
| 33 #include "content/common/content_export.h" | 33 #include "content/common/content_export.h" |
| 34 #include "content/common/url_loader.mojom.h" |
| 34 #include "content/public/browser/global_request_id.h" | 35 #include "content/public/browser/global_request_id.h" |
| 35 #include "content/public/browser/resource_dispatcher_host.h" | 36 #include "content/public/browser/resource_dispatcher_host.h" |
| 36 #include "content/public/common/request_context_type.h" | 37 #include "content/public/common/request_context_type.h" |
| 37 #include "content/public/common/resource_type.h" | 38 #include "content/public/common/resource_type.h" |
| 38 #include "ipc/ipc_message.h" | 39 #include "ipc/ipc_message.h" |
| 40 #include "mojo/public/cpp/system/data_pipe.h" |
| 39 #include "net/base/request_priority.h" | 41 #include "net/base/request_priority.h" |
| 40 #include "net/cookies/canonical_cookie.h" | 42 #include "net/cookies/canonical_cookie.h" |
| 41 #include "net/url_request/url_request.h" | 43 #include "net/url_request/url_request.h" |
| 42 | 44 |
| 43 class ResourceHandler; | 45 class ResourceHandler; |
| 44 | 46 |
| 45 namespace base { | 47 namespace base { |
| 46 class FilePath; | 48 class FilePath; |
| 47 } | 49 } |
| 48 | 50 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 67 class ResourceMessageFilter; | 69 class ResourceMessageFilter; |
| 68 class ResourceRequestInfoImpl; | 70 class ResourceRequestInfoImpl; |
| 69 class SaveFileManager; | 71 class SaveFileManager; |
| 70 class ServiceWorkerNavigationHandleCore; | 72 class ServiceWorkerNavigationHandleCore; |
| 71 struct CommonNavigationParams; | 73 struct CommonNavigationParams; |
| 72 struct DownloadSaveInfo; | 74 struct DownloadSaveInfo; |
| 73 struct NavigationRequestInfo; | 75 struct NavigationRequestInfo; |
| 74 struct Referrer; | 76 struct Referrer; |
| 75 struct ResourceRequest; | 77 struct ResourceRequest; |
| 76 | 78 |
| 79 namespace mojom { |
| 80 class URLLoader; |
| 81 } // namespace mojom |
| 82 |
| 77 class CONTENT_EXPORT ResourceDispatcherHostImpl | 83 class CONTENT_EXPORT ResourceDispatcherHostImpl |
| 78 : public ResourceDispatcherHost, | 84 : public ResourceDispatcherHost, |
| 79 public ResourceLoaderDelegate { | 85 public ResourceLoaderDelegate { |
| 80 public: | 86 public: |
| 81 ResourceDispatcherHostImpl(); | 87 ResourceDispatcherHostImpl(); |
| 82 ~ResourceDispatcherHostImpl() override; | 88 ~ResourceDispatcherHostImpl() override; |
| 83 | 89 |
| 84 // Returns the current ResourceDispatcherHostImpl. May return NULL if it | 90 // Returns the current ResourceDispatcherHostImpl. May return NULL if it |
| 85 // hasn't been created yet. | 91 // hasn't been created yet. |
| 86 static ResourceDispatcherHostImpl* Get(); | 92 static ResourceDispatcherHostImpl* Get(); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 // using its shared memory buffer. Frees up that file descriptor to be used | 284 // using its shared memory buffer. Frees up that file descriptor to be used |
| 279 // elsewhere. | 285 // elsewhere. |
| 280 void FinishedWithResourcesForRequest(net::URLRequest* request); | 286 void FinishedWithResourcesForRequest(net::URLRequest* request); |
| 281 | 287 |
| 282 // PlzNavigate: Begins a request for NavigationURLLoader. |loader| is the | 288 // PlzNavigate: Begins a request for NavigationURLLoader. |loader| is the |
| 283 // loader to attach to the leaf resource handler. | 289 // loader to attach to the leaf resource handler. |
| 284 void BeginNavigationRequest(ResourceContext* resource_context, | 290 void BeginNavigationRequest(ResourceContext* resource_context, |
| 285 const NavigationRequestInfo& info, | 291 const NavigationRequestInfo& info, |
| 286 NavigationURLLoaderImplCore* loader); | 292 NavigationURLLoaderImplCore* loader); |
| 287 | 293 |
| 294 int num_in_flight_requests_for_testing() const { |
| 295 return num_in_flight_requests_; |
| 296 } |
| 297 |
| 288 // Turns on stale-while-revalidate support, regardless of command-line flags | 298 // Turns on stale-while-revalidate support, regardless of command-line flags |
| 289 // or experiment status. For unit tests only. | 299 // or experiment status. For unit tests only. |
| 290 void EnableStaleWhileRevalidateForTesting(); | 300 void EnableStaleWhileRevalidateForTesting(); |
| 291 | 301 |
| 292 // Sets the LoaderDelegate, which must outlive this object. Ownership is not | 302 // Sets the LoaderDelegate, which must outlive this object. Ownership is not |
| 293 // transferred. The LoaderDelegate should be interacted with on the IO thread. | 303 // transferred. The LoaderDelegate should be interacted with on the IO thread. |
| 294 void SetLoaderDelegate(LoaderDelegate* loader_delegate); | 304 void SetLoaderDelegate(LoaderDelegate* loader_delegate); |
| 295 | 305 |
| 296 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); | 306 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); |
| 297 | 307 |
| 308 // Called when loading a request with mojo. |
| 309 void OnRequestResourceWithMojo( |
| 310 int routing_id, |
| 311 int request_id, |
| 312 const ResourceRequest& request, |
| 313 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 314 mojom::URLLoaderClientPtr url_loader_client, |
| 315 ResourceMessageFilter* filter); |
| 316 |
| 298 private: | 317 private: |
| 299 friend class ResourceDispatcherHostTest; | 318 friend class ResourceDispatcherHostTest; |
| 300 | 319 |
| 301 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 320 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 302 TestBlockedRequestsProcessDies); | 321 TestBlockedRequestsProcessDies); |
| 303 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 322 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 304 CalculateApproximateMemoryCost); | 323 CalculateApproximateMemoryCost); |
| 305 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 324 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 306 DetachableResourceTimesOut); | 325 DetachableResourceTimesOut); |
| 307 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 326 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 void UpdateLoadInfo(); | 468 void UpdateLoadInfo(); |
| 450 | 469 |
| 451 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. | 470 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. |
| 452 void ProcessBlockedRequestsForRoute( | 471 void ProcessBlockedRequestsForRoute( |
| 453 const GlobalFrameRoutingId& global_routing_id, | 472 const GlobalFrameRoutingId& global_routing_id, |
| 454 bool cancel_requests); | 473 bool cancel_requests); |
| 455 | 474 |
| 456 void OnRequestResource(int routing_id, | 475 void OnRequestResource(int routing_id, |
| 457 int request_id, | 476 int request_id, |
| 458 const ResourceRequest& request_data); | 477 const ResourceRequest& request_data); |
| 478 |
| 479 void OnRequestResourceInternal( |
| 480 int routing_id, |
| 481 int request_id, |
| 482 const ResourceRequest& request_data, |
| 483 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 484 mojom::URLLoaderClientPtr url_loader_client); |
| 485 |
| 459 void OnSyncLoad(int request_id, | 486 void OnSyncLoad(int request_id, |
| 460 const ResourceRequest& request_data, | 487 const ResourceRequest& request_data, |
| 461 IPC::Message* sync_result); | 488 IPC::Message* sync_result); |
| 462 | 489 |
| 463 bool IsRequestIDInUse(const GlobalRequestID& id) const; | 490 bool IsRequestIDInUse(const GlobalRequestID& id) const; |
| 464 | 491 |
| 465 // Update the ResourceRequestInfo and internal maps when a request is | 492 // Update the ResourceRequestInfo and internal maps when a request is |
| 466 // transferred from one process to another. | 493 // transferred from one process to another. |
| 467 void UpdateRequestForTransfer(int child_id, | 494 void UpdateRequestForTransfer(int child_id, |
| 468 int route_id, | 495 int route_id, |
| 469 int request_id, | 496 int request_id, |
| 470 const ResourceRequest& request_data, | 497 const ResourceRequest& request_data, |
| 471 LoaderMap::iterator iter); | 498 LoaderMap::iterator iter); |
| 472 | 499 |
| 473 void BeginRequest(int request_id, | 500 void BeginRequest(int request_id, |
| 474 const ResourceRequest& request_data, | 501 const ResourceRequest& request_data, |
| 475 IPC::Message* sync_result, // only valid for sync | 502 IPC::Message* sync_result, // only valid for sync |
| 476 int route_id); // only valid for async | 503 int route_id, // only valid for async |
| 504 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 505 mojom::URLLoaderClientPtr url_loader_client); |
| 477 | 506 |
| 478 // There are requests which need decisions to be made like the following: | 507 // There are requests which need decisions to be made like the following: |
| 479 // Whether the presence of certain HTTP headers like the Origin header are | 508 // Whether the presence of certain HTTP headers like the Origin header are |
| 480 // valid, etc. These requests may need to be aborted based on these | 509 // valid, etc. These requests may need to be aborted based on these |
| 481 // decisions which could be time consuming. We allow for these decisions | 510 // decisions which could be time consuming. We allow for these decisions |
| 482 // to be made asynchronously. The request proceeds when we hear back from | 511 // to be made asynchronously. The request proceeds when we hear back from |
| 483 // the interceptors about whether to continue or not. | 512 // the interceptors about whether to continue or not. |
| 484 // The |continue_request| parameter in the function indicates whether the | 513 // The |continue_request| parameter in the function indicates whether the |
| 485 // request should be continued or aborted. The |error_code| parameter is set | 514 // request should be continued or aborted. The |error_code| parameter is set |
| 486 // if |continue_request| is false. | 515 // if |continue_request| is false. |
| 487 void ContinuePendingBeginRequest( | 516 void ContinuePendingBeginRequest( |
| 488 int request_id, | 517 int request_id, |
| 489 const ResourceRequest& request_data, | 518 const ResourceRequest& request_data, |
| 490 IPC::Message* sync_result, // only valid for sync | 519 IPC::Message* sync_result, // only valid for sync |
| 491 int route_id, | 520 int route_id, |
| 492 const net::HttpRequestHeaders& headers, | 521 const net::HttpRequestHeaders& headers, |
| 522 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 523 mojom::URLLoaderClientPtr url_loader_client, |
| 493 bool continue_request, | 524 bool continue_request, |
| 494 int error_code); | 525 int error_code); |
| 495 | 526 |
| 496 // Creates a ResourceHandler to be used by BeginRequest() for normal resource | 527 // Creates a ResourceHandler to be used by BeginRequest() for normal resource |
| 497 // loading. | 528 // loading. |
| 498 std::unique_ptr<ResourceHandler> CreateResourceHandler( | 529 std::unique_ptr<ResourceHandler> CreateResourceHandler( |
| 499 net::URLRequest* request, | 530 net::URLRequest* request, |
| 500 const ResourceRequest& request_data, | 531 const ResourceRequest& request_data, |
| 501 IPC::Message* sync_result, | 532 IPC::Message* sync_result, |
| 502 int route_id, | 533 int route_id, |
| 503 int process_type, | 534 int process_type, |
| 504 int child_id, | 535 int child_id, |
| 505 ResourceContext* resource_context); | 536 ResourceContext* resource_context, |
| 537 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 538 mojom::URLLoaderClientPtr url_loader_client); |
| 506 | 539 |
| 507 // Wraps |handler| in the standard resource handlers for normal resource | 540 // Wraps |handler| in the standard resource handlers for normal resource |
| 508 // loading and navigation requests. This adds MimeTypeResourceHandler and | 541 // loading and navigation requests. This adds MimeTypeResourceHandler and |
| 509 // ResourceThrottles. | 542 // ResourceThrottles. |
| 510 std::unique_ptr<ResourceHandler> AddStandardHandlers( | 543 std::unique_ptr<ResourceHandler> AddStandardHandlers( |
| 511 net::URLRequest* request, | 544 net::URLRequest* request, |
| 512 ResourceType resource_type, | 545 ResourceType resource_type, |
| 513 ResourceContext* resource_context, | 546 ResourceContext* resource_context, |
| 514 RequestContextType fetch_request_context_type, | 547 RequestContextType fetch_request_context_type, |
| 515 AppCacheService* appcache_service, | 548 AppCacheService* appcache_service, |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 | 716 |
| 684 // Used to invoke an interceptor for the HTTP header. | 717 // Used to invoke an interceptor for the HTTP header. |
| 685 HeaderInterceptorMap http_header_interceptor_map_; | 718 HeaderInterceptorMap http_header_interceptor_map_; |
| 686 | 719 |
| 687 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 720 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
| 688 }; | 721 }; |
| 689 | 722 |
| 690 } // namespace content | 723 } // namespace content |
| 691 | 724 |
| 692 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 725 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
| OLD | NEW |