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 <deque> | 10 #include <deque> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
15 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/shared_memory.h" | 16 #include "base/memory/shared_memory.h" |
16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
19 #include "ipc/ipc_listener.h" | 20 #include "ipc/ipc_listener.h" |
20 #include "ipc/ipc_sender.h" | 21 #include "ipc/ipc_sender.h" |
21 #include "net/base/request_priority.h" | 22 #include "net/base/request_priority.h" |
22 #include "webkit/common/resource_type.h" | 23 #include "webkit/common/resource_type.h" |
23 | 24 |
25 struct ResourceHostMsg_Request; | |
24 struct ResourceMsg_RequestCompleteData; | 26 struct ResourceMsg_RequestCompleteData; |
25 | 27 |
26 namespace webkit_glue { | 28 namespace webkit_glue { |
27 class ResourceLoaderBridge; | 29 class ResourceLoaderBridge; |
28 struct ResourceResponseInfo; | 30 struct ResourceResponseInfo; |
29 } | 31 } |
30 | 32 |
31 namespace content { | 33 namespace content { |
32 class RequestPeer; | 34 class RequestPeer; |
33 class ResourceDispatcherDelegate; | 35 class ResourceDispatcherDelegate; |
36 class ResourceRequestBody; | |
34 struct RequestInfo; | 37 struct RequestInfo; |
35 struct ResourceResponseHead; | 38 struct ResourceResponseHead; |
36 struct SiteIsolationResponseMetaData; | 39 struct SiteIsolationResponseMetaData; |
40 struct SyncLoadResponse; | |
37 | 41 |
38 // This class serves as a communication interface between the | 42 // This class serves as a communication interface between the |
39 // ResourceDispatcherHost in the browser process and the ResourceLoaderBridge in | 43 // ResourceDispatcherHost in the browser process and the ResourceLoaderBridge in |
40 // the child process. It can be used from any child process. | 44 // the child process. It can be used from any child process. |
41 class CONTENT_EXPORT ResourceDispatcher : public IPC::Listener { | 45 class CONTENT_EXPORT ResourceDispatcher : public IPC::Listener { |
42 public: | 46 public: |
43 explicit ResourceDispatcher(IPC::Sender* sender); | 47 explicit ResourceDispatcher(IPC::Sender* sender); |
44 virtual ~ResourceDispatcher(); | 48 virtual ~ResourceDispatcher(); |
45 | 49 |
46 // IPC::Listener implementation. | 50 // IPC::Listener implementation. |
47 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 51 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
48 | 52 |
49 // Creates a ResourceLoaderBridge for this type of dispatcher, this is so | 53 void CreateBridge(const RequestInfo& request_info); |
tfarina
2014/04/11 03:00:53
I forgot to ask. John, do you have a better name f
| |
50 // this can be tested regardless of the ResourceLoaderBridge::Create | 54 |
51 // implementation. | 55 // Call this method before calling Start() to set the request body. |
52 webkit_glue::ResourceLoaderBridge* CreateBridge( | 56 // May only be used with HTTP(S) POST requests. |
53 const RequestInfo& request_info); | 57 void SetRequestBody(ResourceRequestBody* request_body); |
58 | |
59 // Call this method to initiate the request. If this method succeeds, then | |
60 // the peer's methods will be called asynchronously to report various events. | |
61 bool Start(RequestPeer* peer); | |
62 | |
63 // Call this method to cancel a request that is in progress. This method | |
64 // causes the request to immediately transition into the 'done' state. The | |
65 // OnCompletedRequest method will be called asynchronously; this assumes | |
66 // the peer is still valid. | |
67 void Cancel(); | |
68 | |
69 // Call this method to suspend or resume a load that is in progress. This | |
70 // method may only be called after a successful call to the Start method. | |
71 void SetDefersLoading(bool value); | |
72 | |
73 // Call this method when the priority of the requested resource changes after | |
74 // Start() has been called. This method may only be called after a successful | |
75 // call to the Start method. | |
76 void DidChangePriority(net::RequestPriority new_priority, | |
77 int intra_priority_value); | |
78 | |
79 // Call this method to load the resource synchronously (i.e., in one shot). | |
80 // This is an alternative to the Start method. Be warned that this method | |
81 // will block the calling thread until the resource is fully downloaded or an | |
82 // error occurs. It could block the calling thread for a long time, so only | |
83 // use this if you really need it! There is also no way for the caller to | |
84 // interrupt this method. Errors are reported via the status field of the | |
85 // response parameter. | |
86 void SyncLoad(SyncLoadResponse* response); | |
54 | 87 |
55 // Adds a request from the pending_requests_ list, returning the new | 88 // Adds a request from the pending_requests_ list, returning the new |
56 // requests' ID | 89 // requests' ID |
57 int AddPendingRequest(RequestPeer* callback, | 90 int AddPendingRequest(RequestPeer* callback, |
58 ResourceType::Type resource_type, | 91 ResourceType::Type resource_type, |
59 int origin_pid, | 92 int origin_pid, |
60 const GURL& frame_origin, | 93 const GURL& frame_origin, |
61 const GURL& request_url); | 94 const GURL& request_url); |
62 | 95 |
63 // Removes a request from the pending_requests_ list, returning true if the | 96 // Removes a request from the pending_requests_ list, returning true if the |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 typedef base::hash_map<int, PendingRequestInfo> PendingRequestList; | 164 typedef base::hash_map<int, PendingRequestInfo> PendingRequestList; |
132 | 165 |
133 // Helper to lookup the info based on the request_id. | 166 // Helper to lookup the info based on the request_id. |
134 // May return NULL if the request as been canceled from the client side. | 167 // May return NULL if the request as been canceled from the client side. |
135 PendingRequestInfo* GetPendingRequestInfo(int request_id); | 168 PendingRequestInfo* GetPendingRequestInfo(int request_id); |
136 | 169 |
137 // Follows redirect, if any, for the given request. | 170 // Follows redirect, if any, for the given request. |
138 void FollowPendingRedirect(int request_id, PendingRequestInfo& request_info); | 171 void FollowPendingRedirect(int request_id, PendingRequestInfo& request_info); |
139 | 172 |
140 // Message response handlers, called by the message handler for this process. | 173 // Message response handlers, called by the message handler for this process. |
141 void OnUploadProgress( | 174 void OnUploadProgress(int request_id, int64 position, int64 size); |
142 int request_id, | |
143 int64 position, | |
144 int64 size); | |
145 void OnReceivedResponse(int request_id, const ResourceResponseHead&); | 175 void OnReceivedResponse(int request_id, const ResourceResponseHead&); |
146 void OnReceivedCachedMetadata(int request_id, const std::vector<char>& data); | 176 void OnReceivedCachedMetadata(int request_id, const std::vector<char>& data); |
147 void OnReceivedRedirect( | 177 void OnReceivedRedirect(int request_id, |
148 int request_id, | 178 const GURL& new_url, |
149 const GURL& new_url, | 179 const ResourceResponseHead& response_head); |
150 const ResourceResponseHead& response_head); | 180 void OnSetDataBuffer(int request_id, |
151 void OnSetDataBuffer( | 181 base::SharedMemoryHandle shm_handle, |
152 int request_id, | 182 int shm_size, |
153 base::SharedMemoryHandle shm_handle, | 183 base::ProcessId renderer_pid); |
154 int shm_size, | 184 void OnReceivedData(int request_id, |
155 base::ProcessId renderer_pid); | 185 int data_offset, |
156 void OnReceivedData( | 186 int data_length, |
157 int request_id, | 187 int encoded_data_length); |
158 int data_offset, | 188 void OnDownloadedData(int request_id, int data_len, int encoded_data_length); |
159 int data_length, | |
160 int encoded_data_length); | |
161 void OnDownloadedData( | |
162 int request_id, | |
163 int data_len, | |
164 int encoded_data_length); | |
165 void OnRequestComplete( | 189 void OnRequestComplete( |
166 int request_id, | 190 int request_id, |
167 const ResourceMsg_RequestCompleteData &request_complete_data); | 191 const ResourceMsg_RequestCompleteData& request_complete_data); |
168 | 192 |
169 // Dispatch the message to one of the message response handlers. | 193 // Dispatch the message to one of the message response handlers. |
170 void DispatchMessage(const IPC::Message& message); | 194 void DispatchMessage(const IPC::Message& message); |
171 | 195 |
172 // Dispatch any deferred messages for the given request, provided it is not | 196 // Dispatch any deferred messages for the given request, provided it is not |
173 // again in the deferred state. | 197 // again in the deferred state. |
174 void FlushDeferredMessages(int request_id); | 198 void FlushDeferredMessages(int request_id); |
175 | 199 |
176 void ToResourceResponseInfo( | 200 void ToResourceResponseInfo( |
177 const PendingRequestInfo& request_info, | 201 const PendingRequestInfo& request_info, |
(...skipping 21 matching lines...) Expand all Loading... | |
199 // Iterate through a message queue and clean up the messages by calling | 223 // Iterate through a message queue and clean up the messages by calling |
200 // ReleaseResourcesInDataMessage and removing them from the queue. Intended | 224 // ReleaseResourcesInDataMessage and removing them from the queue. Intended |
201 // for use on deferred message queues that are no longer needed. | 225 // for use on deferred message queues that are no longer needed. |
202 static void ReleaseResourcesInMessageQueue(MessageQueue* queue); | 226 static void ReleaseResourcesInMessageQueue(MessageQueue* queue); |
203 | 227 |
204 IPC::Sender* message_sender_; | 228 IPC::Sender* message_sender_; |
205 | 229 |
206 // All pending requests issued to the host | 230 // All pending requests issued to the host |
207 PendingRequestList pending_requests_; | 231 PendingRequestList pending_requests_; |
208 | 232 |
233 scoped_ptr<ResourceHostMsg_Request> request_; | |
234 | |
235 RequestPeer* peer_; | |
236 | |
237 // ID for the request, valid once Start()ed, -1 if not valid yet. | |
238 int request_id_; | |
239 | |
240 // The routing id used when sending IPC messages. | |
241 int routing_id_; | |
242 | |
243 // The security origin of the frame that initiates this request. | |
244 GURL frame_origin_; | |
245 | |
246 bool is_synchronous_request_; | |
247 | |
209 base::WeakPtrFactory<ResourceDispatcher> weak_factory_; | 248 base::WeakPtrFactory<ResourceDispatcher> weak_factory_; |
210 | 249 |
211 ResourceDispatcherDelegate* delegate_; | 250 ResourceDispatcherDelegate* delegate_; |
212 | 251 |
213 // IO thread timestamp for ongoing IPC message. | 252 // IO thread timestamp for ongoing IPC message. |
214 base::TimeTicks io_timestamp_; | 253 base::TimeTicks io_timestamp_; |
215 | 254 |
216 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); | 255 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); |
217 }; | 256 }; |
218 | 257 |
219 } // namespace content | 258 } // namespace content |
220 | 259 |
221 #endif // CONTENT_CHILD_RESOURCE_DISPATCHER_H_ | 260 #endif // CONTENT_CHILD_RESOURCE_DISPATCHER_H_ |
OLD | NEW |