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

Side by Side Diff: ppapi/tests/test_utils.cc

Issue 6899055: PPAPI: Force async callback invocation option. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/tests/test_utils.h" 5 #include "ppapi/tests/test_utils.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "ppapi/c/pp_errors.h" 9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/cpp/module.h" 10 #include "ppapi/cpp/module.h"
(...skipping 11 matching lines...) Expand all
22 std::string result = method + std::string(" failed with error: ") + 22 std::string result = method + std::string(" failed with error: ") +
23 error_as_string; 23 error_as_string;
24 if (error == PP_ERROR_NOSPACE) 24 if (error == PP_ERROR_NOSPACE)
25 result += ". Did you run the test with --unlimited-quota-for-files?"; 25 result += ". Did you run the test with --unlimited-quota-for-files?";
26 return result; 26 return result;
27 } 27 }
28 28
29 TestCompletionCallback::TestCompletionCallback(PP_Instance instance) 29 TestCompletionCallback::TestCompletionCallback(PP_Instance instance)
30 : have_result_(false), 30 : have_result_(false),
31 result_(PP_OK_COMPLETIONPENDING), 31 result_(PP_OK_COMPLETIONPENDING),
32 force_async_(false),
33 post_quit_task_(false),
34 run_count_(0),
35 instance_(instance) {
36 }
37
38 TestCompletionCallback::TestCompletionCallback(PP_Instance instance,
39 bool force_async)
40 : result_(PP_OK_COMPLETIONPENDING),
41 force_async_(force_async),
32 post_quit_task_(false), 42 post_quit_task_(false),
33 run_count_(0), 43 run_count_(0),
34 instance_(instance) { 44 instance_(instance) {
35 } 45 }
36 46
37 int32_t TestCompletionCallback::WaitForResult() { 47 int32_t TestCompletionCallback::WaitForResult() {
38 if (!have_result_) { 48 if (!have_result_) {
39 result_ = PP_OK_COMPLETIONPENDING; // Reset 49 result_ = PP_OK_COMPLETIONPENDING; // Reset
40 post_quit_task_ = true; 50 post_quit_task_ = true;
41 GetTestingInterface()->RunMessageLoop(instance_); 51 GetTestingInterface()->RunMessageLoop(instance_);
42 } 52 }
43 have_result_ = false; 53 have_result_ = false;
44 return result_; 54 return result_;
45 } 55 }
46 56
47 TestCompletionCallback::operator pp::CompletionCallback() const { 57 TestCompletionCallback::operator pp::CompletionCallback() const {
48 return pp::CompletionCallback(&TestCompletionCallback::Handler, 58 pp::CompletionCallback cc(&TestCompletionCallback::Handler,
49 const_cast<TestCompletionCallback*>(this)); 59 const_cast<TestCompletionCallback*>(this));
60 if (!force_async_)
61 cc.set_flags(PP_COMPLETIONCALLBACK_FLAG_OPTIONAL);
62 return cc;
50 } 63 }
51 64
52 // static 65 // static
53 void TestCompletionCallback::Handler(void* user_data, int32_t result) { 66 void TestCompletionCallback::Handler(void* user_data, int32_t result) {
54 TestCompletionCallback* callback = 67 TestCompletionCallback* callback =
55 static_cast<TestCompletionCallback*>(user_data); 68 static_cast<TestCompletionCallback*>(user_data);
56 callback->result_ = result; 69 callback->result_ = result;
57 callback->have_result_ = true; 70 callback->have_result_ = true;
58 callback->run_count_++; 71 callback->run_count_++;
59 if (callback->post_quit_task_) { 72 if (callback->post_quit_task_) {
60 callback->post_quit_task_ = false; 73 callback->post_quit_task_ = false;
61 GetTestingInterface()->QuitMessageLoop(callback->instance_); 74 GetTestingInterface()->QuitMessageLoop(callback->instance_);
62 } 75 }
63 } 76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698