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.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" |
11 #include "content/child/webthread_impl.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 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 int request_id, | 120 int request_id, |
121 blink::WebThreadedDataReceiver* threaded_data_receiver, | 121 blink::WebThreadedDataReceiver* threaded_data_receiver, |
122 linked_ptr<base::SharedMemory> shm_buffer, | 122 linked_ptr<base::SharedMemory> shm_buffer, |
123 int shm_size, | 123 int shm_size, |
124 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) | 124 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) |
125 : request_id_(request_id), | 125 : request_id_(request_id), |
126 shm_buffer_(shm_buffer), | 126 shm_buffer_(shm_buffer), |
127 shm_size_(shm_size), | 127 shm_size_(shm_size), |
128 background_thread_(static_cast<WebThreadImpl&>( | 128 background_thread_(static_cast<WebThreadImpl&>( |
129 *threaded_data_receiver->backgroundThread())), | 129 *threaded_data_receiver->backgroundThread())), |
130 ipc_channel_(ChildThread::current()->channel()), | 130 ipc_channel_(ChildThreadImpl::current()->channel()), |
131 threaded_data_receiver_(threaded_data_receiver), | 131 threaded_data_receiver_(threaded_data_receiver), |
132 resource_filter_active_(false), | 132 resource_filter_active_(false), |
133 main_thread_task_runner_(main_thread_task_runner), | 133 main_thread_task_runner_(main_thread_task_runner), |
134 main_thread_weak_factory_(this) { | 134 main_thread_weak_factory_(this) { |
135 DCHECK(ChildThread::current()); | 135 DCHECK(ChildThreadImpl::current()); |
136 DCHECK(ipc_channel_); | 136 DCHECK(ipc_channel_); |
137 DCHECK(threaded_data_receiver_); | 137 DCHECK(threaded_data_receiver_); |
138 DCHECK(main_thread_task_runner_.get()); | 138 DCHECK(main_thread_task_runner_.get()); |
139 | 139 |
140 background_thread_weak_factory_.reset( | 140 background_thread_weak_factory_.reset( |
141 new base::WeakPtrFactory<ThreadedDataProvider>(this)); | 141 new base::WeakPtrFactory<ThreadedDataProvider>(this)); |
142 | 142 |
143 filter_ = new DataProviderMessageFilter( | 143 filter_ = new DataProviderMessageFilter( |
144 ChildProcess::current()->io_message_loop_proxy(), | 144 ChildProcess::current()->io_message_loop_proxy(), |
145 main_thread_task_runner_, background_thread_, | 145 main_thread_task_runner_, background_thread_, |
146 background_thread_weak_factory_->GetWeakPtr(), | 146 background_thread_weak_factory_->GetWeakPtr(), |
147 main_thread_weak_factory_.GetWeakPtr(), request_id); | 147 main_thread_weak_factory_.GetWeakPtr(), request_id); |
148 | 148 |
149 ChildThread::current()->channel()->AddFilter(filter_.get()); | 149 ChildThreadImpl::current()->channel()->AddFilter(filter_.get()); |
150 } | 150 } |
151 | 151 |
152 ThreadedDataProvider::~ThreadedDataProvider() { | 152 ThreadedDataProvider::~ThreadedDataProvider() { |
153 DCHECK(ChildThread::current()); | 153 DCHECK(ChildThreadImpl::current()); |
154 | 154 |
155 ChildThread::current()->channel()->RemoveFilter(filter_.get()); | 155 ChildThreadImpl::current()->channel()->RemoveFilter(filter_.get()); |
156 | 156 |
157 delete threaded_data_receiver_; | 157 delete threaded_data_receiver_; |
158 } | 158 } |
159 | 159 |
160 void DestructOnMainThread(ThreadedDataProvider* data_provider) { | 160 void DestructOnMainThread(ThreadedDataProvider* data_provider) { |
161 DCHECK(ChildThread::current()); | 161 DCHECK(ChildThreadImpl::current()); |
162 | 162 |
163 // The ThreadedDataProvider must be destructed on the main thread to | 163 // The ThreadedDataProvider must be destructed on the main thread to |
164 // be threadsafe when removing the message filter and releasing the shared | 164 // be threadsafe when removing the message filter and releasing the shared |
165 // memory buffer. | 165 // memory buffer. |
166 delete data_provider; | 166 delete data_provider; |
167 } | 167 } |
168 | 168 |
169 void ThreadedDataProvider::Stop() { | 169 void ThreadedDataProvider::Stop() { |
170 DCHECK(ChildThread::current()); | 170 DCHECK(ChildThreadImpl::current()); |
171 | 171 |
172 // Make sure we don't get called by on the main thread anymore via weak | 172 // Make sure we don't get called by on the main thread anymore via weak |
173 // pointers we've passed to the filter. | 173 // pointers we've passed to the filter. |
174 main_thread_weak_factory_.InvalidateWeakPtrs(); | 174 main_thread_weak_factory_.InvalidateWeakPtrs(); |
175 | 175 |
176 blink::WebThread* current_background_thread = | 176 blink::WebThread* current_background_thread = |
177 threaded_data_receiver_->backgroundThread(); | 177 threaded_data_receiver_->backgroundThread(); |
178 | 178 |
179 // 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 |
180 // 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 |
(...skipping 19 matching lines...) Expand all Loading... |
200 // 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. |
201 // Destructing the weak pointer factory means invalidating the weak pointers | 201 // Destructing the weak pointer factory means invalidating the weak pointers |
202 // 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 |
203 // use this instance on the background thread. | 203 // use this instance on the background thread. |
204 background_thread_weak_factory_.reset(NULL); | 204 background_thread_weak_factory_.reset(NULL); |
205 main_thread_task_runner_->PostTask(FROM_HERE, | 205 main_thread_task_runner_->PostTask(FROM_HERE, |
206 base::Bind(&DestructOnMainThread, this)); | 206 base::Bind(&DestructOnMainThread, this)); |
207 } | 207 } |
208 | 208 |
209 void ThreadedDataProvider::OnResourceMessageFilterAddedMainThread() { | 209 void ThreadedDataProvider::OnResourceMessageFilterAddedMainThread() { |
210 DCHECK(ChildThread::current()); | 210 DCHECK(ChildThreadImpl::current()); |
211 DCHECK(background_thread_weak_factory_); | 211 DCHECK(background_thread_weak_factory_); |
212 | 212 |
213 // We bounce this message from the I/O thread via the main thread and then | 213 // We bounce this message from the I/O thread via the main thread and then |
214 // to our background thread, following the same path as incoming data before | 214 // to our background thread, following the same path as incoming data before |
215 // our filter gets added, to make sure there's nothing still incoming. | 215 // our filter gets added, to make sure there's nothing still incoming. |
216 background_thread_.message_loop()->PostTask(FROM_HERE, | 216 background_thread_.message_loop()->PostTask(FROM_HERE, |
217 base::Bind( | 217 base::Bind( |
218 &ThreadedDataProvider::OnResourceMessageFilterAddedBackgroundThread, | 218 &ThreadedDataProvider::OnResourceMessageFilterAddedBackgroundThread, |
219 background_thread_weak_factory_->GetWeakPtr())); | 219 background_thread_weak_factory_->GetWeakPtr())); |
220 } | 220 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 // sure we forward (and ACK) everything in the right order. | 257 // sure we forward (and ACK) everything in the right order. |
258 QueuedSharedMemoryData queued_data; | 258 QueuedSharedMemoryData queued_data; |
259 queued_data.data = data_ptr + data_offset; | 259 queued_data.data = data_ptr + data_offset; |
260 queued_data.length = data_length; | 260 queued_data.length = data_length; |
261 queued_data_.push_back(queued_data); | 261 queued_data_.push_back(queued_data); |
262 } | 262 } |
263 } | 263 } |
264 | 264 |
265 void ThreadedDataProvider::OnReceivedDataOnForegroundThread( | 265 void ThreadedDataProvider::OnReceivedDataOnForegroundThread( |
266 const char* data, int data_length, int encoded_data_length) { | 266 const char* data, int data_length, int encoded_data_length) { |
267 DCHECK(ChildThread::current()); | 267 DCHECK(ChildThreadImpl::current()); |
268 | 268 |
269 background_thread_.message_loop()->PostTask(FROM_HERE, | 269 background_thread_.message_loop()->PostTask(FROM_HERE, |
270 base::Bind(&ThreadedDataProvider::ForwardAndACKData, | 270 base::Bind(&ThreadedDataProvider::ForwardAndACKData, |
271 base::Unretained(this), | 271 base::Unretained(this), |
272 data, data_length)); | 272 data, data_length)); |
273 } | 273 } |
274 | 274 |
275 void ThreadedDataProvider::ForwardAndACKData(const char* data, | 275 void ThreadedDataProvider::ForwardAndACKData(const char* data, |
276 int data_length) { | 276 int data_length) { |
277 DCHECK(background_thread_.isCurrentThread()); | 277 DCHECK(background_thread_.isCurrentThread()); |
278 | 278 |
279 // TODO(oysteine): SiteIsolationPolicy needs to be be checked | 279 // TODO(oysteine): SiteIsolationPolicy needs to be be checked |
280 // here before we pass the data to the data provider | 280 // here before we pass the data to the data provider |
281 // (or earlier on the I/O thread), otherwise once SiteIsolationPolicy does | 281 // (or earlier on the I/O thread), otherwise once SiteIsolationPolicy does |
282 // actual blocking as opposed to just UMA logging this will bypass it. | 282 // actual blocking as opposed to just UMA logging this will bypass it. |
283 threaded_data_receiver_->acceptData(data, data_length); | 283 threaded_data_receiver_->acceptData(data, data_length); |
284 ipc_channel_->Send(new ResourceHostMsg_DataReceived_ACK(request_id_)); | 284 ipc_channel_->Send(new ResourceHostMsg_DataReceived_ACK(request_id_)); |
285 } | 285 } |
286 | 286 |
287 } // namespace content | 287 } // namespace content |
OLD | NEW |