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 18 matching lines...) Expand all Loading... |
73 class ResourceMessageFilter; | 75 class ResourceMessageFilter; |
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; |
| 85 struct ResourceRequestCompletionStatus; |
| 86 struct ResourceResponseHead; |
83 | 87 |
84 // This class is responsible for notifying the IO thread (specifically, the | 88 // This class is responsible for notifying the IO thread (specifically, the |
85 // ResourceDispatcherHostImpl) of frame events. It has an interace for callers | 89 // ResourceDispatcherHostImpl) of frame events. It has an interace for callers |
86 // to use and also sends notifications on WebContentsObserver events. All | 90 // 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 | 91 // methods (static or class) will be called from the UI thread and post to the |
88 // IO thread. | 92 // IO thread. |
89 // TODO(csharrison): Add methods tracking visibility and audio changes, to | 93 // TODO(csharrison): Add methods tracking visibility and audio changes, to |
90 // propogate to the ResourceScheduler. | 94 // propogate to the ResourceScheduler. |
91 class LoaderIOThreadNotifier : public WebContentsObserver { | 95 class LoaderIOThreadNotifier : public WebContentsObserver { |
92 public: | 96 public: |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 void BeginNavigationRequest( | 315 void BeginNavigationRequest( |
312 ResourceContext* resource_context, | 316 ResourceContext* resource_context, |
313 const NavigationRequestInfo& info, | 317 const NavigationRequestInfo& info, |
314 NavigationURLLoaderImplCore* loader, | 318 NavigationURLLoaderImplCore* loader, |
315 ServiceWorkerNavigationHandleCore* service_worker_handle_core); | 319 ServiceWorkerNavigationHandleCore* service_worker_handle_core); |
316 | 320 |
317 // Turns on stale-while-revalidate support, regardless of command-line flags | 321 // Turns on stale-while-revalidate support, regardless of command-line flags |
318 // or experiment status. For unit tests only. | 322 // or experiment status. For unit tests only. |
319 void EnableStaleWhileRevalidateForTesting(); | 323 void EnableStaleWhileRevalidateForTesting(); |
320 | 324 |
| 325 // These functions are used when loading with mojo. |
| 326 // Called when loading a request with mojo. |
| 327 void OnRequestResourceWithMojo(int routing_id, |
| 328 int request_id, |
| 329 const ResourceRequest& request, |
| 330 std::unique_ptr<mojom::URLLoader> url_loader, |
| 331 mojom::URLLoaderClientPtr url_loader_client, |
| 332 ResourceMessageFilter* filter); |
| 333 |
| 334 // Sends |message| with mojo if it is possible and returns whether the message |
| 335 // is sent. |
| 336 bool SendWithMojoIfPossible(const IPC::Message& message, |
| 337 ResourceMessageFilter* filter); |
| 338 |
| 339 // Call |OnStartResponseBody| for the client associated with |id|. |
| 340 void OnStartLoadingResponseBodyWithMojo( |
| 341 const GlobalRequestID& id, |
| 342 mojo::ScopedDataPipeConsumerHandle response_body); |
| 343 |
| 344 // Add an uninitiated (i.e., resource loading is not yet started) loader in |
| 345 // order to keep it alive. |
| 346 void AddUninitiatedURLLoader(int child_id, |
| 347 std::unique_ptr<mojom::URLLoader> loader); |
| 348 // Returns an uninitiated URL loader whose raw pointer equals to |loader|. |
| 349 std::unique_ptr<mojom::URLLoader> TakeUninitiatedURLLoader( |
| 350 mojom::URLLoader* loader); |
| 351 |
321 private: | 352 private: |
322 friend class LoaderIOThreadNotifier; | 353 friend class LoaderIOThreadNotifier; |
323 friend class ResourceDispatcherHostTest; | 354 friend class ResourceDispatcherHostTest; |
| 355 class MojoHelper; |
324 | 356 |
325 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 357 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
326 TestBlockedRequestsProcessDies); | 358 TestBlockedRequestsProcessDies); |
327 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 359 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
328 CalculateApproximateMemoryCost); | 360 CalculateApproximateMemoryCost); |
329 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 361 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
330 DetachableResourceTimesOut); | 362 DetachableResourceTimesOut); |
331 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 363 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
332 TestProcessCancelDetachableTimesOut); | 364 TestProcessCancelDetachableTimesOut); |
333 FRIEND_TEST_ALL_PREFIXES(SitePerProcessIgnoreCertErrorsBrowserTest, | 365 FRIEND_TEST_ALL_PREFIXES(SitePerProcessIgnoreCertErrorsBrowserTest, |
(...skipping 30 matching lines...) Expand all Loading... |
364 | 396 |
365 // An init helper that runs on the IO thread. | 397 // An init helper that runs on the IO thread. |
366 void OnInit(); | 398 void OnInit(); |
367 | 399 |
368 // A shutdown helper that runs on the IO thread. | 400 // A shutdown helper that runs on the IO thread. |
369 void OnShutdown(); | 401 void OnShutdown(); |
370 | 402 |
371 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); | 403 void OnRenderFrameDeleted(const GlobalFrameRoutingId& global_routing_id); |
372 | 404 |
373 // Helper function for regular and download requests. | 405 // Helper function for regular and download requests. |
374 void BeginRequestInternal(std::unique_ptr<net::URLRequest> request, | 406 void BeginRequestInternal( |
375 std::unique_ptr<ResourceHandler> handler); | 407 std::unique_ptr<net::URLRequest> request, |
| 408 std::unique_ptr<ResourceHandler> handler, |
| 409 std::unique_ptr<mojom::URLLoader> url_loader = nullptr, |
| 410 mojom::URLLoaderClientPtr url_loader_client = nullptr); |
376 | 411 |
377 void StartLoading(ResourceRequestInfoImpl* info, | 412 void StartLoading(ResourceRequestInfoImpl* info, |
378 std::unique_ptr<ResourceLoader> loader); | 413 std::unique_ptr<ResourceLoader> loader); |
379 | 414 |
380 // We keep track of how much memory each request needs and how many requests | 415 // 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. | 416 // 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 | 417 // 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 | 418 // 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 | 419 // 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 | 420 // 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(); | 494 void UpdateLoadInfo(); |
460 | 495 |
461 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. | 496 // Resumes or cancels (if |cancel_requests| is true) any blocked requests. |
462 void ProcessBlockedRequestsForRoute( | 497 void ProcessBlockedRequestsForRoute( |
463 const GlobalFrameRoutingId& global_routing_id, | 498 const GlobalFrameRoutingId& global_routing_id, |
464 bool cancel_requests); | 499 bool cancel_requests); |
465 | 500 |
466 void OnRequestResource(int routing_id, | 501 void OnRequestResource(int routing_id, |
467 int request_id, | 502 int request_id, |
468 const ResourceRequest& request_data); | 503 const ResourceRequest& request_data); |
| 504 |
| 505 void OnRequestResourceInternal(int routing_id, |
| 506 int request_id, |
| 507 const ResourceRequest& request_data, |
| 508 std::unique_ptr<mojom::URLLoader> url_loader, |
| 509 mojom::URLLoaderClientPtr url_loader_client); |
| 510 |
469 void OnSyncLoad(int request_id, | 511 void OnSyncLoad(int request_id, |
470 const ResourceRequest& request_data, | 512 const ResourceRequest& request_data, |
471 IPC::Message* sync_result); | 513 IPC::Message* sync_result); |
472 | 514 |
473 bool IsRequestIDInUse(const GlobalRequestID& id) const; | 515 bool IsRequestIDInUse(const GlobalRequestID& id) const; |
474 | 516 |
475 // Update the ResourceRequestInfo and internal maps when a request is | 517 // Update the ResourceRequestInfo and internal maps when a request is |
476 // transferred from one process to another. | 518 // transferred from one process to another. |
477 void UpdateRequestForTransfer(int child_id, | 519 void UpdateRequestForTransfer(int child_id, |
478 int route_id, | 520 int route_id, |
479 int request_id, | 521 int request_id, |
480 const ResourceRequest& request_data, | 522 const ResourceRequest& request_data, |
481 LoaderMap::iterator iter); | 523 LoaderMap::iterator iter); |
482 | 524 |
483 void BeginRequest(int request_id, | 525 void BeginRequest(int request_id, |
484 const ResourceRequest& request_data, | 526 const ResourceRequest& request_data, |
485 IPC::Message* sync_result, // only valid for sync | 527 IPC::Message* sync_result, // only valid for sync |
486 int route_id); // only valid for async | 528 int route_id, // only valid for async |
| 529 std::unique_ptr<mojom::URLLoader> url_loader = nullptr, |
| 530 mojom::URLLoaderClientPtr url_loader_client = nullptr); |
487 | 531 |
488 // Creates a ResourceHandler to be used by BeginRequest() for normal resource | 532 // Creates a ResourceHandler to be used by BeginRequest() for normal resource |
489 // loading. | 533 // loading. |
490 std::unique_ptr<ResourceHandler> CreateResourceHandler( | 534 std::unique_ptr<ResourceHandler> CreateResourceHandler( |
491 net::URLRequest* request, | 535 net::URLRequest* request, |
492 const ResourceRequest& request_data, | 536 const ResourceRequest& request_data, |
493 IPC::Message* sync_result, | 537 IPC::Message* sync_result, |
494 int route_id, | 538 int route_id, |
495 int process_type, | 539 int process_type, |
496 int child_id, | 540 int child_id, |
497 ResourceContext* resource_context); | 541 ResourceContext* resource_context, |
| 542 bool using_mojo); |
498 | 543 |
499 // Wraps |handler| in the standard resource handlers for normal resource | 544 // Wraps |handler| in the standard resource handlers for normal resource |
500 // loading and navigation requests. This adds MimeTypeResourceHandler and | 545 // loading and navigation requests. This adds MimeTypeResourceHandler and |
501 // ResourceThrottles. | 546 // ResourceThrottles. |
502 std::unique_ptr<ResourceHandler> AddStandardHandlers( | 547 std::unique_ptr<ResourceHandler> AddStandardHandlers( |
503 net::URLRequest* request, | 548 net::URLRequest* request, |
504 ResourceType resource_type, | 549 ResourceType resource_type, |
505 ResourceContext* resource_context, | 550 ResourceContext* resource_context, |
506 AppCacheService* appcache_service, | 551 AppCacheService* appcache_service, |
507 int child_id, | 552 int child_id, |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 typedef std::map<GlobalRequestID, | 701 typedef std::map<GlobalRequestID, |
657 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; | 702 base::ObserverList<ResourceMessageDelegate>*> DelegateMap; |
658 DelegateMap delegate_map_; | 703 DelegateMap delegate_map_; |
659 | 704 |
660 std::unique_ptr<ResourceScheduler> scheduler_; | 705 std::unique_ptr<ResourceScheduler> scheduler_; |
661 | 706 |
662 // Allows tests to use a mock CertStore. If set, the CertStore must | 707 // Allows tests to use a mock CertStore. If set, the CertStore must |
663 // outlive this ResourceDispatcherHostImpl. | 708 // outlive this ResourceDispatcherHostImpl. |
664 CertStore* cert_store_for_testing_; | 709 CertStore* cert_store_for_testing_; |
665 | 710 |
| 711 std::unique_ptr<MojoHelper> mojo_helper_; |
| 712 |
666 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 713 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
667 }; | 714 }; |
668 | 715 |
669 } // namespace content | 716 } // namespace content |
670 | 717 |
671 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 718 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
OLD | NEW |