summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/ppapi_shared.gypi1
-rw-r--r--ppapi/proxy/enter_proxy.h90
-rw-r--r--ppapi/proxy/ppb_audio_proxy.cc70
-rw-r--r--ppapi/proxy/ppb_broker_proxy.cc22
-rw-r--r--ppapi/proxy/ppb_file_chooser_proxy.cc12
-rw-r--r--ppapi/proxy/ppb_file_system_proxy.cc13
-rw-r--r--ppapi/proxy/ppb_flash_menu_proxy.cc18
-rw-r--r--ppapi/proxy/ppb_graphics_2d_proxy.cc14
-rw-r--r--ppapi/proxy/ppb_graphics_3d_proxy.cc14
-rw-r--r--ppapi/proxy/ppb_surface_3d_proxy.cc14
-rw-r--r--ppapi/proxy/ppb_url_loader_proxy.cc17
-rw-r--r--ppapi/thunk/ppb_audio_api.h7
-rw-r--r--ppapi/thunk/ppb_audio_thunk.cc10
-rw-r--r--ppapi/thunk/ppb_audio_trusted_api.h27
-rw-r--r--ppapi/thunk/ppb_audio_trusted_thunk.cc11
15 files changed, 143 insertions, 197 deletions
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi
index aa46c74..fea7e66 100644
--- a/ppapi/ppapi_shared.gypi
+++ b/ppapi/ppapi_shared.gypi
@@ -70,6 +70,7 @@
'thunk/ppb_audio_config_api.h',
'thunk/ppb_audio_config_thunk.cc',
'thunk/ppb_audio_thunk.cc',
+ 'thunk/ppb_audio_trusted_api.h',
'thunk/ppb_audio_trusted_thunk.cc',
'thunk/ppb_broker_api.h',
'thunk/ppb_broker_thunk.cc',
diff --git a/ppapi/proxy/enter_proxy.h b/ppapi/proxy/enter_proxy.h
index 584ae30..6e52705 100644
--- a/ppapi/proxy/enter_proxy.h
+++ b/ppapi/proxy/enter_proxy.h
@@ -6,7 +6,6 @@
#define PPAPI_PROXY_ENTER_PROXY_H_
#include "base/logging.h"
-#include "ppapi/cpp/completion_callback.h"
#include "ppapi/proxy/host_dispatcher.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_resource_tracker.h"
@@ -53,95 +52,6 @@ class EnterHostFromHostResource
}
};
-// Enters a resource and forces a completion callback to be issued.
-//
-// This is used when implementing the host (renderer) side of a resource
-// function that issues a completion callback. In all cases, we need to issue
-// the callback to avoid hanging the plugin.
-//
-// This class automatically constructs a callback with the given factory
-// calling the given method. The method will generally be the one that sends
-// the message to trigger the completion callback in the plugin process.
-//
-// It will automatically issue the callback with PP_ERROR_NOINTERFACE if the
-// host resource is invalid (i.e. failed() is set). In all other cases you
-// should call SetResult(), which will issue the callback immediately if the
-// result value isn't PP_OK_COMPLETIONPENDING. In the "completion pending"
-// case, it's assumed the function the proxy is calling will take responsibility
-// of executing the callback (returned by callback()).
-//
-// Example:
-// EnterHostFromHostResourceForceCallback<PPB_Foo_API> enter(
-// resource, callback_factory_, &MyClass::SendResult, resource);
-// if (enter.failed())
-// return; // SendResult automatically called with PP_ERROR_BADRESOURCE.
-// enter.SetResult(enter.object()->DoFoo(enter.callback()));
-//
-// Where DoFoo's signature looks like this:
-// int32_t DoFoo(PP_CompletionCallback callback);
-// And SendResult's implementation looks like this:
-// void MyClass::SendResult(int32_t result, const HostResource& res) {
-// Send(new FooMsg_FooComplete(..., result, res));
-// }
-template<typename ResourceT>
-class EnterHostFromHostResourceForceCallback
- : public EnterHostFromHostResource<ResourceT> {
- public:
- // For callbacks that take no parameters except the "int32_t result". Most
- // implementations will use the 1-extra-argument constructor below.
- template<class CallbackFactory, typename Method>
- EnterHostFromHostResourceForceCallback(const HostResource& host_resource,
- CallbackFactory& factory,
- Method method)
- : EnterHostFromHostResource<ResourceT>(host_resource),
- needs_running_(true),
- callback_(factory.NewOptionalCallback(method)) {
- if (this->failed())
- RunCallback(PP_ERROR_BADRESOURCE);
- }
-
- // For callbacks that take an extra parameter as a closure.
- template<class CallbackFactory, typename Method, typename A>
- EnterHostFromHostResourceForceCallback(const HostResource& host_resource,
- CallbackFactory& factory,
- Method method,
- const A& a)
- : EnterHostFromHostResource<ResourceT>(host_resource),
- needs_running_(true),
- callback_(factory.NewOptionalCallback(method, a)) {
- if (this->failed())
- RunCallback(PP_ERROR_BADRESOURCE);
- }
-
- ~EnterHostFromHostResourceForceCallback() {
- if (needs_running_) {
- NOTREACHED() << "Should always call SetResult except in the "
- "initialization failed case.";
- RunCallback(PP_ERROR_FAILED);
- }
- }
-
- void SetResult(int32_t result) {
- DCHECK(needs_running_) << "Don't call SetResult when there already is one.";
- if (result != PP_OK_COMPLETIONPENDING)
- callback_.Run(result);
- }
-
- PP_CompletionCallback callback() {
- return callback_.pp_completion_callback();
- }
-
- private:
- void RunCallback(int32_t result) {
- DCHECK(needs_running_);
- needs_running_ = false;
- callback_.Run(result);
- }
-
- bool needs_running_;
- pp::CompletionCallback callback_;
-};
-
} // namespace proxy
} // namespace pp
diff --git a/ppapi/proxy/ppb_audio_proxy.cc b/ppapi/proxy/ppb_audio_proxy.cc
index f0db204..76f3046 100644
--- a/ppapi/proxy/ppb_audio_proxy.cc
+++ b/ppapi/proxy/ppb_audio_proxy.cc
@@ -4,7 +4,6 @@
#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"
@@ -18,13 +17,12 @@
#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::EnterResourceNoLock;
-using ppapi::thunk::PPB_Audio_API;
-using ppapi::thunk::PPB_AudioConfig_API;
+using ::ppapi::thunk::PPB_Audio_API;
namespace pp {
namespace proxy {
@@ -44,10 +42,6 @@ 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,
@@ -101,19 +95,6 @@ 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,
@@ -166,7 +147,8 @@ PP_Resource PPB_Audio_Proxy::CreateProxyResource(
if (!dispatcher)
return 0;
- EnterResourceNoLock<PPB_AudioConfig_API> config(config_id, true);
+ ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_AudioConfig_API>
+ config(config_id, true);
if (config.failed())
return 0;
@@ -211,35 +193,26 @@ void PPB_Audio_Proxy::OnMsgCreate(PP_Instance instance_id,
resource_creation.functions()->CreateAudioTrusted(instance_id));
if (result->is_null())
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.
+ ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_AudioTrusted_API>
+ trusted_audio(result->host_resource(), false);
+ if (trusted_audio.failed())
+ return;
// 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) {
- enter.SetResult(PP_ERROR_FAILED);
+ if (!audio_config_res)
return;
- }
// Initiate opening the audio object.
- enter.SetResult(enter.object()->OpenTrusted(audio_config_res,
- enter.callback()));
+ 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);
// Clean up the temporary audio config resource we made.
const PPB_Core* core = static_cast<const PPB_Core*>(
@@ -307,14 +280,15 @@ int32_t PPB_Audio_Proxy::GetAudioConnectedHandles(
IPC::PlatformFileForTransit* foreign_socket_handle,
base::SharedMemoryHandle* foreign_shared_memory_handle,
uint32_t* shared_memory_length) {
- // Get the audio interface which will give us the handles.
- EnterResourceNoLock<PPB_Audio_API> enter(resource.host_resource(), false);
- if (enter.failed())
+ // 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())
return PP_ERROR_NOINTERFACE;
// Get the socket handle for signaling.
int32_t socket_handle;
- int32_t result = enter.object()->GetSyncSocket(&socket_handle);
+ int32_t result = trusted_audio.object()->GetSyncSocket(&socket_handle);
if (result != PP_OK)
return result;
@@ -326,8 +300,8 @@ int32_t PPB_Audio_Proxy::GetAudioConnectedHandles(
// Get the shared memory for the buffer.
int shared_memory_handle;
- result = enter.object()->GetSharedMemory(&shared_memory_handle,
- shared_memory_length);
+ result = trusted_audio.object()->GetSharedMemory(&shared_memory_handle,
+ shared_memory_length);
if (result != PP_OK)
return result;
diff --git a/ppapi/proxy/ppb_broker_proxy.cc b/ppapi/proxy/ppb_broker_proxy.cc
index 637c6a0..37f8ba0 100644
--- a/ppapi/proxy/ppb_broker_proxy.cc
+++ b/ppapi/proxy/ppb_broker_proxy.cc
@@ -14,8 +14,6 @@
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
-using ppapi::thunk::PPB_Broker_API;
-
namespace pp {
namespace proxy {
@@ -48,13 +46,14 @@ InterfaceProxy* CreateBrokerProxy(Dispatcher* dispatcher,
} // namespace
-class Broker : public PPB_Broker_API, public PluginResource {
+class Broker : public ppapi::thunk::PPB_Broker_API,
+ public PluginResource {
public:
explicit Broker(const HostResource& resource);
virtual ~Broker();
// ResourceObjectBase overries.
- virtual PPB_Broker_API* AsPPB_Broker_API() OVERRIDE;
+ virtual ppapi::thunk::PPB_Broker_API* AsPPB_Broker_API() OVERRIDE;
// PPB_Broker_API implementation.
virtual int32_t Connect(PP_CompletionCallback connect_callback) OVERRIDE;
@@ -97,7 +96,7 @@ Broker::~Broker() {
socket_handle_ = base::kInvalidPlatformFileValue;
}
-PPB_Broker_API* Broker::AsPPB_Broker_API() {
+ppapi::thunk::PPB_Broker_API* Broker::AsPPB_Broker_API() {
return this;
}
@@ -205,11 +204,14 @@ void PPB_Broker_Proxy::OnMsgCreate(PP_Instance instance,
}
void PPB_Broker_Proxy::OnMsgConnect(const HostResource& broker) {
- EnterHostFromHostResourceForceCallback<PPB_Broker_API> enter(
- broker, callback_factory_,
+ CompletionCallback callback = callback_factory_.NewOptionalCallback(
&PPB_Broker_Proxy::ConnectCompleteInHost, broker);
- if (enter.succeeded())
- enter.SetResult(enter.object()->Connect(enter.callback()));
+
+ int32_t result = ppb_broker_target()->Connect(
+ broker.host_resource(),
+ callback.pp_completion_callback());
+ if (result != PP_OK_COMPLETIONPENDING)
+ callback.Run(result);
}
// Called in the plugin to handle the connect callback.
@@ -223,7 +225,7 @@ void PPB_Broker_Proxy::OnMsgConnectComplete(
DCHECK(result == PP_OK ||
socket_handle == IPC::InvalidPlatformFileForTransit());
- EnterPluginFromHostResource<PPB_Broker_API> enter(resource);
+ EnterPluginFromHostResource<ppapi::thunk::PPB_Broker_API> enter(resource);
if (enter.failed()) {
// As in Broker::ConnectComplete, we need to close the resource on error.
base::SyncSocket temp_socket(
diff --git a/ppapi/proxy/ppb_file_chooser_proxy.cc b/ppapi/proxy/ppb_file_chooser_proxy.cc
index d8ea705..cda175f 100644
--- a/ppapi/proxy/ppb_file_chooser_proxy.cc
+++ b/ppapi/proxy/ppb_file_chooser_proxy.cc
@@ -194,11 +194,13 @@ void PPB_FileChooser_Proxy::OnMsgCreate(PP_Instance instance,
}
void PPB_FileChooser_Proxy::OnMsgShow(const HostResource& chooser) {
- EnterHostFromHostResourceForceCallback<PPB_FileChooser_API> enter(
- chooser, callback_factory_, &PPB_FileChooser_Proxy::OnShowCallback,
- chooser);
- if (enter.succeeded())
- enter.SetResult(enter.object()->Show(enter.callback()));
+ CompletionCallback callback = callback_factory_.NewOptionalCallback(
+ &PPB_FileChooser_Proxy::OnShowCallback, chooser);
+
+ int32_t result = ppb_file_chooser_target()->Show(
+ chooser.host_resource(), callback.pp_completion_callback());
+ if (result != PP_OK_COMPLETIONPENDING)
+ callback.Run(result);
}
void PPB_FileChooser_Proxy::OnMsgChooseComplete(
diff --git a/ppapi/proxy/ppb_file_system_proxy.cc b/ppapi/proxy/ppb_file_system_proxy.cc
index c13a163..1edf5d7 100644
--- a/ppapi/proxy/ppb_file_system_proxy.cc
+++ b/ppapi/proxy/ppb_file_system_proxy.cc
@@ -174,11 +174,16 @@ void PPB_FileSystem_Proxy::OnMsgCreate(PP_Instance instance,
void PPB_FileSystem_Proxy::OnMsgOpen(const HostResource& host_resource,
int64_t expected_size) {
- EnterHostFromHostResourceForceCallback<PPB_FileSystem_API> enter(
- host_resource, callback_factory_,
+ EnterHostFromHostResource<PPB_FileSystem_API> enter(host_resource);
+ if (enter.failed())
+ return;
+
+ CompletionCallback callback = callback_factory_.NewOptionalCallback(
&PPB_FileSystem_Proxy::OpenCompleteInHost, host_resource);
- if (enter.succeeded())
- enter.SetResult(enter.object()->Open(expected_size, enter.callback()));
+ int32_t result = enter.object()->Open(expected_size,
+ callback.pp_completion_callback());
+ if (result != PP_OK_COMPLETIONPENDING)
+ callback.Run(result);
}
// Called in the plugin to handle the open callback.
diff --git a/ppapi/proxy/ppb_flash_menu_proxy.cc b/ppapi/proxy/ppb_flash_menu_proxy.cc
index a9c195c..c42c10e 100644
--- a/ppapi/proxy/ppb_flash_menu_proxy.cc
+++ b/ppapi/proxy/ppb_flash_menu_proxy.cc
@@ -162,13 +162,21 @@ void PPB_Flash_Menu_Proxy::OnMsgShow(const HostResource& menu,
const PP_Point& location) {
ShowRequest* request = new ShowRequest;
request->menu = menu;
+ CompletionCallback callback = callback_factory_.NewOptionalCallback(
+ &PPB_Flash_Menu_Proxy::SendShowACKToPlugin, request);
- EnterHostFromHostResourceForceCallback<PPB_Flash_Menu_API> enter(
- menu, callback_factory_, &PPB_Flash_Menu_Proxy::SendShowACKToPlugin,
- request);
+ EnterHostFromHostResource<PPB_Flash_Menu_API> enter(menu);
+ int32_t result = PP_ERROR_BADRESOURCE;
if (enter.succeeded()) {
- enter.SetResult(enter.object()->Show(&location, &request->selected_id,
- enter.callback()));
+ result = enter.object()->Show(&location,
+ &request->selected_id,
+ callback.pp_completion_callback());
+ }
+ if (result != PP_OK_COMPLETIONPENDING) {
+ // There was some error, so we won't get a callback. We need to now issue
+ // the ACK to the plugin so that it hears about the error. This will also
+ // clean up the data associated with the callback.
+ callback.Run(result);
}
}
diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.cc b/ppapi/proxy/ppb_graphics_2d_proxy.cc
index c74e244d..0f8a247 100644
--- a/ppapi/proxy/ppb_graphics_2d_proxy.cc
+++ b/ppapi/proxy/ppb_graphics_2d_proxy.cc
@@ -240,12 +240,16 @@ void PPB_Graphics2D_Proxy::OnMsgReplaceContents(
}
void PPB_Graphics2D_Proxy::OnMsgFlush(const HostResource& graphics_2d) {
- EnterHostFromHostResourceForceCallback<PPB_Graphics2D_API> enter(
- graphics_2d, callback_factory_,
+ CompletionCallback callback = callback_factory_.NewOptionalCallback(
&PPB_Graphics2D_Proxy::SendFlushACKToPlugin, graphics_2d);
- if (enter.failed())
- return;
- enter.SetResult(enter.object()->Flush(enter.callback()));
+ int32_t result = ppb_graphics_2d_target()->Flush(
+ graphics_2d.host_resource(), callback.pp_completion_callback());
+ if (result != PP_OK_COMPLETIONPENDING) {
+ // There was some error, so we won't get a flush callback. We need to now
+ // issue the ACK to the plugin hears about the error. This will also clean
+ // up the data associated with the callback.
+ callback.Run(result);
+ }
}
void PPB_Graphics2D_Proxy::OnMsgFlushACK(const HostResource& host_resource,
diff --git a/ppapi/proxy/ppb_graphics_3d_proxy.cc b/ppapi/proxy/ppb_graphics_3d_proxy.cc
index 11250d9..480f06b 100644
--- a/ppapi/proxy/ppb_graphics_3d_proxy.cc
+++ b/ppapi/proxy/ppb_graphics_3d_proxy.cc
@@ -587,11 +587,19 @@ void PPB_Graphics3D_Proxy::OnMsgGetTransferBuffer(
}
void PPB_Graphics3D_Proxy::OnMsgSwapBuffers(const HostResource& context) {
- EnterHostFromHostResourceForceCallback<PPB_Graphics3D_API> enter(
- context, callback_factory_,
+ CompletionCallback callback = callback_factory_.NewOptionalCallback(
&PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin, context);
+
+ EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
+ int32_t result = PP_ERROR_BADRESOURCE;
if (enter.succeeded())
- enter.SetResult(enter.object()->SwapBuffers(enter.callback()));
+ result = enter.object()->SwapBuffers(callback.pp_completion_callback());
+ if (result != PP_OK_COMPLETIONPENDING) {
+ // There was some error, so we won't get a flush callback. We need to now
+ // issue the ACK to the plugin hears about the error. This will also clean
+ // up the data associated with the callback.
+ callback.Run(result);
+ }
}
void PPB_Graphics3D_Proxy::OnMsgSwapBuffersACK(const HostResource& resource,
diff --git a/ppapi/proxy/ppb_surface_3d_proxy.cc b/ppapi/proxy/ppb_surface_3d_proxy.cc
index 2e432bc..c0288d0 100644
--- a/ppapi/proxy/ppb_surface_3d_proxy.cc
+++ b/ppapi/proxy/ppb_surface_3d_proxy.cc
@@ -177,11 +177,19 @@ void PPB_Surface3D_Proxy::OnMsgCreate(PP_Instance instance,
}
void PPB_Surface3D_Proxy::OnMsgSwapBuffers(const HostResource& surface_3d) {
- EnterHostFromHostResourceForceCallback<PPB_Surface3D_API> enter(
- surface_3d, callback_factory_,
+ CompletionCallback callback = callback_factory_.NewOptionalCallback(
&PPB_Surface3D_Proxy::SendSwapBuffersACKToPlugin, surface_3d);
+
+ EnterHostFromHostResource<PPB_Surface3D_API> enter(surface_3d);
+ int32_t result = PP_ERROR_BADRESOURCE;
if (enter.succeeded())
- enter.SetResult(enter.object()->SwapBuffers(enter.callback()));
+ result = enter.object()->SwapBuffers(callback.pp_completion_callback());
+ if (result != PP_OK_COMPLETIONPENDING) {
+ // There was some error, so we won't get a flush callback. We need to now
+ // issue the ACK to the plugin hears about the error. This will also clean
+ // up the data associated with the callback.
+ callback.Run(result);
+ }
}
void PPB_Surface3D_Proxy::OnMsgSwapBuffersACK(const HostResource& resource,
diff --git a/ppapi/proxy/ppb_url_loader_proxy.cc b/ppapi/proxy/ppb_url_loader_proxy.cc
index 1fc4db1..b2d6276 100644
--- a/ppapi/proxy/ppb_url_loader_proxy.cc
+++ b/ppapi/proxy/ppb_url_loader_proxy.cc
@@ -517,12 +517,21 @@ void PPB_URLLoader_Proxy::OnMsgReadResponseBody(
// TODO(brettw) have a way to check for out-of-memory.
info->read_buffer.resize(bytes_to_read);
- EnterHostFromHostResourceForceCallback<PPB_URLLoader_API> enter(
- loader, callback_factory_, &PPB_URLLoader_Proxy::OnReadCallback, info);
+ CompletionCallback callback = callback_factory_.NewOptionalCallback(
+ &PPB_URLLoader_Proxy::OnReadCallback, info);
+
+ EnterHostFromHostResource<PPB_URLLoader_API> enter(loader);
+ int32_t result = PP_ERROR_BADRESOURCE;
if (enter.succeeded()) {
- enter.SetResult(enter.object()->ReadResponseBody(
+ result = enter.object()->ReadResponseBody(
const_cast<char*>(info->read_buffer.c_str()),
- bytes_to_read, enter.callback()));
+ bytes_to_read, callback.pp_completion_callback());
+ }
+ if (result != PP_OK_COMPLETIONPENDING) {
+ // Send error (or perhaps success for synchronous reads) back to plugin.
+ // The callback function is already set up to do this and also delete the
+ // callback info.
+ callback.Run(result);
}
}
diff --git a/ppapi/thunk/ppb_audio_api.h b/ppapi/thunk/ppb_audio_api.h
index 3d21299..d105e1c 100644
--- a/ppapi/thunk/ppb_audio_api.h
+++ b/ppapi/thunk/ppb_audio_api.h
@@ -5,7 +5,6 @@
#ifndef PPAPI_THUNK_AUDIO_API_H_
#define PPAPI_THUNK_AUDIO_API_H_
-#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/ppb_audio.h"
namespace ppapi {
@@ -18,12 +17,6 @@ class PPB_Audio_API {
virtual PP_Resource GetCurrentConfig() = 0;
virtual PP_Bool StartPlayback() = 0;
virtual PP_Bool StopPlayback() = 0;
-
- // Trusted API.
- virtual int32_t OpenTrusted(PP_Resource config_id,
- PP_CompletionCallback create_callback) = 0;
- virtual int32_t GetSyncSocket(int* sync_socket) = 0;
- virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) = 0;
};
} // namespace thunk
diff --git a/ppapi/thunk/ppb_audio_thunk.cc b/ppapi/thunk/ppb_audio_thunk.cc
index 18b70b6..426ba29 100644
--- a/ppapi/thunk/ppb_audio_thunk.cc
+++ b/ppapi/thunk/ppb_audio_thunk.cc
@@ -12,8 +12,6 @@ namespace thunk {
namespace {
-typedef EnterResource<PPB_Audio_API> EnterAudio;
-
PP_Resource Create(PP_Instance instance,
PP_Resource config_id,
PPB_Audio_Callback callback,
@@ -26,26 +24,26 @@ PP_Resource Create(PP_Instance instance,
}
PP_Bool IsAudio(PP_Resource resource) {
- EnterAudio enter(resource, false);
+ EnterResource<PPB_Audio_API> enter(resource, false);
return enter.succeeded() ? PP_TRUE : PP_FALSE;
}
PP_Resource GetCurrentConfiguration(PP_Resource audio_id) {
- EnterAudio enter(audio_id, true);
+ EnterResource<PPB_Audio_API> enter(audio_id, true);
if (enter.failed())
return 0;
return enter.object()->GetCurrentConfig();
}
PP_Bool StartPlayback(PP_Resource audio_id) {
- EnterAudio enter(audio_id, true);
+ EnterResource<PPB_Audio_API> enter(audio_id, true);
if (enter.failed())
return PP_FALSE;
return enter.object()->StartPlayback();
}
PP_Bool StopPlayback(PP_Resource audio_id) {
- EnterAudio enter(audio_id, true);
+ EnterResource<PPB_Audio_API> enter(audio_id, true);
if (enter.failed())
return PP_FALSE;
return enter.object()->StopPlayback();
diff --git a/ppapi/thunk/ppb_audio_trusted_api.h b/ppapi/thunk/ppb_audio_trusted_api.h
new file mode 100644
index 0000000..de4b79a
--- /dev/null
+++ b/ppapi/thunk/ppb_audio_trusted_api.h
@@ -0,0 +1,27 @@
+// 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_AUDIO_TRUSTED_API_H_
+#define PPAPI_THUNK_AUDIO_TRUSTED_API_H_
+
+#include "ppapi/c/trusted/ppb_audio_trusted.h"
+#include "ppapi/c/ppb_audio.h"
+
+namespace ppapi {
+namespace thunk {
+
+class PPB_AudioTrusted_API {
+ public:
+ virtual ~PPB_AudioTrusted_API() {}
+
+ virtual int32_t OpenTrusted(PP_Resource config_id,
+ PP_CompletionCallback create_callback) = 0;
+ virtual int32_t GetSyncSocket(int* sync_socket) = 0;
+ virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) = 0;
+};
+
+} // namespace thunk
+} // namespace ppapi
+
+#endif // PPAPI_THUNK_AUDIO_TRUSTED_API_H_
diff --git a/ppapi/thunk/ppb_audio_trusted_thunk.cc b/ppapi/thunk/ppb_audio_trusted_thunk.cc
index 97f8978..05c1b4e 100644
--- a/ppapi/thunk/ppb_audio_trusted_thunk.cc
+++ b/ppapi/thunk/ppb_audio_trusted_thunk.cc
@@ -3,11 +3,10 @@
// found in the LICENSE file.
#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"
+#include "ppapi/thunk/ppb_audio_trusted_api.h"
#include "ppapi/thunk/resource_creation_api.h"
namespace ppapi {
@@ -15,8 +14,6 @@ namespace thunk {
namespace {
-typedef EnterResource<PPB_Audio_API> EnterAudio;
-
PP_Resource Create(PP_Instance instance_id) {
EnterFunction<ResourceCreationAPI> enter(instance_id, true);
if (enter.failed())
@@ -27,7 +24,7 @@ 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);
+ EnterResource<PPB_AudioTrusted_API> enter(audio_id, true);
if (enter.failed())
return MayForceCallback(create_callback, PP_ERROR_BADRESOURCE);
int32_t result = enter.object()->OpenTrusted(config_id, create_callback);
@@ -35,7 +32,7 @@ int32_t Open(PP_Resource audio_id,
}
int32_t GetSyncSocket(PP_Resource audio_id, int* sync_socket) {
- EnterAudio enter(audio_id, true);
+ EnterResource<PPB_AudioTrusted_API> enter(audio_id, true);
if (enter.failed())
return PP_ERROR_BADRESOURCE;
return enter.object()->GetSyncSocket(sync_socket);
@@ -44,7 +41,7 @@ int32_t GetSyncSocket(PP_Resource audio_id, int* sync_socket) {
int32_t GetSharedMemory(PP_Resource audio_id,
int* shm_handle,
uint32_t* shm_size) {
- EnterAudio enter(audio_id, true);
+ EnterResource<PPB_AudioTrusted_API> enter(audio_id, true);
if (enter.failed())
return PP_ERROR_BADRESOURCE;
return enter.object()->GetSharedMemory(shm_handle, shm_size);