| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 if (completed()) { | 158 if (completed()) { |
| 159 NOTREACHED(); | 159 NOTREACHED(); |
| 160 return; | 160 return; |
| 161 } | 161 } |
| 162 if (result == PP_ERROR_ABORTED) | 162 if (result == PP_ERROR_ABORTED) |
| 163 aborted_ = true; | 163 aborted_ = true; |
| 164 // We might abort when there's already a scheduled callback, but callers | 164 // We might abort when there's already a scheduled callback, but callers |
| 165 // should never try to PostRun more than once otherwise. | 165 // should never try to PostRun more than once otherwise. |
| 166 DCHECK(result == PP_ERROR_ABORTED || !is_scheduled_); | 166 DCHECK(result == PP_ERROR_ABORTED || !is_scheduled_); |
| 167 | 167 |
| 168 base::Closure callback_closure( | 168 if (is_blocking()) { |
| 169 RunWhileLocked(base::Bind(&TrackedCallback::Run, this, result))); | 169 // We might not have a MessageLoop to post to, so we must call Run() |
| 170 if (!target_loop_.get()) { | 170 // directly. |
| 171 // We must be running in-process and on the main thread (the Enter | 171 Run(result); |
| 172 // classes protect against having a null target_loop_ otherwise). | |
| 173 DCHECK(IsMainThread()); | |
| 174 DCHECK(PpapiGlobals::Get()->IsHostGlobals()); | |
| 175 base::MessageLoop::current()->PostTask(FROM_HERE, callback_closure); | |
| 176 } else { | 172 } else { |
| 177 target_loop_->PostClosure(FROM_HERE, callback_closure, 0); | 173 base::Closure callback_closure( |
| 174 RunWhileLocked(base::Bind(&TrackedCallback::Run, this, result))); |
| 175 if (target_loop_) { |
| 176 target_loop_->PostClosure(FROM_HERE, callback_closure, 0); |
| 177 } else { |
| 178 // We must be running in-process and on the main thread (the Enter |
| 179 // classes protect against having a null target_loop_ otherwise). |
| 180 DCHECK(IsMainThread()); |
| 181 DCHECK(PpapiGlobals::Get()->IsHostGlobals()); |
| 182 base::MessageLoop::current()->PostTask(FROM_HERE, callback_closure); |
| 183 } |
| 178 } | 184 } |
| 179 is_scheduled_ = true; | 185 is_scheduled_ = true; |
| 180 } | 186 } |
| 181 | 187 |
| 182 void TrackedCallback::set_completion_task( | 188 void TrackedCallback::set_completion_task( |
| 183 const CompletionTask& completion_task) { | 189 const CompletionTask& completion_task) { |
| 184 DCHECK(completion_task_.is_null()); | 190 DCHECK(completion_task_.is_null()); |
| 185 completion_task_ = completion_task; | 191 completion_task_ = completion_task; |
| 186 } | 192 } |
| 187 | 193 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 // until we're done. | 238 // until we're done. |
| 233 scoped_refptr<TrackedCallback> thiz = this; | 239 scoped_refptr<TrackedCallback> thiz = this; |
| 234 completed_ = true; | 240 completed_ = true; |
| 235 // We may not have a valid resource, in which case we're not in the tracker. | 241 // We may not have a valid resource, in which case we're not in the tracker. |
| 236 if (resource_id_) | 242 if (resource_id_) |
| 237 tracker_->Remove(thiz); | 243 tracker_->Remove(thiz); |
| 238 tracker_ = NULL; | 244 tracker_ = NULL; |
| 239 } | 245 } |
| 240 | 246 |
| 241 } // namespace ppapi | 247 } // namespace ppapi |
| OLD | NEW |