Skip to content

Commit

Permalink
PPAPI: Initialize CompletionCallbackWithOutput storage
Browse files Browse the repository at this point in the history
BUG=250046

Review URL: https://chromiumcodereview.appspot.com/18611004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210999 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
dmichael@chromium.org committed Jul 11, 2013
1 parent ce542d5 commit d06ae7f
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 9 deletions.
8 changes: 8 additions & 0 deletions ppapi/cpp/dev/truetype_font_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ struct CallbackOutputTraits<TrueTypeFontDesc_Dev> {
static inline TrueTypeFontDesc_Dev StorageToPluginArg(StorageType& t) {
return TrueTypeFontDesc_Dev(PASS_REF, t);
}

static inline void Initialize(StorageType* t) {
// Use the same defaults as TrueTypeFontDesc_Dev does.
TrueTypeFontDesc_Dev dummy;
*t = dummy.pp_desc();
}
};

class TrueTypeFontDescArrayOutputAdapterWithStorage
Expand Down Expand Up @@ -255,6 +261,8 @@ struct CallbackOutputTraits< std::vector<TrueTypeFontDesc_Dev> > {
StorageType& t) {
return t.output();
}

static inline void Initialize(StorageType* /* t */) {}
};

} // namespace internal
Expand Down
2 changes: 2 additions & 0 deletions ppapi/cpp/directory_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ struct CallbackOutputTraits< std::vector<DirectoryEntry> > {
StorageType& t) {
return t.output();
}

static inline void Initialize(StorageType* /* t */) {}
};

} // namespace internal
Expand Down
4 changes: 4 additions & 0 deletions ppapi/cpp/extensions/ext_output_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ struct ExtCallbackOutputTraits {
static inline T& StorageToPluginArg(StorageType& t) {
return t.output();
}

static inline void Initialize(StorageType* /* t */) {}
};

// This class provides storage for a PP_Var and a vector of objects which are
Expand Down Expand Up @@ -129,6 +131,8 @@ struct ExtCallbackOutputTraits< std::vector<T> > {
static inline std::vector<T>& StorageToPluginArg(StorageType& t) {
return t.output();
}

static inline void Initialize(StorageType* /* t */) {}
};

} // namespace internal
Expand Down
18 changes: 18 additions & 0 deletions ppapi/cpp/output_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ struct GenericCallbackOutputTraits {
// callbacks. This doesn't actually need to do anything in this case,
// it's needed for some of more complex template specializations below.
static inline T& StorageToPluginArg(StorageType& t) { return t; }

// Initializes the "storage type" to a default value, if necessary. Here,
// we do nothing, assuming that the default constructor for T suffices.
static inline void Initialize(StorageType* /* t */) {}
};

// Output traits for all resource types. It is implemented to pass a
Expand Down Expand Up @@ -113,6 +117,10 @@ struct ResourceCallbackOutputTraits {
static inline T StorageToPluginArg(StorageType& t) {
return T(PASS_REF, t);
}

static inline void Initialize(StorageType* t) {
*t = 0;
}
};

// The general templatized base class for all CallbackOutputTraits. This class
Expand Down Expand Up @@ -147,6 +155,10 @@ struct CallbackOutputTraits<Var> {
static inline pp::Var StorageToPluginArg(StorageType& t) {
return Var(PASS_REF, t);
}

static inline void Initialize(StorageType* t) {
*t = PP_MakeUndefined();
}
};

// Array output parameters -----------------------------------------------------
Expand Down Expand Up @@ -175,6 +187,8 @@ struct GenericVectorCallbackOutputTraits {
static inline std::vector<T>& StorageToPluginArg(StorageType& t) {
return t.output();
}

static inline void Initialize(StorageType* /* t */) {}
};

// Output traits for all vectors of resource types. It is implemented to pass
Expand All @@ -196,6 +210,8 @@ struct ResourceVectorCallbackOutputTraits {
static inline std::vector<T>& StorageToPluginArg(StorageType& t) {
return t.output();
}

static inline void Initialize(StorageType* /* t */) {}
};

// Specialization of CallbackOutputTraits for vectors. This struct covers both
Expand Down Expand Up @@ -233,6 +249,8 @@ struct CallbackOutputTraits< std::vector<pp::Var> > {
static inline std::vector<pp::Var>& StorageToPluginArg(StorageType& t) {
return t.output();
}

static inline void Initialize(StorageType* /* t */) {}
};

} // namespace internal
Expand Down
6 changes: 6 additions & 0 deletions ppapi/cpp/private/pass_file_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef PPAPI_CPP_PRIVATE_PASS_FILE_HANDLE_H_
#define PPAPI_CPP_PRIVATE_PASS_FILE_HANDLE_H_

#include <string.h>

#include "ppapi/c/private/pp_file_handle.h"
#include "ppapi/cpp/output_traits.h"

Expand Down Expand Up @@ -67,6 +69,10 @@ struct CallbackOutputTraits<PassFileHandle> {
static inline PassFileHandle StorageToPluginArg(StorageType& t) {
return PassFileHandle(t);
}

static inline void Initialize(StorageType* t) {
memset(t, 0, sizeof(*t));
}
};

} // namespace internal
Expand Down
7 changes: 7 additions & 0 deletions ppapi/cpp/private/video_frame_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef PPAPI_CPP_PRIVATE_VIDEO_FRAME_PRIVATE_H_
#define PPAPI_CPP_PRIVATE_VIDEO_FRAME_PRIVATE_H_

#include <string.h>

#include "ppapi/c/pp_time.h"
#include "ppapi/c/private/pp_video_frame_private.h"
#include "ppapi/cpp/completion_callback.h"
Expand Down Expand Up @@ -87,6 +89,11 @@ struct CallbackOutputTraits<pp::VideoFrame_Private> {
static inline pp::VideoFrame_Private StorageToPluginArg(StorageType& t) {
return pp::VideoFrame_Private(PASS_REF, t);
}

static inline void Initialize(StorageType* t) {
VideoFrame_Private dummy;
*t = dummy.pp_video_frame();
}
};

} // namespace internal
Expand Down
6 changes: 2 additions & 4 deletions ppapi/tests/test_network_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,15 @@ std::string TestNetworkProxy::TestGetProxyForURL() {
callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
// TODO(dmichael): Add this check below when crbug.com/250046 is fixed.
// ASSERT_TRUE(callback.output().is_undefined());
ASSERT_TRUE(callback.output().is_undefined());

callback.WaitForResult(
pp::NetworkProxy::GetProxyForURL(instance_,
pp::Var(42), // non-string Var
callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
// TODO(dmichael): Add this check below when crbug.com/250046 is fixed.
// ASSERT_TRUE(callback.output().is_undefined());
ASSERT_TRUE(callback.output().is_undefined());

PASS();
}
19 changes: 14 additions & 5 deletions ppapi/tests/test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,22 @@ template <typename OutputT, typename CallbackT>
class TestCompletionCallbackWithOutputBase {
public:
explicit TestCompletionCallbackWithOutputBase(PP_Instance instance)
: callback_(instance) {
: callback_(instance),
output_storage_() {
CallbackT::TraitsType::Initialize(&output_storage_);
}

TestCompletionCallbackWithOutputBase(PP_Instance instance, bool force_async)
: callback_(instance, force_async) {
: callback_(instance, force_async),
output_storage_() {
CallbackT::TraitsType::Initialize(&output_storage_);
}

TestCompletionCallbackWithOutputBase(PP_Instance instance,
CallbackType callback_type)
: callback_(instance, callback_type) {
: callback_(instance, callback_type),
output_storage_() {
CallbackT::TraitsType::Initialize(&output_storage_);
}

CallbackT GetCallback();
Expand All @@ -217,7 +223,10 @@ class TestCompletionCallbackWithOutputBase {
bool failed() { return callback_.failed(); }
const std::string& errors() { return callback_.errors(); }
int32_t result() const { return callback_.result(); }
void Reset() { return callback_.Reset(); }
void Reset() {
CallbackT::TraitsType::Initialize(&output_storage_);
return callback_.Reset();
}

private:
TestCompletionCallback callback_;
Expand All @@ -227,7 +236,7 @@ class TestCompletionCallbackWithOutputBase {
template <typename OutputT, typename CallbackT>
CallbackT
TestCompletionCallbackWithOutputBase<OutputT, CallbackT>::GetCallback() {
callback_.Reset();
this->Reset();
if (callback_.callback_type() == PP_BLOCKING) {
CallbackT cc(&output_storage_);
return cc;
Expand Down
8 changes: 8 additions & 0 deletions ppapi/utility/completion_callback_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,12 @@ class CompletionCallbackFactory {
DispatcherWithOutput0()
: method_(NULL),
output_() {
Traits::Initialize(&output_);
}
DispatcherWithOutput0(Method method)
: method_(method),
output_() {
Traits::Initialize(&output_);
}
void operator()(T* object, int32_t result) {
// We must call Traits::StorageToPluginArg() even if we don't need to call
Expand Down Expand Up @@ -779,11 +781,13 @@ class CompletionCallbackFactory {
: method_(NULL),
a_(),
output_() {
Traits::Initialize(&output_);
}
DispatcherWithOutput1(Method method, const A& a)
: method_(method),
a_(a),
output_() {
Traits::Initialize(&output_);
}
void operator()(T* object, int32_t result) {
// We must call Traits::StorageToPluginArg() even if we don't need to call
Expand Down Expand Up @@ -840,12 +844,14 @@ class CompletionCallbackFactory {
a_(),
b_(),
output_() {
Traits::Initialize(&output_);
}
DispatcherWithOutput2(Method method, const A& a, const B& b)
: method_(method),
a_(a),
b_(b),
output_() {
Traits::Initialize(&output_);
}
void operator()(T* object, int32_t result) {
// We must call Traits::StorageToPluginArg() even if we don't need to call
Expand Down Expand Up @@ -908,13 +914,15 @@ class CompletionCallbackFactory {
b_(),
c_(),
output_() {
Traits::Initialize(&output_);
}
DispatcherWithOutput3(Method method, const A& a, const B& b, const C& c)
: method_(method),
a_(a),
b_(b),
c_(c),
output_() {
Traits::Initialize(&output_);
}
void operator()(T* object, int32_t result) {
// We must call Traits::StorageToPluginArg() even if we don't need to call
Expand Down

0 comments on commit d06ae7f

Please sign in to comment.