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 |
| 11 | 11 |
| 12 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 12 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
| 13 #define CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 13 #define CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
| 14 | 14 |
| 15 #include <stdint.h> | 15 #include <stdint.h> |
| 16 | 16 |
| 17 #include <map> | 17 #include <map> |
| 18 #include <memory> | 18 #include <memory> |
| 19 #include <string> | 19 #include <string> |
| 20 #include <vector> | 20 #include <vector> |
| 21 | 21 |
| 22 #include "base/gtest_prod_util.h" | 22 #include "base/gtest_prod_util.h" |
| 23 #include "base/macros.h" | 23 #include "base/macros.h" |
| 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" | |
| 28 #include "content/browser/download/save_types.h" | 27 #include "content/browser/download/save_types.h" |
| 29 #include "content/browser/loader/global_routing_id.h" | 28 #include "content/browser/loader/global_routing_id.h" |
| 30 #include "content/browser/loader/resource_loader.h" | 29 #include "content/browser/loader/resource_loader.h" |
| 31 #include "content/browser/loader/resource_loader_delegate.h" | 30 #include "content/browser/loader/resource_loader_delegate.h" |
| 32 #include "content/browser/loader/resource_scheduler.h" | 31 #include "content/browser/loader/resource_scheduler.h" |
| 33 #include "content/common/content_export.h" | 32 #include "content/common/content_export.h" |
| 34 #include "content/common/url_loader.mojom.h" | 33 #include "content/common/url_loader.mojom.h" |
| 35 #include "content/public/browser/global_request_id.h" | 34 #include "content/public/browser/global_request_id.h" |
| 36 #include "content/public/browser/resource_dispatcher_host.h" | 35 #include "content/public/browser/resource_dispatcher_host.h" |
| 37 #include "content/public/common/request_context_type.h" | 36 #include "content/public/common/request_context_type.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 58 | 57 |
| 59 namespace content { | 58 namespace content { |
| 60 class AppCacheService; | 59 class AppCacheService; |
| 61 class AsyncRevalidationManager; | 60 class AsyncRevalidationManager; |
| 62 class CertStore; | 61 class CertStore; |
| 63 class LoaderDelegate; | 62 class LoaderDelegate; |
| 64 class NavigationURLLoaderImplCore; | 63 class NavigationURLLoaderImplCore; |
| 65 class RenderFrameHostImpl; | 64 class RenderFrameHostImpl; |
| 66 class ResourceContext; | 65 class ResourceContext; |
| 67 class ResourceDispatcherHostDelegate; | 66 class ResourceDispatcherHostDelegate; |
| 67 class ResourceHandler; | |
| 68 class ResourceMessageDelegate; | 68 class ResourceMessageDelegate; |
| 69 class ResourceMessageFilter; | 69 class ResourceMessageFilter; |
| 70 class ResourceRequestInfoImpl; | 70 class ResourceRequestInfoImpl; |
| 71 class ServiceWorkerNavigationHandleCore; | 71 class ServiceWorkerNavigationHandleCore; |
| 72 struct CommonNavigationParams; | 72 struct CommonNavigationParams; |
| 73 struct DownloadSaveInfo; | |
| 74 struct NavigationRequestInfo; | 73 struct NavigationRequestInfo; |
| 75 struct Referrer; | 74 struct Referrer; |
| 76 struct ResourceRequest; | 75 struct ResourceRequest; |
| 77 | 76 |
| 78 namespace mojom { | 77 namespace mojom { |
| 79 class URLLoader; | 78 class URLLoader; |
| 80 } // namespace mojom | 79 } // namespace mojom |
| 81 | 80 |
| 81 typedef base::Callback< | |
| 82 std::unique_ptr<ResourceHandler>(net::URLRequest*, bool, bool)> | |
| 83 CreateDownloadHandlerIntercept; | |
|
Randy Smith (Not in Mondays)
2016/08/17 15:53:54
nit: I think "using X = " is the new hotness?
ananta
2016/08/18 01:53:25
Done.
| |
| 84 | |
| 82 class CONTENT_EXPORT ResourceDispatcherHostImpl | 85 class CONTENT_EXPORT ResourceDispatcherHostImpl |
| 83 : public ResourceDispatcherHost, | 86 : public ResourceDispatcherHost, |
| 84 public ResourceLoaderDelegate { | 87 public ResourceLoaderDelegate { |
| 85 public: | 88 public: |
| 86 ResourceDispatcherHostImpl(); | 89 ResourceDispatcherHostImpl(); |
| 87 ~ResourceDispatcherHostImpl() override; | 90 ~ResourceDispatcherHostImpl() override; |
| 88 | 91 |
| 89 // Returns the current ResourceDispatcherHostImpl. May return NULL if it | 92 // Returns the current ResourceDispatcherHostImpl. May return NULL if it |
| 90 // hasn't been created yet. | 93 // hasn't been created yet. |
| 91 static ResourceDispatcherHostImpl* Get(); | 94 static ResourceDispatcherHostImpl* Get(); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 122 | 125 |
| 123 // Force cancels any pending requests for the given |context|. This is | 126 // Force cancels any pending requests for the given |context|. This is |
| 124 // necessary to ensure that before |context| goes away, all requests | 127 // necessary to ensure that before |context| goes away, all requests |
| 125 // for it are dead. | 128 // for it are dead. |
| 126 void CancelRequestsForContext(ResourceContext* context); | 129 void CancelRequestsForContext(ResourceContext* context); |
| 127 | 130 |
| 128 // Returns true if the message was a resource message that was processed. | 131 // Returns true if the message was a resource message that was processed. |
| 129 bool OnMessageReceived(const IPC::Message& message, | 132 bool OnMessageReceived(const IPC::Message& message, |
| 130 ResourceMessageFilter* filter); | 133 ResourceMessageFilter* filter); |
| 131 | 134 |
| 132 DownloadInterruptReason BeginDownload( | |
| 133 std::unique_ptr<net::URLRequest> request, | |
| 134 const Referrer& referrer, | |
| 135 bool is_content_initiated, | |
| 136 ResourceContext* context, | |
| 137 int render_process_id, | |
| 138 int render_view_route_id, | |
| 139 int render_frame_route_id, | |
| 140 bool do_not_prompt_for_login); | |
| 141 | |
| 142 // Initiates a save file from the browser process (as opposed to a resource | |
| 143 // request from the renderer or another child process). | |
| 144 void BeginSaveFile(const GURL& url, | |
| 145 const Referrer& referrer, | |
| 146 SaveItemId save_item_id, | |
| 147 SavePackageId save_package_id, | |
| 148 int child_id, | |
| 149 int render_view_route_id, | |
| 150 int render_frame_route_id, | |
| 151 ResourceContext* context); | |
| 152 | |
| 153 // Cancels the given request if it still exists. | 135 // Cancels the given request if it still exists. |
| 154 void CancelRequest(int child_id, int request_id); | 136 void CancelRequest(int child_id, int request_id); |
| 155 | 137 |
| 156 // Marks the request, with its current |response|, as "parked". This | 138 // Marks the request, with its current |response|, as "parked". This |
| 157 // happens if a request is redirected cross-site and needs to be | 139 // happens if a request is redirected cross-site and needs to be |
| 158 // resumed by a new process. | 140 // resumed by a new process. |
| 159 void MarkAsTransferredNavigation( | 141 void MarkAsTransferredNavigation( |
| 160 const GlobalRequestID& id, | 142 const GlobalRequestID& id, |
| 161 const scoped_refptr<ResourceResponse>& response); | 143 const scoped_refptr<ResourceResponse>& response); |
| 162 | 144 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 | 284 |
| 303 // Called when loading a request with mojo. | 285 // Called when loading a request with mojo. |
| 304 void OnRequestResourceWithMojo( | 286 void OnRequestResourceWithMojo( |
| 305 int routing_id, | 287 int routing_id, |
| 306 int request_id, | 288 int request_id, |
| 307 const ResourceRequest& request, | 289 const ResourceRequest& request, |
| 308 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, | 290 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 309 mojom::URLLoaderClientPtr url_loader_client, | 291 mojom::URLLoaderClientPtr url_loader_client, |
| 310 ResourceMessageFilter* filter); | 292 ResourceMessageFilter* filter); |
| 311 | 293 |
| 294 // Helper function for regular and download requests. | |
| 295 void BeginURLRequest(std::unique_ptr<net::URLRequest> request, | |
| 296 std::unique_ptr<ResourceHandler> handler); | |
| 297 | |
| 298 // Creates and returns a ResourceRequestInfoImpl instance. | |
| 299 ResourceRequestInfoImpl* CreateRequestInfo(int child_id, | |
| 300 int render_view_route_id, | |
| 301 int render_frame_route_id, | |
| 302 bool download, | |
| 303 ResourceContext* context); | |
| 304 | |
| 305 bool is_shutdown() const { return is_shutdown_; } | |
| 306 | |
| 307 // Registers the |intercept| as the callback to be invoked when the download | |
| 308 // handler is created for handling downloads. | |
| 309 // TODO(ananta) | |
| 310 // Investigate if we can find a better way to do this. | |
| 311 void RegisterCreateDownloadHandlerInterceptor( | |
| 312 CreateDownloadHandlerIntercept intercept); | |
| 313 | |
| 312 private: | 314 private: |
| 313 friend class ResourceDispatcherHostTest; | 315 friend class ResourceDispatcherHostTest; |
| 314 | 316 |
| 315 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 317 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 316 TestBlockedRequestsProcessDies); | 318 TestBlockedRequestsProcessDies); |
| 317 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 319 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 318 CalculateApproximateMemoryCost); | 320 CalculateApproximateMemoryCost); |
| 319 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 321 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| 320 DetachableResourceTimesOut); | 322 DetachableResourceTimesOut); |
| 321 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 323 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 void DidFinishLoading(ResourceLoader* loader) override; | 373 void DidFinishLoading(ResourceLoader* loader) override; |
| 372 std::unique_ptr<net::ClientCertStore> CreateClientCertStore( | 374 std::unique_ptr<net::ClientCertStore> CreateClientCertStore( |
| 373 ResourceLoader* loader) override; | 375 ResourceLoader* loader) override; |
| 374 | 376 |
| 375 // An init helper that runs on the IO thread. | 377 // An init helper that runs on the IO thread. |
| 376 void OnInit(); | 378 void OnInit(); |
| 377 | 379 |
| 378 // A shutdown helper that runs on the IO thread. | 380 // A shutdown helper that runs on the IO thread. |
| 379 void OnShutdown(); | 381 void OnShutdown(); |
| 380 | 382 |
| 381 // Helper function for regular and download requests. | |
| 382 void BeginRequestInternal(std::unique_ptr<net::URLRequest> request, | |
| 383 std::unique_ptr<ResourceHandler> handler); | |
| 384 | |
| 385 void StartLoading(ResourceRequestInfoImpl* info, | 383 void StartLoading(ResourceRequestInfoImpl* info, |
| 386 std::unique_ptr<ResourceLoader> loader); | 384 std::unique_ptr<ResourceLoader> loader); |
| 387 | 385 |
| 388 // We keep track of how much memory each request needs and how many requests | 386 // We keep track of how much memory each request needs and how many requests |
| 389 // are issued by each renderer. These are known as OustandingRequestStats. | 387 // are issued by each renderer. These are known as OustandingRequestStats. |
| 390 // Memory limits apply to all requests sent to us by the renderers. There is a | 388 // Memory limits apply to all requests sent to us by the renderers. There is a |
| 391 // limit for each renderer. File descriptor limits apply to requests that are | 389 // limit for each renderer. File descriptor limits apply to requests that are |
| 392 // receiving their body. These are known as in-flight requests. There is a | 390 // receiving their body. These are known as in-flight requests. There is a |
| 393 // global limit that applies for the browser process. Each render is allowed | 391 // global limit that applies for the browser process. Each render is allowed |
| 394 // to use up to a fraction of that. | 392 // to use up to a fraction of that. |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 int route_id, | 543 int route_id, |
| 546 std::unique_ptr<ResourceHandler> handler); | 544 std::unique_ptr<ResourceHandler> handler); |
| 547 | 545 |
| 548 void OnDataDownloadedACK(int request_id); | 546 void OnDataDownloadedACK(int request_id); |
| 549 void OnCancelRequest(int request_id); | 547 void OnCancelRequest(int request_id); |
| 550 void OnReleaseDownloadedFile(int request_id); | 548 void OnReleaseDownloadedFile(int request_id); |
| 551 void OnDidChangePriority(int request_id, | 549 void OnDidChangePriority(int request_id, |
| 552 net::RequestPriority new_priority, | 550 net::RequestPriority new_priority, |
| 553 int intra_priority_value); | 551 int intra_priority_value); |
| 554 | 552 |
| 555 // Creates ResourceRequestInfoImpl for a download or page save. | |
| 556 // |download| should be true if the request is a file download. | |
| 557 ResourceRequestInfoImpl* CreateRequestInfo( | |
| 558 int child_id, | |
| 559 int render_view_route_id, | |
| 560 int render_frame_route_id, | |
| 561 bool download, | |
| 562 ResourceContext* context); | |
| 563 | |
| 564 // Relationship of resource being authenticated with the top level page. | 553 // Relationship of resource being authenticated with the top level page. |
| 565 enum HttpAuthRelationType { | 554 enum HttpAuthRelationType { |
| 566 HTTP_AUTH_RELATION_TOP, // Top-level page itself | 555 HTTP_AUTH_RELATION_TOP, // Top-level page itself |
| 567 HTTP_AUTH_RELATION_SAME_DOMAIN, // Sub-content from same domain | 556 HTTP_AUTH_RELATION_SAME_DOMAIN, // Sub-content from same domain |
| 568 HTTP_AUTH_RELATION_BLOCKED_CROSS, // Blocked Sub-content from cross domain | 557 HTTP_AUTH_RELATION_BLOCKED_CROSS, // Blocked Sub-content from cross domain |
| 569 HTTP_AUTH_RELATION_ALLOWED_CROSS, // Allowed Sub-content per command line | 558 HTTP_AUTH_RELATION_ALLOWED_CROSS, // Allowed Sub-content per command line |
| 570 HTTP_AUTH_RELATION_LAST | 559 HTTP_AUTH_RELATION_LAST |
| 571 }; | 560 }; |
| 572 | 561 |
| 573 HttpAuthRelationType HttpAuthRelationTypeOf(const GURL& request_url, | 562 HttpAuthRelationType HttpAuthRelationTypeOf(const GURL& request_url, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 | 691 |
| 703 std::unique_ptr<ResourceScheduler> scheduler_; | 692 std::unique_ptr<ResourceScheduler> scheduler_; |
| 704 | 693 |
| 705 // 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 |
| 706 // outlive this ResourceDispatcherHostImpl. | 695 // outlive this ResourceDispatcherHostImpl. |
| 707 CertStore* cert_store_for_testing_; | 696 CertStore* cert_store_for_testing_; |
| 708 | 697 |
| 709 // Used to invoke an interceptor for the HTTP header. | 698 // Used to invoke an interceptor for the HTTP header. |
| 710 HeaderInterceptorMap http_header_interceptor_map_; | 699 HeaderInterceptorMap http_header_interceptor_map_; |
| 711 | 700 |
| 701 // Points to the registered download handler intercept. | |
| 702 CreateDownloadHandlerIntercept create_download_handler_intercept_; | |
| 703 | |
| 712 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 704 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
| 713 }; | 705 }; |
| 714 | 706 |
| 715 } // namespace content | 707 } // namespace content |
| 716 | 708 |
| 717 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 709 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
| OLD | NEW |