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

Unified Diff: ppapi/proxy/ppb_message_loop_proxy.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/proxy/ppb_message_loop_proxy.cc
diff --git a/ppapi/proxy/ppb_message_loop_proxy.cc b/ppapi/proxy/ppb_message_loop_proxy.cc
index 916002d0795981d4be027dc4b2034ea080c33044..baa45b51ab04696ce4e353dd454ac7d02d5911e4 100644
--- a/ppapi/proxy/ppb_message_loop_proxy.cc
+++ b/ppapi/proxy/ppb_message_loop_proxy.cc
@@ -27,15 +27,15 @@ typedef thunk::EnterResource<PPB_MessageLoop_API> EnterMessageLoop;
}
MessageLoopResource::MessageLoopResource(PP_Instance instance)
- : Resource(OBJECT_IS_PROXY, instance),
+ : MessageLoopShared(instance),
nested_invocations_(0),
destroyed_(false),
should_destroy_(false),
is_main_thread_loop_(false) {
}
-MessageLoopResource::MessageLoopResource(ForMainThread)
- : Resource(Resource::Untracked()),
+MessageLoopResource::MessageLoopResource(ForMainThread for_main_thread)
+ : MessageLoopShared(for_main_thread),
nested_invocations_(0),
destroyed_(false),
should_destroy_(false),
@@ -80,7 +80,7 @@ int32_t MessageLoopResource::AttachToCurrentThread() {
if (slot->Get())
return PP_ERROR_INPROGRESS;
}
- // TODO(brettw) check that the current thread can support a message loop.
+ // TODO(dmichael) check that the current thread can support a message loop.
// Take a ref to the MessageLoop on behalf of the TLS. Note that this is an
// internal ref and not a plugin ref so the plugin can't accidentally
@@ -140,20 +140,24 @@ int32_t MessageLoopResource::PostQuit(PP_Bool should_destroy) {
if (PP_ToBool(should_destroy))
should_destroy_ = true;
- if (IsCurrent())
+ if (IsCurrent() && nested_invocations_ > 0)
loop_->Quit();
else
PostClosure(FROM_HERE, MessageLoop::QuitClosure(), 0);
return PP_OK;
}
-void MessageLoopResource::DetachFromThread() {
- // Never detach the main thread from its loop resource. Other plugin instances
- // might need it.
- if (is_main_thread_loop_)
- return;
+// static
+MessageLoopResource* MessageLoopResource::GetCurrent() {
+ PluginGlobals* globals = PluginGlobals::Get();
+ if (!globals->msg_loop_slot())
+ return 0;
brettw 2012/11/06 23:16:28 I'd use NULL instead of 0.
dmichael (off chromium) 2012/11/06 23:39:26 Done.
+ return reinterpret_cast<MessageLoopResource*>(
+ globals->msg_loop_slot()->Get());
+}
- // Note that the message loop must be destroyed on the thread is was created
+void MessageLoopResource::DetachFromThread() {
+ // Note that the message loop must be destroyed on the thread it was created
// on.
loop_proxy_ = NULL;
loop_.reset();
@@ -208,12 +212,7 @@ PP_Resource GetForMainThread() {
}
PP_Resource GetCurrent() {
- PluginGlobals* globals = PluginGlobals::Get();
- if (!globals->msg_loop_slot())
- return 0;
- MessageLoopResource* loop = reinterpret_cast<MessageLoopResource*>(
- globals->msg_loop_slot()->Get());
- return loop->GetReference();
+ return MessageLoopResource::GetCurrent()->GetReference();
brettw 2012/11/06 23:16:28 I don't think we want this to crash if there's no
dmichael (off chromium) 2012/11/06 23:39:26 Done.
}
int32_t AttachToCurrentThread(PP_Resource message_loop) {

Powered by Google App Engine
This is Rietveld 408576698