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> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 // IPC::Listener implementation. | 46 // IPC::Listener implementation. |
47 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 47 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
48 | 48 |
49 // Creates a ResourceLoaderBridge for this type of dispatcher, this is so | 49 // Creates a ResourceLoaderBridge for this type of dispatcher, this is so |
50 // this can be tested regardless of the ResourceLoaderBridge::Create | 50 // this can be tested regardless of the ResourceLoaderBridge::Create |
51 // implementation. | 51 // implementation. |
52 webkit_glue::ResourceLoaderBridge* CreateBridge( | 52 webkit_glue::ResourceLoaderBridge* CreateBridge( |
53 const RequestInfo& request_info); | 53 const RequestInfo& request_info); |
54 | 54 |
55 // Adds a request from the pending_requests_ list, returning the new | 55 // Adds a request from the |pending_requests_| list, returning the new |
56 // requests' ID | 56 // requests' ID. |
57 int AddPendingRequest(RequestPeer* callback, | 57 int AddPendingRequest(RequestPeer* callback, |
58 ResourceType::Type resource_type, | 58 ResourceType::Type resource_type, |
59 int origin_pid, | 59 int origin_pid, |
60 const GURL& frame_origin, | 60 const GURL& frame_origin, |
61 const GURL& request_url); | 61 const GURL& request_url, |
| 62 bool download_to_file); |
62 | 63 |
63 // Removes a request from the pending_requests_ list, returning true if the | 64 // Removes a request from the |pending_requests_| list, returning true if the |
64 // request was found and removed. | 65 // request was found and removed. |
65 bool RemovePendingRequest(int request_id); | 66 bool RemovePendingRequest(int request_id); |
66 | 67 |
67 // Cancels a request in the pending_requests_ list. | 68 // Cancels a request in the |pending_requests_| list. |
68 void CancelPendingRequest(int request_id); | 69 void CancelPendingRequest(int request_id); |
69 | 70 |
70 IPC::Sender* message_sender() const { | |
71 return message_sender_; | |
72 } | |
73 | |
74 // Toggles the is_deferred attribute for the specified request. | 71 // Toggles the is_deferred attribute for the specified request. |
75 void SetDefersLoading(int request_id, bool value); | 72 void SetDefersLoading(int request_id, bool value); |
76 | 73 |
77 // Indicates the priority of the specified request changed. | 74 // Indicates the priority of the specified request changed. |
78 void DidChangePriority(int routing_id, int request_id, | 75 void DidChangePriority(int routing_id, |
| 76 int request_id, |
79 net::RequestPriority new_priority, | 77 net::RequestPriority new_priority, |
80 int intra_priority_value); | 78 int intra_priority_value); |
81 | 79 |
| 80 IPC::Sender* message_sender() const { return message_sender_; } |
| 81 |
82 // This does not take ownership of the delegate. It is expected that the | 82 // This does not take ownership of the delegate. It is expected that the |
83 // delegate have a longer lifetime than the ResourceDispatcher. | 83 // delegate have a longer lifetime than the ResourceDispatcher. |
84 void set_delegate(ResourceDispatcherDelegate* delegate) { | 84 void set_delegate(ResourceDispatcherDelegate* delegate) { |
85 delegate_ = delegate; | 85 delegate_ = delegate; |
86 } | 86 } |
87 | 87 |
88 // Remembers IO thread timestamp for next resource message. | 88 // Remembers IO thread timestamp for next resource message. |
89 void set_io_timestamp(base::TimeTicks io_timestamp) { | 89 void set_io_timestamp(base::TimeTicks io_timestamp) { |
90 io_timestamp_ = io_timestamp; | 90 io_timestamp_ = io_timestamp; |
91 } | 91 } |
92 | 92 |
93 private: | 93 private: |
94 friend class ResourceDispatcherTest; | 94 friend class ResourceDispatcherTest; |
95 | 95 |
96 typedef std::deque<IPC::Message*> MessageQueue; | 96 typedef std::deque<IPC::Message*> MessageQueue; |
97 struct PendingRequestInfo { | 97 struct PendingRequestInfo { |
98 PendingRequestInfo(); | 98 PendingRequestInfo(); |
99 | 99 |
100 PendingRequestInfo(RequestPeer* peer, | 100 PendingRequestInfo(RequestPeer* peer, |
101 ResourceType::Type resource_type, | 101 ResourceType::Type resource_type, |
102 int origin_pid, | 102 int origin_pid, |
103 const GURL& frame_origin, | 103 const GURL& frame_origin, |
104 const GURL& request_url); | 104 const GURL& request_url, |
| 105 bool download_to_file); |
105 | 106 |
106 ~PendingRequestInfo(); | 107 ~PendingRequestInfo(); |
107 | 108 |
108 RequestPeer* peer; | 109 RequestPeer* peer; |
109 ResourceType::Type resource_type; | 110 ResourceType::Type resource_type; |
110 // The PID of the original process which issued this request. This gets | 111 // The PID of the original process which issued this request. This gets |
111 // non-zero only for a request proxied by another renderer, particularly | 112 // non-zero only for a request proxied by another renderer, particularly |
112 // requests from plugins. | 113 // requests from plugins. |
113 int origin_pid; | 114 int origin_pid; |
114 MessageQueue deferred_message_queue; | 115 MessageQueue deferred_message_queue; |
115 bool is_deferred; | 116 bool is_deferred; |
116 bool is_canceled; | 117 bool is_canceled; |
117 // Original requested url. | 118 // Original requested url. |
118 GURL url; | 119 GURL url; |
119 // The security origin of the frame that initiates this request. | 120 // The security origin of the frame that initiates this request. |
120 GURL frame_origin; | 121 GURL frame_origin; |
121 // The url of the latest response even in case of redirection. | 122 // The url of the latest response even in case of redirection. |
122 GURL response_url; | 123 GURL response_url; |
| 124 bool download_to_file; |
123 linked_ptr<IPC::Message> pending_redirect_message; | 125 linked_ptr<IPC::Message> pending_redirect_message; |
124 base::TimeTicks request_start; | 126 base::TimeTicks request_start; |
125 base::TimeTicks response_start; | 127 base::TimeTicks response_start; |
126 base::TimeTicks completion_time; | 128 base::TimeTicks completion_time; |
127 linked_ptr<base::SharedMemory> buffer; | 129 linked_ptr<base::SharedMemory> buffer; |
128 linked_ptr<SiteIsolationResponseMetaData> site_isolation_metadata; | 130 linked_ptr<SiteIsolationResponseMetaData> site_isolation_metadata; |
129 bool blocked_response; | 131 bool blocked_response; |
130 int buffer_size; | 132 int buffer_size; |
131 }; | 133 }; |
132 typedef base::hash_map<int, PendingRequestInfo> PendingRequestList; | 134 typedef base::hash_map<int, PendingRequestInfo> PendingRequestList; |
133 | 135 |
134 // Helper to lookup the info based on the request_id. | 136 // Helper to lookup the info based on the request_id. |
135 // May return NULL if the request as been canceled from the client side. | 137 // May return NULL if the request as been canceled from the client side. |
136 PendingRequestInfo* GetPendingRequestInfo(int request_id); | 138 PendingRequestInfo* GetPendingRequestInfo(int request_id); |
137 | 139 |
138 // Follows redirect, if any, for the given request. | 140 // Follows redirect, if any, for the given request. |
139 void FollowPendingRedirect(int request_id, PendingRequestInfo& request_info); | 141 void FollowPendingRedirect(int request_id, PendingRequestInfo& request_info); |
140 | 142 |
141 // Message response handlers, called by the message handler for this process. | 143 // Message response handlers, called by the message handler for this process. |
142 void OnUploadProgress( | 144 void OnUploadProgress(int request_id, int64 position, int64 size); |
143 int request_id, | |
144 int64 position, | |
145 int64 size); | |
146 void OnReceivedResponse(int request_id, const ResourceResponseHead&); | 145 void OnReceivedResponse(int request_id, const ResourceResponseHead&); |
147 void OnReceivedCachedMetadata(int request_id, const std::vector<char>& data); | 146 void OnReceivedCachedMetadata(int request_id, const std::vector<char>& data); |
148 void OnReceivedRedirect( | 147 void OnReceivedRedirect(int request_id, |
149 int request_id, | 148 const GURL& new_url, |
150 const GURL& new_url, | 149 const ResourceResponseHead& response_head); |
151 const ResourceResponseHead& response_head); | 150 void OnSetDataBuffer(int request_id, |
152 void OnSetDataBuffer( | 151 base::SharedMemoryHandle shm_handle, |
153 int request_id, | 152 int shm_size, |
154 base::SharedMemoryHandle shm_handle, | 153 base::ProcessId renderer_pid); |
155 int shm_size, | 154 void OnReceivedData(int request_id, |
156 base::ProcessId renderer_pid); | 155 int data_offset, |
157 void OnReceivedData( | 156 int data_length, |
158 int request_id, | 157 int encoded_data_length); |
159 int data_offset, | 158 void OnDownloadedData(int request_id, int data_len, int encoded_data_length); |
160 int data_length, | |
161 int encoded_data_length); | |
162 void OnDownloadedData( | |
163 int request_id, | |
164 int data_len, | |
165 int encoded_data_length); | |
166 void OnRequestComplete( | 159 void OnRequestComplete( |
167 int request_id, | 160 int request_id, |
168 const ResourceMsg_RequestCompleteData &request_complete_data); | 161 const ResourceMsg_RequestCompleteData& request_complete_data); |
169 | 162 |
170 // Dispatch the message to one of the message response handlers. | 163 // Dispatch the message to one of the message response handlers. |
171 void DispatchMessage(const IPC::Message& message); | 164 void DispatchMessage(const IPC::Message& message); |
172 | 165 |
173 // Dispatch any deferred messages for the given request, provided it is not | 166 // Dispatch any deferred messages for the given request, provided it is not |
174 // again in the deferred state. | 167 // again in the deferred state. |
175 void FlushDeferredMessages(int request_id); | 168 void FlushDeferredMessages(int request_id); |
176 | 169 |
177 void ToResourceResponseInfo( | 170 void ToResourceResponseInfo( |
178 const PendingRequestInfo& request_info, | 171 const PendingRequestInfo& request_info, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 206 |
214 // IO thread timestamp for ongoing IPC message. | 207 // IO thread timestamp for ongoing IPC message. |
215 base::TimeTicks io_timestamp_; | 208 base::TimeTicks io_timestamp_; |
216 | 209 |
217 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); | 210 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); |
218 }; | 211 }; |
219 | 212 |
220 } // namespace content | 213 } // namespace content |
221 | 214 |
222 #endif // CONTENT_CHILD_RESOURCE_DISPATCHER_H_ | 215 #endif // CONTENT_CHILD_RESOURCE_DISPATCHER_H_ |
OLD | NEW |