| 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/callback_forward.h" |
| 22 #include "base/gtest_prod_util.h" | 23 #include "base/gtest_prod_util.h" |
| 23 #include "base/macros.h" | 24 #include "base/macros.h" |
| 25 #include "base/memory/ref_counted.h" |
| 24 #include "base/observer_list.h" | 26 #include "base/observer_list.h" |
| 25 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 26 #include "base/timer/timer.h" | 28 #include "base/timer/timer.h" |
| 27 #include "content/browser/download/save_types.h" | 29 #include "content/browser/download/save_types.h" |
| 28 #include "content/browser/loader/global_routing_id.h" | 30 #include "content/browser/loader/global_routing_id.h" |
| 29 #include "content/browser/loader/resource_loader.h" | 31 #include "content/browser/loader/resource_loader.h" |
| 30 #include "content/browser/loader/resource_loader_delegate.h" | 32 #include "content/browser/loader/resource_loader_delegate.h" |
| 31 #include "content/browser/loader/resource_scheduler.h" | 33 #include "content/browser/loader/resource_scheduler.h" |
| 32 #include "content/common/content_export.h" | 34 #include "content/common/content_export.h" |
| 33 #include "content/common/url_loader.mojom.h" | 35 #include "content/common/url_loader.mojom.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 class URLLoader; | 79 class URLLoader; |
| 78 } // namespace mojom | 80 } // namespace mojom |
| 79 | 81 |
| 80 using CreateDownloadHandlerIntercept = | 82 using CreateDownloadHandlerIntercept = |
| 81 base::Callback<std::unique_ptr<ResourceHandler>(net::URLRequest*)>; | 83 base::Callback<std::unique_ptr<ResourceHandler>(net::URLRequest*)>; |
| 82 | 84 |
| 83 class CONTENT_EXPORT ResourceDispatcherHostImpl | 85 class CONTENT_EXPORT ResourceDispatcherHostImpl |
| 84 : public ResourceDispatcherHost, | 86 : public ResourceDispatcherHost, |
| 85 public ResourceLoaderDelegate { | 87 public ResourceLoaderDelegate { |
| 86 public: | 88 public: |
| 89 // Used to handle the result of SyncLoad IPC. |result| is null if it's |
| 90 // unavailable due to an error. |
| 91 using SyncLoadResultCallback = |
| 92 base::Callback<void(const SyncLoadResult* result)>; |
| 93 |
| 87 // This constructor should be used if we want downloads to work correctly. | 94 // This constructor should be used if we want downloads to work correctly. |
| 88 // TODO(ananta) | 95 // TODO(ananta) |
| 89 // Work on moving creation of download handlers out of | 96 // Work on moving creation of download handlers out of |
| 90 // ResourceDispatcherHostImpl. | 97 // ResourceDispatcherHostImpl. |
| 91 ResourceDispatcherHostImpl( | 98 ResourceDispatcherHostImpl( |
| 92 CreateDownloadHandlerIntercept download_handler_intercept); | 99 CreateDownloadHandlerIntercept download_handler_intercept); |
| 93 ResourceDispatcherHostImpl(); | 100 ResourceDispatcherHostImpl(); |
| 94 ~ResourceDispatcherHostImpl() override; | 101 ~ResourceDispatcherHostImpl() override; |
| 95 | 102 |
| 96 // Returns the current ResourceDispatcherHostImpl. May return NULL if it | 103 // Returns the current ResourceDispatcherHostImpl. May return NULL if it |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 bool IsRequestIDInUse(const GlobalRequestID& id) const; | 532 bool IsRequestIDInUse(const GlobalRequestID& id) const; |
| 526 | 533 |
| 527 // Update the ResourceRequestInfo and internal maps when a request is | 534 // Update the ResourceRequestInfo and internal maps when a request is |
| 528 // transferred from one process to another. | 535 // transferred from one process to another. |
| 529 void UpdateRequestForTransfer(int child_id, | 536 void UpdateRequestForTransfer(int child_id, |
| 530 int route_id, | 537 int route_id, |
| 531 int request_id, | 538 int request_id, |
| 532 const ResourceRequest& request_data, | 539 const ResourceRequest& request_data, |
| 533 LoaderMap::iterator iter); | 540 LoaderMap::iterator iter); |
| 534 | 541 |
| 535 void BeginRequest(int request_id, | 542 void BeginRequest( |
| 536 const ResourceRequest& request_data, | 543 int request_id, |
| 537 IPC::Message* sync_result, // only valid for sync | 544 const ResourceRequest& request_data, |
| 538 int route_id, // only valid for async | 545 const SyncLoadResultCallback& sync_result_handler, // only valid for sync |
| 539 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, | 546 int route_id, // only valid for async |
| 540 mojom::URLLoaderClientPtr url_loader_client); | 547 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 548 mojom::URLLoaderClientPtr url_loader_client); |
| 541 | 549 |
| 542 // There are requests which need decisions to be made like the following: | 550 // There are requests which need decisions to be made like the following: |
| 543 // Whether the presence of certain HTTP headers like the Origin header are | 551 // Whether the presence of certain HTTP headers like the Origin header are |
| 544 // valid, etc. These requests may need to be aborted based on these | 552 // valid, etc. These requests may need to be aborted based on these |
| 545 // decisions which could be time consuming. We allow for these decisions | 553 // decisions which could be time consuming. We allow for these decisions |
| 546 // to be made asynchronously. The request proceeds when we hear back from | 554 // to be made asynchronously. The request proceeds when we hear back from |
| 547 // the interceptors about whether to continue or not. | 555 // the interceptors about whether to continue or not. |
| 548 // The |continue_request| parameter in the function indicates whether the | 556 // The |continue_request| parameter in the function indicates whether the |
| 549 // request should be continued or aborted. The |error_code| parameter is set | 557 // request should be continued or aborted. The |error_code| parameter is set |
| 550 // if |continue_request| is false. | 558 // if |continue_request| is false. |
| 551 void ContinuePendingBeginRequest( | 559 void ContinuePendingBeginRequest( |
| 552 int request_id, | 560 int request_id, |
| 553 const ResourceRequest& request_data, | 561 const ResourceRequest& request_data, |
| 554 IPC::Message* sync_result, // only valid for sync | 562 const SyncLoadResultCallback& sync_result_handler, // only valid for sync |
| 555 int route_id, | 563 int route_id, |
| 556 const net::HttpRequestHeaders& headers, | 564 const net::HttpRequestHeaders& headers, |
| 557 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, | 565 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 558 mojom::URLLoaderClientPtr url_loader_client, | 566 mojom::URLLoaderClientPtr url_loader_client, |
| 559 bool continue_request, | 567 bool continue_request, |
| 560 int error_code); | 568 int error_code); |
| 561 | 569 |
| 562 // Creates a ResourceHandler to be used by BeginRequest() for normal resource | 570 // Creates a ResourceHandler to be used by BeginRequest() for normal resource |
| 563 // loading. | 571 // loading. |
| 564 std::unique_ptr<ResourceHandler> CreateResourceHandler( | 572 std::unique_ptr<ResourceHandler> CreateResourceHandler( |
| 565 net::URLRequest* request, | 573 net::URLRequest* request, |
| 566 const ResourceRequest& request_data, | 574 const ResourceRequest& request_data, |
| 567 IPC::Message* sync_result, | 575 const SyncLoadResultCallback& sync_result_handler, |
| 568 int route_id, | 576 int route_id, |
| 569 int process_type, | 577 int process_type, |
| 570 int child_id, | 578 int child_id, |
| 571 ResourceContext* resource_context, | 579 ResourceContext* resource_context, |
| 572 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, | 580 mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
| 573 mojom::URLLoaderClientPtr url_loader_client); | 581 mojom::URLLoaderClientPtr url_loader_client); |
| 574 | 582 |
| 575 // Wraps |handler| in the standard resource handlers for normal resource | 583 // Wraps |handler| in the standard resource handlers for normal resource |
| 576 // loading and navigation requests. This adds MimeTypeResourceHandler and | 584 // loading and navigation requests. This adds MimeTypeResourceHandler and |
| 577 // ResourceThrottles. | 585 // ResourceThrottles. |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 | 757 |
| 750 // Points to the registered download handler intercept. | 758 // Points to the registered download handler intercept. |
| 751 CreateDownloadHandlerIntercept create_download_handler_intercept_; | 759 CreateDownloadHandlerIntercept create_download_handler_intercept_; |
| 752 | 760 |
| 753 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 761 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
| 754 }; | 762 }; |
| 755 | 763 |
| 756 } // namespace content | 764 } // namespace content |
| 757 | 765 |
| 758 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 766 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
| OLD | NEW |