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 |
50 // this can be tested regardless of the ResourceLoaderBridge::Create | 54 // Call this method to load the resource synchronously (i.e., in one shot). |
51 // implementation. | 55 // This is an alternative to the StartAsync method. Be warned that this method |
52 webkit_glue::ResourceLoaderBridge* CreateBridge( | 56 // will block the calling thread until the resource is fully downloaded or an |
53 const RequestInfo& request_info); | 57 // error occurs. It could block the calling thread for a long time, so only |
58 // use this if you really need it! There is also no way for the caller to | |
59 // interrupt this method. Errors are reported via the status field of the | |
60 // response parameter. | |
61 void StartSync(const RequestInfo& request_info, | |
62 ResourceRequestBody* request_body, | |
63 SyncLoadResponse* response); | |
64 | |
65 // Call this method to initiate the request. If this method succeeds, then | |
66 // the peer's methods will be called asynchronously to report various events. | |
67 // Returns the request id. | |
68 int StartAsync(const RequestInfo& request_info, | |
69 ResourceRequestBody* request_body, | |
70 RequestPeer* peer); | |
71 | |
72 // Call this method to cancel a request that is in progress. This method | |
73 // causes the request to immediately transition into the 'done' state. The | |
74 // OnCompletedRequest method will be called asynchronously; this assumes | |
75 // the peer is still valid. | |
76 void Cancel(int request_id); | |
54 | 77 |
55 // Adds a request from the pending_requests_ list, returning the new | 78 // Adds a request from the pending_requests_ list, returning the new |
56 // requests' ID | 79 // requests' ID |
57 int AddPendingRequest(RequestPeer* callback, | 80 int AddPendingRequest(RequestPeer* callback, |
58 ResourceType::Type resource_type, | 81 ResourceType::Type resource_type, |
59 int origin_pid, | 82 int origin_pid, |
60 const GURL& frame_origin, | 83 const GURL& frame_origin, |
61 const GURL& request_url); | 84 const GURL& request_url); |
62 | 85 |
63 // Removes a request from the pending_requests_ list, returning true if the | 86 // Removes a request from the pending_requests_ list, returning true if the |
64 // request was found and removed. | 87 // request was found and removed. |
65 bool RemovePendingRequest(int request_id); | 88 bool RemovePendingRequest(int request_id); |
66 | 89 |
67 // Cancels a request in the pending_requests_ list. | 90 // Cancels a request in the pending_requests_ list. |
68 void CancelPendingRequest(int request_id); | 91 void CancelPendingRequest(int request_id); |
69 | 92 |
70 IPC::Sender* message_sender() const { | 93 IPC::Sender* message_sender() const { return message_sender_; } |
71 return message_sender_; | |
72 } | |
73 | 94 |
74 // Toggles the is_deferred attribute for the specified request. | 95 // Toggles the is_deferred attribute for the specified request. |
75 void SetDefersLoading(int request_id, bool value); | 96 void SetDefersLoading(int request_id, bool value); |
76 | 97 |
77 // Indicates the priority of the specified request changed. | 98 // Indicates the priority of the specified request changed. |
78 void DidChangePriority(int routing_id, int request_id, | 99 void DidChangePriority(int routing_id, |
100 int request_id, | |
79 net::RequestPriority new_priority, | 101 net::RequestPriority new_priority, |
80 int intra_priority_value); | 102 int intra_priority_value); |
81 | 103 |
82 // This does not take ownership of the delegate. It is expected that the | 104 // This does not take ownership of the delegate. It is expected that the |
83 // delegate have a longer lifetime than the ResourceDispatcher. | 105 // delegate have a longer lifetime than the ResourceDispatcher. |
84 void set_delegate(ResourceDispatcherDelegate* delegate) { | 106 void set_delegate(ResourceDispatcherDelegate* delegate) { |
85 delegate_ = delegate; | 107 delegate_ = delegate; |
86 } | 108 } |
87 | 109 |
88 // Remembers IO thread timestamp for next resource message. | 110 // Remembers IO thread timestamp for next resource message. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 typedef base::hash_map<int, PendingRequestInfo> PendingRequestList; | 153 typedef base::hash_map<int, PendingRequestInfo> PendingRequestList; |
132 | 154 |
133 // Helper to lookup the info based on the request_id. | 155 // Helper to lookup the info based on the request_id. |
134 // May return NULL if the request as been canceled from the client side. | 156 // May return NULL if the request as been canceled from the client side. |
135 PendingRequestInfo* GetPendingRequestInfo(int request_id); | 157 PendingRequestInfo* GetPendingRequestInfo(int request_id); |
136 | 158 |
137 // Follows redirect, if any, for the given request. | 159 // Follows redirect, if any, for the given request. |
138 void FollowPendingRedirect(int request_id, PendingRequestInfo& request_info); | 160 void FollowPendingRedirect(int request_id, PendingRequestInfo& request_info); |
139 | 161 |
140 // Message response handlers, called by the message handler for this process. | 162 // Message response handlers, called by the message handler for this process. |
141 void OnUploadProgress( | 163 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&); | 164 void OnReceivedResponse(int request_id, const ResourceResponseHead&); |
146 void OnReceivedCachedMetadata(int request_id, const std::vector<char>& data); | 165 void OnReceivedCachedMetadata(int request_id, const std::vector<char>& data); |
147 void OnReceivedRedirect( | 166 void OnReceivedRedirect(int request_id, |
148 int request_id, | 167 const GURL& new_url, |
149 const GURL& new_url, | 168 const ResourceResponseHead& response_head); |
150 const ResourceResponseHead& response_head); | 169 void OnSetDataBuffer(int request_id, |
151 void OnSetDataBuffer( | 170 base::SharedMemoryHandle shm_handle, |
152 int request_id, | 171 int shm_size, |
153 base::SharedMemoryHandle shm_handle, | 172 base::ProcessId renderer_pid); |
154 int shm_size, | 173 void OnReceivedData(int request_id, |
155 base::ProcessId renderer_pid); | 174 int data_offset, |
156 void OnReceivedData( | 175 int data_length, |
157 int request_id, | 176 int encoded_data_length); |
158 int data_offset, | 177 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( | 178 void OnRequestComplete( |
166 int request_id, | 179 int request_id, |
167 const ResourceMsg_RequestCompleteData &request_complete_data); | 180 const ResourceMsg_RequestCompleteData& request_complete_data); |
168 | 181 |
169 // Dispatch the message to one of the message response handlers. | 182 // Dispatch the message to one of the message response handlers. |
170 void DispatchMessage(const IPC::Message& message); | 183 void DispatchMessage(const IPC::Message& message); |
171 | 184 |
172 // Dispatch any deferred messages for the given request, provided it is not | 185 // Dispatch any deferred messages for the given request, provided it is not |
173 // again in the deferred state. | 186 // again in the deferred state. |
174 void FlushDeferredMessages(int request_id); | 187 void FlushDeferredMessages(int request_id); |
175 | 188 |
176 void ToResourceResponseInfo( | 189 void ToResourceResponseInfo( |
177 const PendingRequestInfo& request_info, | 190 const PendingRequestInfo& request_info, |
(...skipping 16 matching lines...) Expand all Loading... | |
194 // handle in it that we should cleanup it up nicely. This method accepts any | 207 // handle in it that we should cleanup it up nicely. This method accepts any |
195 // message and determine whether the message is | 208 // message and determine whether the message is |
196 // ViewHostMsg_Resource_DataReceived and clean up the shared memory handle. | 209 // ViewHostMsg_Resource_DataReceived and clean up the shared memory handle. |
197 static void ReleaseResourcesInDataMessage(const IPC::Message& message); | 210 static void ReleaseResourcesInDataMessage(const IPC::Message& message); |
198 | 211 |
199 // Iterate through a message queue and clean up the messages by calling | 212 // Iterate through a message queue and clean up the messages by calling |
200 // ReleaseResourcesInDataMessage and removing them from the queue. Intended | 213 // ReleaseResourcesInDataMessage and removing them from the queue. Intended |
201 // for use on deferred message queues that are no longer needed. | 214 // for use on deferred message queues that are no longer needed. |
202 static void ReleaseResourcesInMessageQueue(MessageQueue* queue); | 215 static void ReleaseResourcesInMessageQueue(MessageQueue* queue); |
203 | 216 |
217 void CreateRequest(const RequestInfo& request_info, | |
218 ResourceRequestBody* request_body); | |
219 | |
204 IPC::Sender* message_sender_; | 220 IPC::Sender* message_sender_; |
205 | 221 |
206 // All pending requests issued to the host | 222 // All pending requests issued to the host |
207 PendingRequestList pending_requests_; | 223 PendingRequestList pending_requests_; |
208 | 224 |
225 scoped_ptr<ResourceHostMsg_Request> request_; | |
226 | |
227 // ID for the request, valid once Start()ed, -1 if not valid yet. | |
228 int request_id_; | |
229 | |
230 // The security origin of the frame that initiates this request. | |
231 GURL frame_origin_; | |
232 | |
233 bool is_synchronous_request_; | |
jam
2014/04/16 16:24:04
remove this entire section (see my second-last mes
| |
234 | |
209 base::WeakPtrFactory<ResourceDispatcher> weak_factory_; | 235 base::WeakPtrFactory<ResourceDispatcher> weak_factory_; |
210 | 236 |
211 ResourceDispatcherDelegate* delegate_; | 237 ResourceDispatcherDelegate* delegate_; |
212 | 238 |
213 // IO thread timestamp for ongoing IPC message. | 239 // IO thread timestamp for ongoing IPC message. |
214 base::TimeTicks io_timestamp_; | 240 base::TimeTicks io_timestamp_; |
215 | 241 |
216 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); | 242 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); |
217 }; | 243 }; |
218 | 244 |
219 } // namespace content | 245 } // namespace content |
220 | 246 |
221 #endif // CONTENT_CHILD_RESOURCE_DISPATCHER_H_ | 247 #endif // CONTENT_CHILD_RESOURCE_DISPATCHER_H_ |
OLD | NEW |