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 using CreateDownloadHandlerIntercept = | |
82 base::Callback<std::unique_ptr<ResourceHandler>(net::URLRequest*)>; | |
83 | |
82 class CONTENT_EXPORT ResourceDispatcherHostImpl | 84 class CONTENT_EXPORT ResourceDispatcherHostImpl |
83 : public ResourceDispatcherHost, | 85 : public ResourceDispatcherHost, |
84 public ResourceLoaderDelegate { | 86 public ResourceLoaderDelegate { |
85 public: | 87 public: |
86 ResourceDispatcherHostImpl(); | 88 ResourceDispatcherHostImpl(); |
87 ~ResourceDispatcherHostImpl() override; | 89 ~ResourceDispatcherHostImpl() override; |
88 | 90 |
89 // Returns the current ResourceDispatcherHostImpl. May return NULL if it | 91 // Returns the current ResourceDispatcherHostImpl. May return NULL if it |
90 // hasn't been created yet. | 92 // hasn't been created yet. |
91 static ResourceDispatcherHostImpl* Get(); | 93 static ResourceDispatcherHostImpl* Get(); |
(...skipping 30 matching lines...) Expand all Loading... | |
122 | 124 |
123 // Force cancels any pending requests for the given |context|. This is | 125 // Force cancels any pending requests for the given |context|. This is |
124 // necessary to ensure that before |context| goes away, all requests | 126 // necessary to ensure that before |context| goes away, all requests |
125 // for it are dead. | 127 // for it are dead. |
126 void CancelRequestsForContext(ResourceContext* context); | 128 void CancelRequestsForContext(ResourceContext* context); |
127 | 129 |
128 // Returns true if the message was a resource message that was processed. | 130 // Returns true if the message was a resource message that was processed. |
129 bool OnMessageReceived(const IPC::Message& message, | 131 bool OnMessageReceived(const IPC::Message& message, |
130 ResourceMessageFilter* filter); | 132 ResourceMessageFilter* filter); |
131 | 133 |
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. | 134 // Cancels the given request if it still exists. |
154 void CancelRequest(int child_id, int request_id); | 135 void CancelRequest(int child_id, int request_id); |
155 | 136 |
156 // Marks the request, with its current |response|, as "parked". This | 137 // Marks the request, with its current |response|, as "parked". This |
157 // happens if a request is redirected cross-site and needs to be | 138 // happens if a request is redirected cross-site and needs to be |
158 // resumed by a new process. | 139 // resumed by a new process. |
159 void MarkAsTransferredNavigation( | 140 void MarkAsTransferredNavigation( |
160 const GlobalRequestID& id, | 141 const GlobalRequestID& id, |
161 const scoped_refptr<ResourceResponse>& response); | 142 const scoped_refptr<ResourceResponse>& response); |
162 | 143 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 // dialog boxes. | 218 // dialog boxes. |
238 bool allow_cross_origin_auth_prompt(); | 219 bool allow_cross_origin_auth_prompt(); |
239 | 220 |
240 ResourceDispatcherHostDelegate* delegate() { | 221 ResourceDispatcherHostDelegate* delegate() { |
241 return delegate_; | 222 return delegate_; |
242 } | 223 } |
243 | 224 |
244 // Must be called after the ResourceRequestInfo has been created | 225 // Must be called after the ResourceRequestInfo has been created |
245 // and associated with the request. | 226 // and associated with the request. |
246 // This is marked virtual so it can be overriden in testing. | 227 // This is marked virtual so it can be overriden in testing. |
228 // TODO(ananta) | |
229 // This method should be removed or moved outside this class. | |
247 virtual std::unique_ptr<ResourceHandler> CreateResourceHandlerForDownload( | 230 virtual std::unique_ptr<ResourceHandler> CreateResourceHandlerForDownload( |
248 net::URLRequest* request, | 231 net::URLRequest* request, |
249 bool is_content_initiated, | 232 bool is_content_initiated, |
250 bool must_download); | 233 bool must_download); |
251 | 234 |
252 // Called to determine whether the response to |request| should be intercepted | 235 // Called to determine whether the response to |request| should be intercepted |
253 // and handled as a stream. Streams are used to pass direct access to a | 236 // and handled as a stream. Streams are used to pass direct access to a |
254 // resource response to another application (e.g. a web page) without being | 237 // resource response to another application (e.g. a web page) without being |
255 // handled by the browser itself. If the request should be intercepted as a | 238 // handled by the browser itself. If the request should be intercepted as a |
256 // stream, a StreamResourceHandler is returned which provides access to the | 239 // stream, a StreamResourceHandler is returned which provides access to the |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 | 285 |
303 // Called when loading a request with mojo. | 286 // Called when loading a request with mojo. |
304 void OnRequestResourceWithMojo( | 287 void OnRequestResourceWithMojo( |
305 int routing_id, | 288 int routing_id, |
306 int request_id, | 289 int request_id, |
307 const ResourceRequest& request, | 290 const ResourceRequest& request, |
308 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, | 291 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
309 mojom::URLLoaderClientPtr url_loader_client, | 292 mojom::URLLoaderClientPtr url_loader_client, |
310 ResourceMessageFilter* filter); | 293 ResourceMessageFilter* filter); |
311 | 294 |
295 // This enum contains possible return values for the BeginURLRequest() | |
296 // function declared below. | |
297 enum URLRequestStatus { | |
mmenke
2016/08/22 14:40:08
Given that we already have a net::URLRequestState
ananta
2016/08/22 19:14:57
Left it as void. It does not return anything usefu
| |
298 URL_REQUEST_FAILED_SHUTDOWN = 0, | |
299 URL_REQUEST_ISSUED = 1, | |
300 URL_REQUEST_LAST = URL_REQUEST_ISSUED, | |
301 }; | |
302 | |
303 // Helper function for initiating a URL request. The |is_download| and | |
304 // |is_content_initiated and |do_not_prompt_for_login| parameters are | |
305 // specific to download requests. | |
306 // TODO(ananta) | |
307 // Look into a better way of passing these parameters in. | |
308 // Returns values defined in the URLRequestStatus enum above. | |
309 URLRequestStatus BeginURLRequest(std::unique_ptr<net::URLRequest> request, | |
310 std::unique_ptr<ResourceHandler> handler, | |
311 const Referrer& referrer, | |
312 bool is_download, | |
313 bool is_content_initiated, | |
314 bool do_not_prompt_for_login, | |
315 int render_process_host_id, | |
316 int render_view_routing_id, | |
317 int render_frame_routing_id, | |
318 ResourceContext* context); | |
319 | |
320 bool is_shutdown() const { return is_shutdown_; } | |
Randy Smith (Not in Mondays)
2016/08/21 23:32:57
I don't think this function is needed anymore?
ananta
2016/08/22 19:14:57
Needed. We check the shutdown state in the Downloa
| |
321 | |
322 // Registers the |intercept| as the callback to be invoked when the download | |
323 // handler is created for handling downloads. | |
324 // TODO(ananta) | |
325 // Investigate if we can find a better way to do this. | |
326 void RegisterCreateDownloadHandlerInterceptor( | |
327 CreateDownloadHandlerIntercept intercept); | |
328 | |
312 private: | 329 private: |
313 friend class ResourceDispatcherHostTest; | 330 friend class ResourceDispatcherHostTest; |
314 | 331 |
315 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 332 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
316 TestBlockedRequestsProcessDies); | 333 TestBlockedRequestsProcessDies); |
317 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 334 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
318 CalculateApproximateMemoryCost); | 335 CalculateApproximateMemoryCost); |
319 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 336 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
320 DetachableResourceTimesOut); | 337 DetachableResourceTimesOut); |
321 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 338 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 void DidFinishLoading(ResourceLoader* loader) override; | 388 void DidFinishLoading(ResourceLoader* loader) override; |
372 std::unique_ptr<net::ClientCertStore> CreateClientCertStore( | 389 std::unique_ptr<net::ClientCertStore> CreateClientCertStore( |
373 ResourceLoader* loader) override; | 390 ResourceLoader* loader) override; |
374 | 391 |
375 // An init helper that runs on the IO thread. | 392 // An init helper that runs on the IO thread. |
376 void OnInit(); | 393 void OnInit(); |
377 | 394 |
378 // A shutdown helper that runs on the IO thread. | 395 // A shutdown helper that runs on the IO thread. |
379 void OnShutdown(); | 396 void OnShutdown(); |
380 | 397 |
381 // Helper function for regular and download requests. | 398 // Helper function for URL requests. |
382 void BeginRequestInternal(std::unique_ptr<net::URLRequest> request, | 399 void BeginRequestInternal(std::unique_ptr<net::URLRequest> request, |
383 std::unique_ptr<ResourceHandler> handler); | 400 std::unique_ptr<ResourceHandler> handler); |
384 | 401 |
385 void StartLoading(ResourceRequestInfoImpl* info, | 402 void StartLoading(ResourceRequestInfoImpl* info, |
386 std::unique_ptr<ResourceLoader> loader); | 403 std::unique_ptr<ResourceLoader> loader); |
387 | 404 |
388 // We keep track of how much memory each request needs and how many requests | 405 // 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. | 406 // 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 | 407 // 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 | 408 // limit for each renderer. File descriptor limits apply to requests that are |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
608 // ResourceDispatcherHostImpl should service this request. A request might | 625 // ResourceDispatcherHostImpl should service this request. A request might |
609 // be disallowed if the renderer is not authorized to retrieve the request | 626 // be disallowed if the renderer is not authorized to retrieve the request |
610 // URL or if the renderer is attempting to upload an unauthorized file. | 627 // URL or if the renderer is attempting to upload an unauthorized file. |
611 bool ShouldServiceRequest(int process_type, | 628 bool ShouldServiceRequest(int process_type, |
612 int child_id, | 629 int child_id, |
613 const ResourceRequest& request_data, | 630 const ResourceRequest& request_data, |
614 const net::HttpRequestHeaders& headers, | 631 const net::HttpRequestHeaders& headers, |
615 ResourceMessageFilter* filter, | 632 ResourceMessageFilter* filter, |
616 ResourceContext* resource_context); | 633 ResourceContext* resource_context); |
617 | 634 |
635 // Notifies the ResourceDispatcherHostDelegate about a download having | |
636 // started. The function returns the |handler| passed in, if the download | |
637 // is not throttled. If the download is to be throttled (Decided by the | |
638 // delegate) the function returns a ThrottlingResourceHandler to handle the | |
639 // download. | |
640 std::unique_ptr<ResourceHandler> HandleDownloadStarted( | |
641 net::URLRequest* request, | |
642 std::unique_ptr<ResourceHandler> handler, | |
643 bool is_content_initiated, | |
644 bool must_download); | |
645 | |
618 LoaderMap pending_loaders_; | 646 LoaderMap pending_loaders_; |
619 | 647 |
620 // Collection of temp files downloaded for child processes via | 648 // Collection of temp files downloaded for child processes via |
621 // the download_to_file mechanism. We avoid deleting them until | 649 // the download_to_file mechanism. We avoid deleting them until |
622 // the client no longer needs them. | 650 // the client no longer needs them. |
623 typedef std::map<int, scoped_refptr<storage::ShareableFileReference> > | 651 typedef std::map<int, scoped_refptr<storage::ShareableFileReference> > |
624 DeletableFilesMap; // key is request id | 652 DeletableFilesMap; // key is request id |
625 typedef std::map<int, DeletableFilesMap> | 653 typedef std::map<int, DeletableFilesMap> |
626 RegisteredTempFiles; // key is child process id | 654 RegisteredTempFiles; // key is child process id |
627 RegisteredTempFiles registered_temp_files_; | 655 RegisteredTempFiles registered_temp_files_; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
702 | 730 |
703 std::unique_ptr<ResourceScheduler> scheduler_; | 731 std::unique_ptr<ResourceScheduler> scheduler_; |
704 | 732 |
705 // Allows tests to use a mock CertStore. If set, the CertStore must | 733 // Allows tests to use a mock CertStore. If set, the CertStore must |
706 // outlive this ResourceDispatcherHostImpl. | 734 // outlive this ResourceDispatcherHostImpl. |
707 CertStore* cert_store_for_testing_; | 735 CertStore* cert_store_for_testing_; |
708 | 736 |
709 // Used to invoke an interceptor for the HTTP header. | 737 // Used to invoke an interceptor for the HTTP header. |
710 HeaderInterceptorMap http_header_interceptor_map_; | 738 HeaderInterceptorMap http_header_interceptor_map_; |
711 | 739 |
740 // Points to the registered download handler intercept. | |
741 CreateDownloadHandlerIntercept create_download_handler_intercept_; | |
742 | |
712 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 743 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
713 }; | 744 }; |
714 | 745 |
715 } // namespace content | 746 } // namespace content |
716 | 747 |
717 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 748 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
OLD | NEW |