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/callback_forward.h" |
23 #include "base/gtest_prod_util.h" | 23 #include "base/gtest_prod_util.h" |
24 #include "base/macros.h" | 24 #include "base/macros.h" |
25 #include "base/memory/ref_counted.h" | 25 #include "base/memory/ref_counted.h" |
26 #include "base/observer_list.h" | 26 #include "base/observer_list.h" |
| 27 #include "base/single_thread_task_runner.h" |
27 #include "base/time/time.h" | 28 #include "base/time/time.h" |
28 #include "content/browser/loader/global_routing_id.h" | 29 #include "content/browser/loader/global_routing_id.h" |
29 #include "content/browser/loader/resource_loader_delegate.h" | 30 #include "content/browser/loader/resource_loader_delegate.h" |
30 #include "content/common/content_export.h" | 31 #include "content/common/content_export.h" |
31 #include "content/common/url_loader.mojom.h" | 32 #include "content/common/url_loader.mojom.h" |
32 #include "content/public/browser/global_request_id.h" | 33 #include "content/public/browser/global_request_id.h" |
33 #include "content/public/browser/resource_dispatcher_host.h" | 34 #include "content/public/browser/resource_dispatcher_host.h" |
34 #include "content/public/browser/resource_request_info.h" | 35 #include "content/public/browser/resource_request_info.h" |
35 #include "content/public/common/previews_state.h" | 36 #include "content/public/common/previews_state.h" |
36 #include "content/public/common/request_context_type.h" | 37 #include "content/public/common/request_context_type.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // Used to handle the result of SyncLoad IPC. |result| is null if it's | 85 // Used to handle the result of SyncLoad IPC. |result| is null if it's |
85 // unavailable due to an error. | 86 // unavailable due to an error. |
86 using SyncLoadResultCallback = | 87 using SyncLoadResultCallback = |
87 base::Callback<void(const SyncLoadResult* result)>; | 88 base::Callback<void(const SyncLoadResult* result)>; |
88 | 89 |
89 // This constructor should be used if we want downloads to work correctly. | 90 // This constructor should be used if we want downloads to work correctly. |
90 // TODO(ananta) | 91 // TODO(ananta) |
91 // Work on moving creation of download handlers out of | 92 // Work on moving creation of download handlers out of |
92 // ResourceDispatcherHostImpl. | 93 // ResourceDispatcherHostImpl. |
93 ResourceDispatcherHostImpl( | 94 ResourceDispatcherHostImpl( |
94 CreateDownloadHandlerIntercept download_handler_intercept); | 95 CreateDownloadHandlerIntercept download_handler_intercept, |
| 96 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread_runner, |
| 97 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_runner); |
95 ResourceDispatcherHostImpl(); | 98 ResourceDispatcherHostImpl(); |
96 ~ResourceDispatcherHostImpl() override; | 99 ~ResourceDispatcherHostImpl() override; |
97 | 100 |
98 // Returns the current ResourceDispatcherHostImpl. May return NULL if it | 101 // Returns the current ResourceDispatcherHostImpl. May return NULL if it |
99 // hasn't been created yet. | 102 // hasn't been created yet. |
100 static ResourceDispatcherHostImpl* Get(); | 103 static ResourceDispatcherHostImpl* Get(); |
101 | 104 |
102 // ResourceDispatcherHost implementation: | 105 // ResourceDispatcherHost implementation: |
103 void SetDelegate(ResourceDispatcherHostDelegate* delegate) override; | 106 void SetDelegate(ResourceDispatcherHostDelegate* delegate) override; |
104 void SetAllowCrossOriginAuthPrompt(bool value) override; | 107 void SetAllowCrossOriginAuthPrompt(bool value) override; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 // Creates a new request ID for browser initiated requests. See the comments | 324 // Creates a new request ID for browser initiated requests. See the comments |
322 // of |request_id_| for the details. Must be called on the IO thread. | 325 // of |request_id_| for the details. Must be called on the IO thread. |
323 int MakeRequestID(); | 326 int MakeRequestID(); |
324 | 327 |
325 // Cancels a request as requested by a renderer. This function is called when | 328 // Cancels a request as requested by a renderer. This function is called when |
326 // a mojo connection is lost. | 329 // a mojo connection is lost. |
327 // Note that this cancel is subtly different from the other CancelRequest | 330 // Note that this cancel is subtly different from the other CancelRequest |
328 // methods in this file, which also tear down the loader. | 331 // methods in this file, which also tear down the loader. |
329 void CancelRequestFromRenderer(GlobalRequestID request_id); | 332 void CancelRequestFromRenderer(GlobalRequestID request_id); |
330 | 333 |
| 334 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner() const { |
| 335 return io_thread_task_runner_; |
| 336 } |
| 337 |
| 338 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner() const { |
| 339 return main_thread_task_runner_; |
| 340 } |
| 341 |
331 private: | 342 private: |
332 friend class ResourceDispatcherHostTest; | 343 friend class ResourceDispatcherHostTest; |
333 | 344 |
334 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 345 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
335 TestBlockedRequestsProcessDies); | 346 TestBlockedRequestsProcessDies); |
336 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 347 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
337 CalculateApproximateMemoryCost); | 348 CalculateApproximateMemoryCost); |
338 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 349 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
339 DetachableResourceTimesOut); | 350 DetachableResourceTimesOut); |
340 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, | 351 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 DelegateMap delegate_map_; | 761 DelegateMap delegate_map_; |
751 | 762 |
752 std::unique_ptr<ResourceScheduler> scheduler_; | 763 std::unique_ptr<ResourceScheduler> scheduler_; |
753 | 764 |
754 // Used to invoke an interceptor for the HTTP header. | 765 // Used to invoke an interceptor for the HTTP header. |
755 HeaderInterceptorMap http_header_interceptor_map_; | 766 HeaderInterceptorMap http_header_interceptor_map_; |
756 | 767 |
757 // Points to the registered download handler intercept. | 768 // Points to the registered download handler intercept. |
758 CreateDownloadHandlerIntercept create_download_handler_intercept_; | 769 CreateDownloadHandlerIntercept create_download_handler_intercept_; |
759 | 770 |
| 771 // Task runner for the main thread. |
| 772 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
| 773 |
| 774 // Task runner for the IO thead. |
| 775 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; |
| 776 |
760 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); | 777 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); |
761 }; | 778 }; |
762 | 779 |
763 } // namespace content | 780 } // namespace content |
764 | 781 |
765 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ | 782 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ |
OLD | NEW |