| 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/browser/web_contents_observer.h" | 37 #include "content/public/browser/web_contents_observer.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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 // using its shared memory buffer. Frees up that file descriptor to be used | 294 // using its shared memory buffer. Frees up that file descriptor to be used |
| 293 // elsewhere. | 295 // elsewhere. |
| 294 void FinishedWithResourcesForRequest(net::URLRequest* request); | 296 void FinishedWithResourcesForRequest(net::URLRequest* request); |
| 295 | 297 |
| 296 // PlzNavigate: Begins a request for NavigationURLLoader. |loader| is the | 298 // PlzNavigate: Begins a request for NavigationURLLoader. |loader| is the |
| 297 // loader to attach to the leaf resource handler. | 299 // loader to attach to the leaf resource handler. |
| 298 void BeginNavigationRequest(ResourceContext* resource_context, | 300 void BeginNavigationRequest(ResourceContext* resource_context, |
| 299 const NavigationRequestInfo& info, | 301 const NavigationRequestInfo& info, |
| 300 NavigationURLLoaderImplCore* loader); | 302 NavigationURLLoaderImplCore* loader); |
| 301 | 303 |
| 304 int num_in_flight_requests_for_testing() const { |
| 305 return num_in_flight_requests_; |
| 306 } |
| 307 |
| 302 // Turns on stale-while-revalidate support, regardless of command-line flags | 308 // Turns on stale-while-revalidate support, regardless of command-line flags |
| 303 // or experiment status. For unit tests only. | 309 // or experiment status. For unit tests only. |
| 304 void EnableStaleWhileRevalidateForTesting(); | 310 void EnableStaleWhileRevalidateForTesting(); |
| 305 | 311 |
| 306 // Sets the LoaderDelegate, which must outlive this object. Ownership is not | 312 // Sets the LoaderDelegate, which must outlive this object. Ownership is not |
| 307 // transferred. The LoaderDelegate should be interacted with on the IO thread. | 313 // transferred. The LoaderDelegate should be interacted with on the IO thread. |
| 308 void SetLoaderDelegate(LoaderDelegate* loader_delegate); | 314 void SetLoaderDelegate(LoaderDelegate* loader_delegate); |
| 309 | 315 |
| 316 // This function is used when loading with mojo. |
| 317 // Called when loading a request with mojo. |
| 318 void OnRequestResourceWithMojo( |
| 319 int routing_id, |
| 320 int request_id, |
| 321 const ResourceRequest& request, |
| 322 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 323 mojom::URLLoaderClientPtr url_loader_client, |
| 324 ResourceMessageFilter* filter); |
| 325 |
| 310 private: | 326 private: |
| 311 friend class LoaderIOThreadNotifier; | 327 friend class LoaderIOThreadNotifier; |
| 312 friend class ResourceDispatcherHostTest; | 328 friend class ResourceDispatcherHostTest; |
| 313 | 329 |
| 314 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 330 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 315 TestBlockedRequestsProcessDies); | 331 TestBlockedRequestsProcessDies); |
| 316 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 332 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 317 CalculateApproximateMemoryCost); | 333 CalculateApproximateMemoryCost); |
| 318 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 334 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 319 DetachableResourceTimesOut); | 335 DetachableResourceTimesOut); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 void UpdateLoadInfo(); | 462 void UpdateLoadInfo(); |
| 447 | 463 |
| 448 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. | 464 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. |
| 449 void ProcessBlockedRequestsForRoute( | 465 void ProcessBlockedRequestsForRoute( |
| 450 const GlobalFrameRoutingId& global_routing_id, | 466 const GlobalFrameRoutingId& global_routing_id, |
| 451 bool cancel_requests); | 467 bool cancel_requests); |
| 452 | 468 |
| 453 void OnRequestResource(int routing_id, | 469 void OnRequestResource(int routing_id, |
| 454 int request_id, | 470 int request_id, |
| 455 const ResourceRequest& request_data); | 471 const ResourceRequest& request_data); |
| 472 |
| 473 void OnRequestResourceInternal( |
| 474 int routing_id, |
| 475 int request_id, |
| 476 const ResourceRequest& request_data, |
| 477 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 478 mojom::URLLoaderClientPtr url_loader_client); |
| 479 |
| 456 void OnSyncLoad(int request_id, | 480 void OnSyncLoad(int request_id, |
| 457 const ResourceRequest& request_data, | 481 const ResourceRequest& request_data, |
| 458 IPC::Message* sync_result); | 482 IPC::Message* sync_result); |
| 459 | 483 |
| 460 bool IsRequestIDInUse(const GlobalRequestID& id) const; | 484 bool IsRequestIDInUse(const GlobalRequestID& id) const; |
| 461 | 485 |
| 462 // Update the ResourceRequestInfo and internal maps when a request is | 486 // Update the ResourceRequestInfo and internal maps when a request is |
| 463 // transferred from one process to another. | 487 // transferred from one process to another. |
| 464 void UpdateRequestForTransfer(int child_id, | 488 void UpdateRequestForTransfer(int child_id, |
| 465 int route_id, | 489 int route_id, |
| 466 int request_id, | 490 int request_id, |
| 467 const ResourceRequest& request_data, | 491 const ResourceRequest& request_data, |
| 468 LoaderMap::iterator iter); | 492 LoaderMap::iterator iter); |
| 469 | 493 |
| 470 void BeginRequest(int request_id, | 494 void BeginRequest(int request_id, |
| 471 const ResourceRequest& request_data, | 495 const ResourceRequest& request_data, |
| 472 IPC::Message* sync_result, // only valid for sync | 496 IPC::Message* sync_result, // only valid for sync |
| 473 int route_id); // only valid for async | 497 int route_id, // only valid for async |
| 498 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 499 mojom::URLLoaderClientPtr url_loader_client); |
| 474 | 500 |
| 475 // Creates a ResourceHandler to be used by BeginRequest() for normal resource | 501 // Creates a ResourceHandler to be used by BeginRequest() for normal resource |
| 476 // loading. | 502 // loading. |
| 477 std::unique_ptr<ResourceHandler> CreateResourceHandler( | 503 std::unique_ptr<ResourceHandler> CreateResourceHandler( |
| 478 net::URLRequest* request, | 504 net::URLRequest* request, |
| 479 const ResourceRequest& request_data, | 505 const ResourceRequest& request_data, |
| 480 IPC::Message* sync_result, | 506 IPC::Message* sync_result, |
| 481 int route_id, | 507 int route_id, |
| 482 int process_type, | 508 int process_type, |
| 483 int child_id, | 509 int child_id, |
| 484 ResourceContext* resource_context); | 510 ResourceContext* resource_context, |
| 511 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 512 mojom::URLLoaderClientPtr url_loader_client); |
| 485 | 513 |
| 486 // Wraps |handler| in the standard resource handlers for normal resource | 514 // Wraps |handler| in the standard resource handlers for normal resource |
| 487 // loading and navigation requests. This adds MimeTypeResourceHandler and | 515 // loading and navigation requests. This adds MimeTypeResourceHandler and |
| 488 // ResourceThrottles. | 516 // ResourceThrottles. |
| 489 std::unique_ptr<ResourceHandler> AddStandardHandlers( | 517 std::unique_ptr<ResourceHandler> AddStandardHandlers( |
| 490 net::URLRequest* request, | 518 net::URLRequest* request, |
| 491 ResourceType resource_type, | 519 ResourceType resource_type, |
| 492 ResourceContext* resource_context, | 520 ResourceContext* resource_context, |
| 493 AppCacheService* appcache_service, | 521 AppCacheService* appcache_service, |
| 494 int child_id, | 522 int child_id, |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 // Allows tests to use a mock CertStore. If set, the CertStore must | 675 // Allows tests to use a mock CertStore. If set, the CertStore must |
| 648 // outlive this ResourceDispatcherHostImpl. | 676 // outlive this ResourceDispatcherHostImpl. |
| 649 CertStore* cert_store_for_testing_; | 677 CertStore* cert_store_for_testing_; |
| 650 | 678 |
| 651 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 679 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
| 652 }; | 680 }; |
| 653 | 681 |
| 654 } // namespace content | 682 } // namespace content |
| 655 | 683 |
| 656 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 684 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
| OLD | NEW |