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 #include "ppapi/shared_impl/tracked_callback.h" | 5 #include "ppapi/shared_impl/tracked_callback.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 | 30 |
31 int32_t RunCompletionTask(TrackedCallback::CompletionTask completion_task, | 31 int32_t RunCompletionTask(TrackedCallback::CompletionTask completion_task, |
32 int32_t result) { | 32 int32_t result) { |
33 ProxyLock::AssertAcquired(); | 33 ProxyLock::AssertAcquired(); |
34 int32_t task_result = completion_task.Run(result); | 34 int32_t task_result = completion_task.Run(result); |
35 if (result != PP_ERROR_ABORTED) | 35 if (result != PP_ERROR_ABORTED) |
36 result = task_result; | 36 result = task_result; |
37 return result; | 37 return result; |
38 } | 38 } |
39 | 39 |
40 void AcquireProxyLockAndRun(const base::Closure& closure) { | |
41 ProxyAutoLock acquire; | |
42 closure.Run(); | |
43 } | |
44 | |
45 | |
46 } // namespace | 40 } // namespace |
47 | 41 |
48 // TrackedCallback ------------------------------------------------------------- | 42 // TrackedCallback ------------------------------------------------------------- |
49 | 43 |
50 // Note: don't keep a Resource* since it may go out of scope before us. | 44 // Note: don't keep a Resource* since it may go out of scope before us. |
51 TrackedCallback::TrackedCallback(Resource* resource, | 45 TrackedCallback::TrackedCallback(Resource* resource, |
52 const PP_CompletionCallback& callback) | 46 const PP_CompletionCallback& callback) |
53 : is_scheduled_(false), | 47 : is_scheduled_(false), |
54 resource_id_(resource ? resource->pp_resource() : 0), | 48 resource_id_(resource ? resource->pp_resource() : 0), |
55 completed_(false), | 49 completed_(false), |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 aborted_ = true; | 239 aborted_ = true; |
246 // We might abort when there's already a scheduled callback, but callers | 240 // We might abort when there's already a scheduled callback, but callers |
247 // should never try to PostRun more than once otherwise. | 241 // should never try to PostRun more than once otherwise. |
248 DCHECK(result == PP_ERROR_ABORTED || !is_scheduled_); | 242 DCHECK(result == PP_ERROR_ABORTED || !is_scheduled_); |
249 | 243 |
250 if (is_blocking()) { | 244 if (is_blocking()) { |
251 // We might not have a MessageLoop to post to, so we must Signal | 245 // We might not have a MessageLoop to post to, so we must Signal |
252 // directly. | 246 // directly. |
253 SignalBlockingCallback(result); | 247 SignalBlockingCallback(result); |
254 } else { | 248 } else { |
255 // Note we can't use "RunWhileLocked" from proxy_lock.h, because it requires | |
256 // that the ProxyLock is held (to protect Resource and Var ref-counting). | |
257 // Here, we must not acquire the ProxyLock, because we may be on the IO | |
258 // thread. But we're not passing any parameters that would require | |
259 // the ProxyLock (such as Var or Resource). | |
260 base::Closure callback_closure( | 249 base::Closure callback_closure( |
261 base::Bind(&ppapi::AcquireProxyLockAndRun, | 250 RunWhileLocked(base::Bind(&TrackedCallback::Run, this, result))); |
raymes
2015/03/25 01:43:59
I don't really understand this change but maybe bb
dmichael (off chromium)
2015/03/25 17:35:04
That CL hasn't landed yet, and you're right... th
| |
262 base::Bind(&TrackedCallback::Run, this, result))); | |
263 if (target_loop_) { | 251 if (target_loop_) { |
264 target_loop_->PostClosure(FROM_HERE, callback_closure, 0); | 252 target_loop_->PostClosure(FROM_HERE, callback_closure, 0); |
265 } else { | 253 } else { |
266 // We must be running in-process and on the main thread (the Enter | 254 // We must be running in-process and on the main thread (the Enter |
267 // classes protect against having a null target_loop_ otherwise). | 255 // classes protect against having a null target_loop_ otherwise). |
268 DCHECK(IsMainThread()); | 256 DCHECK(IsMainThread()); |
269 DCHECK(PpapiGlobals::Get()->IsHostGlobals()); | 257 DCHECK(PpapiGlobals::Get()->IsHostGlobals()); |
270 base::MessageLoop::current()->PostTask(FROM_HERE, callback_closure); | 258 base::MessageLoop::current()->PostTask(FROM_HERE, callback_closure); |
271 } | 259 } |
272 } | 260 } |
(...skipping 17 matching lines...) Expand all Loading... | |
290 // tracker. Then MarkAsCompleted before waking up the blocked thread, | 278 // tracker. Then MarkAsCompleted before waking up the blocked thread, |
291 // which could potentially re-enter. | 279 // which could potentially re-enter. |
292 scoped_refptr<TrackedCallback> thiz(this); | 280 scoped_refptr<TrackedCallback> thiz(this); |
293 MarkAsCompletedWithLock(); | 281 MarkAsCompletedWithLock(); |
294 // Wake up the blocked thread. See BlockUntilComplete for where the thread | 282 // Wake up the blocked thread. See BlockUntilComplete for where the thread |
295 // Wait()s. | 283 // Wait()s. |
296 operation_completed_condvar_->Signal(); | 284 operation_completed_condvar_->Signal(); |
297 } | 285 } |
298 | 286 |
299 } // namespace ppapi | 287 } // namespace ppapi |
OLD | NEW |