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

Unified Diff: ppapi/native_client/tests/ppapi_test_lib/testable_callback.cc

Issue 7740013: Cloning a bunch of stuff from the native_client repository at r6528 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/native_client/tests/ppapi_test_lib/testable_callback.cc
===================================================================
--- ppapi/native_client/tests/ppapi_test_lib/testable_callback.cc (revision 0)
+++ ppapi/native_client/tests/ppapi_test_lib/testable_callback.cc (revision 0)
@@ -0,0 +1,53 @@
+// Copyright (c) 2011 The Native Client Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/c/dev/ppb_testing_dev.h"
+#include "ppapi/c/pp_errors.h"
+#include "native_client/tests/ppapi_test_lib/get_browser_interface.h"
+#include "native_client/tests/ppapi_test_lib/testable_callback.h"
+
+TestableCallback::TestableCallback(PP_Instance instance, bool force_async)
+ : have_result_(false),
+ result_(PP_OK_COMPLETIONPENDING),
+ force_async_(force_async),
+ post_quit_task_(false),
+ run_count_(0),
+ instance_(instance) {
+}
+
+int32_t TestableCallback::WaitForResult() {
+ if (!have_result_) {
+ result_ = PP_OK_COMPLETIONPENDING; // Reset
+ post_quit_task_ = true;
+
+ // This waits until PPBTestingDev()->QuitMessageLoop() is called
+ // by the "Handler" which represents the actual callback code.
+ PPBTestingDev()->RunMessageLoop(instance_);
+ }
+ have_result_ = false;
+ return result_;
+}
+
+PP_CompletionCallback TestableCallback::GetCallback() {
+ int32_t flags = force_async_ ? 0 : PP_COMPLETIONCALLBACK_FLAG_OPTIONAL;
+ PP_CompletionCallback cc =
+ PP_MakeCompletionCallback(&TestableCallback::Handler, this);
+ cc.flags = flags;
+ return cc;
+}
+
+// static, so we can take it's address
+// This is the actual callback, all it does is record
+// the result and wake up whoever is block on
+// "WaitForResult"
+void TestableCallback::Handler(void* user_data, int32_t result) {
+ TestableCallback* callback = static_cast<TestableCallback*>(user_data);
+ callback->result_ = result;
+ callback->have_result_ = true;
+ ++callback->run_count_;
+ if (callback->post_quit_task_) {
+ callback->post_quit_task_ = false;
+ PPBTestingDev()->QuitMessageLoop(callback->instance_);
+ }
+}
« no previous file with comments | « ppapi/native_client/tests/ppapi_test_lib/testable_callback.h ('k') | ppapi/native_client/tests/ppapi_tests/build.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698