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

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

Issue 10661026: WebSocket Pepper API: allow to release in completion callbacks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use WeakPtr to protect |this| Created 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <stdlib.h> 8 #include <stdlib.h>
9 #if defined(_MSC_VER) 9 #if defined(_MSC_VER)
10 #include <windows.h> 10 #include <windows.h>
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 TestCompletionCallback::TestCompletionCallback(PP_Instance instance) 92 TestCompletionCallback::TestCompletionCallback(PP_Instance instance)
93 : wait_for_result_called_(false), 93 : wait_for_result_called_(false),
94 have_result_(false), 94 have_result_(false),
95 result_(PP_OK_COMPLETIONPENDING), 95 result_(PP_OK_COMPLETIONPENDING),
96 // TODO(dmichael): The default should probably be PP_REQUIRED, but this is 96 // TODO(dmichael): The default should probably be PP_REQUIRED, but this is
97 // what the tests currently expect. 97 // what the tests currently expect.
98 callback_type_(PP_OPTIONAL), 98 callback_type_(PP_OPTIONAL),
99 post_quit_task_(false), 99 post_quit_task_(false),
100 run_count_(0), // TODO(dmichael): Remove when all tests are updated. 100 run_count_(0), // TODO(dmichael): Remove when all tests are updated.
101 instance_(instance) { 101 instance_(instance),
102 delegate_(NULL) {
102 } 103 }
103 104
104 TestCompletionCallback::TestCompletionCallback(PP_Instance instance, 105 TestCompletionCallback::TestCompletionCallback(PP_Instance instance,
105 bool force_async) 106 bool force_async)
106 : wait_for_result_called_(false), 107 : wait_for_result_called_(false),
107 have_result_(false), 108 have_result_(false),
108 result_(PP_OK_COMPLETIONPENDING), 109 result_(PP_OK_COMPLETIONPENDING),
109 callback_type_(force_async ? PP_REQUIRED : PP_OPTIONAL), 110 callback_type_(force_async ? PP_REQUIRED : PP_OPTIONAL),
110 post_quit_task_(false), 111 post_quit_task_(false),
111 instance_(instance) { 112 instance_(instance),
113 delegate_(NULL) {
112 } 114 }
113 115
114 TestCompletionCallback::TestCompletionCallback(PP_Instance instance, 116 TestCompletionCallback::TestCompletionCallback(PP_Instance instance,
115 CallbackType callback_type) 117 CallbackType callback_type)
116 : wait_for_result_called_(false), 118 : wait_for_result_called_(false),
117 have_result_(false), 119 have_result_(false),
118 result_(PP_OK_COMPLETIONPENDING), 120 result_(PP_OK_COMPLETIONPENDING),
119 callback_type_(callback_type), 121 callback_type_(callback_type),
120 post_quit_task_(false), 122 post_quit_task_(false),
121 instance_(instance) { 123 instance_(instance),
124 delegate_(NULL) {
122 } 125 }
123 126
124 int32_t TestCompletionCallback::WaitForResult() { 127 int32_t TestCompletionCallback::WaitForResult() {
125 PP_DCHECK(!wait_for_result_called_); 128 PP_DCHECK(!wait_for_result_called_);
126 wait_for_result_called_ = true; 129 wait_for_result_called_ = true;
127 errors_.clear(); 130 errors_.clear();
128 if (!have_result_) { 131 if (!have_result_) {
129 post_quit_task_ = true; 132 post_quit_task_ = true;
130 GetTestingInterface()->RunMessageLoop(instance_); 133 GetTestingInterface()->RunMessageLoop(instance_);
131 } 134 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 const_cast<TestCompletionCallback*>(this), 196 const_cast<TestCompletionCallback*>(this),
194 flags); 197 flags);
195 } 198 }
196 199
197 void TestCompletionCallback::Reset() { 200 void TestCompletionCallback::Reset() {
198 wait_for_result_called_ = false; 201 wait_for_result_called_ = false;
199 result_ = PP_OK_COMPLETIONPENDING; 202 result_ = PP_OK_COMPLETIONPENDING;
200 have_result_ = false; 203 have_result_ = false;
201 post_quit_task_ = false; 204 post_quit_task_ = false;
202 run_count_ = 0; // TODO(dmichael): Remove when all tests are updated. 205 run_count_ = 0; // TODO(dmichael): Remove when all tests are updated.
206 delegate_ = NULL;
203 errors_.clear(); 207 errors_.clear();
204 } 208 }
205 209
206 // static 210 // static
207 void TestCompletionCallback::Handler(void* user_data, int32_t result) { 211 void TestCompletionCallback::Handler(void* user_data, int32_t result) {
208 TestCompletionCallback* callback = 212 TestCompletionCallback* callback =
209 static_cast<TestCompletionCallback*>(user_data); 213 static_cast<TestCompletionCallback*>(user_data);
210 // If this check fails, it means that the callback was invoked twice or that 214 // If this check fails, it means that the callback was invoked twice or that
211 // the PPAPI call completed synchronously, but also ran the callback. 215 // the PPAPI call completed synchronously, but also ran the callback.
212 PP_DCHECK(!callback->have_result_); 216 PP_DCHECK(!callback->have_result_);
213 callback->result_ = result; 217 callback->result_ = result;
214 callback->have_result_ = true; 218 callback->have_result_ = true;
215 callback->run_count_++; // TODO(dmichael): Remove when all tests are updated. 219 callback->run_count_++; // TODO(dmichael): Remove when all tests are updated.
220 if (callback->delegate_)
221 callback->delegate_->OnCallback(user_data, result);
216 if (callback->post_quit_task_) { 222 if (callback->post_quit_task_) {
217 callback->post_quit_task_ = false; 223 callback->post_quit_task_ = false;
218 GetTestingInterface()->QuitMessageLoop(callback->instance_); 224 GetTestingInterface()->QuitMessageLoop(callback->instance_);
219 } 225 }
220 } 226 }
221 227
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698