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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
6 | 6 |
7 #ifndef CONTENT_CHILD_RESOURCE_DISPATCHER_H_ | 7 #ifndef CONTENT_CHILD_RESOURCE_DISPATCHER_H_ |
8 #define CONTENT_CHILD_RESOURCE_DISPATCHER_H_ | 8 #define CONTENT_CHILD_RESOURCE_DISPATCHER_H_ |
9 | 9 |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
12 #include <deque> | 12 #include <deque> |
13 #include <map> | 13 #include <map> |
14 #include <memory> | 14 #include <memory> |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 #include "base/containers/hash_tables.h" | 17 #include "base/containers/hash_tables.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/memory/linked_ptr.h" | 19 #include "base/memory/linked_ptr.h" |
20 #include "base/memory/shared_memory.h" | 20 #include "base/memory/shared_memory.h" |
21 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
22 #include "base/single_thread_task_runner.h" | 22 #include "base/single_thread_task_runner.h" |
23 #include "base/time/time.h" | 23 #include "base/time/time.h" |
24 #include "content/common/content_export.h" | 24 #include "content/common/content_export.h" |
| 25 #include "content/common/url_loader.mojom.h" |
25 #include "content/public/common/resource_type.h" | 26 #include "content/public/common/resource_type.h" |
26 #include "ipc/ipc_listener.h" | 27 #include "ipc/ipc_listener.h" |
27 #include "ipc/ipc_sender.h" | 28 #include "ipc/ipc_sender.h" |
28 #include "net/base/request_priority.h" | 29 #include "net/base/request_priority.h" |
29 #include "url/gurl.h" | 30 #include "url/gurl.h" |
30 | 31 |
31 struct ResourceHostMsg_Request; | 32 struct ResourceHostMsg_Request; |
32 struct ResourceMsg_RequestCompleteData; | 33 struct ResourceMsg_RequestCompleteData; |
33 | 34 |
34 namespace net { | 35 namespace net { |
(...skipping 27 matching lines...) Expand all Loading... |
62 | 63 |
63 // Call this method to load the resource synchronously (i.e., in one shot). | 64 // Call this method to load the resource synchronously (i.e., in one shot). |
64 // This is an alternative to the StartAsync method. Be warned that this method | 65 // This is an alternative to the StartAsync method. Be warned that this method |
65 // will block the calling thread until the resource is fully downloaded or an | 66 // will block the calling thread until the resource is fully downloaded or an |
66 // error occurs. It could block the calling thread for a long time, so only | 67 // error occurs. It could block the calling thread for a long time, so only |
67 // use this if you really need it! There is also no way for the caller to | 68 // use this if you really need it! There is also no way for the caller to |
68 // interrupt this method. Errors are reported via the status field of the | 69 // interrupt this method. Errors are reported via the status field of the |
69 // response parameter. | 70 // response parameter. |
70 void StartSync(const RequestInfo& request_info, | 71 void StartSync(const RequestInfo& request_info, |
71 ResourceRequestBody* request_body, | 72 ResourceRequestBody* request_body, |
72 SyncLoadResponse* response); | 73 SyncLoadResponse* response, |
| 74 mojom::URLLoaderPtr url_loader); |
73 | 75 |
74 // Call this method to initiate the request. If this method succeeds, then | 76 // Call this method to initiate the request. If this method succeeds, then |
75 // the peer's methods will be called asynchronously to report various events. | 77 // the peer's methods will be called asynchronously to report various events. |
76 // Returns the request id. | 78 // Returns the request id. |
77 virtual int StartAsync(const RequestInfo& request_info, | 79 virtual int StartAsync(const RequestInfo& request_info, |
78 ResourceRequestBody* request_body, | 80 ResourceRequestBody* request_body, |
79 std::unique_ptr<RequestPeer> peer); | 81 std::unique_ptr<RequestPeer> peer, |
| 82 mojom::URLLoaderPtr url_loader); |
80 | 83 |
81 // Removes a request from the |pending_requests_| list, returning true if the | 84 // Removes a request from the |pending_requests_| list, returning true if the |
82 // request was found and removed. | 85 // request was found and removed. |
83 bool RemovePendingRequest(int request_id); | 86 bool RemovePendingRequest(int request_id); |
84 | 87 |
85 // Cancels a request in the |pending_requests_| list. The request will be | 88 // Cancels a request in the |pending_requests_| list. The request will be |
86 // removed from the dispatcher as well. | 89 // removed from the dispatcher as well. |
87 virtual void Cancel(int request_id); | 90 virtual void Cancel(int request_id); |
88 | 91 |
89 // Toggles the is_deferred attribute for the specified request. | 92 // Toggles the is_deferred attribute for the specified request. |
(...skipping 23 matching lines...) Expand all Loading... |
113 | 116 |
114 void SetMainThreadTaskRunner( | 117 void SetMainThreadTaskRunner( |
115 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) { | 118 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) { |
116 main_thread_task_runner_ = main_thread_task_runner; | 119 main_thread_task_runner_ = main_thread_task_runner; |
117 } | 120 } |
118 | 121 |
119 void SetResourceSchedulingFilter( | 122 void SetResourceSchedulingFilter( |
120 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter); | 123 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter); |
121 | 124 |
122 private: | 125 private: |
| 126 friend class BodyConsumer; |
123 friend class ResourceDispatcherTest; | 127 friend class ResourceDispatcherTest; |
124 | 128 |
125 typedef std::deque<IPC::Message*> MessageQueue; | 129 typedef std::deque<IPC::Message*> MessageQueue; |
126 struct PendingRequestInfo { | 130 struct PendingRequestInfo { |
127 PendingRequestInfo(std::unique_ptr<RequestPeer> peer, | 131 PendingRequestInfo(std::unique_ptr<RequestPeer> peer, |
128 ResourceType resource_type, | 132 ResourceType resource_type, |
129 int origin_pid, | 133 int origin_pid, |
130 const GURL& frame_origin, | 134 const GURL& frame_origin, |
131 const GURL& request_url, | 135 const GURL& request_url, |
132 bool download_to_file); | 136 bool download_to_file); |
(...skipping 15 matching lines...) Expand all Loading... |
148 // The url of the latest response even in case of redirection. | 152 // The url of the latest response even in case of redirection. |
149 GURL response_url; | 153 GURL response_url; |
150 bool download_to_file; | 154 bool download_to_file; |
151 std::unique_ptr<IPC::Message> pending_redirect_message; | 155 std::unique_ptr<IPC::Message> pending_redirect_message; |
152 base::TimeTicks request_start; | 156 base::TimeTicks request_start; |
153 base::TimeTicks response_start; | 157 base::TimeTicks response_start; |
154 base::TimeTicks completion_time; | 158 base::TimeTicks completion_time; |
155 linked_ptr<base::SharedMemory> buffer; | 159 linked_ptr<base::SharedMemory> buffer; |
156 scoped_refptr<SharedMemoryReceivedDataFactory> received_data_factory; | 160 scoped_refptr<SharedMemoryReceivedDataFactory> received_data_factory; |
157 std::unique_ptr<SiteIsolationResponseMetaData> site_isolation_metadata; | 161 std::unique_ptr<SiteIsolationResponseMetaData> site_isolation_metadata; |
| 162 mojom::URLLoaderPtr url_loader; |
| 163 std::unique_ptr<mojom::URLLoaderClient> url_loader_client; |
158 int buffer_size; | 164 int buffer_size; |
159 }; | 165 }; |
160 using PendingRequestMap = std::map<int, std::unique_ptr<PendingRequestInfo>>; | 166 using PendingRequestMap = std::map<int, std::unique_ptr<PendingRequestInfo>>; |
161 | 167 |
162 // Helper to lookup the info based on the request_id. | 168 // Helper to lookup the info based on the request_id. |
163 // May return NULL if the request as been canceled from the client side. | 169 // May return NULL if the request as been canceled from the client side. |
164 PendingRequestInfo* GetPendingRequestInfo(int request_id); | 170 PendingRequestInfo* GetPendingRequestInfo(int request_id); |
165 | 171 |
166 // Follows redirect, if any, for the given request. | 172 // Follows redirect, if any, for the given request. |
167 void FollowPendingRedirect(int request_id, PendingRequestInfo* request_info); | 173 void FollowPendingRedirect(int request_id, PendingRequestInfo* request_info); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter_; | 248 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter_; |
243 | 249 |
244 base::WeakPtrFactory<ResourceDispatcher> weak_factory_; | 250 base::WeakPtrFactory<ResourceDispatcher> weak_factory_; |
245 | 251 |
246 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); | 252 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); |
247 }; | 253 }; |
248 | 254 |
249 } // namespace content | 255 } // namespace content |
250 | 256 |
251 #endif // CONTENT_CHILD_RESOURCE_DISPATCHER_H_ | 257 #endif // CONTENT_CHILD_RESOURCE_DISPATCHER_H_ |
OLD | NEW |