OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "content/child/threaded_data_provider.h" | 5 #include "content/child/threaded_data_provider.h" |
6 | 6 |
7 #include "content/child/child_process.h" | 7 #include "content/child/child_process.h" |
8 #include "content/child/child_thread_impl.h" | 8 #include "content/child/child_thread_impl.h" |
9 #include "content/child/resource_dispatcher.h" | 9 #include "content/child/resource_dispatcher.h" |
10 #include "content/child/thread_safe_sender.h" | 10 #include "content/child/thread_safe_sender.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } | 101 } |
102 | 102 |
103 return false; | 103 return false; |
104 } | 104 } |
105 | 105 |
106 void DataProviderMessageFilter::OnReceivedData(int request_id, | 106 void DataProviderMessageFilter::OnReceivedData(int request_id, |
107 int data_offset, | 107 int data_offset, |
108 int data_length, | 108 int data_length, |
109 int encoded_data_length) { | 109 int encoded_data_length) { |
110 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 110 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
111 background_thread_.TaskRunner()->PostTask( | 111 background_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
112 FROM_HERE, | 112 &ThreadedDataProvider::OnReceivedDataOnBackgroundThread, |
113 base::Bind(&ThreadedDataProvider::OnReceivedDataOnBackgroundThread, | 113 background_thread_resource_provider_, |
114 background_thread_resource_provider_, data_offset, data_length, | 114 data_offset, data_length, encoded_data_length)); |
115 encoded_data_length)); | |
116 } | 115 } |
117 | 116 |
118 } // anonymous namespace | 117 } // anonymous namespace |
119 | 118 |
120 ThreadedDataProvider::ThreadedDataProvider( | 119 ThreadedDataProvider::ThreadedDataProvider( |
121 int request_id, | 120 int request_id, |
122 blink::WebThreadedDataReceiver* threaded_data_receiver, | 121 blink::WebThreadedDataReceiver* threaded_data_receiver, |
123 linked_ptr<base::SharedMemory> shm_buffer, | 122 linked_ptr<base::SharedMemory> shm_buffer, |
124 int shm_size, | 123 int shm_size, |
125 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) | 124 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 // We can't destroy this instance directly; we need to bounce a message over | 179 // We can't destroy this instance directly; we need to bounce a message over |
181 // to the background thread and back to make sure nothing else will access it | 180 // to the background thread and back to make sure nothing else will access it |
182 // there, before we can destruct it. We also need to make sure the background | 181 // there, before we can destruct it. We also need to make sure the background |
183 // thread is still alive, since Blink could have shut down at this point | 182 // thread is still alive, since Blink could have shut down at this point |
184 // and freed the thread. | 183 // and freed the thread. |
185 if (current_background_thread) { | 184 if (current_background_thread) { |
186 // We should never end up with a different parser thread than from when the | 185 // We should never end up with a different parser thread than from when the |
187 // ThreadedDataProvider gets created. | 186 // ThreadedDataProvider gets created. |
188 DCHECK(current_background_thread == | 187 DCHECK(current_background_thread == |
189 static_cast<WebThreadImpl*>(&background_thread_)); | 188 static_cast<WebThreadImpl*>(&background_thread_)); |
190 background_thread_.TaskRunner()->PostTask( | 189 background_thread_.message_loop()->PostTask(FROM_HERE, |
191 FROM_HERE, base::Bind(&ThreadedDataProvider::StopOnBackgroundThread, | 190 base::Bind(&ThreadedDataProvider::StopOnBackgroundThread, |
192 base::Unretained(this))); | 191 base::Unretained(this))); |
193 } | 192 } |
194 } | 193 } |
195 | 194 |
196 void ThreadedDataProvider::StopOnBackgroundThread() { | 195 void ThreadedDataProvider::StopOnBackgroundThread() { |
197 DCHECK(background_thread_.isCurrentThread()); | 196 DCHECK(background_thread_.isCurrentThread()); |
198 DCHECK(background_thread_weak_factory_); | 197 DCHECK(background_thread_weak_factory_); |
199 | 198 |
200 // When this happens, the provider should no longer be called on the | 199 // When this happens, the provider should no longer be called on the |
201 // background thread as it's about to be destroyed on the main thread. | 200 // background thread as it's about to be destroyed on the main thread. |
202 // Destructing the weak pointer factory means invalidating the weak pointers | 201 // Destructing the weak pointer factory means invalidating the weak pointers |
203 // which means no callbacks from the filter will happen and nothing else will | 202 // which means no callbacks from the filter will happen and nothing else will |
204 // use this instance on the background thread. | 203 // use this instance on the background thread. |
205 background_thread_weak_factory_.reset(NULL); | 204 background_thread_weak_factory_.reset(NULL); |
206 main_thread_task_runner_->PostTask(FROM_HERE, | 205 main_thread_task_runner_->PostTask(FROM_HERE, |
207 base::Bind(&ThreadedDataProvider::DestructOnMainThread, | 206 base::Bind(&ThreadedDataProvider::DestructOnMainThread, |
208 base::Unretained(this))); | 207 base::Unretained(this))); |
209 } | 208 } |
210 | 209 |
211 void ThreadedDataProvider::OnRequestCompleteForegroundThread( | 210 void ThreadedDataProvider::OnRequestCompleteForegroundThread( |
212 base::WeakPtr<ResourceDispatcher> resource_dispatcher, | 211 base::WeakPtr<ResourceDispatcher> resource_dispatcher, |
213 const ResourceMsg_RequestCompleteData& request_complete_data, | 212 const ResourceMsg_RequestCompleteData& request_complete_data, |
214 const base::TimeTicks& renderer_completion_time) { | 213 const base::TimeTicks& renderer_completion_time) { |
215 DCHECK(ChildThreadImpl::current()); | 214 DCHECK(ChildThreadImpl::current()); |
216 | 215 |
217 background_thread_.TaskRunner()->PostTask( | 216 background_thread_.message_loop()->PostTask(FROM_HERE, |
218 FROM_HERE, | |
219 base::Bind(&ThreadedDataProvider::OnRequestCompleteBackgroundThread, | 217 base::Bind(&ThreadedDataProvider::OnRequestCompleteBackgroundThread, |
220 base::Unretained(this), resource_dispatcher, | 218 base::Unretained(this), resource_dispatcher, |
221 request_complete_data, renderer_completion_time)); | 219 request_complete_data, renderer_completion_time)); |
222 } | 220 } |
223 | 221 |
224 void ThreadedDataProvider::OnRequestCompleteBackgroundThread( | 222 void ThreadedDataProvider::OnRequestCompleteBackgroundThread( |
225 base::WeakPtr<ResourceDispatcher> resource_dispatcher, | 223 base::WeakPtr<ResourceDispatcher> resource_dispatcher, |
226 const ResourceMsg_RequestCompleteData& request_complete_data, | 224 const ResourceMsg_RequestCompleteData& request_complete_data, |
227 const base::TimeTicks& renderer_completion_time) { | 225 const base::TimeTicks& renderer_completion_time) { |
228 DCHECK(background_thread_.isCurrentThread()); | 226 DCHECK(background_thread_.isCurrentThread()); |
229 | 227 |
230 main_thread_task_runner_->PostTask(FROM_HERE, | 228 main_thread_task_runner_->PostTask(FROM_HERE, |
231 base::Bind( | 229 base::Bind( |
232 &ResourceDispatcher::CompletedRequestAfterBackgroundThreadFlush, | 230 &ResourceDispatcher::CompletedRequestAfterBackgroundThreadFlush, |
233 resource_dispatcher, | 231 resource_dispatcher, |
234 request_id_, | 232 request_id_, |
235 request_complete_data, | 233 request_complete_data, |
236 renderer_completion_time)); | 234 renderer_completion_time)); |
237 } | 235 } |
238 | 236 |
239 void ThreadedDataProvider::OnResourceMessageFilterAddedMainThread() { | 237 void ThreadedDataProvider::OnResourceMessageFilterAddedMainThread() { |
240 DCHECK(ChildThreadImpl::current()); | 238 DCHECK(ChildThreadImpl::current()); |
241 DCHECK(background_thread_weak_factory_); | 239 DCHECK(background_thread_weak_factory_); |
242 | 240 |
243 // We bounce this message from the I/O thread via the main thread and then | 241 // We bounce this message from the I/O thread via the main thread and then |
244 // to our background thread, following the same path as incoming data before | 242 // to our background thread, following the same path as incoming data before |
245 // our filter gets added, to make sure there's nothing still incoming. | 243 // our filter gets added, to make sure there's nothing still incoming. |
246 background_thread_.TaskRunner()->PostTask( | 244 background_thread_.message_loop()->PostTask(FROM_HERE, |
247 FROM_HERE, | |
248 base::Bind( | 245 base::Bind( |
249 &ThreadedDataProvider::OnResourceMessageFilterAddedBackgroundThread, | 246 &ThreadedDataProvider::OnResourceMessageFilterAddedBackgroundThread, |
250 background_thread_weak_factory_->GetWeakPtr())); | 247 background_thread_weak_factory_->GetWeakPtr())); |
251 } | 248 } |
252 | 249 |
253 void ThreadedDataProvider::OnResourceMessageFilterAddedBackgroundThread() { | 250 void ThreadedDataProvider::OnResourceMessageFilterAddedBackgroundThread() { |
254 DCHECK(background_thread_.isCurrentThread()); | 251 DCHECK(background_thread_.isCurrentThread()); |
255 resource_filter_active_ = true; | 252 resource_filter_active_ = true; |
256 | 253 |
257 // At this point we know no more data is going to arrive from the main thread, | 254 // At this point we know no more data is going to arrive from the main thread, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 queued_data.length = data_length; | 288 queued_data.length = data_length; |
292 queued_data.encoded_length = encoded_data_length; | 289 queued_data.encoded_length = encoded_data_length; |
293 queued_data_.push_back(queued_data); | 290 queued_data_.push_back(queued_data); |
294 } | 291 } |
295 } | 292 } |
296 | 293 |
297 void ThreadedDataProvider::OnReceivedDataOnForegroundThread( | 294 void ThreadedDataProvider::OnReceivedDataOnForegroundThread( |
298 const char* data, int data_length, int encoded_data_length) { | 295 const char* data, int data_length, int encoded_data_length) { |
299 DCHECK(ChildThreadImpl::current()); | 296 DCHECK(ChildThreadImpl::current()); |
300 | 297 |
301 background_thread_.TaskRunner()->PostTask( | 298 background_thread_.message_loop()->PostTask(FROM_HERE, |
302 FROM_HERE, base::Bind(&ThreadedDataProvider::ForwardAndACKData, | 299 base::Bind(&ThreadedDataProvider::ForwardAndACKData, |
303 base::Unretained(this), data, data_length, | 300 base::Unretained(this), |
304 encoded_data_length)); | 301 data, data_length, encoded_data_length)); |
305 } | 302 } |
306 | 303 |
307 void ThreadedDataProvider::ForwardAndACKData(const char* data, | 304 void ThreadedDataProvider::ForwardAndACKData(const char* data, |
308 int data_length, | 305 int data_length, |
309 int encoded_data_length) { | 306 int encoded_data_length) { |
310 DCHECK(background_thread_.isCurrentThread()); | 307 DCHECK(background_thread_.isCurrentThread()); |
311 | 308 |
312 // TODO(oysteine): SiteIsolationPolicy needs to be be checked | 309 // TODO(oysteine): SiteIsolationPolicy needs to be be checked |
313 // here before we pass the data to the data provider | 310 // here before we pass the data to the data provider |
314 // (or earlier on the I/O thread), otherwise once SiteIsolationPolicy does | 311 // (or earlier on the I/O thread), otherwise once SiteIsolationPolicy does |
(...skipping 23 matching lines...) Expand all Loading... |
338 DCHECK(threaded_data_receiver_->needsMainthreadDataCopy()); | 335 DCHECK(threaded_data_receiver_->needsMainthreadDataCopy()); |
339 DCHECK_EQ((size_t)data_length, data_copy->size()); | 336 DCHECK_EQ((size_t)data_length, data_copy->size()); |
340 } | 337 } |
341 | 338 |
342 threaded_data_receiver_->acceptMainthreadDataNotification( | 339 threaded_data_receiver_->acceptMainthreadDataNotification( |
343 (data_copy && !data_copy->empty()) ? &data_copy->front() : NULL, | 340 (data_copy && !data_copy->empty()) ? &data_copy->front() : NULL, |
344 data_length, encoded_data_length); | 341 data_length, encoded_data_length); |
345 } | 342 } |
346 | 343 |
347 } // namespace content | 344 } // namespace content |
OLD | NEW |