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

Unified Diff: ppapi/proxy/ppb_audio_proxy.cc

Issue 7551032: Add a template to handle properly issuing completion callbacks. This fixes (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/proxy/ppb_audio_proxy.cc
===================================================================
--- ppapi/proxy/ppb_audio_proxy.cc (revision 94913)
+++ ppapi/proxy/ppb_audio_proxy.cc (working copy)
@@ -17,12 +17,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 +43,10 @@
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 +100,19 @@
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 +165,7 @@
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 +210,35 @@
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 +306,14 @@
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 +325,8 @@
// 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;

Powered by Google App Engine
This is Rietveld 408576698