diff options
32 files changed, 298 insertions, 341 deletions
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index d294edb..9047e54 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -136,8 +136,6 @@ 'shared_impl/private/udp_socket_private_impl.cc', 'shared_impl/private/udp_socket_private_impl.h', - 'thunk/common.h', - 'thunk/common.cc', 'thunk/enter.cc', 'thunk/enter.h', 'thunk/ppb_audio_api.h', diff --git a/ppapi/thunk/common.cc b/ppapi/thunk/common.cc deleted file mode 100644 index 9a952a2..0000000 --- a/ppapi/thunk/common.cc +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ppapi/thunk/common.h" - -#include "base/bind.h" -#include "base/message_loop.h" -#include "ppapi/c/pp_errors.h" - -namespace ppapi { -namespace thunk { - -int32_t MayForceCallback(PP_CompletionCallback callback, int32_t result) { - if (result == PP_OK_COMPLETIONPENDING) - return result; - - if (callback.func == NULL || - (callback.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL) != 0) - return result; - - // TODO(polina): make this work off the main thread as well - // (At this point this should not be an issue because PPAPI is only supported - // on the main thread). - MessageLoop::current()->PostTask(FROM_HERE, base::Bind( - callback.func, callback.user_data, result)); - return PP_OK_COMPLETIONPENDING; -} - -} // namespace thunk -} // namespace ppapi diff --git a/ppapi/thunk/common.h b/ppapi/thunk/common.h deleted file mode 100644 index 7966da4..0000000 --- a/ppapi/thunk/common.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef PPAPI_THUNK_COMMON_H_ -#define PPAPI_THUNK_COMMON_H_ - -#include "ppapi/c/pp_completion_callback.h" - -namespace ppapi { -namespace thunk { - -// Skips callback invocation and returns |result| if callback function is NULL -// or PP_COMPLETIONCALLBACK_FLAG_OPTIONAL is set. Otherwise, schedules the -// callback with |result| as an argument and returns PP_OK_COMPLETIONPENDING. -int32_t MayForceCallback(PP_CompletionCallback callback, int32_t result); - -} // namespace thunk -} // namespace ppapi - -#endif // PPAPI_THUNK_COMMON_H_ diff --git a/ppapi/thunk/enter.cc b/ppapi/thunk/enter.cc index 43e80fe..42ff670 100644 --- a/ppapi/thunk/enter.cc +++ b/ppapi/thunk/enter.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -83,7 +83,16 @@ void EnterBase::SetStateForResourceError(PP_Resource pp_resource, if (object) return; // Everything worked. - retval_ = PP_ERROR_BADRESOURCE; + if (callback_.func) { + // Required callback, issue the async completion. + MessageLoop::current()->PostTask(FROM_HERE, base::Bind( + callback_.func, callback_.user_data, + static_cast<int32_t>(PP_ERROR_BADRESOURCE))); + callback_ = PP_BlockUntilComplete(); + retval_ = PP_OK_COMPLETIONPENDING; + } else { + retval_ = PP_ERROR_BADRESOURCE; + } // We choose to silently ignore the error when the pp_resource is null // because this is a pretty common case and we don't want to have lots @@ -104,6 +113,35 @@ void EnterBase::SetStateForResourceError(PP_Resource pp_resource, } } +void EnterBase::SetStateForFunctionError(PP_Instance pp_instance, + void* object, + bool report_error) { + if (object) + return; // Everything worked. + + if (callback_.func) { + // Required callback, issue the async completion. + MessageLoop::current()->PostTask(FROM_HERE, base::Bind( + callback_.func, callback_.user_data, + static_cast<int32_t>(PP_ERROR_BADARGUMENT))); + callback_ = PP_BlockUntilComplete(); + retval_ = PP_OK_COMPLETIONPENDING; + } else { + retval_ = PP_ERROR_BADARGUMENT; + } + + // We choose to silently ignore the error when the pp_instance is null as + // for PP_Resources above. + if (report_error && pp_instance) { + std::string message; + message = base::StringPrintf( + "0x%X is not a valid instance ID.", + pp_instance); + PpapiGlobals::Get()->BroadcastLogWithSource(0, PP_LOGLEVEL_ERROR, + std::string(), message); + } +} + } // namespace subtle EnterResourceCreation::EnterResourceCreation(PP_Instance instance) @@ -114,7 +152,12 @@ EnterResourceCreation::~EnterResourceCreation() { } EnterInstance::EnterInstance(PP_Instance instance) - : EnterFunctionNoLock<PPB_Instance_FunctionAPI>(instance, true) { + : EnterFunction<PPB_Instance_FunctionAPI>(instance, true) { +} + +EnterInstance::EnterInstance(PP_Instance instance, + const PP_CompletionCallback& callback) + : EnterFunction<PPB_Instance_FunctionAPI>(instance, callback, true) { } EnterInstance::~EnterInstance() { diff --git a/ppapi/thunk/enter.h b/ppapi/thunk/enter.h index 86d6022..3b82a96 100644 --- a/ppapi/thunk/enter.h +++ b/ppapi/thunk/enter.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -108,6 +108,11 @@ class PPAPI_THUNK_EXPORT EnterBase { void* object, bool report_error); + // Same as SetStateForResourceError except for function API. + void SetStateForFunctionError(PP_Instance pp_instance, + void* object, + bool report_error); + private: // Holds the callback. The function will only be non-NULL when the // callback is requried. Optional callbacks don't require any special @@ -119,17 +124,21 @@ class PPAPI_THUNK_EXPORT EnterBase { } // namespace subtle +// EnterFunction -------------------------------------------------------------- template<typename FunctionsT, bool lock_on_entry = true> class EnterFunction : public subtle::EnterBase, public subtle::LockOnEntry<lock_on_entry> { public: EnterFunction(PP_Instance instance, bool report_error) - : functions_(NULL) { - FunctionGroupBase* base = GetFunctions(instance, FunctionsT::kApiID); - if (base) - functions_ = base->GetAs<FunctionsT>(); - // TODO(brettw) check error and if report_error is set, do something. + : EnterBase() { + Init(instance, report_error); + } + EnterFunction(PP_Instance instance, + const PP_CompletionCallback& callback, + bool report_error) + : EnterBase(callback) { + Init(instance, report_error); } ~EnterFunction() {} @@ -140,6 +149,15 @@ class EnterFunction : public subtle::EnterBase, FunctionsT* functions() { return functions_; } private: + void Init(PP_Instance instance, bool report_error) { + FunctionGroupBase* base = GetFunctions(instance, FunctionsT::kApiID); + if (base) + functions_ = base->GetAs<FunctionsT>(); + else + functions_ = NULL; + SetStateForFunctionError(instance, functions_, report_error); + } + FunctionsT* functions_; DISALLOW_COPY_AND_ASSIGN(EnterFunction); @@ -212,6 +230,8 @@ class EnterResource : public subtle::EnterBase, DISALLOW_COPY_AND_ASSIGN(EnterResource); }; +// ---------------------------------------------------------------------------- + // Like EnterResource but assumes the lock is already held. template<typename ResourceT> class EnterResourceNoLock : public EnterResource<ResourceT, false> { @@ -235,9 +255,10 @@ class PPAPI_THUNK_EXPORT EnterResourceCreation // many interfaces so we have this helper function to save template // instantiations and typing. class PPAPI_THUNK_EXPORT EnterInstance - : public EnterFunctionNoLock<PPB_Instance_FunctionAPI> { + : public EnterFunction<PPB_Instance_FunctionAPI> { public: EnterInstance(PP_Instance instance); + EnterInstance(PP_Instance instance, const PP_CompletionCallback& callback); ~EnterInstance(); }; diff --git a/ppapi/thunk/ppb_audio_input_thunk.cc b/ppapi/thunk/ppb_audio_input_thunk.cc index dbc697f..f2a65c8 100644 --- a/ppapi/thunk/ppb_audio_input_thunk.cc +++ b/ppapi/thunk/ppb_audio_input_thunk.cc @@ -3,7 +3,6 @@ // found in the LICENSE file. #include "ppapi/c/pp_errors.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_audio_input_api.h" #include "ppapi/thunk/resource_creation_api.h" diff --git a/ppapi/thunk/ppb_audio_input_trusted_thunk.cc b/ppapi/thunk/ppb_audio_input_trusted_thunk.cc index 3a44a30..ac9f0bb 100644 --- a/ppapi/thunk/ppb_audio_input_trusted_thunk.cc +++ b/ppapi/thunk/ppb_audio_input_trusted_thunk.cc @@ -4,7 +4,6 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/trusted/ppb_audio_input_trusted_dev.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_audio_input_api.h" #include "ppapi/thunk/resource_creation_api.h" @@ -26,18 +25,17 @@ PP_Resource Create(PP_Instance instance_id) { int32_t Open(PP_Resource audio_id, PP_Resource config_id, - PP_CompletionCallback create_callback) { - EnterAudioInput enter(audio_id, true); + PP_CompletionCallback callback) { + EnterAudioInput enter(audio_id, callback, true); if (enter.failed()) - return MayForceCallback(create_callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->OpenTrusted(config_id, create_callback); - return MayForceCallback(create_callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->OpenTrusted(config_id, callback)); } int32_t GetSyncSocket(PP_Resource audio_id, int* sync_socket) { EnterAudioInput enter(audio_id, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; + return enter.retval(); return enter.object()->GetSyncSocket(sync_socket); } @@ -46,7 +44,7 @@ int32_t GetSharedMemory(PP_Resource audio_id, uint32_t* shm_size) { EnterAudioInput enter(audio_id, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; + return enter.retval(); return enter.object()->GetSharedMemory(shm_handle, shm_size); } diff --git a/ppapi/thunk/ppb_audio_trusted_thunk.cc b/ppapi/thunk/ppb_audio_trusted_thunk.cc index da49425..a990415 100644 --- a/ppapi/thunk/ppb_audio_trusted_thunk.cc +++ b/ppapi/thunk/ppb_audio_trusted_thunk.cc @@ -4,7 +4,6 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/trusted/ppb_audio_trusted.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_audio_api.h" @@ -26,18 +25,17 @@ PP_Resource Create(PP_Instance instance_id) { int32_t Open(PP_Resource audio_id, PP_Resource config_id, - PP_CompletionCallback create_callback) { - EnterAudio enter(audio_id, true); + PP_CompletionCallback callback) { + EnterAudio enter(audio_id, callback, true); if (enter.failed()) - return MayForceCallback(create_callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->OpenTrusted(config_id, create_callback); - return MayForceCallback(create_callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->OpenTrusted(config_id, callback)); } int32_t GetSyncSocket(PP_Resource audio_id, int* sync_socket) { EnterAudio enter(audio_id, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; + return enter.retval(); return enter.object()->GetSyncSocket(sync_socket); } @@ -46,7 +44,7 @@ int32_t GetSharedMemory(PP_Resource audio_id, uint32_t* shm_size) { EnterAudio enter(audio_id, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; + return enter.retval(); return enter.object()->GetSharedMemory(shm_handle, shm_size); } diff --git a/ppapi/thunk/ppb_broker_thunk.cc b/ppapi/thunk/ppb_broker_thunk.cc index 6b3f936..a3ef579 100644 --- a/ppapi/thunk/ppb_broker_thunk.cc +++ b/ppapi/thunk/ppb_broker_thunk.cc @@ -4,7 +4,6 @@ #include "ppapi/c/trusted/ppb_broker_trusted.h" #include "ppapi/c/pp_errors.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_broker_api.h" @@ -28,18 +27,17 @@ PP_Bool IsBrokerTrusted(PP_Resource resource) { } int32_t Connect(PP_Resource resource, - PP_CompletionCallback connect_callback) { - EnterResource<PPB_Broker_API> enter(resource, true); + PP_CompletionCallback callback) { + EnterResource<PPB_Broker_API> enter(resource, callback, true); if (enter.failed()) - return MayForceCallback(connect_callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Connect(connect_callback); - return MayForceCallback(connect_callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Connect(callback)); } int32_t GetHandle(PP_Resource resource, int32_t* handle) { EnterResource<PPB_Broker_API> enter(resource, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; + return enter.retval(); return enter.object()->GetHandle(handle); } diff --git a/ppapi/thunk/ppb_buffer_trusted_thunk.cc b/ppapi/thunk/ppb_buffer_trusted_thunk.cc index 19506db..ba6c32e 100644 --- a/ppapi/thunk/ppb_buffer_trusted_thunk.cc +++ b/ppapi/thunk/ppb_buffer_trusted_thunk.cc @@ -16,7 +16,7 @@ namespace { int32_t GetSharedMemory(PP_Resource buffer_id, int* shm_handle) { EnterResource<PPB_BufferTrusted_API> enter(buffer_id, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; + return enter.retval(); return enter.object()->GetSharedMemory(shm_handle); } diff --git a/ppapi/thunk/ppb_directory_reader_thunk.cc b/ppapi/thunk/ppb_directory_reader_thunk.cc index f03b165..369283c 100644 --- a/ppapi/thunk/ppb_directory_reader_thunk.cc +++ b/ppapi/thunk/ppb_directory_reader_thunk.cc @@ -5,7 +5,6 @@ #include "ppapi/c/dev/ppb_directory_reader_dev.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_directory_reader_api.h" @@ -31,11 +30,11 @@ PP_Bool IsDirectoryReader(PP_Resource resource) { int32_t GetNextEntry(PP_Resource directory_reader, PP_DirectoryEntry_Dev* entry, PP_CompletionCallback callback) { - EnterResource<PPB_DirectoryReader_API> enter(directory_reader, true); + EnterResource<PPB_DirectoryReader_API> enter( + directory_reader, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->GetNextEntry(entry, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->GetNextEntry(entry, callback)); } const PPB_DirectoryReader_Dev g_ppb_directory_reader_thunk = { diff --git a/ppapi/thunk/ppb_file_chooser_thunk.cc b/ppapi/thunk/ppb_file_chooser_thunk.cc index 1e783f9..b43b06a 100644 --- a/ppapi/thunk/ppb_file_chooser_thunk.cc +++ b/ppapi/thunk/ppb_file_chooser_thunk.cc @@ -7,7 +7,6 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/trusted/ppb_file_chooser_trusted.h" #include "ppapi/shared_impl/var.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_file_chooser_api.h" @@ -21,7 +20,7 @@ namespace { PP_Resource Create(PP_Instance instance, PP_FileChooserMode_Dev mode, struct PP_Var accept_mime_types) { - EnterFunction<ResourceCreationAPI> enter(instance, true); + EnterResourceCreation enter(instance); if (enter.failed()) return 0; scoped_refptr<StringVar> string_var = @@ -36,11 +35,10 @@ PP_Bool IsFileChooser(PP_Resource resource) { } int32_t Show(PP_Resource chooser, PP_CompletionCallback callback) { - EnterResource<PPB_FileChooser_API> enter(chooser, true); + EnterResource<PPB_FileChooser_API> enter(chooser, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Show(callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Show(callback)); } PP_Resource GetNextChosenFile(PP_Resource chooser) { @@ -54,15 +52,14 @@ int32_t ShowWithoutUserGesture(PP_Resource chooser, PP_Bool save_as, PP_Var suggested_file_name, PP_CompletionCallback callback) { - EnterResource<PPB_FileChooser_API> enter(chooser, true); + EnterResource<PPB_FileChooser_API> enter(chooser, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); + return enter.retval(); scoped_refptr<StringVar> string_var = StringVar::FromPPVar(suggested_file_name); std::string str = string_var ? string_var->value() : std::string(); - int32_t result = enter.object()->ShowWithoutUserGesture( - save_as == PP_TRUE, str.c_str(), callback); - return MayForceCallback(callback, result); + return enter.SetResult(enter.object()->ShowWithoutUserGesture( + save_as == PP_TRUE, str.c_str(), callback)); } const PPB_FileChooser_Dev g_ppb_file_chooser_thunk = { diff --git a/ppapi/thunk/ppb_file_io_thunk.cc b/ppapi/thunk/ppb_file_io_thunk.cc index 52d4ea6..a129a62 100644 --- a/ppapi/thunk/ppb_file_io_thunk.cc +++ b/ppapi/thunk/ppb_file_io_thunk.cc @@ -4,7 +4,6 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_file_io_api.h" @@ -15,15 +14,17 @@ namespace thunk { namespace { +typedef EnterResource<PPB_FileIO_API> EnterFileIO; + PP_Resource Create(PP_Instance instance) { - EnterFunction<ResourceCreationAPI> enter(instance, true); + EnterResourceCreation enter(instance); if (enter.failed()) return 0; return enter.functions()->CreateFileIO(instance); } PP_Bool IsFileIO(PP_Resource resource) { - EnterResource<PPB_FileIO_API> enter(resource, false); + EnterFileIO enter(resource, false); return PP_FromBool(enter.succeeded()); } @@ -31,33 +32,30 @@ int32_t Open(PP_Resource file_io, PP_Resource file_ref, int32_t open_flags, PP_CompletionCallback callback) { - EnterResource<PPB_FileIO_API> enter(file_io, true); + EnterFileIO enter(file_io, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Open(file_ref, open_flags, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Open(file_ref, open_flags, callback)); } int32_t Query(PP_Resource file_io, PP_FileInfo* info, PP_CompletionCallback callback) { - EnterResource<PPB_FileIO_API> enter(file_io, true); + EnterFileIO enter(file_io, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Query(info, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Query(info, callback)); } int32_t Touch(PP_Resource file_io, PP_Time last_access_time, PP_Time last_modified_time, PP_CompletionCallback callback) { - EnterResource<PPB_FileIO_API> enter(file_io, true); + EnterFileIO enter(file_io, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Touch(last_access_time, last_modified_time, - callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Touch( + last_access_time, last_modified_time, callback)); } int32_t Read(PP_Resource file_io, @@ -65,12 +63,11 @@ int32_t Read(PP_Resource file_io, char* buffer, int32_t bytes_to_read, PP_CompletionCallback callback) { - EnterResource<PPB_FileIO_API> enter(file_io, true); + EnterFileIO enter(file_io, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Read(offset, buffer, bytes_to_read, - callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Read(offset, buffer, bytes_to_read, + callback)); } int32_t Write(PP_Resource file_io, @@ -78,35 +75,32 @@ int32_t Write(PP_Resource file_io, const char* buffer, int32_t bytes_to_write, PP_CompletionCallback callback) { - EnterResource<PPB_FileIO_API> enter(file_io, true); + EnterFileIO enter(file_io, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Write(offset, buffer, bytes_to_write, - callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Write(offset, buffer, bytes_to_write, + callback)); } int32_t SetLength(PP_Resource file_io, int64_t length, PP_CompletionCallback callback) { - EnterResource<PPB_FileIO_API> enter(file_io, true); + EnterFileIO enter(file_io, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->SetLength(length, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->SetLength(length, callback)); } int32_t Flush(PP_Resource file_io, PP_CompletionCallback callback) { - EnterResource<PPB_FileIO_API> enter(file_io, true); + EnterFileIO enter(file_io, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Flush(callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Flush(callback)); } void Close(PP_Resource file_io) { - EnterResource<PPB_FileIO_API> enter(file_io, true); + EnterFileIO enter(file_io, true); if (enter.succeeded()) enter.object()->Close(); } diff --git a/ppapi/thunk/ppb_file_io_trusted_thunk.cc b/ppapi/thunk/ppb_file_io_trusted_thunk.cc index 709af437..c291ec8 100644 --- a/ppapi/thunk/ppb_file_io_trusted_thunk.cc +++ b/ppapi/thunk/ppb_file_io_trusted_thunk.cc @@ -5,7 +5,6 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/trusted/ppb_file_io_trusted.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_file_io_api.h" @@ -16,32 +15,33 @@ namespace thunk { namespace { +typedef EnterResource<PPB_FileIO_API> EnterFileIO; + int32_t GetOSFileDescriptor(PP_Resource file_io) { - EnterResource<PPB_FileIO_API> enter(file_io, true); + EnterFileIO enter(file_io, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; - return enter.object()->GetOSFileDescriptor(); + return enter.retval(); + return enter.SetResult(enter.object()->GetOSFileDescriptor()); } int32_t WillWrite(PP_Resource file_io, int64_t offset, int32_t bytes_to_write, PP_CompletionCallback callback) { - EnterResource<PPB_FileIO_API> enter(file_io, true); + EnterFileIO enter(file_io, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->WillWrite(offset, bytes_to_write, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->WillWrite(offset, bytes_to_write, + callback)); } int32_t WillSetLength(PP_Resource file_io, int64_t length, PP_CompletionCallback callback) { - EnterResource<PPB_FileIO_API> enter(file_io, true); + EnterFileIO enter(file_io, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->WillSetLength(length, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->WillSetLength(length, callback)); } const PPB_FileIOTrusted g_ppb_file_io_trusted_thunk = { diff --git a/ppapi/thunk/ppb_file_ref_thunk.cc b/ppapi/thunk/ppb_file_ref_thunk.cc index 7fdb8ac..8752b7f 100644 --- a/ppapi/thunk/ppb_file_ref_thunk.cc +++ b/ppapi/thunk/ppb_file_ref_thunk.cc @@ -7,7 +7,6 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/private/ppb_file_ref_private.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_file_ref_api.h" @@ -18,6 +17,8 @@ namespace thunk { namespace { +typedef EnterResource<PPB_FileRef_API> EnterFileRef; + PP_Resource Create(PP_Resource file_system, const char* path) { EnterFunctionGivenResource<ResourceCreationAPI> enter(file_system, true); if (enter.failed()) @@ -26,81 +27,78 @@ PP_Resource Create(PP_Resource file_system, const char* path) { } PP_Bool IsFileRef(PP_Resource resource) { - EnterResource<PPB_FileRef_API> enter(resource, false); + EnterFileRef enter(resource, false); return PP_FromBool(enter.succeeded()); } PP_FileSystemType GetFileSystemType(PP_Resource file_ref) { - EnterResource<PPB_FileRef_API> enter(file_ref, true); + EnterFileRef enter(file_ref, true); if (enter.failed()) return PP_FILESYSTEMTYPE_INVALID; return enter.object()->GetFileSystemType(); } PP_Var GetName(PP_Resource file_ref) { - EnterResource<PPB_FileRef_API> enter(file_ref, true); + EnterFileRef enter(file_ref, true); if (enter.failed()) return PP_MakeUndefined(); return enter.object()->GetName(); } PP_Var GetPath(PP_Resource file_ref) { - EnterResource<PPB_FileRef_API> enter(file_ref, true); + EnterFileRef enter(file_ref, true); if (enter.failed()) return PP_MakeUndefined(); return enter.object()->GetPath(); } PP_Resource GetParent(PP_Resource file_ref) { - EnterResource<PPB_FileRef_API> enter(file_ref, true); + EnterFileRef enter(file_ref, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; + return 0; return enter.object()->GetParent(); } int32_t MakeDirectory(PP_Resource directory_ref, PP_Bool make_ancestors, PP_CompletionCallback callback) { - EnterResource<PPB_FileRef_API> enter(directory_ref, true); + EnterFileRef enter(directory_ref, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->MakeDirectory(make_ancestors, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->MakeDirectory(make_ancestors, + callback)); } int32_t Touch(PP_Resource file_ref, PP_Time last_access_time, PP_Time last_modified_time, PP_CompletionCallback callback) { - EnterResource<PPB_FileRef_API> enter(file_ref, true); + EnterFileRef enter(file_ref, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Touch(last_access_time, last_modified_time, - callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Touch( + last_access_time, last_modified_time, callback)); } int32_t Delete(PP_Resource file_ref, PP_CompletionCallback callback) { - EnterResource<PPB_FileRef_API> enter(file_ref, true); + EnterFileRef enter(file_ref, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Delete(callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Delete(callback)); } int32_t Rename(PP_Resource file_ref, PP_Resource new_file_ref, PP_CompletionCallback callback) { - EnterResource<PPB_FileRef_API> enter(file_ref, true); + EnterFileRef enter(file_ref, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Rename(new_file_ref, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Rename(new_file_ref, callback)); } PP_Var GetAbsolutePath(PP_Resource file_ref) { - EnterResource<PPB_FileRef_API> enter(file_ref, true); + EnterFileRef enter(file_ref, true); if (enter.failed()) return PP_MakeUndefined(); return enter.object()->GetAbsolutePath(); diff --git a/ppapi/thunk/ppb_file_system_thunk.cc b/ppapi/thunk/ppb_file_system_thunk.cc index 1e82c91..d0d41f8 100644 --- a/ppapi/thunk/ppb_file_system_thunk.cc +++ b/ppapi/thunk/ppb_file_system_thunk.cc @@ -5,7 +5,6 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppb_file_system.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_file_system_api.h" @@ -16,30 +15,31 @@ namespace thunk { namespace { +typedef EnterResource<PPB_FileSystem_API> EnterFileSystem; + PP_Resource Create(PP_Instance instance, PP_FileSystemType type) { - EnterFunction<ResourceCreationAPI> enter(instance, true); + EnterResourceCreation enter(instance); if (enter.failed()) return 0; return enter.functions()->CreateFileSystem(instance, type); } PP_Bool IsFileSystem(PP_Resource resource) { - EnterResource<PPB_FileSystem_API> enter(resource, false); + EnterFileSystem enter(resource, false); return PP_FromBool(enter.succeeded()); } int32_t Open(PP_Resource file_system, int64 expected_size, PP_CompletionCallback callback) { - EnterResource<PPB_FileSystem_API> enter(file_system, true); + EnterFileSystem enter(file_system, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Open(expected_size, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Open(expected_size, callback)); } PP_FileSystemType GetType(PP_Resource file_system) { - EnterResource<PPB_FileSystem_API> enter(file_system, true); + EnterFileSystem enter(file_system, true); if (enter.failed()) return PP_FILESYSTEMTYPE_INVALID; return enter.object()->GetType(); diff --git a/ppapi/thunk/ppb_flash_clipboard_thunk.cc b/ppapi/thunk/ppb_flash_clipboard_thunk.cc index ffecb34..ba2fca3 100644 --- a/ppapi/thunk/ppb_flash_clipboard_thunk.cc +++ b/ppapi/thunk/ppb_flash_clipboard_thunk.cc @@ -37,7 +37,7 @@ int32_t WritePlainText(PP_Instance instance, PP_Var text) { EnterFlashClipboard enter(instance, true); if (enter.failed()) - return PP_ERROR_NOINTERFACE; + return enter.retval(); return enter.functions()->WritePlainText(instance, clipboard_type, text); } diff --git a/ppapi/thunk/ppb_flash_menu_thunk.cc b/ppapi/thunk/ppb_flash_menu_thunk.cc index 9426aa9..68c9b50 100644 --- a/ppapi/thunk/ppb_flash_menu_thunk.cc +++ b/ppapi/thunk/ppb_flash_menu_thunk.cc @@ -5,7 +5,6 @@ #include "ppapi/c/private/ppb_flash_menu.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_flash_menu_api.h" @@ -17,7 +16,7 @@ namespace thunk { namespace { PP_Resource Create(PP_Instance instance, const PP_Flash_Menu* menu_data) { - EnterFunction<ResourceCreationAPI> enter(instance, true); + EnterResourceCreation enter(instance); if (enter.failed()) return 0; return enter.functions()->CreateFlashMenu(instance, menu_data); @@ -32,11 +31,10 @@ int32_t Show(PP_Resource resource, const PP_Point* location, int32_t* selected_id, PP_CompletionCallback callback) { - EnterResource<PPB_Flash_Menu_API> enter(resource, true); + EnterResource<PPB_Flash_Menu_API> enter(resource, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Show(location, selected_id, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Show(location, selected_id, callback)); } const PPB_Flash_Menu g_ppb_flash_menu_thunk = { diff --git a/ppapi/thunk/ppb_flash_net_connector_thunk.cc b/ppapi/thunk/ppb_flash_net_connector_thunk.cc index 35ba2f0..0be5043 100644 --- a/ppapi/thunk/ppb_flash_net_connector_thunk.cc +++ b/ppapi/thunk/ppb_flash_net_connector_thunk.cc @@ -1,11 +1,10 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ppapi/c/private/ppb_flash_net_connector.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_flash_net_connector_api.h" @@ -16,15 +15,17 @@ namespace thunk { namespace { +typedef EnterResource<PPB_Flash_NetConnector_API> EnterNetConnector; + PP_Resource Create(PP_Instance instance) { - EnterFunction<ResourceCreationAPI> enter(instance, true); + EnterResourceCreation enter(instance); if (enter.failed()) return 0; return enter.functions()->CreateFlashNetConnector(instance); } PP_Bool IsFlashNetConnector(PP_Resource resource) { - EnterResource<PPB_Flash_NetConnector_API> enter(resource, false); + EnterNetConnector enter(resource, false); return PP_FromBool(enter.succeeded()); } @@ -35,13 +36,11 @@ int32_t ConnectTcp(PP_Resource resource, PP_NetAddress_Private* local_addr_out, PP_NetAddress_Private* remote_addr_out, PP_CompletionCallback callback) { - EnterResource<PPB_Flash_NetConnector_API> enter(resource, true); + EnterNetConnector enter(resource, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = - enter.object()->ConnectTcp(host, port, socket_out, local_addr_out, - remote_addr_out, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->ConnectTcp( + host, port, socket_out, local_addr_out, remote_addr_out, callback)); } int32_t ConnectTcpAddress(PP_Resource resource, @@ -50,13 +49,11 @@ int32_t ConnectTcpAddress(PP_Resource resource, PP_NetAddress_Private* local_addr_out, PP_NetAddress_Private* remote_addr_out, PP_CompletionCallback callback) { - EnterResource<PPB_Flash_NetConnector_API> enter(resource, true); + EnterNetConnector enter(resource, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = - enter.object()->ConnectTcpAddress(addr, socket_out, local_addr_out, - remote_addr_out, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->ConnectTcpAddress( + addr, socket_out, local_addr_out, remote_addr_out, callback)); } const PPB_Flash_NetConnector g_ppb_flash_net_connector_thunk = { diff --git a/ppapi/thunk/ppb_graphics_2d_thunk.cc b/ppapi/thunk/ppb_graphics_2d_thunk.cc index edb7ea9..393b4c6 100644 --- a/ppapi/thunk/ppb_graphics_2d_thunk.cc +++ b/ppapi/thunk/ppb_graphics_2d_thunk.cc @@ -5,7 +5,6 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppb_graphics_2d.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_graphics_2d_api.h" #include "ppapi/thunk/resource_creation_api.h" diff --git a/ppapi/thunk/ppb_graphics_3d_thunk.cc b/ppapi/thunk/ppb_graphics_3d_thunk.cc index 490561b..0aeeb27 100644 --- a/ppapi/thunk/ppb_graphics_3d_thunk.cc +++ b/ppapi/thunk/ppb_graphics_3d_thunk.cc @@ -4,7 +4,6 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_graphics_3d_api.h" @@ -27,7 +26,7 @@ int32_t GetAttribMaxValue(PP_Resource instance, PP_Resource Create(PP_Instance instance, PP_Resource share_context, const int32_t* attrib_list) { - EnterFunction<ResourceCreationAPI> enter(instance, true); + EnterResourceCreation enter(instance); if (enter.failed()) return 0; return enter.functions()->CreateGraphics3D( @@ -42,38 +41,36 @@ PP_Bool IsGraphics3D(PP_Resource resource) { int32_t GetAttribs(PP_Resource graphics_3d, int32_t* attrib_list) { EnterGraphics3D enter(graphics_3d, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; + return enter.retval(); return enter.object()->GetAttribs(attrib_list); } int32_t SetAttribs(PP_Resource graphics_3d, int32_t* attrib_list) { EnterGraphics3D enter(graphics_3d, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; + return enter.retval(); return enter.object()->SetAttribs(attrib_list); } int32_t GetError(PP_Resource graphics_3d) { EnterGraphics3D enter(graphics_3d, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; - + return enter.retval(); return enter.object()->GetError(); } int32_t ResizeBuffers(PP_Resource graphics_3d, int32_t width, int32_t height) { EnterGraphics3D enter(graphics_3d, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; + return enter.retval(); return enter.object()->ResizeBuffers(width, height); } int32_t SwapBuffers(PP_Resource graphics_3d, PP_CompletionCallback callback) { - EnterGraphics3D enter(graphics_3d, true); + EnterGraphics3D enter(graphics_3d, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->SwapBuffers(callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->SwapBuffers(callback)); } const PPB_Graphics3D g_ppb_graphics_3d_thunk = { diff --git a/ppapi/thunk/ppb_image_data_trusted_thunk.cc b/ppapi/thunk/ppb_image_data_trusted_thunk.cc index 8cf6789..86554a7 100644 --- a/ppapi/thunk/ppb_image_data_trusted_thunk.cc +++ b/ppapi/thunk/ppb_image_data_trusted_thunk.cc @@ -18,7 +18,7 @@ int32_t GetSharedMemory(PP_Resource resource, uint32_t* byte_count) { EnterResource<PPB_ImageData_API> enter(resource, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; + return enter.retval(); return enter.object()->GetSharedMemory(handle, byte_count); } diff --git a/ppapi/thunk/ppb_input_event_thunk.cc b/ppapi/thunk/ppb_input_event_thunk.cc index 5023461..388b011 100644 --- a/ppapi/thunk/ppb_input_event_thunk.cc +++ b/ppapi/thunk/ppb_input_event_thunk.cc @@ -22,7 +22,7 @@ typedef EnterResource<PPB_InputEvent_API> EnterInputEvent; int32_t RequestInputEvents(PP_Instance instance, uint32_t event_classes) { EnterInstance enter(instance, true); if (enter.failed()) - return PP_ERROR_BADARGUMENT; + return enter.retval(); return enter.functions()->RequestInputEvents(instance, event_classes); } @@ -30,7 +30,7 @@ int32_t RequestFilteringInputEvents(PP_Instance instance, uint32_t event_classes) { EnterInstance enter(instance, true); if (enter.failed()) - return PP_ERROR_BADARGUMENT; + return enter.retval(); return enter.functions()->RequestFilteringInputEvents(instance, event_classes); } diff --git a/ppapi/thunk/ppb_layer_compositor_thunk.cc b/ppapi/thunk/ppb_layer_compositor_thunk.cc index df03a43..98007d3 100644 --- a/ppapi/thunk/ppb_layer_compositor_thunk.cc +++ b/ppapi/thunk/ppb_layer_compositor_thunk.cc @@ -4,7 +4,6 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/dev/ppb_layer_compositor_dev.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_layer_compositor_api.h" @@ -46,7 +45,7 @@ void MarkAsDirty(PP_Resource compositor, PP_Resource layer) { int32_t SwapBuffers(PP_Resource compositor, struct PP_CompletionCallback callback) { - return MayForceCallback(callback, PP_ERROR_FAILED); + return PP_ERROR_NOINTERFACE; } const PPB_LayerCompositor_Dev g_ppb_layer_compositor_thunk = { diff --git a/ppapi/thunk/ppb_mouse_lock_thunk.cc b/ppapi/thunk/ppb_mouse_lock_thunk.cc index 167a537..11d2012 100644 --- a/ppapi/thunk/ppb_mouse_lock_thunk.cc +++ b/ppapi/thunk/ppb_mouse_lock_thunk.cc @@ -4,7 +4,6 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppb_mouse_lock.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_instance_api.h" #include "ppapi/thunk/thunk.h" @@ -15,11 +14,10 @@ namespace thunk { namespace { int32_t LockMouse(PP_Instance instance, PP_CompletionCallback callback) { - EnterFunction<PPB_Instance_FunctionAPI> enter(instance, true); + EnterFunction<PPB_Instance_FunctionAPI> enter(instance, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADARGUMENT); - int32_t result = enter.functions()->LockMouse(instance, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.functions()->LockMouse(instance, callback)); } void UnlockMouse(PP_Instance instance) { diff --git a/ppapi/thunk/ppb_tcp_socket_private_thunk.cc b/ppapi/thunk/ppb_tcp_socket_private_thunk.cc index 9085e9b..3997d08 100644 --- a/ppapi/thunk/ppb_tcp_socket_private_thunk.cc +++ b/ppapi/thunk/ppb_tcp_socket_private_thunk.cc @@ -5,7 +5,6 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/private/ppb_tcp_socket_private.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_tcp_socket_private_api.h" @@ -16,6 +15,8 @@ namespace thunk { namespace { +typedef EnterResource<PPB_TCPSocket_Private_API> EnterTCP; + PP_Resource Create(PP_Instance instance) { EnterFunction<ResourceCreationAPI> enter(instance, true); if (enter.failed()) @@ -24,7 +25,7 @@ PP_Resource Create(PP_Instance instance) { } PP_Bool IsTCPSocket(PP_Resource resource) { - EnterResource<PPB_TCPSocket_Private_API> enter(resource, false); + EnterTCP enter(resource, false); return PP_FromBool(enter.succeeded()); } @@ -32,26 +33,24 @@ int32_t Connect(PP_Resource tcp_socket, const char* host, uint16_t port, PP_CompletionCallback callback) { - EnterResource<PPB_TCPSocket_Private_API> enter(tcp_socket, true); + EnterTCP enter(tcp_socket, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Connect(host, port, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Connect(host, port, callback)); } int32_t ConnectWithNetAddress(PP_Resource tcp_socket, const PP_NetAddress_Private* addr, PP_CompletionCallback callback) { - EnterResource<PPB_TCPSocket_Private_API> enter(tcp_socket, true); + EnterTCP enter(tcp_socket, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->ConnectWithNetAddress(addr, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->ConnectWithNetAddress(addr, callback)); } PP_Bool GetLocalAddress(PP_Resource tcp_socket, PP_NetAddress_Private* local_addr) { - EnterResource<PPB_TCPSocket_Private_API> enter(tcp_socket, true); + EnterTCP enter(tcp_socket, true); if (enter.failed()) return PP_FALSE; return enter.object()->GetLocalAddress(local_addr); @@ -59,7 +58,7 @@ PP_Bool GetLocalAddress(PP_Resource tcp_socket, PP_Bool GetRemoteAddress(PP_Resource tcp_socket, PP_NetAddress_Private* remote_addr) { - EnterResource<PPB_TCPSocket_Private_API> enter(tcp_socket, true); + EnterTCP enter(tcp_socket, true); if (enter.failed()) return PP_FALSE; return enter.object()->GetRemoteAddress(remote_addr); @@ -69,38 +68,36 @@ int32_t SSLHandshake(PP_Resource tcp_socket, const char* server_name, uint16_t server_port, PP_CompletionCallback callback) { - EnterResource<PPB_TCPSocket_Private_API> enter(tcp_socket, true); + EnterTCP enter(tcp_socket, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->SSLHandshake(server_name, server_port, - callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->SSLHandshake(server_name, server_port, + callback)); } int32_t Read(PP_Resource tcp_socket, char* buffer, int32_t bytes_to_read, PP_CompletionCallback callback) { - EnterResource<PPB_TCPSocket_Private_API> enter(tcp_socket, true); + EnterTCP enter(tcp_socket, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Read(buffer, bytes_to_read, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Read(buffer, bytes_to_read, callback)); } int32_t Write(PP_Resource tcp_socket, const char* buffer, int32_t bytes_to_write, PP_CompletionCallback callback) { - EnterResource<PPB_TCPSocket_Private_API> enter(tcp_socket, true); + EnterTCP enter(tcp_socket, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Write(buffer, bytes_to_write, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Write(buffer, bytes_to_write, + callback)); } void Disconnect(PP_Resource tcp_socket) { - EnterResource<PPB_TCPSocket_Private_API> enter(tcp_socket, true); + EnterTCP enter(tcp_socket, true); if (enter.succeeded()) enter.object()->Disconnect(); } diff --git a/ppapi/thunk/ppb_transport_thunk.cc b/ppapi/thunk/ppb_transport_thunk.cc index 0e6e7d7..31266e8 100644 --- a/ppapi/thunk/ppb_transport_thunk.cc +++ b/ppapi/thunk/ppb_transport_thunk.cc @@ -4,7 +4,6 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_transport_api.h" @@ -41,56 +40,52 @@ int32_t SetProperty(PP_Resource transport, PP_TransportProperty property, PP_Var value) { EnterTransport enter(transport, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; + return enter.retval(); return enter.object()->SetProperty(property, value); } int32_t Connect(PP_Resource transport, PP_CompletionCallback callback) { - EnterTransport enter(transport, true); + EnterTransport enter(transport, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Connect(callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Connect(callback)); } int32_t GetNextAddress(PP_Resource transport, PP_Var* address, PP_CompletionCallback callback) { - EnterTransport enter(transport, true); + EnterTransport enter(transport, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->GetNextAddress(address, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->GetNextAddress(address, callback)); } int32_t ReceiveRemoteAddress(PP_Resource transport, PP_Var address) { EnterTransport enter(transport, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; + return enter.retval(); return enter.object()->ReceiveRemoteAddress(address); } int32_t Recv(PP_Resource transport, void* data, uint32_t len, PP_CompletionCallback callback) { - EnterTransport enter(transport, true); + EnterTransport enter(transport, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Recv(data, len, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Recv(data, len, callback)); } int32_t Send(PP_Resource transport, const void* data, uint32_t len, PP_CompletionCallback callback) { - EnterTransport enter(transport, true); + EnterTransport enter(transport, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Send(data, len, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Send(data, len, callback)); } int32_t Close(PP_Resource transport) { EnterTransport enter(transport, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; + return enter.retval(); return enter.object()->Close(); } diff --git a/ppapi/thunk/ppb_udp_socket_private_thunk.cc b/ppapi/thunk/ppb_udp_socket_private_thunk.cc index 60e95fe..9ee8b9d 100644 --- a/ppapi/thunk/ppb_udp_socket_private_thunk.cc +++ b/ppapi/thunk/ppb_udp_socket_private_thunk.cc @@ -5,7 +5,6 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/private/ppb_udp_socket_private.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_udp_socket_private_api.h" #include "ppapi/thunk/resource_creation_api.h" @@ -16,6 +15,8 @@ namespace thunk { namespace { +typedef EnterResource<PPB_UDPSocket_Private_API> EnterUDP; + PP_Resource Create(PP_Instance instance) { EnterFunction<ResourceCreationAPI> enter(instance, true); if (enter.failed()) @@ -24,36 +25,32 @@ PP_Resource Create(PP_Instance instance) { } PP_Bool IsUDPSocket(PP_Resource resource) { - EnterResource<PPB_UDPSocket_Private_API> enter(resource, false); + EnterUDP enter(resource, false); return PP_FromBool(enter.succeeded()); } int32_t Bind(PP_Resource udp_socket, const PP_NetAddress_Private *addr, PP_CompletionCallback callback) { - EnterResource<PPB_UDPSocket_Private_API> enter(udp_socket, true); + EnterUDP enter(udp_socket, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Bind(addr, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Bind(addr, callback)); } int32_t RecvFrom(PP_Resource udp_socket, char* buffer, int32_t num_bytes, PP_CompletionCallback callback) { - EnterResource<PPB_UDPSocket_Private_API> enter(udp_socket, true); + EnterUDP enter(udp_socket, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->RecvFrom(buffer, - num_bytes, - callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->RecvFrom(buffer, num_bytes, callback)); } PP_Bool GetRecvFromAddress(PP_Resource udp_socket, PP_NetAddress_Private* addr) { - EnterResource<PPB_UDPSocket_Private_API> enter(udp_socket, true); + EnterUDP enter(udp_socket, true); if (enter.failed()) return PP_FALSE; return enter.object()->GetRecvFromAddress(addr); @@ -64,15 +61,15 @@ int32_t SendTo(PP_Resource udp_socket, int32_t num_bytes, const PP_NetAddress_Private* addr, PP_CompletionCallback callback) { - EnterResource<PPB_UDPSocket_Private_API> enter(udp_socket, true); + EnterUDP enter(udp_socket, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->SendTo(buffer, num_bytes, addr, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->SendTo(buffer, num_bytes, addr, + callback)); } void Close(PP_Resource udp_socket) { - EnterResource<PPB_UDPSocket_Private_API> enter(udp_socket, true); + EnterUDP enter(udp_socket, true); if (enter.succeeded()) enter.object()->Close(); } diff --git a/ppapi/thunk/ppb_url_loader_thunk.cc b/ppapi/thunk/ppb_url_loader_thunk.cc index a4a2b3d..71dbdad 100644 --- a/ppapi/thunk/ppb_url_loader_thunk.cc +++ b/ppapi/thunk/ppb_url_loader_thunk.cc @@ -4,7 +4,6 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_url_loader_api.h" diff --git a/ppapi/thunk/ppb_video_capture_thunk.cc b/ppapi/thunk/ppb_video_capture_thunk.cc index fbd1f2b..d677471 100644 --- a/ppapi/thunk/ppb_video_capture_thunk.cc +++ b/ppapi/thunk/ppb_video_capture_thunk.cc @@ -3,7 +3,6 @@ // found in the LICENSE file. #include "ppapi/c/pp_errors.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_video_capture_api.h" @@ -33,8 +32,7 @@ int32_t StartCapture(PP_Resource video_capture, uint32_t buffer_count) { EnterVideoCapture enter(video_capture, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; - + return enter.retval(); return enter.object()->StartCapture(*requested_info, buffer_count); } @@ -42,16 +40,14 @@ int32_t ReuseBuffer(PP_Resource video_capture, uint32_t buffer) { EnterVideoCapture enter(video_capture, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; - + return enter.retval(); return enter.object()->ReuseBuffer(buffer); } int32_t StopCapture(PP_Resource video_capture) { EnterVideoCapture enter(video_capture, true); if (enter.failed()) - return PP_ERROR_BADRESOURCE; - + return enter.retval(); return enter.object()->StopCapture(); } diff --git a/ppapi/thunk/ppb_video_decoder_thunk.cc b/ppapi/thunk/ppb_video_decoder_thunk.cc index 5ff707c..3895c71 100644 --- a/ppapi/thunk/ppb_video_decoder_thunk.cc +++ b/ppapi/thunk/ppb_video_decoder_thunk.cc @@ -3,7 +3,6 @@ // found in the LICENSE file. #include "ppapi/c/pp_errors.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/ppb_video_decoder_api.h" @@ -33,11 +32,10 @@ PP_Bool IsVideoDecoder(PP_Resource resource) { int32_t Decode(PP_Resource video_decoder, const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, PP_CompletionCallback callback) { - EnterVideoDecoder enter(video_decoder, true); + EnterVideoDecoder enter(video_decoder, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Decode(bitstream_buffer, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Decode(bitstream_buffer, callback)); } void AssignPictureBuffers(PP_Resource video_decoder, @@ -55,20 +53,18 @@ void ReusePictureBuffer(PP_Resource video_decoder, int32_t picture_buffer_id) { } int32_t Flush(PP_Resource video_decoder, PP_CompletionCallback callback) { - EnterVideoDecoder enter(video_decoder, true); + EnterVideoDecoder enter(video_decoder, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Flush(callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Flush(callback)); } int32_t Reset(PP_Resource video_decoder, PP_CompletionCallback callback) { - EnterVideoDecoder enter(video_decoder, true); + EnterVideoDecoder enter(video_decoder, callback, true); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Reset(callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Reset(callback)); } void Destroy(PP_Resource video_decoder) { diff --git a/ppapi/thunk/ppb_websocket_thunk.cc b/ppapi/thunk/ppb_websocket_thunk.cc index 1fcae10..e83293c 100644 --- a/ppapi/thunk/ppb_websocket_thunk.cc +++ b/ppapi/thunk/ppb_websocket_thunk.cc @@ -4,7 +4,6 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_var.h" -#include "ppapi/thunk/common.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_websocket_api.h" @@ -15,15 +14,17 @@ namespace thunk { namespace { +typedef EnterResource<PPB_WebSocket_API> EnterWebSocket; + PP_Resource Create(PP_Instance instance) { - EnterFunction<ResourceCreationAPI> enter(instance, true); + EnterResourceCreation enter(instance); if (enter.failed()) return 0; return enter.functions()->CreateWebSocket(instance); } PP_Bool IsWebSocket(PP_Resource resource) { - EnterResource<PPB_WebSocket_API> enter(resource, false); + EnterWebSocket enter(resource, false); return PP_FromBool(enter.succeeded()); } @@ -32,93 +33,90 @@ int32_t Connect(PP_Resource resource, const PP_Var protocols[], uint32_t protocol_count, PP_CompletionCallback callback) { - EnterResource<PPB_WebSocket_API> enter(resource, false); + EnterWebSocket enter(resource, callback, false); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = - enter.object()->Connect(url, protocols, protocol_count, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Connect( + url, protocols, protocol_count, callback)); } int32_t Close(PP_Resource resource, uint16_t code, PP_Var reason, PP_CompletionCallback callback) { - EnterResource<PPB_WebSocket_API> enter(resource, false); + EnterWebSocket enter(resource, callback, false); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->Close(code, reason, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->Close(code, reason, callback)); } int32_t ReceiveMessage(PP_Resource resource, PP_Var* message, PP_CompletionCallback callback) { - EnterResource<PPB_WebSocket_API> enter(resource, false); + EnterWebSocket enter(resource, callback, false); if (enter.failed()) - return MayForceCallback(callback, PP_ERROR_BADRESOURCE); - int32_t result = enter.object()->ReceiveMessage(message, callback); - return MayForceCallback(callback, result); + return enter.retval(); + return enter.SetResult(enter.object()->ReceiveMessage(message, callback)); } int32_t SendMessage(PP_Resource resource, PP_Var message) { - EnterResource<PPB_WebSocket_API> enter(resource, false); + EnterWebSocket enter(resource, false); if (enter.failed()) - return PP_ERROR_BADRESOURCE; + return enter.retval(); return enter.object()->SendMessage(message); } uint64_t GetBufferedAmount(PP_Resource resource) { - EnterResource<PPB_WebSocket_API> enter(resource, false); + EnterWebSocket enter(resource, false); if (enter.failed()) return 0; return enter.object()->GetBufferedAmount(); } uint16_t GetCloseCode(PP_Resource resource) { - EnterResource<PPB_WebSocket_API> enter(resource, false); + EnterWebSocket enter(resource, false); if (enter.failed()) return 0; return enter.object()->GetCloseCode(); } PP_Var GetCloseReason(PP_Resource resource) { - EnterResource<PPB_WebSocket_API> enter(resource, false); + EnterWebSocket enter(resource, false); if (enter.failed()) return PP_MakeUndefined(); return enter.object()->GetCloseReason(); } PP_Bool GetCloseWasClean(PP_Resource resource) { - EnterResource<PPB_WebSocket_API> enter(resource, false); + EnterWebSocket enter(resource, false); if (enter.failed()) return PP_FALSE; return enter.object()->GetCloseWasClean(); } PP_Var GetExtensions(PP_Resource resource) { - EnterResource<PPB_WebSocket_API> enter(resource, false); + EnterWebSocket enter(resource, false); if (enter.failed()) return PP_MakeUndefined(); return enter.object()->GetExtensions(); } PP_Var GetProtocol(PP_Resource resource) { - EnterResource<PPB_WebSocket_API> enter(resource, false); + EnterWebSocket enter(resource, false); if (enter.failed()) return PP_MakeUndefined(); return enter.object()->GetProtocol(); } PP_WebSocketReadyState GetReadyState(PP_Resource resource) { - EnterResource<PPB_WebSocket_API> enter(resource, false); + EnterWebSocket enter(resource, false); if (enter.failed()) return PP_WEBSOCKETREADYSTATE_INVALID; return enter.object()->GetReadyState(); } PP_Var GetURL(PP_Resource resource) { - EnterResource<PPB_WebSocket_API> enter(resource, false); + EnterWebSocket enter(resource, false); if (enter.failed()) return PP_MakeUndefined(); return enter.object()->GetURL(); |