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

Unified Diff: ppapi/tests/test_utils.cc

Issue 10910099: PPAPI: Make CompletionCallbacks work right on background threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge 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
« no previous file with comments | « ppapi/tests/test_utils.h ('k') | ppapi/thunk/enter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/tests/test_utils.cc
diff --git a/ppapi/tests/test_utils.cc b/ppapi/tests/test_utils.cc
index 9776e3459556dcd20287552b6085fd94d7f8bdd9..20a8a81e2f92f49991928ca9d15b71d42728e4cc 100644
--- a/ppapi/tests/test_utils.cc
+++ b/ppapi/tests/test_utils.cc
@@ -13,6 +13,7 @@
#endif
#include "ppapi/c/pp_errors.h"
+#include "ppapi/cpp/dev/message_loop_dev.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/var.h"
@@ -138,7 +139,7 @@ int32_t TestCompletionCallback::WaitForResult() {
errors_.clear();
if (!have_result_) {
post_quit_task_ = true;
- GetTestingInterface()->RunMessageLoop(instance_);
+ RunMessageLoop();
}
return result_;
}
@@ -150,7 +151,7 @@ void TestCompletionCallback::WaitForResult(int32_t result) {
if (result == PP_OK_COMPLETIONPENDING) {
if (!have_result_) {
post_quit_task_ = true;
- GetTestingInterface()->RunMessageLoop(instance_);
+ RunMessageLoop();
}
if (callback_type_ == PP_BLOCKING) {
errors_.assign(
@@ -200,6 +201,7 @@ pp::CompletionCallback TestCompletionCallback::GetCallback() {
return pp::CompletionCallback();
else if (callback_type_ == PP_OPTIONAL)
flags = PP_COMPLETIONCALLBACK_FLAG_OPTIONAL;
+ target_loop_ = pp::MessageLoop_Dev::GetCurrent();
return pp::CompletionCallback(&TestCompletionCallback::Handler,
const_cast<TestCompletionCallback*>(this),
flags);
@@ -229,7 +231,36 @@ void TestCompletionCallback::Handler(void* user_data, int32_t result) {
callback->delegate_->OnCallback(user_data, result);
if (callback->post_quit_task_) {
callback->post_quit_task_ = false;
- GetTestingInterface()->QuitMessageLoop(callback->instance_);
+ callback->QuitMessageLoop();
+ }
+ if (callback->target_loop_ != pp::MessageLoop_Dev::GetCurrent()) {
+ // Note, in-process, loop_ and GetCurrent() will both be NULL, so should
+ // still be equal.
+ callback->errors_.assign(
+ ReportError("TestCompletionCallback: Callback ran on the wrong message "
+ "loop!",
+ result));
}
}
+void TestCompletionCallback::RunMessageLoop() {
+ pp::MessageLoop_Dev loop(pp::MessageLoop_Dev::GetCurrent());
+ // If we don't have a message loop, we're probably running in process, where
+ // PPB_MessageLoop is not supported. Just use the Testing message loop.
+ if (loop.is_null() || loop == pp::MessageLoop_Dev::GetForMainThread())
+ GetTestingInterface()->RunMessageLoop(instance_);
+ else
+ loop.Run();
+}
+
+void TestCompletionCallback::QuitMessageLoop() {
+ pp::MessageLoop_Dev loop(pp::MessageLoop_Dev::GetCurrent());
+ // If we don't have a message loop, we're probably running in process, where
+ // PPB_MessageLoop is not supported. Just use the Testing message loop.
+ if (loop.is_null() || loop == pp::MessageLoop_Dev::GetForMainThread()) {
+ GetTestingInterface()->QuitMessageLoop(instance_);
+ } else {
+ const bool should_quit = false;
+ loop.PostQuit(should_quit);
+ }
+}
« no previous file with comments | « ppapi/tests/test_utils.h ('k') | ppapi/thunk/enter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698