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/scheduler/webthread_impl_for_worker_scheduler.h" | |
11 #include "content/child/thread_safe_sender.h" | 10 #include "content/child/thread_safe_sender.h" |
| 11 #include "content/child/webthread_impl.h" |
12 #include "content/common/resource_messages.h" | 12 #include "content/common/resource_messages.h" |
13 #include "ipc/ipc_sync_channel.h" | 13 #include "ipc/ipc_sync_channel.h" |
14 #include "third_party/WebKit/public/platform/WebThread.h" | 14 #include "third_party/WebKit/public/platform/WebThread.h" |
15 #include "third_party/WebKit/public/platform/WebThreadedDataReceiver.h" | 15 #include "third_party/WebKit/public/platform/WebThreadedDataReceiver.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 class DataProviderMessageFilter : public IPC::MessageFilter { | 21 class DataProviderMessageFilter : public IPC::MessageFilter { |
22 public: | 22 public: |
23 DataProviderMessageFilter( | 23 DataProviderMessageFilter( |
24 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, | 24 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, |
25 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, | 25 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, |
26 const WebThreadImplForWorkerScheduler& background_thread, | 26 const WebThreadImpl& background_thread, |
27 const base::WeakPtr<ThreadedDataProvider>& | 27 const base::WeakPtr<ThreadedDataProvider>& |
28 background_thread_resource_provider, | 28 background_thread_resource_provider, |
29 const base::WeakPtr<ThreadedDataProvider>& main_thread_resource_provider, | 29 const base::WeakPtr<ThreadedDataProvider>& main_thread_resource_provider, |
30 int request_id); | 30 int request_id); |
31 | 31 |
32 // IPC::ChannelProxy::MessageFilter | 32 // IPC::ChannelProxy::MessageFilter |
33 void OnFilterAdded(IPC::Sender* sender) final; | 33 void OnFilterAdded(IPC::Sender* sender) final; |
34 bool OnMessageReceived(const IPC::Message& message) final; | 34 bool OnMessageReceived(const IPC::Message& message) final; |
35 | 35 |
36 private: | 36 private: |
37 ~DataProviderMessageFilter() override {} | 37 ~DataProviderMessageFilter() override {} |
38 | 38 |
39 void OnReceivedData(int request_id, int data_offset, int data_length, | 39 void OnReceivedData(int request_id, int data_offset, int data_length, |
40 int encoded_data_length); | 40 int encoded_data_length); |
41 | 41 |
42 const scoped_refptr<base::MessageLoopProxy> io_message_loop_; | 42 const scoped_refptr<base::MessageLoopProxy> io_message_loop_; |
43 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 43 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
44 const WebThreadImplForWorkerScheduler& background_thread_; | 44 const WebThreadImpl& background_thread_; |
45 // This weakptr can only be dereferenced on the background thread. | 45 // This weakptr can only be dereferenced on the background thread. |
46 base::WeakPtr<ThreadedDataProvider> | 46 base::WeakPtr<ThreadedDataProvider> |
47 background_thread_resource_provider_; | 47 background_thread_resource_provider_; |
48 // This weakptr can only be dereferenced on the main thread. | 48 // This weakptr can only be dereferenced on the main thread. |
49 base::WeakPtr<ThreadedDataProvider> | 49 base::WeakPtr<ThreadedDataProvider> |
50 main_thread_resource_provider_; | 50 main_thread_resource_provider_; |
51 int request_id_; | 51 int request_id_; |
52 }; | 52 }; |
53 | 53 |
54 DataProviderMessageFilter::DataProviderMessageFilter( | 54 DataProviderMessageFilter::DataProviderMessageFilter( |
55 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, | 55 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, |
56 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, | 56 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, |
57 const WebThreadImplForWorkerScheduler& background_thread, | 57 const WebThreadImpl& background_thread, |
58 const base::WeakPtr<ThreadedDataProvider>& | 58 const base::WeakPtr<ThreadedDataProvider>& |
59 background_thread_resource_provider, | 59 background_thread_resource_provider, |
60 const base::WeakPtr<ThreadedDataProvider>& main_thread_resource_provider, | 60 const base::WeakPtr<ThreadedDataProvider>& main_thread_resource_provider, |
61 int request_id) | 61 int request_id) |
62 : io_message_loop_(io_message_loop), | 62 : io_message_loop_(io_message_loop), |
63 main_thread_task_runner_(main_thread_task_runner), | 63 main_thread_task_runner_(main_thread_task_runner), |
64 background_thread_(background_thread), | 64 background_thread_(background_thread), |
65 background_thread_resource_provider_(background_thread_resource_provider), | 65 background_thread_resource_provider_(background_thread_resource_provider), |
66 main_thread_resource_provider_(main_thread_resource_provider), | 66 main_thread_resource_provider_(main_thread_resource_provider), |
67 request_id_(request_id) { | 67 request_id_(request_id) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 ThreadedDataProvider::ThreadedDataProvider( | 120 ThreadedDataProvider::ThreadedDataProvider( |
121 int request_id, | 121 int request_id, |
122 blink::WebThreadedDataReceiver* threaded_data_receiver, | 122 blink::WebThreadedDataReceiver* threaded_data_receiver, |
123 linked_ptr<base::SharedMemory> shm_buffer, | 123 linked_ptr<base::SharedMemory> shm_buffer, |
124 int shm_size, | 124 int shm_size, |
125 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) | 125 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) |
126 : request_id_(request_id), | 126 : request_id_(request_id), |
127 shm_buffer_(shm_buffer), | 127 shm_buffer_(shm_buffer), |
128 shm_size_(shm_size), | 128 shm_size_(shm_size), |
129 background_thread_(static_cast<WebThreadImplForWorkerScheduler&>( | 129 background_thread_(static_cast<WebThreadImpl&>( |
130 *threaded_data_receiver->backgroundThread())), | 130 *threaded_data_receiver->backgroundThread())), |
131 ipc_channel_(ChildThreadImpl::current()->channel()), | 131 ipc_channel_(ChildThreadImpl::current()->channel()), |
132 threaded_data_receiver_(threaded_data_receiver), | 132 threaded_data_receiver_(threaded_data_receiver), |
133 resource_filter_active_(false), | 133 resource_filter_active_(false), |
134 main_thread_task_runner_(main_thread_task_runner), | 134 main_thread_task_runner_(main_thread_task_runner), |
135 main_thread_weak_factory_(this) { | 135 main_thread_weak_factory_(this) { |
136 DCHECK(ChildThreadImpl::current()); | 136 DCHECK(ChildThreadImpl::current()); |
137 DCHECK(ipc_channel_); | 137 DCHECK(ipc_channel_); |
138 DCHECK(threaded_data_receiver_); | 138 DCHECK(threaded_data_receiver_); |
139 DCHECK(main_thread_task_runner_.get()); | 139 DCHECK(main_thread_task_runner_.get()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 179 |
180 // We can't destroy this instance directly; we need to bounce a message over | 180 // 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 | 181 // 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 | 182 // 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 | 183 // thread is still alive, since Blink could have shut down at this point |
184 // and freed the thread. | 184 // and freed the thread. |
185 if (current_background_thread) { | 185 if (current_background_thread) { |
186 // We should never end up with a different parser thread than from when the | 186 // We should never end up with a different parser thread than from when the |
187 // ThreadedDataProvider gets created. | 187 // ThreadedDataProvider gets created. |
188 DCHECK(current_background_thread == | 188 DCHECK(current_background_thread == |
189 static_cast<WebThreadImplForWorkerScheduler*>(&background_thread_)); | 189 static_cast<WebThreadImpl*>(&background_thread_)); |
190 background_thread_.TaskRunner()->PostTask( | 190 background_thread_.TaskRunner()->PostTask( |
191 FROM_HERE, base::Bind(&ThreadedDataProvider::StopOnBackgroundThread, | 191 FROM_HERE, base::Bind(&ThreadedDataProvider::StopOnBackgroundThread, |
192 base::Unretained(this))); | 192 base::Unretained(this))); |
193 } | 193 } |
194 } | 194 } |
195 | 195 |
196 void ThreadedDataProvider::StopOnBackgroundThread() { | 196 void ThreadedDataProvider::StopOnBackgroundThread() { |
197 DCHECK(background_thread_.isCurrentThread()); | 197 DCHECK(background_thread_.isCurrentThread()); |
198 DCHECK(background_thread_weak_factory_); | 198 DCHECK(background_thread_weak_factory_); |
199 | 199 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 DCHECK(threaded_data_receiver_->needsMainthreadDataCopy()); | 338 DCHECK(threaded_data_receiver_->needsMainthreadDataCopy()); |
339 DCHECK_EQ((size_t)data_length, data_copy->size()); | 339 DCHECK_EQ((size_t)data_length, data_copy->size()); |
340 } | 340 } |
341 | 341 |
342 threaded_data_receiver_->acceptMainthreadDataNotification( | 342 threaded_data_receiver_->acceptMainthreadDataNotification( |
343 (data_copy && !data_copy->empty()) ? &data_copy->front() : NULL, | 343 (data_copy && !data_copy->empty()) ? &data_copy->front() : NULL, |
344 data_length, encoded_data_length); | 344 data_length, encoded_data_length); |
345 } | 345 } |
346 | 346 |
347 } // namespace content | 347 } // namespace content |
OLD | NEW |