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 13 matching lines...) Expand all Loading... | |
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" | 27 #include "content/browser/download/download_resource_handler.h" |
28 #include "content/browser/download/save_types.h" | 28 #include "content/browser/download/save_types.h" |
29 #include "content/browser/loader/global_routing_id.h" | 29 #include "content/browser/loader/global_routing_id.h" |
30 #include "content/browser/loader/resource_loader.h" | 30 #include "content/browser/loader/resource_loader.h" |
31 #include "content/browser/loader/resource_loader_delegate.h" | 31 #include "content/browser/loader/resource_loader_delegate.h" |
32 #include "content/browser/loader/resource_scheduler.h" | 32 #include "content/browser/loader/resource_scheduler.h" |
33 #include "content/common/content_export.h" | 33 #include "content/common/content_export.h" |
34 #include "content/common/url_loader.mojom.h" | |
34 #include "content/public/browser/global_request_id.h" | 35 #include "content/public/browser/global_request_id.h" |
35 #include "content/public/browser/resource_dispatcher_host.h" | 36 #include "content/public/browser/resource_dispatcher_host.h" |
36 #include "content/public/common/request_context_type.h" | 37 #include "content/public/common/request_context_type.h" |
37 #include "content/public/common/resource_type.h" | 38 #include "content/public/common/resource_type.h" |
38 #include "ipc/ipc_message.h" | 39 #include "ipc/ipc_message.h" |
40 #include "mojo/public/cpp/system/data_pipe.h" | |
39 #include "net/base/request_priority.h" | 41 #include "net/base/request_priority.h" |
40 #include "net/cookies/canonical_cookie.h" | 42 #include "net/cookies/canonical_cookie.h" |
41 #include "net/url_request/url_request.h" | 43 #include "net/url_request/url_request.h" |
42 | 44 |
43 class ResourceHandler; | 45 class ResourceHandler; |
44 | 46 |
45 namespace base { | 47 namespace base { |
46 class FilePath; | 48 class FilePath; |
47 } | 49 } |
48 | 50 |
(...skipping 18 matching lines...) Expand all Loading... | |
67 class ResourceMessageFilter; | 69 class ResourceMessageFilter; |
68 class ResourceRequestInfoImpl; | 70 class ResourceRequestInfoImpl; |
69 class SaveFileManager; | 71 class SaveFileManager; |
70 class ServiceWorkerNavigationHandleCore; | 72 class ServiceWorkerNavigationHandleCore; |
71 struct CommonNavigationParams; | 73 struct CommonNavigationParams; |
72 struct DownloadSaveInfo; | 74 struct DownloadSaveInfo; |
73 struct NavigationRequestInfo; | 75 struct NavigationRequestInfo; |
74 struct Referrer; | 76 struct Referrer; |
75 struct ResourceRequest; | 77 struct ResourceRequest; |
76 | 78 |
79 namespace mojom { | |
80 class URLLoader; | |
81 } // namespace mojom | |
82 | |
77 class CONTENT_EXPORT ResourceDispatcherHostImpl | 83 class CONTENT_EXPORT ResourceDispatcherHostImpl |
78 : public ResourceDispatcherHost, | 84 : public ResourceDispatcherHost, |
79 public ResourceLoaderDelegate { | 85 public ResourceLoaderDelegate { |
80 public: | 86 public: |
81 ResourceDispatcherHostImpl(); | 87 ResourceDispatcherHostImpl(); |
82 ~ResourceDispatcherHostImpl() override; | 88 ~ResourceDispatcherHostImpl() override; |
83 | 89 |
84 // Returns the current ResourceDispatcherHostImpl. May return NULL if it | 90 // Returns the current ResourceDispatcherHostImpl. May return NULL if it |
85 // hasn't been created yet. | 91 // hasn't been created yet. |
86 static ResourceDispatcherHostImpl* Get(); | 92 static ResourceDispatcherHostImpl* Get(); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 // using its shared memory buffer. Frees up that file descriptor to be used | 281 // using its shared memory buffer. Frees up that file descriptor to be used |
276 // elsewhere. | 282 // elsewhere. |
277 void FinishedWithResourcesForRequest(net::URLRequest* request); | 283 void FinishedWithResourcesForRequest(net::URLRequest* request); |
278 | 284 |
279 // PlzNavigate: Begins a request for NavigationURLLoader. |loader| is the | 285 // PlzNavigate: Begins a request for NavigationURLLoader. |loader| is the |
280 // loader to attach to the leaf resource handler. | 286 // loader to attach to the leaf resource handler. |
281 void BeginNavigationRequest(ResourceContext* resource_context, | 287 void BeginNavigationRequest(ResourceContext* resource_context, |
282 const NavigationRequestInfo& info, | 288 const NavigationRequestInfo& info, |
283 NavigationURLLoaderImplCore* loader); | 289 NavigationURLLoaderImplCore* loader); |
284 | 290 |
291 int num_in_flight_requests_for_testing() const { | |
292 return num_in_flight_requests_; | |
293 } | |
294 | |
285 // Turns on stale-while-revalidate support, regardless of command-line flags | 295 // Turns on stale-while-revalidate support, regardless of command-line flags |
286 // or experiment status. For unit tests only. | 296 // or experiment status. For unit tests only. |
287 void EnableStaleWhileRevalidateForTesting(); | 297 void EnableStaleWhileRevalidateForTesting(); |
288 | 298 |
289 // Sets the LoaderDelegate, which must outlive this object. Ownership is not | 299 // Sets the LoaderDelegate, which must outlive this object. Ownership is not |
290 // transferred. The LoaderDelegate should be interacted with on the IO thread. | 300 // transferred. The LoaderDelegate should be interacted with on the IO thread. |
291 void SetLoaderDelegate(LoaderDelegate* loader_delegate); | 301 void SetLoaderDelegate(LoaderDelegate* loader_delegate); |
292 | 302 |
293 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); | 303 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); |
294 | 304 |
305 // This function is used when loading with mojo. | |
306 // Called when loading a request with mojo. | |
kinuko
2016/08/03 18:20:07
nit: these two lines of comment feel a bit verbose
yhirano
2016/08/04 12:50:51
Done.
| |
307 void OnRequestResourceWithMojo( | |
308 int routing_id, | |
309 int request_id, | |
310 const ResourceRequest& request, | |
311 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, | |
312 mojom::URLLoaderClientPtr url_loader_client, | |
313 ResourceMessageFilter* filter); | |
314 | |
295 private: | 315 private: |
296 friend class ResourceDispatcherHostTest; | 316 friend class ResourceDispatcherHostTest; |
297 | 317 |
298 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 318 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
299 TestBlockedRequestsProcessDies); | 319 TestBlockedRequestsProcessDies); |
300 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 320 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
301 CalculateApproximateMemoryCost); | 321 CalculateApproximateMemoryCost); |
302 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 322 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
303 DetachableResourceTimesOut); | 323 DetachableResourceTimesOut); |
304 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 324 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 void UpdateLoadInfo(); | 448 void UpdateLoadInfo(); |
429 | 449 |
430 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. | 450 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. |
431 void ProcessBlockedRequestsForRoute( | 451 void ProcessBlockedRequestsForRoute( |
432 const GlobalFrameRoutingId& global_routing_id, | 452 const GlobalFrameRoutingId& global_routing_id, |
433 bool cancel_requests); | 453 bool cancel_requests); |
434 | 454 |
435 void OnRequestResource(int routing_id, | 455 void OnRequestResource(int routing_id, |
436 int request_id, | 456 int request_id, |
437 const ResourceRequest& request_data); | 457 const ResourceRequest& request_data); |
458 | |
459 void OnRequestResourceInternal( | |
460 int routing_id, | |
461 int request_id, | |
462 const ResourceRequest& request_data, | |
463 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, | |
464 mojom::URLLoaderClientPtr url_loader_client); | |
465 | |
438 void OnSyncLoad(int request_id, | 466 void OnSyncLoad(int request_id, |
439 const ResourceRequest& request_data, | 467 const ResourceRequest& request_data, |
440 IPC::Message* sync_result); | 468 IPC::Message* sync_result); |
441 | 469 |
442 bool IsRequestIDInUse(const GlobalRequestID& id) const; | 470 bool IsRequestIDInUse(const GlobalRequestID& id) const; |
443 | 471 |
444 // Update the ResourceRequestInfo and internal maps when a request is | 472 // Update the ResourceRequestInfo and internal maps when a request is |
445 // transferred from one process to another. | 473 // transferred from one process to another. |
446 void UpdateRequestForTransfer(int child_id, | 474 void UpdateRequestForTransfer(int child_id, |
447 int route_id, | 475 int route_id, |
448 int request_id, | 476 int request_id, |
449 const ResourceRequest& request_data, | 477 const ResourceRequest& request_data, |
450 LoaderMap::iterator iter); | 478 LoaderMap::iterator iter); |
451 | 479 |
452 void BeginRequest(int request_id, | 480 void BeginRequest(int request_id, |
453 const ResourceRequest& request_data, | 481 const ResourceRequest& request_data, |
454 IPC::Message* sync_result, // only valid for sync | 482 IPC::Message* sync_result, // only valid for sync |
455 int route_id); // only valid for async | 483 int route_id, // only valid for async |
484 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, | |
485 mojom::URLLoaderClientPtr url_loader_client); | |
456 | 486 |
457 // Creates a ResourceHandler to be used by BeginRequest() for normal resource | 487 // Creates a ResourceHandler to be used by BeginRequest() for normal resource |
458 // loading. | 488 // loading. |
459 std::unique_ptr<ResourceHandler> CreateResourceHandler( | 489 std::unique_ptr<ResourceHandler> CreateResourceHandler( |
460 net::URLRequest* request, | 490 net::URLRequest* request, |
461 const ResourceRequest& request_data, | 491 const ResourceRequest& request_data, |
462 IPC::Message* sync_result, | 492 IPC::Message* sync_result, |
463 int route_id, | 493 int route_id, |
464 int process_type, | 494 int process_type, |
465 int child_id, | 495 int child_id, |
466 ResourceContext* resource_context); | 496 ResourceContext* resource_context, |
497 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, | |
498 mojom::URLLoaderClientPtr url_loader_client); | |
467 | 499 |
468 // Wraps |handler| in the standard resource handlers for normal resource | 500 // Wraps |handler| in the standard resource handlers for normal resource |
469 // loading and navigation requests. This adds MimeTypeResourceHandler and | 501 // loading and navigation requests. This adds MimeTypeResourceHandler and |
470 // ResourceThrottles. | 502 // ResourceThrottles. |
471 std::unique_ptr<ResourceHandler> AddStandardHandlers( | 503 std::unique_ptr<ResourceHandler> AddStandardHandlers( |
472 net::URLRequest* request, | 504 net::URLRequest* request, |
473 ResourceType resource_type, | 505 ResourceType resource_type, |
474 ResourceContext* resource_context, | 506 ResourceContext* resource_context, |
475 RequestContextType fetch_request_context_type, | 507 RequestContextType fetch_request_context_type, |
476 AppCacheService* appcache_service, | 508 AppCacheService* appcache_service, |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 // Allows tests to use a mock CertStore. If set, the CertStore must | 662 // Allows tests to use a mock CertStore. If set, the CertStore must |
631 // outlive this ResourceDispatcherHostImpl. | 663 // outlive this ResourceDispatcherHostImpl. |
632 CertStore* cert_store_for_testing_; | 664 CertStore* cert_store_for_testing_; |
633 | 665 |
634 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 666 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
635 }; | 667 }; |
636 | 668 |
637 } // namespace content | 669 } // namespace content |
638 | 670 |
639 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 671 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
OLD | NEW |