Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(666)

Side by Side Diff: ppapi/shared_impl/tracked_callback.cc

Issue 23706006: PPAPI: Blocking callbacks shouldn't need a target_loop_ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 base::Closure callback_closure(
169 RunWhileLocked(base::Bind(&TrackedCallback::Run, this, result))); 169 RunWhileLocked(base::Bind(&TrackedCallback::Run, this, result)));
170 if (!target_loop_.get()) { 170 if (is_blocking()) {
171 // We might not have a MessageLoop to post to, so we must call Run()
172 // directly.
173 callback_closure.Run();
174 } else if (!target_loop_.get()) {
bbudge 2013/09/04 22:29:19 It seems like the most common case is last. Do you
171 // We must be running in-process and on the main thread (the Enter 175 // We must be running in-process and on the main thread (the Enter
172 // classes protect against having a null target_loop_ otherwise). 176 // classes protect against having a null target_loop_ otherwise).
173 DCHECK(IsMainThread()); 177 DCHECK(IsMainThread());
174 DCHECK(PpapiGlobals::Get()->IsHostGlobals()); 178 DCHECK(PpapiGlobals::Get()->IsHostGlobals());
175 base::MessageLoop::current()->PostTask(FROM_HERE, callback_closure); 179 base::MessageLoop::current()->PostTask(FROM_HERE, callback_closure);
176 } else { 180 } else {
177 target_loop_->PostClosure(FROM_HERE, callback_closure, 0); 181 target_loop_->PostClosure(FROM_HERE, callback_closure, 0);
178 } 182 }
179 is_scheduled_ = true; 183 is_scheduled_ = true;
180 } 184 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // until we're done. 236 // until we're done.
233 scoped_refptr<TrackedCallback> thiz = this; 237 scoped_refptr<TrackedCallback> thiz = this;
234 completed_ = true; 238 completed_ = true;
235 // We may not have a valid resource, in which case we're not in the tracker. 239 // We may not have a valid resource, in which case we're not in the tracker.
236 if (resource_id_) 240 if (resource_id_)
237 tracker_->Remove(thiz); 241 tracker_->Remove(thiz);
238 tracker_ = NULL; 242 tracker_ = NULL;
239 } 243 }
240 244
241 } // namespace ppapi 245 } // namespace ppapi
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698