| 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 15 matching lines...) Expand all Loading... |
| 26 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 27 #include "base/timer/timer.h" | 27 #include "base/timer/timer.h" |
| 28 #include "content/browser/download/download_resource_handler.h" | 28 #include "content/browser/download/download_resource_handler.h" |
| 29 #include "content/browser/download/save_types.h" | 29 #include "content/browser/download/save_types.h" |
| 30 #include "content/browser/loader/global_routing_id.h" | 30 #include "content/browser/loader/global_routing_id.h" |
| 31 #include "content/browser/loader/resource_loader.h" | 31 #include "content/browser/loader/resource_loader.h" |
| 32 #include "content/browser/loader/resource_loader_delegate.h" | 32 #include "content/browser/loader/resource_loader_delegate.h" |
| 33 #include "content/browser/loader/resource_scheduler.h" | 33 #include "content/browser/loader/resource_scheduler.h" |
| 34 #include "content/common/content_export.h" | 34 #include "content/common/content_export.h" |
| 35 #include "content/common/resource_request_body.h" | 35 #include "content/common/resource_request_body.h" |
| 36 #include "content/common/url_loader.mojom.h" |
| 36 #include "content/public/browser/child_process_data.h" | 37 #include "content/public/browser/child_process_data.h" |
| 37 #include "content/public/browser/download_item.h" | 38 #include "content/public/browser/download_item.h" |
| 38 #include "content/public/browser/download_url_parameters.h" | 39 #include "content/public/browser/download_url_parameters.h" |
| 39 #include "content/public/browser/global_request_id.h" | 40 #include "content/public/browser/global_request_id.h" |
| 40 #include "content/public/browser/notification_types.h" | 41 #include "content/public/browser/notification_types.h" |
| 41 #include "content/public/browser/resource_dispatcher_host.h" | 42 #include "content/public/browser/resource_dispatcher_host.h" |
| 42 #include "content/public/browser/web_contents_observer.h" | 43 #include "content/public/browser/web_contents_observer.h" |
| 43 #include "content/public/common/resource_type.h" | 44 #include "content/public/common/resource_type.h" |
| 44 #include "ipc/ipc_message.h" | 45 #include "ipc/ipc_message.h" |
| 46 #include "mojo/public/cpp/system/data_pipe.h" |
| 45 #include "net/base/request_priority.h" | 47 #include "net/base/request_priority.h" |
| 46 #include "net/cookies/canonical_cookie.h" | 48 #include "net/cookies/canonical_cookie.h" |
| 47 #include "net/url_request/url_request.h" | 49 #include "net/url_request/url_request.h" |
| 48 | 50 |
| 49 class ResourceHandler; | 51 class ResourceHandler; |
| 50 | 52 |
| 51 namespace base { | 53 namespace base { |
| 52 class FilePath; | 54 class FilePath; |
| 53 } | 55 } |
| 54 | 56 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 void BeginNavigationRequest( | 313 void BeginNavigationRequest( |
| 312 ResourceContext* resource_context, | 314 ResourceContext* resource_context, |
| 313 const NavigationRequestInfo& info, | 315 const NavigationRequestInfo& info, |
| 314 NavigationURLLoaderImplCore* loader, | 316 NavigationURLLoaderImplCore* loader, |
| 315 ServiceWorkerNavigationHandleCore* service_worker_handle_core); | 317 ServiceWorkerNavigationHandleCore* service_worker_handle_core); |
| 316 | 318 |
| 317 // Turns on stale-while-revalidate support, regardless of command-line flags | 319 // Turns on stale-while-revalidate support, regardless of command-line flags |
| 318 // or experiment status. For unit tests only. | 320 // or experiment status. For unit tests only. |
| 319 void EnableStaleWhileRevalidateForTesting(); | 321 void EnableStaleWhileRevalidateForTesting(); |
| 320 | 322 |
| 323 // These functions are used when loading with mojo. |
| 324 // Called when loading a request with mojo. |
| 325 void OnRequestResourceWithMojo(int routing_id, |
| 326 int request_id, |
| 327 const ResourceRequest& request, |
| 328 std::unique_ptr<mojom::URLLoader> url_loader, |
| 329 mojom::URLLoaderClientPtr url_loader_client, |
| 330 ResourceMessageFilter* filter); |
| 331 |
| 332 // Add an uninitiated (i.e., resource loading is not yet started) loader in |
| 333 // order to keep it alive. |
| 334 void AddUninitiatedURLLoader(int child_id, |
| 335 std::unique_ptr<mojom::URLLoader> loader); |
| 336 // Returns an uninitiated URL loader whose raw pointer equals to |loader|. |
| 337 std::unique_ptr<mojom::URLLoader> TakeUninitiatedURLLoader( |
| 338 mojom::URLLoader* loader); |
| 339 |
| 321 private: | 340 private: |
| 322 friend class LoaderIOThreadNotifier; | 341 friend class LoaderIOThreadNotifier; |
| 323 friend class ResourceDispatcherHostTest; | 342 friend class ResourceDispatcherHostTest; |
| 343 class MojoHelper; |
| 324 | 344 |
| 325 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 345 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 326 TestBlockedRequestsProcessDies); | 346 TestBlockedRequestsProcessDies); |
| 327 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 347 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 328 CalculateApproximateMemoryCost); | 348 CalculateApproximateMemoryCost); |
| 329 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 349 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 330 DetachableResourceTimesOut); | 350 DetachableResourceTimesOut); |
| 331 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 351 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 332 TestProcessCancelDetachableTimesOut); | 352 TestProcessCancelDetachableTimesOut); |
| 333 FRIEND_TEST_ALL_PREFIXES(SitePerProcessIgnoreCertErrorsBrowserTest, | 353 FRIEND_TEST_ALL_PREFIXES(SitePerProcessIgnoreCertErrorsBrowserTest, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 void UpdateLoadInfo(); | 479 void UpdateLoadInfo(); |
| 460 | 480 |
| 461 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. | 481 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. |
| 462 void ProcessBlockedRequestsForRoute( | 482 void ProcessBlockedRequestsForRoute( |
| 463 const GlobalFrameRoutingId& global_routing_id, | 483 const GlobalFrameRoutingId& global_routing_id, |
| 464 bool cancel_requests); | 484 bool cancel_requests); |
| 465 | 485 |
| 466 void OnRequestResource(int routing_id, | 486 void OnRequestResource(int routing_id, |
| 467 int request_id, | 487 int request_id, |
| 468 const ResourceRequest& request_data); | 488 const ResourceRequest& request_data); |
| 489 |
| 490 void OnRequestResourceInternal(int routing_id, |
| 491 int request_id, |
| 492 const ResourceRequest& request_data, |
| 493 std::unique_ptr<mojom::URLLoader> url_loader, |
| 494 mojom::URLLoaderClientPtr url_loader_client); |
| 495 |
| 469 void OnSyncLoad(int request_id, | 496 void OnSyncLoad(int request_id, |
| 470 const ResourceRequest& request_data, | 497 const ResourceRequest& request_data, |
| 471 IPC::Message* sync_result); | 498 IPC::Message* sync_result); |
| 472 | 499 |
| 473 bool IsRequestIDInUse(const GlobalRequestID& id) const; | 500 bool IsRequestIDInUse(const GlobalRequestID& id) const; |
| 474 | 501 |
| 475 // Update the ResourceRequestInfo and internal maps when a request is | 502 // Update the ResourceRequestInfo and internal maps when a request is |
| 476 // transferred from one process to another. | 503 // transferred from one process to another. |
| 477 void UpdateRequestForTransfer(int child_id, | 504 void UpdateRequestForTransfer(int child_id, |
| 478 int route_id, | 505 int route_id, |
| 479 int request_id, | 506 int request_id, |
| 480 const ResourceRequest& request_data, | 507 const ResourceRequest& request_data, |
| 481 LoaderMap::iterator iter); | 508 LoaderMap::iterator iter); |
| 482 | 509 |
| 483 void BeginRequest(int request_id, | 510 void BeginRequest(int request_id, |
| 484 const ResourceRequest& request_data, | 511 const ResourceRequest& request_data, |
| 485 IPC::Message* sync_result, // only valid for sync | 512 IPC::Message* sync_result, // only valid for sync |
| 486 int route_id); // only valid for async | 513 int route_id, // only valid for async |
| 514 std::unique_ptr<mojom::URLLoader> url_loader, |
| 515 mojom::URLLoaderClientPtr url_loader_client); |
| 487 | 516 |
| 488 // Creates a ResourceHandler to be used by BeginRequest() for normal resource | 517 // Creates a ResourceHandler to be used by BeginRequest() for normal resource |
| 489 // loading. | 518 // loading. |
| 490 std::unique_ptr<ResourceHandler> CreateResourceHandler( | 519 std::unique_ptr<ResourceHandler> CreateResourceHandler( |
| 491 net::URLRequest* request, | 520 net::URLRequest* request, |
| 492 const ResourceRequest& request_data, | 521 const ResourceRequest& request_data, |
| 493 IPC::Message* sync_result, | 522 IPC::Message* sync_result, |
| 494 int route_id, | 523 int route_id, |
| 495 int process_type, | 524 int process_type, |
| 496 int child_id, | 525 int child_id, |
| 497 ResourceContext* resource_context); | 526 ResourceContext* resource_context, |
| 527 std::unique_ptr<mojom::URLLoader> url_loader, |
| 528 mojom::URLLoaderClientPtr url_loader_client); |
| 498 | 529 |
| 499 // Wraps |handler| in the standard resource handlers for normal resource | 530 // Wraps |handler| in the standard resource handlers for normal resource |
| 500 // loading and navigation requests. This adds MimeTypeResourceHandler and | 531 // loading and navigation requests. This adds MimeTypeResourceHandler and |
| 501 // ResourceThrottles. | 532 // ResourceThrottles. |
| 502 std::unique_ptr<ResourceHandler> AddStandardHandlers( | 533 std::unique_ptr<ResourceHandler> AddStandardHandlers( |
| 503 net::URLRequest* request, | 534 net::URLRequest* request, |
| 504 ResourceType resource_type, | 535 ResourceType resource_type, |
| 505 ResourceContext* resource_context, | 536 ResourceContext* resource_context, |
| 506 AppCacheService* appcache_service, | 537 AppCacheService* appcache_service, |
| 507 int child_id, | 538 int child_id, |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 typedef std::map<GlobalRequestID, | 687 typedef std::map<GlobalRequestID, |
| 657 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; | 688 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; |
| 658 DelegateMap delegate_map_; | 689 DelegateMap delegate_map_; |
| 659 | 690 |
| 660 std::unique_ptr<ResourceScheduler> scheduler_; | 691 std::unique_ptr<ResourceScheduler> scheduler_; |
| 661 | 692 |
| 662 // Allows tests to use a mock CertStore. If set, the CertStore must | 693 // Allows tests to use a mock CertStore. If set, the CertStore must |
| 663 // outlive this ResourceDispatcherHostImpl. | 694 // outlive this ResourceDispatcherHostImpl. |
| 664 CertStore* cert_store_for_testing_; | 695 CertStore* cert_store_for_testing_; |
| 665 | 696 |
| 697 std::unique_ptr<MojoHelper> mojo_helper_; |
| 698 |
| 666 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 699 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
| 667 }; | 700 }; |
| 668 | 701 |
| 669 } // namespace content | 702 } // namespace content |
| 670 | 703 |
| 671 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 704 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
| OLD | NEW |