| 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" |
| 45 #include "net/base/request_priority.h" | 46 #include "net/base/request_priority.h" |
| 46 #include "net/cookies/canonical_cookie.h" | 47 #include "net/cookies/canonical_cookie.h" |
| 47 #include "net/url_request/url_request.h" | 48 #include "net/url_request/url_request.h" |
| 48 | 49 |
| 49 class ResourceHandler; | 50 class ResourceHandler; |
| 50 struct ResourceHostMsg_Request; | 51 struct ResourceHostMsg_Request; |
| 52 struct ResourceMsg_RequestCompleteData; |
| 51 | 53 |
| 52 namespace base { | 54 namespace base { |
| 53 class FilePath; | 55 class FilePath; |
| 54 } | 56 } |
| 55 | 57 |
| 56 namespace net { | 58 namespace net { |
| 57 class URLRequestJobFactory; | 59 class URLRequestJobFactory; |
| 58 } | 60 } |
| 59 | 61 |
| 60 namespace storage { | 62 namespace storage { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 73 class ResourceMessageDelegate; | 75 class ResourceMessageDelegate; |
| 74 class ResourceMessageFilter; | 76 class ResourceMessageFilter; |
| 75 class ResourceRequestInfoImpl; | 77 class ResourceRequestInfoImpl; |
| 76 class SaveFileManager; | 78 class SaveFileManager; |
| 77 class ServiceWorkerNavigationHandleCore; | 79 class ServiceWorkerNavigationHandleCore; |
| 78 class WebContentsImpl; | 80 class WebContentsImpl; |
| 79 struct CommonNavigationParams; | 81 struct CommonNavigationParams; |
| 80 struct DownloadSaveInfo; | 82 struct DownloadSaveInfo; |
| 81 struct NavigationRequestInfo; | 83 struct NavigationRequestInfo; |
| 82 struct Referrer; | 84 struct Referrer; |
| 85 struct ResourceResponseHead; |
| 83 | 86 |
| 84 // This class is responsible for notifying the IO thread (specifically, the | 87 // This class is responsible for notifying the IO thread (specifically, the |
| 85 // ResourceDispatcherHostImpl) of frame events. It has an interace for callers | 88 // ResourceDispatcherHostImpl) of frame events. It has an interace for callers |
| 86 // to use and also sends notifications on WebContentsObserver events. All | 89 // to use and also sends notifications on WebContentsObserver events. All |
| 87 // methods (static or class) will be called from the UI thread and post to the | 90 // methods (static or class) will be called from the UI thread and post to the |
| 88 // IO thread. | 91 // IO thread. |
| 89 // TODO(csharrison): Add methods tracking visibility and audio changes, to | 92 // TODO(csharrison): Add methods tracking visibility and audio changes, to |
| 90 // propogate to the ResourceScheduler. | 93 // propogate to the ResourceScheduler. |
| 91 class LoaderIOThreadNotifier : public WebContentsObserver { | 94 class LoaderIOThreadNotifier : public WebContentsObserver { |
| 92 public: | 95 public: |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 void BeginNavigationRequest( | 314 void BeginNavigationRequest( |
| 312 ResourceContext* resource_context, | 315 ResourceContext* resource_context, |
| 313 const NavigationRequestInfo& info, | 316 const NavigationRequestInfo& info, |
| 314 NavigationURLLoaderImplCore* loader, | 317 NavigationURLLoaderImplCore* loader, |
| 315 ServiceWorkerNavigationHandleCore* service_worker_handle_core); | 318 ServiceWorkerNavigationHandleCore* service_worker_handle_core); |
| 316 | 319 |
| 317 // Turns on stale-while-revalidate support, regardless of command-line flags | 320 // Turns on stale-while-revalidate support, regardless of command-line flags |
| 318 // or experiment status. For unit tests only. | 321 // or experiment status. For unit tests only. |
| 319 void EnableStaleWhileRevalidateForTesting(); | 322 void EnableStaleWhileRevalidateForTesting(); |
| 320 | 323 |
| 324 // For mojo: |
| 325 void SetMojoLoaderAndClientrForNextLoadRequest( |
| 326 std::unique_ptr<mojom::URLLoader> loader, |
| 327 mojom::URLLoaderClientPtr client); |
| 328 void OnRequestResourceFromMojo(int routing_id, |
| 329 int request_id, |
| 330 mojom::URLLoaderClientPtr client, |
| 331 const ResourceHostMsg_Request& request_data, |
| 332 ResourceMessageFilter* filter); |
| 333 bool SendWithMojoIfPossible(const IPC::Message& message, |
| 334 ResourceMessageFilter* filter); |
| 335 void AddUninitiatedURLLoader(int child_id, |
| 336 std::unique_ptr<mojom::URLLoader> 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; |
| 324 | 343 |
| 325 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 344 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 326 TestBlockedRequestsProcessDies); | 345 TestBlockedRequestsProcessDies); |
| 327 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 346 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 328 CalculateApproximateMemoryCost); | 347 CalculateApproximateMemoryCost); |
| 329 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 348 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 330 DetachableResourceTimesOut); | 349 DetachableResourceTimesOut); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 | 383 |
| 365 // An init helper that runs on the IO thread. | 384 // An init helper that runs on the IO thread. |
| 366 void OnInit(); | 385 void OnInit(); |
| 367 | 386 |
| 368 // A shutdown helper that runs on the IO thread. | 387 // A shutdown helper that runs on the IO thread. |
| 369 void OnShutdown(); | 388 void OnShutdown(); |
| 370 | 389 |
| 371 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); | 390 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); |
| 372 | 391 |
| 373 // Helper function for regular and download requests. | 392 // Helper function for regular and download requests. |
| 374 void BeginRequestInternal(std::unique_ptr<net::URLRequest> request, | 393 void BeginRequestInternal( |
| 375 std::unique_ptr<ResourceHandler> handler); | 394 std::unique_ptr<net::URLRequest> request, |
| 395 std::unique_ptr<ResourceHandler> handler, |
| 396 std::unique_ptr<mojom::URLLoader> url_loader = nullptr, |
| 397 mojom::URLLoaderClientPtr client = nullptr); |
| 376 | 398 |
| 377 void StartLoading(ResourceRequestInfoImpl* info, | 399 void StartLoading(ResourceRequestInfoImpl* info, |
| 378 std::unique_ptr<ResourceLoader> loader); | 400 std::unique_ptr<ResourceLoader> loader); |
| 379 | 401 |
| 380 // We keep track of how much memory each request needs and how many requests | 402 // We keep track of how much memory each request needs and how many requests |
| 381 // are issued by each renderer. These are known as OustandingRequestStats. | 403 // are issued by each renderer. These are known as OustandingRequestStats. |
| 382 // Memory limits apply to all requests sent to us by the renderers. There is a | 404 // Memory limits apply to all requests sent to us by the renderers. There is a |
| 383 // limit for each renderer. File descriptor limits apply to requests that are | 405 // limit for each renderer. File descriptor limits apply to requests that are |
| 384 // receiving their body. These are known as in-flight requests. There is a | 406 // receiving their body. These are known as in-flight requests. There is a |
| 385 // global limit that applies for the browser process. Each render is allowed | 407 // global limit that applies for the browser process. Each render is allowed |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 // transferred from one process to another. | 498 // transferred from one process to another. |
| 477 void UpdateRequestForTransfer(int child_id, | 499 void UpdateRequestForTransfer(int child_id, |
| 478 int route_id, | 500 int route_id, |
| 479 int request_id, | 501 int request_id, |
| 480 const ResourceHostMsg_Request& request_data, | 502 const ResourceHostMsg_Request& request_data, |
| 481 LoaderMap::iterator iter); | 503 LoaderMap::iterator iter); |
| 482 | 504 |
| 483 void BeginRequest(int request_id, | 505 void BeginRequest(int request_id, |
| 484 const ResourceHostMsg_Request& request_data, | 506 const ResourceHostMsg_Request& request_data, |
| 485 IPC::Message* sync_result, // only valid for sync | 507 IPC::Message* sync_result, // only valid for sync |
| 486 int route_id); // only valid for async | 508 int route_id, // only valid for async |
| 509 std::unique_ptr<mojom::URLLoader> url_loader = nullptr, |
| 510 mojom::URLLoaderClientPtr client = nullptr); |
| 487 | 511 |
| 488 // Creates a ResourceHandler to be used by BeginRequest() for normal resource | 512 // Creates a ResourceHandler to be used by BeginRequest() for normal resource |
| 489 // loading. | 513 // loading. |
| 490 std::unique_ptr<ResourceHandler> CreateResourceHandler( | 514 std::unique_ptr<ResourceHandler> CreateResourceHandler( |
| 491 net::URLRequest* request, | 515 net::URLRequest* request, |
| 492 const ResourceHostMsg_Request& request_data, | 516 const ResourceHostMsg_Request& request_data, |
| 493 IPC::Message* sync_result, | 517 IPC::Message* sync_result, |
| 494 int route_id, | 518 int route_id, |
| 495 int process_type, | 519 int process_type, |
| 496 int child_id, | 520 int child_id, |
| 497 ResourceContext* resource_context); | 521 ResourceContext* resource_context, |
| 522 bool using_mojo); |
| 498 | 523 |
| 499 // Wraps |handler| in the standard resource handlers for normal resource | 524 // Wraps |handler| in the standard resource handlers for normal resource |
| 500 // loading and navigation requests. This adds MimeTypeResourceHandler and | 525 // loading and navigation requests. This adds MimeTypeResourceHandler and |
| 501 // ResourceThrottles. | 526 // ResourceThrottles. |
| 502 std::unique_ptr<ResourceHandler> AddStandardHandlers( | 527 std::unique_ptr<ResourceHandler> AddStandardHandlers( |
| 503 net::URLRequest* request, | 528 net::URLRequest* request, |
| 504 ResourceType resource_type, | 529 ResourceType resource_type, |
| 505 ResourceContext* resource_context, | 530 ResourceContext* resource_context, |
| 506 AppCacheService* appcache_service, | 531 AppCacheService* appcache_service, |
| 507 int child_id, | 532 int child_id, |
| 508 int route_id, | 533 int route_id, |
| 509 std::unique_ptr<ResourceHandler> handler); | 534 std::unique_ptr<ResourceHandler> handler); |
| 510 | 535 |
| 511 void OnDataDownloadedACK(int request_id); | 536 void OnDataDownloadedACK(int request_id); |
| 512 void OnCancelRequest(int request_id); | 537 void OnCancelRequest(int request_id); |
| 513 void OnReleaseDownloadedFile(int request_id); | 538 void OnReleaseDownloadedFile(int request_id); |
| 514 void OnDidChangePriority(int request_id, | 539 void OnDidChangePriority(int request_id, |
| 515 net::RequestPriority new_priority, | 540 net::RequestPriority new_priority, |
| 516 int intra_priority_value); | 541 int intra_priority_value); |
| 517 | 542 |
| 543 // These function are used to trap messages about to sent to the renderer |
| 544 // and send them via mojo. |
| 545 void OnReceivedResponseForMojo(int request_id, |
| 546 const ResourceResponseHead& head); |
| 547 void OnRequestCompleteForMojo(int request_id, |
| 548 const ResourceMsg_RequestCompleteData& data); |
| 549 |
| 518 // Creates ResourceRequestInfoImpl for a download or page save. | 550 // Creates ResourceRequestInfoImpl for a download or page save. |
| 519 // |download| should be true if the request is a file download. | 551 // |download| should be true if the request is a file download. |
| 520 ResourceRequestInfoImpl* CreateRequestInfo( | 552 ResourceRequestInfoImpl* CreateRequestInfo( |
| 521 int child_id, | 553 int child_id, |
| 522 int render_view_route_id, | 554 int render_view_route_id, |
| 523 int render_frame_route_id, | 555 int render_frame_route_id, |
| 524 bool download, | 556 bool download, |
| 525 ResourceContext* context); | 557 ResourceContext* context); |
| 526 | 558 |
| 527 // Relationship of resource being authenticated with the top level page. | 559 // Relationship of resource being authenticated with the top level page. |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 typedef std::map<GlobalRequestID, | 688 typedef std::map<GlobalRequestID, |
| 657 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; | 689 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; |
| 658 DelegateMap delegate_map_; | 690 DelegateMap delegate_map_; |
| 659 | 691 |
| 660 std::unique_ptr<ResourceScheduler> scheduler_; | 692 std::unique_ptr<ResourceScheduler> scheduler_; |
| 661 | 693 |
| 662 // Allows tests to use a mock CertStore. If set, the CertStore must | 694 // Allows tests to use a mock CertStore. If set, the CertStore must |
| 663 // outlive this ResourceDispatcherHostImpl. | 695 // outlive this ResourceDispatcherHostImpl. |
| 664 CertStore* cert_store_for_testing_; | 696 CertStore* cert_store_for_testing_; |
| 665 | 697 |
| 698 std::unique_ptr<mojom::URLLoader> mojo_loader_for_next_load_request_; |
| 699 mojom::URLLoaderClientPtr mojo_loader_client_for_next_load_request_; |
| 700 std::map<mojom::URLLoader*, std::pair<int, std::unique_ptr<mojom::URLLoader>>> |
| 701 uninitiated_url_loaders_; |
| 702 |
| 666 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 703 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
| 667 }; | 704 }; |
| 668 | 705 |
| 669 } // namespace content | 706 } // namespace content |
| 670 | 707 |
| 671 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 708 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
| OLD | NEW |