diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-08 19:40:40 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-08 19:40:40 +0000 |
commit | 79d23c7eca174feb74093670569088c2c8956e82 (patch) | |
tree | b176a3fd8cc3f00ffcf1c33997115c0254267059 /ppapi/proxy/ppb_audio_proxy.cc | |
parent | 3e15fdfe40bd5484a6c764ab65b2e6ffd2f1aa7d (diff) | |
download | chromium_src-79d23c7eca174feb74093670569088c2c8956e82.zip chromium_src-79d23c7eca174feb74093670569088c2c8956e82.tar.gz chromium_src-79d23c7eca174feb74093670569088c2c8956e82.tar.bz2 |
Reland 95309. Add a template to handle properly issuing completion callbacks.
This fixes some bugs where we forgot to issue completion callbacks in some
error cases in the proxy, and cleans up the cases that were already doing this
properly.
This removes the PPB_AudioTrusted_API and folds those functions into the
regular Audio API. I'm trying to merge more things to have a smaller explosion
of APIs and the boilerplate associated with them.
Original review URL: http://codereview.chromium.org/7551032
Review URL: http://codereview.chromium.org/7585025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95859 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/ppb_audio_proxy.cc')
-rw-r--r-- | ppapi/proxy/ppb_audio_proxy.cc | 70 |
1 files changed, 48 insertions, 22 deletions
diff --git a/ppapi/proxy/ppb_audio_proxy.cc b/ppapi/proxy/ppb_audio_proxy.cc index 76f3046..f0db204 100644 --- a/ppapi/proxy/ppb_audio_proxy.cc +++ b/ppapi/proxy/ppb_audio_proxy.cc @@ -4,6 +4,7 @@ #include "ppapi/proxy/ppb_audio_proxy.h" +#include "base/compiler_specific.h" #include "base/threading/simple_thread.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppb_audio.h" @@ -17,12 +18,13 @@ #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/shared_impl/audio_impl.h" #include "ppapi/thunk/ppb_audio_config_api.h" -#include "ppapi/thunk/ppb_audio_trusted_api.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/resource_creation_api.h" #include "ppapi/thunk/thunk.h" -using ::ppapi::thunk::PPB_Audio_API; +using ppapi::thunk::EnterResourceNoLock; +using ppapi::thunk::PPB_Audio_API; +using ppapi::thunk::PPB_AudioConfig_API; namespace pp { namespace proxy { @@ -42,6 +44,10 @@ class Audio : public PluginResource, public ppapi::AudioImpl { virtual PP_Resource GetCurrentConfig() OVERRIDE; virtual PP_Bool StartPlayback() OVERRIDE; virtual PP_Bool StopPlayback() OVERRIDE; + virtual int32_t OpenTrusted(PP_Resource config_id, + PP_CompletionCallback create_callback) OVERRIDE; + virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE; + virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE; private: // Owning reference to the current config object. This isn't actually used, @@ -95,6 +101,19 @@ PP_Bool Audio::StopPlayback() { return PP_TRUE; } +int32_t Audio::OpenTrusted(PP_Resource config_id, + PP_CompletionCallback create_callback) { + return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. +} + +int32_t Audio::GetSyncSocket(int* sync_socket) { + return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. +} + +int32_t Audio::GetSharedMemory(int* shm_handle, uint32_t* shm_size) { + return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. +} + namespace { InterfaceProxy* CreateAudioProxy(Dispatcher* dispatcher, @@ -147,8 +166,7 @@ PP_Resource PPB_Audio_Proxy::CreateProxyResource( if (!dispatcher) return 0; - ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_AudioConfig_API> - config(config_id, true); + EnterResourceNoLock<PPB_AudioConfig_API> config(config_id, true); if (config.failed()) return 0; @@ -193,26 +211,35 @@ void PPB_Audio_Proxy::OnMsgCreate(PP_Instance instance_id, resource_creation.functions()->CreateAudioTrusted(instance_id)); if (result->is_null()) return; - ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_AudioTrusted_API> - trusted_audio(result->host_resource(), false); - if (trusted_audio.failed()) - return; + + // At this point, we've set the result resource, and this is a sync request. + // Anything below this point must issue the AudioChannelConnected callback + // to the browser. Since that's an async message, it will be issued back to + // the plugin after the Create function returns (which is good because it + // would be weird to get a connected message with a failure code for a + // resource you haven't finished creating yet). + // + // The ...ForceCallback class will help ensure the callback is always called. + // All error cases must call SetResult on this class. + EnterHostFromHostResourceForceCallback<PPB_Audio_API> enter( + *result, callback_factory_, + &PPB_Audio_Proxy::AudioChannelConnected, *result); + if (enter.failed()) + return; // When enter fails, it will internally schedule the callback. // Make an audio config object. PP_Resource audio_config_res = resource_creation.functions()->CreateAudioConfig( instance_id, static_cast<PP_AudioSampleRate>(sample_rate), sample_frame_count); - if (!audio_config_res) + if (!audio_config_res) { + enter.SetResult(PP_ERROR_FAILED); return; + } // Initiate opening the audio object. - CompletionCallback callback = callback_factory_.NewOptionalCallback( - &PPB_Audio_Proxy::AudioChannelConnected, *result); - int32_t open_error = trusted_audio.object()->OpenTrusted( - audio_config_res, callback.pp_completion_callback()); - if (open_error != PP_OK_COMPLETIONPENDING) - callback.Run(open_error); + enter.SetResult(enter.object()->OpenTrusted(audio_config_res, + enter.callback())); // Clean up the temporary audio config resource we made. const PPB_Core* core = static_cast<const PPB_Core*>( @@ -280,15 +307,14 @@ int32_t PPB_Audio_Proxy::GetAudioConnectedHandles( IPC::PlatformFileForTransit* foreign_socket_handle, base::SharedMemoryHandle* foreign_shared_memory_handle, uint32_t* shared_memory_length) { - // Get the trusted audio interface which will give us the handles. - ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_AudioTrusted_API> - trusted_audio(resource.host_resource(), false); - if (trusted_audio.failed()) + // Get the audio interface which will give us the handles. + EnterResourceNoLock<PPB_Audio_API> enter(resource.host_resource(), false); + if (enter.failed()) return PP_ERROR_NOINTERFACE; // Get the socket handle for signaling. int32_t socket_handle; - int32_t result = trusted_audio.object()->GetSyncSocket(&socket_handle); + int32_t result = enter.object()->GetSyncSocket(&socket_handle); if (result != PP_OK) return result; @@ -300,8 +326,8 @@ int32_t PPB_Audio_Proxy::GetAudioConnectedHandles( // Get the shared memory for the buffer. int shared_memory_handle; - result = trusted_audio.object()->GetSharedMemory(&shared_memory_handle, - shared_memory_length); + result = enter.object()->GetSharedMemory(&shared_memory_handle, + shared_memory_length); if (result != PP_OK) return result; |