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

Unified Diff: ppapi/thunk/enter.cc

Issue 10910099: PPAPI: Make CompletionCallbacks work right on background threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add ppb_message_loop_shared.cc/.h Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/thunk/enter.cc
diff --git a/ppapi/thunk/enter.cc b/ppapi/thunk/enter.cc
index c89c9695b5a09b4486510d0e9be5430aeea6baaa..296a8b4a7615726475cb708d769f1225e2b1de4b 100644
--- a/ppapi/thunk/enter.cc
+++ b/ppapi/thunk/enter.cc
@@ -87,8 +87,6 @@ int32_t EnterBase::SetResult(int32_t result) {
// The function completed synchronously.
if (callback_->is_required()) {
// This is a required callback, so we must issue it asynchronously.
- // TODO(dmichael) make this work so that a call from a background thread
- // goes back to that thread.
callback_->PostRun(result);
retval_ = PP_OK_COMPLETIONPENDING;
} else {
@@ -108,23 +106,52 @@ Resource* EnterBase::GetResource(PP_Resource resource) {
}
void EnterBase::SetStateForCallbackError(bool report_error) {
- if (!CallbackIsValid()) {
- callback_->MarkAsCompleted();
- callback_ = NULL;
- retval_ = PP_ERROR_BLOCKS_MAIN_THREAD;
- if (report_error) {
- std::string message(
- "Blocking callbacks are not allowed on the main thread.");
- PpapiGlobals::Get()->BroadcastLogWithSource(0, PP_LOGLEVEL_ERROR,
- std::string(), message);
- }
+ if (PpapiGlobals::Get()->IsHostGlobals()) {
+ // In-process plugins can't make PPAPI calls off the main thread.
+ CHECK(IsMainThread());
dmichael (off chromium) 2012/11/06 22:49:39 ^^^ I'm mildly afraid this could break internal pl
brettw 2012/11/06 23:16:28 I'm happy with this.
}
-}
+ if (callback_) {
+ if (callback_->is_blocking() && IsMainThread()) {
+ // Blocking callbacks are never allowed on the main thread.
+ callback_->MarkAsCompleted();
+ callback_ = NULL;
+ retval_ = PP_ERROR_BLOCKS_MAIN_THREAD;
+ if (report_error) {
+ std::string message(
+ "Blocking callbacks are not allowed on the main thread.");
+ PpapiGlobals::Get()->BroadcastLogWithSource(0, PP_LOGLEVEL_ERROR,
+ std::string(), message);
+ }
+ } else if (!IsMainThread() &&
+ callback_->has_null_target_loop() &&
+ !callback_->is_blocking()) {
+ // On a non-main thread, there must be a valid target loop for non-
+ // blocking callbacks, or we will have no place to run them.
+
+ // If the callback is required, there's no nice way to tell the plugin.
+ // We can't run their callback asynchronously without a message loop, and
+ // the plugin won't expect any return code other than
+ // PP_OK_COMPLETIONPENDING. So we crash to make the problem more obvious.
brettw 2012/11/06 23:16:28 This contradicts the documentation. I'm also wonde
dmichael (off chromium) 2012/11/06 23:39:26 This is *only* for required callbacks. They're not
brettw 2012/11/07 00:02:21 Okay, I don't care that much and since this was al
dmichael (off chromium) 2012/11/07 18:44:34 I didn't see anything wrong in the message loop do
brettw 2012/11/07 18:52:15 You're right, I was looking at PostWork.
+ if (callback_->is_required()) {
+ std::string message("Attempted to use a required callback, but there"
+ "is no attached message loop on which to run the"
+ "callback.");
+ PpapiGlobals::Get()->BroadcastLogWithSource(0, PP_LOGLEVEL_ERROR,
+ std::string(), message);
+ LOG(FATAL) << message;
brettw 2012/11/06 23:16:28 Does this do the right thing in NaCl? I'm not posi
dmichael (off chromium) 2012/11/06 23:39:26 It looks like it to me in base/logging and base/de
+ }
-bool EnterBase::CallbackIsValid() const {
- // A callback is only considered invalid if it is blocking and we're on the
- // main thread.
- return !callback_ || !callback_->is_blocking() || !IsMainThread();
+ callback_->MarkAsCompleted();
+ callback_ = NULL;
+ retval_ = PP_ERROR_NO_MESSAGE_LOOP;
+ if (report_error) {
+ std::string message(
+ "The calling thread must have a message loop attached.");
+ PpapiGlobals::Get()->BroadcastLogWithSource(0, PP_LOGLEVEL_ERROR,
+ std::string(), message);
+ }
+ }
+ }
}
void EnterBase::ClearCallback() {
@@ -145,8 +172,6 @@ void EnterBase::SetStateForResourceError(PP_Resource pp_resource,
return; // Everything worked.
if (callback_ && callback_->is_required()) {
- // TODO(dmichael) make this work so that a call from a background thread
- // goes back to that thread.
callback_->PostRun(static_cast<int32_t>(PP_ERROR_BADRESOURCE));
callback_ = NULL;
retval_ = PP_OK_COMPLETIONPENDING;

Powered by Google App Engine
This is Rietveld 408576698