1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/c/dev/ppb_testing_dev.h"
6 #include "ppapi/c/pp_errors.h"
7 #include "native_client/tests/ppapi_test_lib/get_browser_interface.h"
8 #include "native_client/tests/ppapi_test_lib/testable_callback.h"
10 TestableCallback::TestableCallback(PP_Instance instance
, bool force_async
)
11 : have_result_(false),
12 result_(PP_OK_COMPLETIONPENDING
),
13 force_async_(force_async
),
14 post_quit_task_(false),
19 int32_t TestableCallback::WaitForResult() {
21 result_
= PP_OK_COMPLETIONPENDING
; // Reset
22 post_quit_task_
= true;
24 // This waits until PPBTestingDev()->QuitMessageLoop() is called
25 // by the "Handler" which represents the actual callback code.
26 PPBTestingDev()->RunMessageLoop(instance_
);
32 PP_CompletionCallback
TestableCallback::GetCallback() {
33 int32_t flags
= force_async_
? 0 : PP_COMPLETIONCALLBACK_FLAG_OPTIONAL
;
34 PP_CompletionCallback cc
=
35 PP_MakeCompletionCallback(&TestableCallback::Handler
, this);
40 // static, so we can take it's address
41 // This is the actual callback, all it does is record
42 // the result and wake up whoever is block on
44 void TestableCallback::Handler(void* user_data
, int32_t result
) {
45 TestableCallback
* callback
= static_cast<TestableCallback
*>(user_data
);
46 callback
->result_
= result
;
47 callback
->have_result_
= true;
48 ++callback
->run_count_
;
49 if (callback
->post_quit_task_
) {
50 callback
->post_quit_task_
= false;
51 PPBTestingDev()->QuitMessageLoop(callback
->instance_
);