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/location.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 11 #include "base/single_thread_task_runner.h" |
11 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "base/thread_task_runner_handle.h" |
12 #include "ppapi/c/pp_completion_callback.h" | 14 #include "ppapi/c/pp_completion_callback.h" |
13 #include "ppapi/c/pp_errors.h" | 15 #include "ppapi/c/pp_errors.h" |
14 #include "ppapi/c/ppb_message_loop.h" | 16 #include "ppapi/c/ppb_message_loop.h" |
15 #include "ppapi/shared_impl/callback_tracker.h" | 17 #include "ppapi/shared_impl/callback_tracker.h" |
16 #include "ppapi/shared_impl/ppapi_globals.h" | 18 #include "ppapi/shared_impl/ppapi_globals.h" |
17 #include "ppapi/shared_impl/ppb_message_loop_shared.h" | 19 #include "ppapi/shared_impl/ppb_message_loop_shared.h" |
18 #include "ppapi/shared_impl/proxy_lock.h" | 20 #include "ppapi/shared_impl/proxy_lock.h" |
19 #include "ppapi/shared_impl/resource.h" | 21 #include "ppapi/shared_impl/resource.h" |
20 | 22 |
21 namespace ppapi { | 23 namespace ppapi { |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 } else { | 250 } else { |
249 base::Closure callback_closure( | 251 base::Closure callback_closure( |
250 RunWhileLocked(base::Bind(&TrackedCallback::Run, this, result))); | 252 RunWhileLocked(base::Bind(&TrackedCallback::Run, this, result))); |
251 if (target_loop_) { | 253 if (target_loop_) { |
252 target_loop_->PostClosure(FROM_HERE, callback_closure, 0); | 254 target_loop_->PostClosure(FROM_HERE, callback_closure, 0); |
253 } else { | 255 } else { |
254 // We must be running in-process and on the main thread (the Enter | 256 // We must be running in-process and on the main thread (the Enter |
255 // classes protect against having a null target_loop_ otherwise). | 257 // classes protect against having a null target_loop_ otherwise). |
256 DCHECK(IsMainThread()); | 258 DCHECK(IsMainThread()); |
257 DCHECK(PpapiGlobals::Get()->IsHostGlobals()); | 259 DCHECK(PpapiGlobals::Get()->IsHostGlobals()); |
258 base::MessageLoop::current()->PostTask(FROM_HERE, callback_closure); | 260 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 261 callback_closure); |
259 } | 262 } |
260 } | 263 } |
261 is_scheduled_ = true; | 264 is_scheduled_ = true; |
262 } | 265 } |
263 | 266 |
264 void TrackedCallback::SignalBlockingCallback(int32_t result) { | 267 void TrackedCallback::SignalBlockingCallback(int32_t result) { |
265 lock_.AssertAcquired(); | 268 lock_.AssertAcquired(); |
266 DCHECK(is_blocking()); | 269 DCHECK(is_blocking()); |
267 if (!operation_completed_condvar_) { | 270 if (!operation_completed_condvar_) { |
268 // If the condition variable is invalid, there are two possibilities. One, | 271 // If the condition variable is invalid, there are two possibilities. One, |
269 // we're running in-process, in which case the call should have come in on | 272 // we're running in-process, in which case the call should have come in on |
270 // the main thread and we should have returned PP_ERROR_BLOCKS_MAIN_THREAD | 273 // the main thread and we should have returned PP_ERROR_BLOCKS_MAIN_THREAD |
271 // well before this. Otherwise, this callback was not created as a | 274 // well before this. Otherwise, this callback was not created as a |
272 // blocking callback. Either way, there's some internal error. | 275 // blocking callback. Either way, there's some internal error. |
273 NOTREACHED(); | 276 NOTREACHED(); |
274 return; | 277 return; |
275 } | 278 } |
276 result_for_blocked_callback_ = result; | 279 result_for_blocked_callback_ = result; |
277 // Retain ourselves, since MarkAsCompleted will remove us from the | 280 // Retain ourselves, since MarkAsCompleted will remove us from the |
278 // tracker. Then MarkAsCompleted before waking up the blocked thread, | 281 // tracker. Then MarkAsCompleted before waking up the blocked thread, |
279 // which could potentially re-enter. | 282 // which could potentially re-enter. |
280 scoped_refptr<TrackedCallback> thiz(this); | 283 scoped_refptr<TrackedCallback> thiz(this); |
281 MarkAsCompletedWithLock(); | 284 MarkAsCompletedWithLock(); |
282 // Wake up the blocked thread. See BlockUntilComplete for where the thread | 285 // Wake up the blocked thread. See BlockUntilComplete for where the thread |
283 // Wait()s. | 286 // Wait()s. |
284 operation_completed_condvar_->Signal(); | 287 operation_completed_condvar_->Signal(); |
285 } | 288 } |
286 | 289 |
287 } // namespace ppapi | 290 } // namespace ppapi |
OLD | NEW |