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. Since we don't want to attempt to re-acquire the lock, we |
171 // We must be running in-process and on the main thread (the Enter | 171 // don't use the locking closure. |
bbudge
2013/09/04 22:52:16
Second part of comment needs tweaking. Maybe s/use
| |
172 // classes protect against having a null target_loop_ otherwise). | 172 Run(result); |
173 DCHECK(IsMainThread()); | |
174 DCHECK(PpapiGlobals::Get()->IsHostGlobals()); | |
175 base::MessageLoop::current()->PostTask(FROM_HERE, callback_closure); | |
176 } else { | 173 } else { |
177 target_loop_->PostClosure(FROM_HERE, callback_closure, 0); | 174 base::Closure callback_closure( |
175 RunWhileLocked(base::Bind(&TrackedCallback::Run, this, result))); | |
176 if (target_loop_) { | |
bbudge
2013/09/04 22:50:36
Do we have a conversion operator now? Should we st
| |
177 target_loop_->PostClosure(FROM_HERE, callback_closure, 0); | |
178 } else { | |
179 // We must be running in-process and on the main thread (the Enter | |
180 // classes protect against having a null target_loop_ otherwise). | |
181 DCHECK(IsMainThread()); | |
182 DCHECK(PpapiGlobals::Get()->IsHostGlobals()); | |
183 base::MessageLoop::current()->PostTask(FROM_HERE, callback_closure); | |
184 } | |
178 } | 185 } |
179 is_scheduled_ = true; | 186 is_scheduled_ = true; |
180 } | 187 } |
181 | 188 |
182 void TrackedCallback::set_completion_task( | 189 void TrackedCallback::set_completion_task( |
183 const CompletionTask& completion_task) { | 190 const CompletionTask& completion_task) { |
184 DCHECK(completion_task_.is_null()); | 191 DCHECK(completion_task_.is_null()); |
185 completion_task_ = completion_task; | 192 completion_task_ = completion_task; |
186 } | 193 } |
187 | 194 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 // until we're done. | 239 // until we're done. |
233 scoped_refptr<TrackedCallback> thiz = this; | 240 scoped_refptr<TrackedCallback> thiz = this; |
234 completed_ = true; | 241 completed_ = true; |
235 // We may not have a valid resource, in which case we're not in the tracker. | 242 // We may not have a valid resource, in which case we're not in the tracker. |
236 if (resource_id_) | 243 if (resource_id_) |
237 tracker_->Remove(thiz); | 244 tracker_->Remove(thiz); |
238 tracker_ = NULL; | 245 tracker_ = NULL; |
239 } | 246 } |
240 | 247 |
241 } // namespace ppapi | 248 } // namespace ppapi |
OLD | NEW |