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 // Called when loading a request with mojo. |
| 326 void OnRequestResourceWithMojo(int routing_id, |
| 327 int request_id, |
| 328 const ResourceRequest& request, |
| 329 std::unique_ptr<mojom::URLLoader> loader, |
| 330 mojom::URLLoaderClientPtr client, |
| 331 ResourceMessageFilter* filter); |
| 332 |
| 333 // Sends |message| with mojo if it is possible and returns whether the message |
| 334 // is sent. |
| 335 bool SendWithMojoIfPossible(const IPC::Message& message, |
| 336 ResourceMessageFilter* filter); |
| 337 // Add an uninitiated (i.e., resource loading is not yet started) loader in |
| 338 // order to keep it alive. |
| 339 void AddUninitiatedURLLoader(int child_id, |
| 340 std::unique_ptr<mojom::URLLoader> loader); |
| 341 // Returns an uninitiated URL loader whose raw pointer equals to |loader|. |
| 342 std::unique_ptr<mojom::URLLoader> TakeUninitiatedURLLoader( |
| 343 mojom::URLLoader* loader); |
| 344 |
321 private: | 345 private: |
322 friend class LoaderIOThreadNotifier; | 346 friend class LoaderIOThreadNotifier; |
323 friend class ResourceDispatcherHostTest; | 347 friend class ResourceDispatcherHostTest; |
| 348 class MojoHelper; |
324 | 349 |
325 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 350 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
326 TestBlockedRequestsProcessDies); | 351 TestBlockedRequestsProcessDies); |
327 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 352 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
328 CalculateApproximateMemoryCost); | 353 CalculateApproximateMemoryCost); |
329 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 354 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
330 DetachableResourceTimesOut); | 355 DetachableResourceTimesOut); |
331 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 356 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
332 TestProcessCancelDetachableTimesOut); | 357 TestProcessCancelDetachableTimesOut); |
333 FRIEND_TEST_ALL_PREFIXES(SitePerProcessIgnoreCertErrorsBrowserTest, | 358 FRIEND_TEST_ALL_PREFIXES(SitePerProcessIgnoreCertErrorsBrowserTest, |
(...skipping 30 matching lines...) Expand all Loading... |
364 | 389 |
365 // An init helper that runs on the IO thread. | 390 // An init helper that runs on the IO thread. |
366 void OnInit(); | 391 void OnInit(); |
367 | 392 |
368 // A shutdown helper that runs on the IO thread. | 393 // A shutdown helper that runs on the IO thread. |
369 void OnShutdown(); | 394 void OnShutdown(); |
370 | 395 |
371 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); | 396 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); |
372 | 397 |
373 // Helper function for regular and download requests. | 398 // Helper function for regular and download requests. |
374 void BeginRequestInternal(std::unique_ptr<net::URLRequest> request, | 399 void BeginRequestInternal( |
375 std::unique_ptr<ResourceHandler> handler); | 400 std::unique_ptr<net::URLRequest> request, |
| 401 std::unique_ptr<ResourceHandler> handler, |
| 402 std::unique_ptr<mojom::URLLoader> url_loader = nullptr, |
| 403 mojom::URLLoaderClientPtr client = nullptr); |
376 | 404 |
377 void StartLoading(ResourceRequestInfoImpl* info, | 405 void StartLoading(ResourceRequestInfoImpl* info, |
378 std::unique_ptr<ResourceLoader> loader); | 406 std::unique_ptr<ResourceLoader> loader); |
379 | 407 |
380 // We keep track of how much memory each request needs and how many requests | 408 // 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. | 409 // 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 | 410 // 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 | 411 // 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 | 412 // 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 | 413 // global limit that applies for the browser process. Each render is allowed |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 void UpdateLoadInfo(); | 487 void UpdateLoadInfo(); |
460 | 488 |
461 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. | 489 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. |
462 void ProcessBlockedRequestsForRoute( | 490 void ProcessBlockedRequestsForRoute( |
463 const GlobalFrameRoutingId& global_routing_id, | 491 const GlobalFrameRoutingId& global_routing_id, |
464 bool cancel_requests); | 492 bool cancel_requests); |
465 | 493 |
466 void OnRequestResource(int routing_id, | 494 void OnRequestResource(int routing_id, |
467 int request_id, | 495 int request_id, |
468 const ResourceRequest& request_data); | 496 const ResourceRequest& request_data); |
| 497 |
| 498 void OnRequestResourceInternal(int routing_id, |
| 499 int request_id, |
| 500 const ResourceRequest& request_data, |
| 501 std::unique_ptr<mojom::URLLoader> loader, |
| 502 mojom::URLLoaderClientPtr client); |
| 503 |
469 void OnSyncLoad(int request_id, | 504 void OnSyncLoad(int request_id, |
470 const ResourceRequest& request_data, | 505 const ResourceRequest& request_data, |
471 IPC::Message* sync_result); | 506 IPC::Message* sync_result); |
472 | 507 |
473 bool IsRequestIDInUse(const GlobalRequestID& id) const; | 508 bool IsRequestIDInUse(const GlobalRequestID& id) const; |
474 | 509 |
475 // Update the ResourceRequestInfo and internal maps when a request is | 510 // Update the ResourceRequestInfo and internal maps when a request is |
476 // transferred from one process to another. | 511 // transferred from one process to another. |
477 void UpdateRequestForTransfer(int child_id, | 512 void UpdateRequestForTransfer(int child_id, |
478 int route_id, | 513 int route_id, |
479 int request_id, | 514 int request_id, |
480 const ResourceRequest& request_data, | 515 const ResourceRequest& request_data, |
481 LoaderMap::iterator iter); | 516 LoaderMap::iterator iter); |
482 | 517 |
483 void BeginRequest(int request_id, | 518 void BeginRequest(int request_id, |
484 const ResourceRequest& request_data, | 519 const ResourceRequest& request_data, |
485 IPC::Message* sync_result, // only valid for sync | 520 IPC::Message* sync_result, // only valid for sync |
486 int route_id); // only valid for async | 521 int route_id, // only valid for async |
| 522 std::unique_ptr<mojom::URLLoader> url_loader = nullptr, |
| 523 mojom::URLLoaderClientPtr client = nullptr); |
487 | 524 |
488 // Creates a ResourceHandler to be used by BeginRequest() for normal resource | 525 // Creates a ResourceHandler to be used by BeginRequest() for normal resource |
489 // loading. | 526 // loading. |
490 std::unique_ptr<ResourceHandler> CreateResourceHandler( | 527 std::unique_ptr<ResourceHandler> CreateResourceHandler( |
491 net::URLRequest* request, | 528 net::URLRequest* request, |
492 const ResourceRequest& request_data, | 529 const ResourceRequest& request_data, |
493 IPC::Message* sync_result, | 530 IPC::Message* sync_result, |
494 int route_id, | 531 int route_id, |
495 int process_type, | 532 int process_type, |
496 int child_id, | 533 int child_id, |
497 ResourceContext* resource_context); | 534 ResourceContext* resource_context, |
| 535 bool using_mojo); |
498 | 536 |
499 // Wraps |handler| in the standard resource handlers for normal resource | 537 // Wraps |handler| in the standard resource handlers for normal resource |
500 // loading and navigation requests. This adds MimeTypeResourceHandler and | 538 // loading and navigation requests. This adds MimeTypeResourceHandler and |
501 // ResourceThrottles. | 539 // ResourceThrottles. |
502 std::unique_ptr<ResourceHandler> AddStandardHandlers( | 540 std::unique_ptr<ResourceHandler> AddStandardHandlers( |
503 net::URLRequest* request, | 541 net::URLRequest* request, |
504 ResourceType resource_type, | 542 ResourceType resource_type, |
505 ResourceContext* resource_context, | 543 ResourceContext* resource_context, |
506 AppCacheService* appcache_service, | 544 AppCacheService* appcache_service, |
507 int child_id, | 545 int child_id, |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 typedef std::map<GlobalRequestID, | 694 typedef std::map<GlobalRequestID, |
657 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; | 695 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; |
658 DelegateMap delegate_map_; | 696 DelegateMap delegate_map_; |
659 | 697 |
660 std::unique_ptr<ResourceScheduler> scheduler_; | 698 std::unique_ptr<ResourceScheduler> scheduler_; |
661 | 699 |
662 // Allows tests to use a mock CertStore. If set, the CertStore must | 700 // Allows tests to use a mock CertStore. If set, the CertStore must |
663 // outlive this ResourceDispatcherHostImpl. | 701 // outlive this ResourceDispatcherHostImpl. |
664 CertStore* cert_store_for_testing_; | 702 CertStore* cert_store_for_testing_; |
665 | 703 |
| 704 std::unique_ptr<MojoHelper> mojo_helper_; |
| 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 |