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

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

Issue 18611004: PPAPI: Initialize CompletionCallbackWithOutput storage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 7 years, 5 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
« no previous file with comments | « ppapi/tests/test_network_proxy.cc ('k') | ppapi/utility/completion_callback_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef PPAPI_TESTS_TEST_UTILS_H_ 5 #ifndef PPAPI_TESTS_TEST_UTILS_H_
6 #define PPAPI_TESTS_TEST_UTILS_H_ 6 #define PPAPI_TESTS_TEST_UTILS_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "ppapi/c/dev/ppb_testing_dev.h" 10 #include "ppapi/c/dev/ppb_testing_dev.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 Delegate* delegate_; 181 Delegate* delegate_;
182 pp::MessageLoop target_loop_; 182 pp::MessageLoop target_loop_;
183 }; 183 };
184 184
185 namespace internal { 185 namespace internal {
186 186
187 template <typename OutputT, typename CallbackT> 187 template <typename OutputT, typename CallbackT>
188 class TestCompletionCallbackWithOutputBase { 188 class TestCompletionCallbackWithOutputBase {
189 public: 189 public:
190 explicit TestCompletionCallbackWithOutputBase(PP_Instance instance) 190 explicit TestCompletionCallbackWithOutputBase(PP_Instance instance)
191 : callback_(instance) { 191 : callback_(instance),
192 output_storage_() {
193 CallbackT::TraitsType::Initialize(&output_storage_);
192 } 194 }
193 195
194 TestCompletionCallbackWithOutputBase(PP_Instance instance, bool force_async) 196 TestCompletionCallbackWithOutputBase(PP_Instance instance, bool force_async)
195 : callback_(instance, force_async) { 197 : callback_(instance, force_async),
198 output_storage_() {
199 CallbackT::TraitsType::Initialize(&output_storage_);
196 } 200 }
197 201
198 TestCompletionCallbackWithOutputBase(PP_Instance instance, 202 TestCompletionCallbackWithOutputBase(PP_Instance instance,
199 CallbackType callback_type) 203 CallbackType callback_type)
200 : callback_(instance, callback_type) { 204 : callback_(instance, callback_type),
205 output_storage_() {
206 CallbackT::TraitsType::Initialize(&output_storage_);
201 } 207 }
202 208
203 CallbackT GetCallback(); 209 CallbackT GetCallback();
204 OutputT output() { 210 OutputT output() {
205 return CallbackT::TraitsType::StorageToPluginArg( 211 return CallbackT::TraitsType::StorageToPluginArg(
206 output_storage_); 212 output_storage_);
207 } 213 }
208 214
209 // Delegate functions to TestCompletionCallback 215 // Delegate functions to TestCompletionCallback
210 void SetDelegate(TestCompletionCallback::Delegate* delegate) { 216 void SetDelegate(TestCompletionCallback::Delegate* delegate) {
211 callback_.SetDelegate(delegate); 217 callback_.SetDelegate(delegate);
212 } 218 }
213 void WaitForResult(int32_t result) { callback_.WaitForResult(result); } 219 void WaitForResult(int32_t result) { callback_.WaitForResult(result); }
214 void WaitForAbortResult(int32_t result) { 220 void WaitForAbortResult(int32_t result) {
215 callback_.WaitForAbortResult(result); 221 callback_.WaitForAbortResult(result);
216 } 222 }
217 bool failed() { return callback_.failed(); } 223 bool failed() { return callback_.failed(); }
218 const std::string& errors() { return callback_.errors(); } 224 const std::string& errors() { return callback_.errors(); }
219 int32_t result() const { return callback_.result(); } 225 int32_t result() const { return callback_.result(); }
220 void Reset() { return callback_.Reset(); } 226 void Reset() {
227 CallbackT::TraitsType::Initialize(&output_storage_);
228 return callback_.Reset();
229 }
221 230
222 private: 231 private:
223 TestCompletionCallback callback_; 232 TestCompletionCallback callback_;
224 typename CallbackT::OutputStorageType output_storage_; 233 typename CallbackT::OutputStorageType output_storage_;
225 }; 234 };
226 235
227 template <typename OutputT, typename CallbackT> 236 template <typename OutputT, typename CallbackT>
228 CallbackT 237 CallbackT
229 TestCompletionCallbackWithOutputBase<OutputT, CallbackT>::GetCallback() { 238 TestCompletionCallbackWithOutputBase<OutputT, CallbackT>::GetCallback() {
230 callback_.Reset(); 239 this->Reset();
231 if (callback_.callback_type() == PP_BLOCKING) { 240 if (callback_.callback_type() == PP_BLOCKING) {
232 CallbackT cc(&output_storage_); 241 CallbackT cc(&output_storage_);
233 return cc; 242 return cc;
234 } 243 }
235 244
236 callback_.set_target_loop(pp::MessageLoop::GetCurrent()); 245 callback_.set_target_loop(pp::MessageLoop::GetCurrent());
237 CallbackT cc(&TestCompletionCallback::Handler, this, &output_storage_); 246 CallbackT cc(&TestCompletionCallback::Handler, this, &output_storage_);
238 if (callback_.callback_type() == PP_OPTIONAL) 247 if (callback_.callback_type() == PP_OPTIONAL)
239 cc.set_flags(PP_COMPLETIONCALLBACK_FLAG_OPTIONAL); 248 cc.set_flags(PP_COMPLETIONCALLBACK_FLAG_OPTIONAL);
240 return cc; 249 return cc;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 #error Please add support for your platform in ppapi/tests/test_utils.h 331 #error Please add support for your platform in ppapi/tests/test_utils.h
323 #endif 332 #endif
324 333
325 /* These are used to determine POSIX-like implementations vs Windows. */ 334 /* These are used to determine POSIX-like implementations vs Windows. */
326 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ 335 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
327 defined(__OpenBSD__) || defined(__sun) || defined(__native_client__) 336 defined(__OpenBSD__) || defined(__sun) || defined(__native_client__)
328 #define PPAPI_POSIX 1 337 #define PPAPI_POSIX 1
329 #endif 338 #endif
330 339
331 #endif // PPAPI_TESTS_TEST_UTILS_H_ 340 #endif // PPAPI_TESTS_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « ppapi/tests/test_network_proxy.cc ('k') | ppapi/utility/completion_callback_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698