Chromium Code Reviews| 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" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 73 class ResourceMessageFilter; | 74 class ResourceMessageFilter; |
| 74 class ResourceRequestInfoImpl; | 75 class ResourceRequestInfoImpl; |
| 75 class SaveFileManager; | 76 class SaveFileManager; |
| 76 class ServiceWorkerNavigationHandleCore; | 77 class ServiceWorkerNavigationHandleCore; |
| 77 class WebContentsImpl; | 78 class WebContentsImpl; |
| 78 struct CommonNavigationParams; | 79 struct CommonNavigationParams; |
| 79 struct DownloadSaveInfo; | 80 struct DownloadSaveInfo; |
| 80 struct NavigationRequestInfo; | 81 struct NavigationRequestInfo; |
| 81 struct Referrer; | 82 struct Referrer; |
| 82 struct ResourceRequest; | 83 struct ResourceRequest; |
| 84 struct ResourceRequestCompletionStatus; | |
| 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 // These functions are used when loading with mojo. | |
| 325 // Stores a URLLoader and a URLLoaderClient in |this| object in order to use | |
| 326 // them in the next OnRequestResource call. | |
| 327 void SetMojoLoaderAndClientrForNextLoadRequest( | |
|
kinuko
2016/05/20 09:38:51
nit: ...AndClientrFor -> ...AndClientFor ? (extra
yhirano
2016/05/20 11:32:54
Done.
| |
| 328 std::unique_ptr<mojom::URLLoader> loader, | |
| 329 mojom::URLLoaderClientPtr client); | |
| 330 // Sends |message| with mojo if it is possible and returns whether the message | |
| 331 // is sent. | |
| 332 bool SendWithMojoIfPossible(const IPC::Message& message, | |
| 333 ResourceMessageFilter* filter); | |
| 334 // Add an uninitiated (i.e., resource loading is not yet started) loader in | |
| 335 // order to keep it alive. | |
| 336 void AddUninitiatedURLLoader(int child_id, | |
| 337 std::unique_ptr<mojom::URLLoader> loader); | |
| 338 // Returns an uninitiated URL loader whose raw pointer equals to |loader|. | |
| 339 std::unique_ptr<mojom::URLLoader> TakeUninitiatedURLLoader( | |
| 340 mojom::URLLoader* loader); | |
|
kinuko
2016/05/20 09:38:51
ditto, these are mojo-only impl details, is it pos
yhirano
2016/05/20 11:32:54
Done, but I'm not sure whether the code is getting
| |
| 341 | |
| 321 private: | 342 private: |
| 322 friend class LoaderIOThreadNotifier; | 343 friend class LoaderIOThreadNotifier; |
| 323 friend class ResourceDispatcherHostTest; | 344 friend class ResourceDispatcherHostTest; |
| 324 | 345 |
| 325 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 346 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 326 TestBlockedRequestsProcessDies); | 347 TestBlockedRequestsProcessDies); |
| 327 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 348 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 328 CalculateApproximateMemoryCost); | 349 CalculateApproximateMemoryCost); |
| 329 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 350 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 330 DetachableResourceTimesOut); | 351 DetachableResourceTimesOut); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 | 385 |
| 365 // An init helper that runs on the IO thread. | 386 // An init helper that runs on the IO thread. |
| 366 void OnInit(); | 387 void OnInit(); |
| 367 | 388 |
| 368 // A shutdown helper that runs on the IO thread. | 389 // A shutdown helper that runs on the IO thread. |
| 369 void OnShutdown(); | 390 void OnShutdown(); |
| 370 | 391 |
| 371 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); | 392 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); |
| 372 | 393 |
| 373 // Helper function for regular and download requests. | 394 // Helper function for regular and download requests. |
| 374 void BeginRequestInternal(std::unique_ptr<net::URLRequest> request, | 395 void BeginRequestInternal( |
| 375 std::unique_ptr<ResourceHandler> handler); | 396 std::unique_ptr<net::URLRequest> request, |
| 397 std::unique_ptr<ResourceHandler> handler, | |
| 398 std::unique_ptr<mojom::URLLoader> url_loader = nullptr, | |
| 399 mojom::URLLoaderClientPtr client = nullptr); | |
| 376 | 400 |
| 377 void StartLoading(ResourceRequestInfoImpl* info, | 401 void StartLoading(ResourceRequestInfoImpl* info, |
| 378 std::unique_ptr<ResourceLoader> loader); | 402 std::unique_ptr<ResourceLoader> loader); |
| 379 | 403 |
| 380 // We keep track of how much memory each request needs and how many requests | 404 // 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. | 405 // 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 | 406 // 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 | 407 // 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 | 408 // 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 | 409 // 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. | 500 // transferred from one process to another. |
| 477 void UpdateRequestForTransfer(int child_id, | 501 void UpdateRequestForTransfer(int child_id, |
| 478 int route_id, | 502 int route_id, |
| 479 int request_id, | 503 int request_id, |
| 480 const ResourceRequest& request_data, | 504 const ResourceRequest& request_data, |
| 481 LoaderMap::iterator iter); | 505 LoaderMap::iterator iter); |
| 482 | 506 |
| 483 void BeginRequest(int request_id, | 507 void BeginRequest(int request_id, |
| 484 const ResourceRequest& request_data, | 508 const ResourceRequest& request_data, |
| 485 IPC::Message* sync_result, // only valid for sync | 509 IPC::Message* sync_result, // only valid for sync |
| 486 int route_id); // only valid for async | 510 int route_id, // only valid for async |
| 511 std::unique_ptr<mojom::URLLoader> url_loader = nullptr, | |
| 512 mojom::URLLoaderClientPtr client = nullptr); | |
| 487 | 513 |
| 488 // Creates a ResourceHandler to be used by BeginRequest() for normal resource | 514 // Creates a ResourceHandler to be used by BeginRequest() for normal resource |
| 489 // loading. | 515 // loading. |
| 490 std::unique_ptr<ResourceHandler> CreateResourceHandler( | 516 std::unique_ptr<ResourceHandler> CreateResourceHandler( |
| 491 net::URLRequest* request, | 517 net::URLRequest* request, |
| 492 const ResourceRequest& request_data, | 518 const ResourceRequest& request_data, |
| 493 IPC::Message* sync_result, | 519 IPC::Message* sync_result, |
| 494 int route_id, | 520 int route_id, |
| 495 int process_type, | 521 int process_type, |
| 496 int child_id, | 522 int child_id, |
| 497 ResourceContext* resource_context); | 523 ResourceContext* resource_context, |
| 524 bool using_mojo); | |
| 498 | 525 |
| 499 // Wraps |handler| in the standard resource handlers for normal resource | 526 // Wraps |handler| in the standard resource handlers for normal resource |
| 500 // loading and navigation requests. This adds MimeTypeResourceHandler and | 527 // loading and navigation requests. This adds MimeTypeResourceHandler and |
| 501 // ResourceThrottles. | 528 // ResourceThrottles. |
| 502 std::unique_ptr<ResourceHandler> AddStandardHandlers( | 529 std::unique_ptr<ResourceHandler> AddStandardHandlers( |
| 503 net::URLRequest* request, | 530 net::URLRequest* request, |
| 504 ResourceType resource_type, | 531 ResourceType resource_type, |
| 505 ResourceContext* resource_context, | 532 ResourceContext* resource_context, |
| 506 AppCacheService* appcache_service, | 533 AppCacheService* appcache_service, |
| 507 int child_id, | 534 int child_id, |
| 508 int route_id, | 535 int route_id, |
| 509 std::unique_ptr<ResourceHandler> handler); | 536 std::unique_ptr<ResourceHandler> handler); |
| 510 | 537 |
| 511 void OnDataDownloadedACK(int request_id); | 538 void OnDataDownloadedACK(int request_id); |
| 512 void OnCancelRequest(int request_id); | 539 void OnCancelRequest(int request_id); |
| 513 void OnReleaseDownloadedFile(int request_id); | 540 void OnReleaseDownloadedFile(int request_id); |
| 514 void OnDidChangePriority(int request_id, | 541 void OnDidChangePriority(int request_id, |
| 515 net::RequestPriority new_priority, | 542 net::RequestPriority new_priority, |
| 516 int intra_priority_value); | 543 int intra_priority_value); |
| 517 | 544 |
| 545 // These function are used to trap messages about to sent to the renderer | |
|
kinuko
2016/05/20 09:38:51
nit: function -> functions
yhirano
2016/05/20 11:32:54
Deleted
| |
| 546 // and send them via mojo. | |
| 547 void OnReceivedResponseForMojo(int request_id, | |
| 548 const ResourceResponseHead& head); | |
| 549 void OnRequestCompleteForMojo(int request_id, | |
| 550 const ResourceRequestCompletionStatus& status); | |
| 551 | |
| 518 // Creates ResourceRequestInfoImpl for a download or page save. | 552 // Creates ResourceRequestInfoImpl for a download or page save. |
| 519 // |download| should be true if the request is a file download. | 553 // |download| should be true if the request is a file download. |
| 520 ResourceRequestInfoImpl* CreateRequestInfo( | 554 ResourceRequestInfoImpl* CreateRequestInfo( |
| 521 int child_id, | 555 int child_id, |
| 522 int render_view_route_id, | 556 int render_view_route_id, |
| 523 int render_frame_route_id, | 557 int render_frame_route_id, |
| 524 bool download, | 558 bool download, |
| 525 ResourceContext* context); | 559 ResourceContext* context); |
| 526 | 560 |
| 527 // Relationship of resource being authenticated with the top level page. | 561 // 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, | 690 typedef std::map<GlobalRequestID, |
| 657 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; | 691 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; |
| 658 DelegateMap delegate_map_; | 692 DelegateMap delegate_map_; |
| 659 | 693 |
| 660 std::unique_ptr<ResourceScheduler> scheduler_; | 694 std::unique_ptr<ResourceScheduler> scheduler_; |
| 661 | 695 |
| 662 // Allows tests to use a mock CertStore. If set, the CertStore must | 696 // Allows tests to use a mock CertStore. If set, the CertStore must |
| 663 // outlive this ResourceDispatcherHostImpl. | 697 // outlive this ResourceDispatcherHostImpl. |
| 664 CertStore* cert_store_for_testing_; | 698 CertStore* cert_store_for_testing_; |
| 665 | 699 |
| 700 std::unique_ptr<mojom::URLLoader> mojo_loader_for_next_load_request_; | |
| 701 mojom::URLLoaderClientPtr mojo_loader_client_for_next_load_request_; | |
| 702 std::map<mojom::URLLoader*, std::pair<int, std::unique_ptr<mojom::URLLoader>>> | |
| 703 uninitiated_url_loaders_; | |
| 704 | |
| 666 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 705 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
| 667 }; | 706 }; |
| 668 | 707 |
| 669 } // namespace content | 708 } // namespace content |
| 670 | 709 |
| 671 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 710 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
| OLD | NEW |