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" |
| 46 #include "mojo/public/cpp/system/data_pipe.h" |
45 #include "net/base/request_priority.h" | 47 #include "net/base/request_priority.h" |
46 #include "net/cookies/canonical_cookie.h" | 48 #include "net/cookies/canonical_cookie.h" |
47 #include "net/url_request/url_request.h" | 49 #include "net/url_request/url_request.h" |
48 | 50 |
49 class ResourceHandler; | 51 class ResourceHandler; |
50 | 52 |
51 namespace base { | 53 namespace base { |
52 class FilePath; | 54 class FilePath; |
53 } | 55 } |
54 | 56 |
(...skipping 19 matching lines...) Expand all Loading... |
74 class ResourceRequestInfoImpl; | 76 class ResourceRequestInfoImpl; |
75 class SaveFileManager; | 77 class SaveFileManager; |
76 class ServiceWorkerNavigationHandleCore; | 78 class ServiceWorkerNavigationHandleCore; |
77 class WebContentsImpl; | 79 class WebContentsImpl; |
78 struct CommonNavigationParams; | 80 struct CommonNavigationParams; |
79 struct DownloadSaveInfo; | 81 struct DownloadSaveInfo; |
80 struct NavigationRequestInfo; | 82 struct NavigationRequestInfo; |
81 struct Referrer; | 83 struct Referrer; |
82 struct ResourceRequest; | 84 struct ResourceRequest; |
83 | 85 |
| 86 namespace mojom { |
| 87 class URLLoader; |
| 88 } // namespace mojom |
| 89 |
84 // This class is responsible for notifying the IO thread (specifically, the | 90 // This class is responsible for notifying the IO thread (specifically, the |
85 // ResourceDispatcherHostImpl) of frame events. It has an interace for callers | 91 // ResourceDispatcherHostImpl) of frame events. It has an interace for callers |
86 // to use and also sends notifications on WebContentsObserver events. All | 92 // 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 | 93 // methods (static or class) will be called from the UI thread and post to the |
88 // IO thread. | 94 // IO thread. |
89 // TODO(csharrison): Add methods tracking visibility and audio changes, to | 95 // TODO(csharrison): Add methods tracking visibility and audio changes, to |
90 // propogate to the ResourceScheduler. | 96 // propogate to the ResourceScheduler. |
91 class LoaderIOThreadNotifier : public WebContentsObserver { | 97 class LoaderIOThreadNotifier : public WebContentsObserver { |
92 public: | 98 public: |
93 explicit LoaderIOThreadNotifier(WebContents* web_contents); | 99 explicit LoaderIOThreadNotifier(WebContents* web_contents); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 void BeginNavigationRequest( | 317 void BeginNavigationRequest( |
312 ResourceContext* resource_context, | 318 ResourceContext* resource_context, |
313 const NavigationRequestInfo& info, | 319 const NavigationRequestInfo& info, |
314 NavigationURLLoaderImplCore* loader, | 320 NavigationURLLoaderImplCore* loader, |
315 ServiceWorkerNavigationHandleCore* service_worker_handle_core); | 321 ServiceWorkerNavigationHandleCore* service_worker_handle_core); |
316 | 322 |
317 // Turns on stale-while-revalidate support, regardless of command-line flags | 323 // Turns on stale-while-revalidate support, regardless of command-line flags |
318 // or experiment status. For unit tests only. | 324 // or experiment status. For unit tests only. |
319 void EnableStaleWhileRevalidateForTesting(); | 325 void EnableStaleWhileRevalidateForTesting(); |
320 | 326 |
| 327 // These functions are used when loading with mojo. |
| 328 // Called when loading a request with mojo. |
| 329 void OnRequestResourceWithMojo(int routing_id, |
| 330 int request_id, |
| 331 const ResourceRequest& request, |
| 332 std::unique_ptr<mojom::URLLoader> url_loader, |
| 333 mojom::URLLoaderClientPtr url_loader_client, |
| 334 ResourceMessageFilter* filter); |
| 335 |
| 336 // Add an unstarted (i.e., resource loading is not yet started) loader in |
| 337 // order to keep it alive. |
| 338 void AddUnstartedURLLoader(int child_id, |
| 339 std::unique_ptr<mojom::URLLoader> loader); |
| 340 // Returns an unstarted URL loader whose raw pointer equals to |loader|. |
| 341 std::unique_ptr<mojom::URLLoader> TakeUnstartedURLLoader( |
| 342 mojom::URLLoader* loader); |
| 343 |
321 private: | 344 private: |
322 friend class LoaderIOThreadNotifier; | 345 friend class LoaderIOThreadNotifier; |
323 friend class ResourceDispatcherHostTest; | 346 friend class ResourceDispatcherHostTest; |
| 347 class MojoHelper; |
324 | 348 |
325 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 349 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
326 TestBlockedRequestsProcessDies); | 350 TestBlockedRequestsProcessDies); |
327 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 351 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
328 CalculateApproximateMemoryCost); | 352 CalculateApproximateMemoryCost); |
329 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 353 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
330 DetachableResourceTimesOut); | 354 DetachableResourceTimesOut); |
331 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 355 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
332 TestProcessCancelDetachableTimesOut); | 356 TestProcessCancelDetachableTimesOut); |
333 FRIEND_TEST_ALL_PREFIXES(SitePerProcessIgnoreCertErrorsBrowserTest, | 357 FRIEND_TEST_ALL_PREFIXES(SitePerProcessIgnoreCertErrorsBrowserTest, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 void UpdateLoadInfo(); | 483 void UpdateLoadInfo(); |
460 | 484 |
461 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. | 485 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. |
462 void ProcessBlockedRequestsForRoute( | 486 void ProcessBlockedRequestsForRoute( |
463 const GlobalFrameRoutingId& global_routing_id, | 487 const GlobalFrameRoutingId& global_routing_id, |
464 bool cancel_requests); | 488 bool cancel_requests); |
465 | 489 |
466 void OnRequestResource(int routing_id, | 490 void OnRequestResource(int routing_id, |
467 int request_id, | 491 int request_id, |
468 const ResourceRequest& request_data); | 492 const ResourceRequest& request_data); |
| 493 |
| 494 void OnRequestResourceInternal(int routing_id, |
| 495 int request_id, |
| 496 const ResourceRequest& request_data, |
| 497 std::unique_ptr<mojom::URLLoader> url_loader, |
| 498 mojom::URLLoaderClientPtr url_loader_client); |
| 499 |
469 void OnSyncLoad(int request_id, | 500 void OnSyncLoad(int request_id, |
470 const ResourceRequest& request_data, | 501 const ResourceRequest& request_data, |
471 IPC::Message* sync_result); | 502 IPC::Message* sync_result); |
472 | 503 |
473 bool IsRequestIDInUse(const GlobalRequestID& id) const; | 504 bool IsRequestIDInUse(const GlobalRequestID& id) const; |
474 | 505 |
475 // Update the ResourceRequestInfo and internal maps when a request is | 506 // Update the ResourceRequestInfo and internal maps when a request is |
476 // transferred from one process to another. | 507 // transferred from one process to another. |
477 void UpdateRequestForTransfer(int child_id, | 508 void UpdateRequestForTransfer(int child_id, |
478 int route_id, | 509 int route_id, |
479 int request_id, | 510 int request_id, |
480 const ResourceRequest& request_data, | 511 const ResourceRequest& request_data, |
481 LoaderMap::iterator iter); | 512 LoaderMap::iterator iter); |
482 | 513 |
483 void BeginRequest(int request_id, | 514 void BeginRequest(int request_id, |
484 const ResourceRequest& request_data, | 515 const ResourceRequest& request_data, |
485 IPC::Message* sync_result, // only valid for sync | 516 IPC::Message* sync_result, // only valid for sync |
486 int route_id); // only valid for async | 517 int route_id, // only valid for async |
| 518 std::unique_ptr<mojom::URLLoader> url_loader, |
| 519 mojom::URLLoaderClientPtr url_loader_client); |
487 | 520 |
488 // Creates a ResourceHandler to be used by BeginRequest() for normal resource | 521 // Creates a ResourceHandler to be used by BeginRequest() for normal resource |
489 // loading. | 522 // loading. |
490 std::unique_ptr<ResourceHandler> CreateResourceHandler( | 523 std::unique_ptr<ResourceHandler> CreateResourceHandler( |
491 net::URLRequest* request, | 524 net::URLRequest* request, |
492 const ResourceRequest& request_data, | 525 const ResourceRequest& request_data, |
493 IPC::Message* sync_result, | 526 IPC::Message* sync_result, |
494 int route_id, | 527 int route_id, |
495 int process_type, | 528 int process_type, |
496 int child_id, | 529 int child_id, |
497 ResourceContext* resource_context); | 530 ResourceContext* resource_context, |
| 531 std::unique_ptr<mojom::URLLoader> url_loader, |
| 532 mojom::URLLoaderClientPtr url_loader_client); |
498 | 533 |
499 // Wraps |handler| in the standard resource handlers for normal resource | 534 // Wraps |handler| in the standard resource handlers for normal resource |
500 // loading and navigation requests. This adds MimeTypeResourceHandler and | 535 // loading and navigation requests. This adds MimeTypeResourceHandler and |
501 // ResourceThrottles. | 536 // ResourceThrottles. |
502 std::unique_ptr<ResourceHandler> AddStandardHandlers( | 537 std::unique_ptr<ResourceHandler> AddStandardHandlers( |
503 net::URLRequest* request, | 538 net::URLRequest* request, |
504 ResourceType resource_type, | 539 ResourceType resource_type, |
505 ResourceContext* resource_context, | 540 ResourceContext* resource_context, |
506 AppCacheService* appcache_service, | 541 AppCacheService* appcache_service, |
507 int child_id, | 542 int child_id, |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 typedef std::map<GlobalRequestID, | 691 typedef std::map<GlobalRequestID, |
657 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; | 692 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; |
658 DelegateMap delegate_map_; | 693 DelegateMap delegate_map_; |
659 | 694 |
660 std::unique_ptr<ResourceScheduler> scheduler_; | 695 std::unique_ptr<ResourceScheduler> scheduler_; |
661 | 696 |
662 // Allows tests to use a mock CertStore. If set, the CertStore must | 697 // Allows tests to use a mock CertStore. If set, the CertStore must |
663 // outlive this ResourceDispatcherHostImpl. | 698 // outlive this ResourceDispatcherHostImpl. |
664 CertStore* cert_store_for_testing_; | 699 CertStore* cert_store_for_testing_; |
665 | 700 |
| 701 // |unstarted_url_loader_| is a set of mojom::URLLoaders that are not yet |
| 702 // started. |
| 703 std::map<mojom::URLLoader*, std::pair<int, std::unique_ptr<mojom::URLLoader>>> |
| 704 unstarted_url_loaders_; |
| 705 |
666 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 706 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
667 }; | 707 }; |
668 | 708 |
669 } // namespace content | 709 } // namespace content |
670 | 710 |
671 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 711 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
OLD | NEW |