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" |
| 30 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
29 #include "url/gurl.h" | 31 #include "url/gurl.h" |
30 | 32 |
31 namespace net { | 33 namespace net { |
32 struct RedirectInfo; | 34 struct RedirectInfo; |
33 } | 35 } |
34 | 36 |
35 namespace content { | 37 namespace content { |
36 class RequestPeer; | 38 class RequestPeer; |
37 class ResourceDispatcherDelegate; | 39 class ResourceDispatcherDelegate; |
38 class ResourceRequestBodyImpl; | 40 class ResourceRequestBodyImpl; |
39 class ResourceSchedulingFilter; | 41 class ResourceSchedulingFilter; |
40 struct ResourceResponseInfo; | 42 struct ResourceResponseInfo; |
41 struct RequestInfo; | 43 struct RequestInfo; |
42 struct ResourceRequest; | 44 struct ResourceRequest; |
43 struct ResourceRequestCompletionStatus; | 45 struct ResourceRequestCompletionStatus; |
44 struct ResourceResponseHead; | 46 struct ResourceResponseHead; |
45 class SharedMemoryReceivedDataFactory; | 47 class SharedMemoryReceivedDataFactory; |
46 struct SiteIsolationResponseMetaData; | 48 struct SiteIsolationResponseMetaData; |
47 struct SyncLoadResponse; | 49 struct SyncLoadResponse; |
48 | 50 |
| 51 namespace mojom { |
| 52 class URLLoaderFactory; |
| 53 } // namespace mojom |
| 54 |
49 // This class serves as a communication interface to the ResourceDispatcherHost | 55 // This class serves as a communication interface to the ResourceDispatcherHost |
50 // in the browser process. It can be used from any child process. | 56 // in the browser process. It can be used from any child process. |
51 // Virtual methods are for tests. | 57 // Virtual methods are for tests. |
52 class CONTENT_EXPORT ResourceDispatcher : public IPC::Listener { | 58 class CONTENT_EXPORT ResourceDispatcher : public IPC::Listener { |
53 public: | 59 public: |
54 ResourceDispatcher( | 60 ResourceDispatcher( |
55 IPC::Sender* sender, | 61 IPC::Sender* sender, |
56 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner); | 62 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner); |
57 ~ResourceDispatcher() override; | 63 ~ResourceDispatcher() override; |
58 | 64 |
59 // IPC::Listener implementation. | 65 // IPC::Listener implementation. |
60 bool OnMessageReceived(const IPC::Message& message) override; | 66 bool OnMessageReceived(const IPC::Message& message) override; |
61 | 67 |
62 // Call this method to load the resource synchronously (i.e., in one shot). | 68 // Call this method to load the resource synchronously (i.e., in one shot). |
63 // This is an alternative to the StartAsync method. Be warned that this method | 69 // This is an alternative to the StartAsync method. Be warned that this method |
64 // will block the calling thread until the resource is fully downloaded or an | 70 // will block the calling thread until the resource is fully downloaded or an |
65 // error occurs. It could block the calling thread for a long time, so only | 71 // error occurs. It could block the calling thread for a long time, so only |
66 // use this if you really need it! There is also no way for the caller to | 72 // use this if you really need it! There is also no way for the caller to |
67 // interrupt this method. Errors are reported via the status field of the | 73 // interrupt this method. Errors are reported via the status field of the |
68 // response parameter. | 74 // response parameter. |
69 virtual void StartSync(const RequestInfo& request_info, | 75 virtual void StartSync(const RequestInfo& request_info, |
70 ResourceRequestBodyImpl* request_body, | 76 ResourceRequestBodyImpl* request_body, |
71 SyncLoadResponse* response); | 77 SyncLoadResponse* response, |
| 78 blink::WebURLRequest::LoadingIPCType ipc_type, |
| 79 mojom::URLLoaderFactory* url_loader_factory); |
72 | 80 |
73 // Call this method to initiate the request. If this method succeeds, then | 81 // Call this method to initiate the request. If this method succeeds, then |
74 // the peer's methods will be called asynchronously to report various events. | 82 // the peer's methods will be called asynchronously to report various events. |
75 // Returns the request id. | 83 // Returns the request id. |
76 virtual int StartAsync(const RequestInfo& request_info, | 84 virtual int StartAsync(const RequestInfo& request_info, |
77 ResourceRequestBodyImpl* request_body, | 85 ResourceRequestBodyImpl* request_body, |
78 std::unique_ptr<RequestPeer> peer); | 86 std::unique_ptr<RequestPeer> peer, |
| 87 blink::WebURLRequest::LoadingIPCType ipc_type, |
| 88 mojom::URLLoaderFactory* url_loader_factory); |
79 | 89 |
80 // Removes a request from the |pending_requests_| list, returning true if the | 90 // Removes a request from the |pending_requests_| list, returning true if the |
81 // request was found and removed. | 91 // request was found and removed. |
82 bool RemovePendingRequest(int request_id); | 92 bool RemovePendingRequest(int request_id); |
83 | 93 |
84 // Cancels a request in the |pending_requests_| list. The request will be | 94 // Cancels a request in the |pending_requests_| list. The request will be |
85 // removed from the dispatcher as well. | 95 // removed from the dispatcher as well. |
86 virtual void Cancel(int request_id); | 96 virtual void Cancel(int request_id); |
87 | 97 |
88 // Toggles the is_deferred attribute for the specified request. | 98 // Toggles the is_deferred attribute for the specified request. |
(...skipping 23 matching lines...) Expand all Loading... |
112 | 122 |
113 void SetMainThreadTaskRunner( | 123 void SetMainThreadTaskRunner( |
114 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) { | 124 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) { |
115 main_thread_task_runner_ = main_thread_task_runner; | 125 main_thread_task_runner_ = main_thread_task_runner; |
116 } | 126 } |
117 | 127 |
118 void SetResourceSchedulingFilter( | 128 void SetResourceSchedulingFilter( |
119 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter); | 129 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter); |
120 | 130 |
121 private: | 131 private: |
| 132 friend class URLResponseBodyConsumer; |
122 friend class ResourceDispatcherTest; | 133 friend class ResourceDispatcherTest; |
123 | 134 |
124 typedef std::deque<IPC::Message*> MessageQueue; | 135 typedef std::deque<IPC::Message*> MessageQueue; |
125 struct PendingRequestInfo { | 136 struct PendingRequestInfo { |
126 PendingRequestInfo(std::unique_ptr<RequestPeer> peer, | 137 PendingRequestInfo(std::unique_ptr<RequestPeer> peer, |
127 ResourceType resource_type, | 138 ResourceType resource_type, |
128 int origin_pid, | 139 int origin_pid, |
129 const GURL& frame_origin, | 140 const GURL& frame_origin, |
130 const GURL& request_url, | 141 const GURL& request_url, |
131 bool download_to_file); | 142 bool download_to_file); |
(...skipping 16 matching lines...) Expand all Loading... |
148 GURL response_url; | 159 GURL response_url; |
149 bool download_to_file; | 160 bool download_to_file; |
150 std::unique_ptr<IPC::Message> pending_redirect_message; | 161 std::unique_ptr<IPC::Message> pending_redirect_message; |
151 base::TimeTicks request_start; | 162 base::TimeTicks request_start; |
152 base::TimeTicks response_start; | 163 base::TimeTicks response_start; |
153 base::TimeTicks completion_time; | 164 base::TimeTicks completion_time; |
154 linked_ptr<base::SharedMemory> buffer; | 165 linked_ptr<base::SharedMemory> buffer; |
155 scoped_refptr<SharedMemoryReceivedDataFactory> received_data_factory; | 166 scoped_refptr<SharedMemoryReceivedDataFactory> received_data_factory; |
156 std::unique_ptr<SiteIsolationResponseMetaData> site_isolation_metadata; | 167 std::unique_ptr<SiteIsolationResponseMetaData> site_isolation_metadata; |
157 int buffer_size; | 168 int buffer_size; |
| 169 |
| 170 // For mojo loading. |
| 171 mojom::URLLoaderPtr url_loader; |
| 172 std::unique_ptr<mojom::URLLoaderClient> url_loader_client; |
158 }; | 173 }; |
159 using PendingRequestMap = std::map<int, std::unique_ptr<PendingRequestInfo>>; | 174 using PendingRequestMap = std::map<int, std::unique_ptr<PendingRequestInfo>>; |
160 | 175 |
161 // Helper to lookup the info based on the request_id. | 176 // Helper to lookup the info based on the request_id. |
162 // May return NULL if the request as been canceled from the client side. | 177 // May return NULL if the request as been canceled from the client side. |
163 PendingRequestInfo* GetPendingRequestInfo(int request_id); | 178 PendingRequestInfo* GetPendingRequestInfo(int request_id); |
164 | 179 |
165 // Follows redirect, if any, for the given request. | 180 // Follows redirect, if any, for the given request. |
166 void FollowPendingRedirect(int request_id, PendingRequestInfo* request_info); | 181 void FollowPendingRedirect(int request_id, PendingRequestInfo* request_info); |
167 | 182 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter_; | 258 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter_; |
244 | 259 |
245 base::WeakPtrFactory<ResourceDispatcher> weak_factory_; | 260 base::WeakPtrFactory<ResourceDispatcher> weak_factory_; |
246 | 261 |
247 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); | 262 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); |
248 }; | 263 }; |
249 | 264 |
250 } // namespace content | 265 } // namespace content |
251 | 266 |
252 #endif // CONTENT_CHILD_RESOURCE_DISPATCHER_H_ | 267 #endif // CONTENT_CHILD_RESOURCE_DISPATCHER_H_ |
OLD | NEW |