summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-23 14:27:42 +0000
committerdmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-23 14:27:42 +0000
commitaed965375dec978e7feb8722b1b94250a2a6e039 (patch)
tree9f8ccdf7a3902fa1db54e0c036f7cb9ca96775fb
parent94bd0a2e94c1f07ccc0236a95e57a2e16b94038a (diff)
downloadchromium_src-aed965375dec978e7feb8722b1b94250a2a6e039.zip
chromium_src-aed965375dec978e7feb8722b1b94250a2a6e039.tar.gz
chromium_src-aed965375dec978e7feb8722b1b94250a2a6e039.tar.bz2
PPAPI: Make blocking completion callbacks work.
This also makes scoped_refptr<TrackedCallback> the "new" way to pass completion callbacks in an API. This allows the Enter object to handle checking for blocking callbacks on the main thread to report error, and blocking if on the background thread. This way, interfaces don't have to write any special cases for blocking callbacks. When built with enable_pepper_threading=1 locally, URLLoader tests all pass for blocking completion callbacks. I haven't updated all tests yet. BUG=92909 TEST= Review URL: https://chromiumcodereview.appspot.com/10081020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143806 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ppapi/proxy/enter_proxy.h57
-rw-r--r--ppapi/proxy/plugin_dispatcher.cc10
-rw-r--r--ppapi/proxy/plugin_dispatcher.h6
-rw-r--r--ppapi/proxy/ppb_audio_input_proxy.cc33
-rw-r--r--ppapi/proxy/ppb_audio_proxy.cc7
-rw-r--r--ppapi/proxy/ppb_broker_proxy.cc12
-rw-r--r--ppapi/proxy/ppb_core_proxy.cc16
-rw-r--r--ppapi/proxy/ppb_file_chooser_proxy.cc25
-rw-r--r--ppapi/proxy/ppb_file_io_proxy.cc74
-rw-r--r--ppapi/proxy/ppb_file_ref_proxy.cc71
-rw-r--r--ppapi/proxy/ppb_file_system_proxy.cc6
-rw-r--r--ppapi/proxy/ppb_flash_menu_proxy.cc6
-rw-r--r--ppapi/proxy/ppb_graphics_2d_proxy.cc11
-rw-r--r--ppapi/proxy/ppb_instance_proxy.cc18
-rw-r--r--ppapi/proxy/ppb_instance_proxy.h2
-rw-r--r--ppapi/proxy/ppb_message_loop_proxy.cc6
-rw-r--r--ppapi/proxy/ppb_network_monitor_private_proxy.cc19
-rw-r--r--ppapi/proxy/ppb_network_monitor_private_proxy.h2
-rw-r--r--ppapi/proxy/ppb_talk_private_proxy.cc4
-rw-r--r--ppapi/proxy/ppb_tcp_server_socket_private_proxy.cc6
-rw-r--r--ppapi/proxy/ppb_url_loader_proxy.cc42
-rw-r--r--ppapi/proxy/ppb_video_capture_proxy.cc17
-rw-r--r--ppapi/proxy/ppb_video_decoder_proxy.cc14
-rw-r--r--ppapi/proxy/proxy_array_output.h2
-rw-r--r--ppapi/shared_impl/ppapi_globals.cc7
-rw-r--r--ppapi/shared_impl/ppapi_globals.h6
-rw-r--r--ppapi/shared_impl/ppb_audio_config_shared.cc4
-rw-r--r--ppapi/shared_impl/ppb_audio_input_shared.cc18
-rw-r--r--ppapi/shared_impl/ppb_audio_input_shared.h16
-rw-r--r--ppapi/shared_impl/ppb_file_io_shared.cc49
-rw-r--r--ppapi/shared_impl/ppb_file_io_shared.h39
-rw-r--r--ppapi/shared_impl/ppb_graphics_3d_shared.cc11
-rw-r--r--ppapi/shared_impl/ppb_graphics_3d_shared.h2
-rw-r--r--ppapi/shared_impl/ppb_video_capture_shared.cc6
-rw-r--r--ppapi/shared_impl/ppb_video_capture_shared.h8
-rw-r--r--ppapi/shared_impl/ppb_video_decoder_shared.cc17
-rw-r--r--ppapi/shared_impl/ppb_video_decoder_shared.h10
-rw-r--r--ppapi/shared_impl/private/ppb_host_resolver_shared.cc6
-rw-r--r--ppapi/shared_impl/private/ppb_host_resolver_shared.h2
-rw-r--r--ppapi/shared_impl/private/ppb_tcp_server_socket_shared.cc20
-rw-r--r--ppapi/shared_impl/private/ppb_tcp_server_socket_shared.h4
-rw-r--r--ppapi/shared_impl/private/tcp_socket_private_impl.cc37
-rw-r--r--ppapi/shared_impl/private/tcp_socket_private_impl.h15
-rw-r--r--ppapi/shared_impl/private/udp_socket_private_impl.cc25
-rw-r--r--ppapi/shared_impl/private/udp_socket_private_impl.h6
-rw-r--r--ppapi/shared_impl/proxy_lock.cc5
-rw-r--r--ppapi/shared_impl/proxy_lock.h1
-rw-r--r--ppapi/shared_impl/tracked_callback.cc132
-rw-r--r--ppapi/shared_impl/tracked_callback.h66
-rw-r--r--ppapi/tests/test_broker.cc33
-rw-r--r--ppapi/tests/test_case.cc30
-rw-r--r--ppapi/tests/test_case.h126
-rw-r--r--ppapi/tests/test_url_loader.cc63
-rw-r--r--ppapi/tests/test_utils.cc11
-rw-r--r--ppapi/thunk/enter.cc166
-rw-r--r--ppapi/thunk/enter.h99
-rw-r--r--ppapi/thunk/ppb_audio_api.h11
-rw-r--r--ppapi/thunk/ppb_audio_input_api.h11
-rw-r--r--ppapi/thunk/ppb_audio_input_thunk.cc6
-rw-r--r--ppapi/thunk/ppb_audio_input_trusted_thunk.cc4
-rw-r--r--ppapi/thunk/ppb_audio_trusted_thunk.cc4
-rw-r--r--ppapi/thunk/ppb_broker_api.h8
-rw-r--r--ppapi/thunk/ppb_broker_thunk.cc3
-rw-r--r--ppapi/thunk/ppb_directory_reader_api.h8
-rw-r--r--ppapi/thunk/ppb_directory_reader_thunk.cc3
-rw-r--r--ppapi/thunk/ppb_file_chooser_api.h14
-rw-r--r--ppapi/thunk/ppb_file_chooser_thunk.cc9
-rw-r--r--ppapi/thunk/ppb_file_io_api.h24
-rw-r--r--ppapi/thunk/ppb_file_io_thunk.cc16
-rw-r--r--ppapi/thunk/ppb_file_io_trusted_thunk.cc8
-rw-r--r--ppapi/thunk/ppb_file_ref_api.h12
-rw-r--r--ppapi/thunk/ppb_file_ref_thunk.cc10
-rw-r--r--ppapi/thunk/ppb_file_system_api.h8
-rw-r--r--ppapi/thunk/ppb_file_system_thunk.cc3
-rw-r--r--ppapi/thunk/ppb_flash_menu_api.h8
-rw-r--r--ppapi/thunk/ppb_flash_menu_thunk.cc4
-rw-r--r--ppapi/thunk/ppb_graphics_2d_api.h8
-rw-r--r--ppapi/thunk/ppb_graphics_2d_thunk.cc6
-rw-r--r--ppapi/thunk/ppb_graphics_3d_api.h6
-rw-r--r--ppapi/thunk/ppb_graphics_3d_thunk.cc3
-rw-r--r--ppapi/thunk/ppb_host_resolver_private_api.h6
-rw-r--r--ppapi/thunk/ppb_host_resolver_private_thunk.cc4
-rw-r--r--ppapi/thunk/ppb_instance_api.h5
-rw-r--r--ppapi/thunk/ppb_layer_compositor_api.h8
-rw-r--r--ppapi/thunk/ppb_message_loop_api.h12
-rw-r--r--ppapi/thunk/ppb_mouse_lock_thunk.cc4
-rw-r--r--ppapi/thunk/ppb_talk_private_api.h6
-rw-r--r--ppapi/thunk/ppb_talk_private_thunk.cc3
-rw-r--r--ppapi/thunk/ppb_tcp_server_socket_private_api.h8
-rw-r--r--ppapi/thunk/ppb_tcp_server_socket_private_thunk.cc6
-rw-r--r--ppapi/thunk/ppb_tcp_socket_private_api.h17
-rw-r--r--ppapi/thunk/ppb_tcp_socket_private_thunk.cc13
-rw-r--r--ppapi/thunk/ppb_udp_socket_private_api.h10
-rw-r--r--ppapi/thunk/ppb_udp_socket_private_thunk.cc8
-rw-r--r--ppapi/thunk/ppb_url_loader_api.h15
-rw-r--r--ppapi/thunk/ppb_url_loader_thunk.cc10
-rw-r--r--ppapi/thunk/ppb_video_capture_api.h6
-rw-r--r--ppapi/thunk/ppb_video_capture_thunk.cc6
-rw-r--r--ppapi/thunk/ppb_video_decoder_api.h12
-rw-r--r--ppapi/thunk/ppb_video_decoder_thunk.cc8
-rw-r--r--ppapi/thunk/ppb_websocket_api.h10
-rw-r--r--ppapi/thunk/ppb_websocket_thunk.cc8
-rw-r--r--webkit/plugins/ppapi/file_callbacks.cc6
-rw-r--r--webkit/plugins/ppapi/file_callbacks.h4
-rw-r--r--webkit/plugins/ppapi/plugin_module.cc14
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.cc20
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.h8
-rw-r--r--webkit/plugins/ppapi/ppb_audio_impl.cc7
-rw-r--r--webkit/plugins/ppapi/ppb_audio_impl.h7
-rw-r--r--webkit/plugins/ppapi/ppb_audio_input_impl.cc19
-rw-r--r--webkit/plugins/ppapi/ppb_audio_input_impl.h13
-rw-r--r--webkit/plugins/ppapi/ppb_broker_impl.cc10
-rw-r--r--webkit/plugins/ppapi/ppb_broker_impl.h3
-rw-r--r--webkit/plugins/ppapi/ppb_directory_reader_impl.cc5
-rw-r--r--webkit/plugins/ppapi/ppb_directory_reader_impl.h8
-rw-r--r--webkit/plugins/ppapi/ppb_file_chooser_impl.cc19
-rw-r--r--webkit/plugins/ppapi/ppb_file_chooser_impl.h18
-rw-r--r--webkit/plugins/ppapi/ppb_file_io_impl.cc61
-rw-r--r--webkit/plugins/ppapi/ppb_file_io_impl.h61
-rw-r--r--webkit/plugins/ppapi/ppb_file_ref_impl.cc20
-rw-r--r--webkit/plugins/ppapi/ppb_file_ref_impl.h20
-rw-r--r--webkit/plugins/ppapi/ppb_file_system_impl.cc14
-rw-r--r--webkit/plugins/ppapi/ppb_file_system_impl.h5
-rw-r--r--webkit/plugins/ppapi/ppb_flash_menu_impl.cc10
-rw-r--r--webkit/plugins/ppapi/ppb_flash_menu_impl.h9
-rw-r--r--webkit/plugins/ppapi/ppb_graphics_2d_impl.cc11
-rw-r--r--webkit/plugins/ppapi/ppb_graphics_2d_impl.h3
-rw-r--r--webkit/plugins/ppapi/ppb_layer_compositor_impl.cc5
-rw-r--r--webkit/plugins/ppapi/ppb_layer_compositor_impl.h5
-rw-r--r--webkit/plugins/ppapi/ppb_url_loader_impl.cc27
-rw-r--r--webkit/plugins/ppapi/ppb_url_loader_impl.h23
-rw-r--r--webkit/plugins/ppapi/ppb_video_capture_impl.cc11
-rw-r--r--webkit/plugins/ppapi/ppb_video_capture_impl.h4
-rw-r--r--webkit/plugins/ppapi/ppb_video_decoder_impl.cc16
-rw-r--r--webkit/plugins/ppapi/ppb_video_decoder_impl.h11
-rw-r--r--webkit/plugins/ppapi/ppb_websocket_impl.cc27
-rw-r--r--webkit/plugins/ppapi/ppb_websocket_impl.h21
137 files changed, 1432 insertions, 981 deletions
diff --git a/ppapi/proxy/enter_proxy.h b/ppapi/proxy/enter_proxy.h
index 6ee93a3..3832a13 100644
--- a/ppapi/proxy/enter_proxy.h
+++ b/ppapi/proxy/enter_proxy.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.
@@ -45,8 +45,20 @@ class EnterHostFromHostResource
: public thunk::EnterResourceNoLock<ResourceT> {
public:
explicit EnterHostFromHostResource(const HostResource& host_resource)
- : thunk::EnterResourceNoLock<ResourceT>(
- host_resource.host_resource(), false) {
+ : thunk::EnterResourceNoLock<ResourceT>(host_resource.host_resource(),
+ false) {
+ // Validate that we're in the host rather than the plugin. Otherwise this
+ // object will do the wrong thing. In the host, the instance should have
+ // a corresponding host disptacher (assuming the resource is valid).
+ DCHECK(this->failed() ||
+ HostDispatcher::GetForInstance(host_resource.instance()));
+ }
+
+ EnterHostFromHostResource(const HostResource& host_resource,
+ const pp::CompletionCallback& callback)
+ : thunk::EnterResourceNoLock<ResourceT>(host_resource.host_resource(),
+ callback.pp_completion_callback(),
+ false) {
// Validate that we're in the host rather than the plugin. Otherwise this
// object will do the wrong thing. In the host, the instance should have
// a corresponding host disptacher (assuming the resource is valid).
@@ -92,9 +104,8 @@ class EnterHostFromHostResourceForceCallback
EnterHostFromHostResourceForceCallback(
const HostResource& host_resource,
const pp::CompletionCallback& callback)
- : EnterHostFromHostResource<ResourceT>(host_resource),
- needs_running_(true),
- callback_(callback) {
+ : EnterHostFromHostResource<ResourceT>(host_resource, callback),
+ needs_running_(true) {
}
// For callbacks that take no parameters except the "int32_t result". Most
@@ -104,9 +115,9 @@ class EnterHostFromHostResourceForceCallback
const HostResource& host_resource,
CallbackFactory& factory,
Method method)
- : EnterHostFromHostResource<ResourceT>(host_resource),
- needs_running_(true),
- callback_(factory.NewOptionalCallback(method)) {
+ : EnterHostFromHostResource<ResourceT>(host_resource,
+ factory.NewOptionalCallback(method)),
+ needs_running_(true) {
if (this->failed())
RunCallback(PP_ERROR_BADRESOURCE);
}
@@ -118,9 +129,9 @@ class EnterHostFromHostResourceForceCallback
CallbackFactory& factory,
Method method,
const A& a)
- : EnterHostFromHostResource<ResourceT>(host_resource),
- needs_running_(true),
- callback_(factory.NewOptionalCallback(method, a)) {
+ : EnterHostFromHostResource<ResourceT>(host_resource,
+ factory.NewOptionalCallback(method, a)),
+ needs_running_(true) {
if (this->failed())
RunCallback(PP_ERROR_BADRESOURCE);
}
@@ -133,9 +144,9 @@ class EnterHostFromHostResourceForceCallback
Method method,
const A& a,
const B& b)
- : EnterHostFromHostResource<ResourceT>(host_resource),
- needs_running_(true),
- callback_(factory.NewOptionalCallback(method, a, b)) {
+ : EnterHostFromHostResource<ResourceT>(host_resource,
+ factory.NewOptionalCallback(method, a, b)),
+ needs_running_(true) {
if (this->failed())
RunCallback(PP_ERROR_BADRESOURCE);
}
@@ -150,24 +161,24 @@ class EnterHostFromHostResourceForceCallback
void SetResult(int32_t result) {
DCHECK(needs_running_) << "Don't call SetResult when there already is one.";
- needs_running_ = false;
if (result != PP_OK_COMPLETIONPENDING)
- callback_.Run(result);
- }
-
- PP_CompletionCallback callback() {
- return callback_.pp_completion_callback();
+ RunCallback(result);
+ needs_running_ = false;
+ // Either we already ran the callback, or it will be run asynchronously. We
+ // clear the callback so it isn't accidentally run again (and because
+ // EnterBase checks that the callback has been cleared).
+ this->ClearCallback();
}
private:
void RunCallback(int32_t result) {
DCHECK(needs_running_);
needs_running_ = false;
- callback_.Run(result);
+ this->callback()->Run(result);
+ this->ClearCallback();
}
bool needs_running_;
- pp::CompletionCallback callback_;
};
} // namespace proxy
diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc
index ad8c620..9cf606e 100644
--- a/ppapi/proxy/plugin_dispatcher.cc
+++ b/ppapi/proxy/plugin_dispatcher.cc
@@ -45,17 +45,13 @@ DispatcherSet* g_live_dispatchers = NULL;
} // namespace
InstanceData::InstanceData()
- : flash_fullscreen(PP_FALSE),
- mouse_lock_callback(PP_BlockUntilComplete()) {
+ : flash_fullscreen(PP_FALSE) {
}
InstanceData::~InstanceData() {
// Run any pending mouse lock callback to prevent leaks.
- if (mouse_lock_callback.func) {
- CallWhileUnlocked(PP_RunAndClearCompletionCallback,
- &mouse_lock_callback,
- static_cast<int32_t>(PP_ERROR_ABORTED));
- }
+ if (mouse_lock_callback)
+ mouse_lock_callback->Abort();
}
PluginDispatcher::PluginDispatcher(PP_GetInterface_Func get_interface,
diff --git a/ppapi/proxy/plugin_dispatcher.h b/ppapi/proxy/plugin_dispatcher.h
index 0639d29..5dd6725 100644
--- a/ppapi/proxy/plugin_dispatcher.h
+++ b/ppapi/proxy/plugin_dispatcher.h
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/hash_tables.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/process.h"
#include "build/build_config.h"
@@ -19,6 +20,7 @@
#include "ppapi/proxy/dispatcher.h"
#include "ppapi/shared_impl/ppapi_preferences.h"
#include "ppapi/shared_impl/ppb_view_shared.h"
+#include "ppapi/shared_impl/tracked_callback.h"
namespace ppapi {
@@ -41,8 +43,8 @@ struct InstanceData {
PP_Bool flash_fullscreen; // Used for PPB_FlashFullscreen.
- // When non-0, indicates the callback to execute when mouse lock is lost.
- PP_CompletionCallback mouse_lock_callback;
+ // When non-NULL, indicates the callback to execute when mouse lock is lost.
+ scoped_refptr<TrackedCallback> mouse_lock_callback;
};
class PPAPI_PROXY_EXPORT PluginDispatcher
diff --git a/ppapi/proxy/ppb_audio_input_proxy.cc b/ppapi/proxy/ppb_audio_input_proxy.cc
index 32aa6b7..011e332 100644
--- a/ppapi/proxy/ppb_audio_input_proxy.cc
+++ b/ppapi/proxy/ppb_audio_input_proxy.cc
@@ -36,7 +36,7 @@ class AudioInput : public PPB_AudioInput_Shared {
virtual int32_t OpenTrusted(
const std::string& device_id,
PP_Resource config,
- const PP_CompletionCallback& create_callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> create_callback) OVERRIDE;
virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE;
virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE;
virtual const std::vector<DeviceRefData>& GetDeviceRefData() const OVERRIDE;
@@ -45,11 +45,12 @@ class AudioInput : public PPB_AudioInput_Shared {
// PPB_AudioInput_Shared implementation.
virtual int32_t InternalEnumerateDevices(
PP_Resource* devices,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t InternalOpen(const std::string& device_id,
- PP_AudioSampleRate sample_rate,
- uint32_t sample_frame_count,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t InternalOpen(
+ const std::string& device_id,
+ PP_AudioSampleRate sample_rate,
+ uint32_t sample_frame_count,
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual PP_Bool InternalStartCapture() OVERRIDE;
virtual PP_Bool InternalStopCapture() OVERRIDE;
virtual void InternalClose() OVERRIDE;
@@ -69,9 +70,10 @@ AudioInput::~AudioInput() {
Close();
}
-int32_t AudioInput::OpenTrusted(const std::string& device_id,
- PP_Resource config,
- const PP_CompletionCallback& create_callback) {
+int32_t AudioInput::OpenTrusted(
+ const std::string& device_id,
+ PP_Resource config,
+ scoped_refptr<TrackedCallback> create_callback) {
return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface.
}
@@ -89,10 +91,11 @@ const std::vector<DeviceRefData>& AudioInput::GetDeviceRefData() const {
return result;
}
-int32_t AudioInput::InternalEnumerateDevices(PP_Resource* devices,
- PP_CompletionCallback callback) {
+int32_t AudioInput::InternalEnumerateDevices(
+ PP_Resource* devices,
+ scoped_refptr<TrackedCallback> callback) {
devices_ = devices;
- enumerate_devices_callback_ = new TrackedCallback(this, callback);
+ enumerate_devices_callback_ = callback;
GetDispatcher()->Send(new PpapiHostMsg_PPBAudioInput_EnumerateDevices(
API_ID_PPB_AUDIO_INPUT_DEV, host_resource()));
return PP_OK_COMPLETIONPENDING;
@@ -101,8 +104,8 @@ int32_t AudioInput::InternalEnumerateDevices(PP_Resource* devices,
int32_t AudioInput::InternalOpen(const std::string& device_id,
PP_AudioSampleRate sample_rate,
uint32_t sample_frame_count,
- PP_CompletionCallback callback) {
- open_callback_ = new TrackedCallback(this, callback);
+ scoped_refptr<TrackedCallback> callback) {
+ open_callback_ = callback;
GetDispatcher()->Send(new PpapiHostMsg_PPBAudioInput_Open(
API_ID_PPB_AUDIO_INPUT_DEV, host_resource(), device_id, sample_rate,
sample_frame_count));
@@ -154,7 +157,7 @@ PP_Resource PPB_AudioInput_Proxy::CreateProxyResource0_1(
AudioInput* audio_input = new AudioInput(result);
int32_t open_result = audio_input->Open("", config, audio_input_callback,
- user_data, AudioInput::MakeIgnoredCompletionCallback());
+ user_data, AudioInput::MakeIgnoredCompletionCallback(audio_input));
if (open_result != PP_OK && open_result != PP_OK_COMPLETIONPENDING) {
delete audio_input;
return 0;
diff --git a/ppapi/proxy/ppb_audio_proxy.cc b/ppapi/proxy/ppb_audio_proxy.cc
index 380bc39..7b2c015 100644
--- a/ppapi/proxy/ppb_audio_proxy.cc
+++ b/ppapi/proxy/ppb_audio_proxy.cc
@@ -47,8 +47,9 @@ class Audio : public Resource, public PPB_Audio_Shared {
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 OpenTrusted(
+ PP_Resource config_id,
+ scoped_refptr<TrackedCallback> create_callback) OVERRIDE;
virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE;
virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE;
@@ -105,7 +106,7 @@ PP_Bool Audio::StopPlayback() {
}
int32_t Audio::OpenTrusted(PP_Resource config_id,
- PP_CompletionCallback create_callback) {
+ scoped_refptr<TrackedCallback> create_callback) {
return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface.
}
diff --git a/ppapi/proxy/ppb_broker_proxy.cc b/ppapi/proxy/ppb_broker_proxy.cc
index b9549e0..9800d32 100644
--- a/ppapi/proxy/ppb_broker_proxy.cc
+++ b/ppapi/proxy/ppb_broker_proxy.cc
@@ -33,7 +33,8 @@ class Broker : public PPB_Broker_API, public Resource {
virtual PPB_Broker_API* AsPPB_Broker_API() OVERRIDE;
// PPB_Broker_API implementation.
- virtual int32_t Connect(PP_CompletionCallback connect_callback) OVERRIDE;
+ virtual int32_t Connect(
+ scoped_refptr<TrackedCallback> connect_callback) OVERRIDE;
virtual int32_t GetHandle(int32_t* handle) OVERRIDE;
// Called by the proxy when the host side has completed the request.
@@ -67,18 +68,13 @@ PPB_Broker_API* Broker::AsPPB_Broker_API() {
return this;
}
-int32_t Broker::Connect(PP_CompletionCallback connect_callback) {
- if (!connect_callback.func) {
- // Synchronous calls are not supported.
- return PP_ERROR_BLOCKS_MAIN_THREAD;
- }
-
+int32_t Broker::Connect(scoped_refptr<TrackedCallback> connect_callback) {
if (TrackedCallback::IsPending(current_connect_callback_))
return PP_ERROR_INPROGRESS;
else if (called_connect_)
return PP_ERROR_FAILED;
- current_connect_callback_ = new TrackedCallback(this, connect_callback);
+ current_connect_callback_ = connect_callback;
called_connect_ = true;
bool success = PluginDispatcher::GetForResource(this)->Send(
diff --git a/ppapi/proxy/ppb_core_proxy.cc b/ppapi/proxy/ppb_core_proxy.cc
index fc6da8f..ad8773b 100644
--- a/ppapi/proxy/ppb_core_proxy.cc
+++ b/ppapi/proxy/ppb_core_proxy.cc
@@ -9,8 +9,6 @@
#include "base/bind.h"
#include "base/debug/trace_event.h"
#include "base/logging.h"
-#include "base/message_loop.h"
-#include "base/message_loop_proxy.h"
#include "base/time.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_resource.h"
@@ -27,12 +25,6 @@ namespace proxy {
namespace {
-base::MessageLoopProxy* GetMainThreadMessageLoop() {
- CR_DEFINE_STATIC_LOCAL(scoped_refptr<base::MessageLoopProxy>, proxy,
- (base::MessageLoopProxy::current()));
- return proxy.get();
-}
-
void AddRefResource(PP_Resource resource) {
ppapi::ProxyAutoLock lock;
PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(resource);
@@ -61,14 +53,18 @@ void CallbackWrapper(PP_CompletionCallback callback, int32_t result) {
void CallOnMainThread(int delay_in_ms,
PP_CompletionCallback callback,
int32_t result) {
- GetMainThreadMessageLoop()->PostDelayedTask(
+ DCHECK(callback.func);
+ if (!callback.func)
+ return;
+ PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostDelayedTask(
FROM_HERE,
RunWhileLocked(base::Bind(&CallbackWrapper, callback, result)),
base::TimeDelta::FromMilliseconds(delay_in_ms));
}
PP_Bool IsMainThread() {
- return PP_FromBool(GetMainThreadMessageLoop()->BelongsToCurrentThread());
+ return PP_FromBool(PpapiGlobals::Get()->
+ GetMainThreadMessageLoop()->BelongsToCurrentThread());
}
const PPB_Core core_interface = {
diff --git a/ppapi/proxy/ppb_file_chooser_proxy.cc b/ppapi/proxy/ppb_file_chooser_proxy.cc
index 8bf83da..26ab430 100644
--- a/ppapi/proxy/ppb_file_chooser_proxy.cc
+++ b/ppapi/proxy/ppb_file_chooser_proxy.cc
@@ -46,18 +46,18 @@ class FileChooser : public Resource,
// PPB_FileChooser_API implementation.
virtual int32_t Show(const PP_ArrayOutput& output,
- const PP_CompletionCallback& callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t ShowWithoutUserGesture(
PP_Bool save_as,
PP_Var suggested_file_name,
const PP_ArrayOutput& output,
- const PP_CompletionCallback& callback);
- virtual int32_t Show0_5(const PP_CompletionCallback& callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback);
+ virtual int32_t Show0_5(scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual PP_Resource GetNextChosenFile() OVERRIDE;
virtual int32_t ShowWithoutUserGesture0_5(
PP_Bool save_as,
PP_Var suggested_file_name,
- const PP_CompletionCallback& callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
// Handles the choose complete notification from the host.
void ChooseComplete(
@@ -68,7 +68,7 @@ class FileChooser : public Resource,
int32_t Show(bool require_user_gesture,
PP_Bool save_as,
PP_Var suggested_file_name,
- const PP_CompletionCallback& callback);
+ scoped_refptr<TrackedCallback> callback);
// When using v0.6 of the API, contains the array output info.
ArrayWriter output_;
@@ -103,7 +103,7 @@ PPB_FileChooser_API* FileChooser::AsPPB_FileChooser_API() {
}
int32_t FileChooser::Show(const PP_ArrayOutput& output,
- const PP_CompletionCallback& callback) {
+ scoped_refptr<TrackedCallback> callback) {
int32_t result = Show(true, PP_FALSE, PP_MakeUndefined(), callback);
if (result == PP_OK_COMPLETIONPENDING)
output_.set_pp_array_output(output);
@@ -114,35 +114,32 @@ int32_t FileChooser::ShowWithoutUserGesture(
PP_Bool save_as,
PP_Var suggested_file_name,
const PP_ArrayOutput& output,
- const PP_CompletionCallback& callback) {
+ scoped_refptr<TrackedCallback> callback) {
int32_t result = Show(false, save_as, suggested_file_name, callback);
if (result == PP_OK_COMPLETIONPENDING)
output_.set_pp_array_output(output);
return result;
}
-int32_t FileChooser::Show0_5(const PP_CompletionCallback& callback) {
+int32_t FileChooser::Show0_5(scoped_refptr<TrackedCallback> callback) {
return Show(true, PP_FALSE, PP_MakeUndefined(), callback);
}
int32_t FileChooser::ShowWithoutUserGesture0_5(
PP_Bool save_as,
PP_Var suggested_file_name,
- const PP_CompletionCallback& callback) {
+ scoped_refptr<TrackedCallback> callback) {
return Show(false, save_as, suggested_file_name, callback);
}
int32_t FileChooser::Show(bool require_user_gesture,
PP_Bool save_as,
PP_Var suggested_file_name,
- const PP_CompletionCallback& callback) {
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
-
+ scoped_refptr<TrackedCallback> callback) {
if (TrackedCallback::IsPending(current_show_callback_))
return PP_ERROR_INPROGRESS; // Can't show more than once.
- current_show_callback_ = new TrackedCallback(this, callback);
+ current_show_callback_ = callback;
PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this);
dispatcher->Send(
new PpapiHostMsg_PPBFileChooser_Show(
diff --git a/ppapi/proxy/ppb_file_io_proxy.cc b/ppapi/proxy/ppb_file_io_proxy.cc
index 0acd3ac..6858655 100644
--- a/ppapi/proxy/ppb_file_io_proxy.cc
+++ b/ppapi/proxy/ppb_file_io_proxy.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.
@@ -41,32 +41,40 @@ class FileIO : public PPB_FileIO_Shared {
virtual int32_t GetOSFileDescriptor() OVERRIDE;
virtual int32_t WillWrite(int64_t offset,
int32_t bytes_to_write,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t WillSetLength(int64_t length,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t WillSetLength(
+ int64_t length,
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
private:
// FileIOImpl overrides.
- virtual int32_t OpenValidated(PP_Resource file_ref_resource,
- PPB_FileRef_API* file_ref_api,
- int32_t open_flags,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t QueryValidated(PP_FileInfo* info,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t TouchValidated(PP_Time last_access_time,
- PP_Time last_modified_time,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t ReadValidated(int64_t offset,
- char* buffer,
- int32_t bytes_to_read,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t WriteValidated(int64_t offset,
- const char* buffer,
- int32_t bytes_to_write,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t SetLengthValidated(int64_t length,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t FlushValidated(PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t OpenValidated(
+ PP_Resource file_ref_resource,
+ PPB_FileRef_API* file_ref_api,
+ int32_t open_flags,
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t QueryValidated(
+ PP_FileInfo* info,
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t TouchValidated(
+ PP_Time last_access_time,
+ PP_Time last_modified_time,
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t ReadValidated(
+ int64_t offset,
+ char* buffer,
+ int32_t bytes_to_read,
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t WriteValidated(
+ int64_t offset,
+ const char* buffer,
+ int32_t bytes_to_write,
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t SetLengthValidated(
+ int64_t length,
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t FlushValidated(
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
PluginDispatcher* GetDispatcher() const {
return PluginDispatcher::GetForResource(this);
@@ -98,7 +106,7 @@ int32_t FileIO::GetOSFileDescriptor() {
int32_t FileIO::WillWrite(int64_t offset,
int32_t bytes_to_write,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_WillWrite(
kApiID, host_resource(), offset, bytes_to_write));
RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL);
@@ -106,7 +114,7 @@ int32_t FileIO::WillWrite(int64_t offset,
}
int32_t FileIO::WillSetLength(int64_t length,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_WillSetLength(
kApiID, host_resource(), length));
RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL);
@@ -116,7 +124,7 @@ int32_t FileIO::WillSetLength(int64_t length,
int32_t FileIO::OpenValidated(PP_Resource file_ref_resource,
PPB_FileRef_API* file_ref_api,
int32_t open_flags,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
Resource* file_ref_object =
PpapiGlobals::Get()->GetResourceTracker()->GetResource(file_ref_resource);
@@ -127,7 +135,7 @@ int32_t FileIO::OpenValidated(PP_Resource file_ref_resource,
}
int32_t FileIO::QueryValidated(PP_FileInfo* info,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Query(
kApiID, host_resource()));
RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, info);
@@ -136,7 +144,7 @@ int32_t FileIO::QueryValidated(PP_FileInfo* info,
int32_t FileIO::TouchValidated(PP_Time last_access_time,
PP_Time last_modified_time,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Touch(
kApiID, host_resource(), last_access_time, last_modified_time));
RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL);
@@ -146,7 +154,7 @@ int32_t FileIO::TouchValidated(PP_Time last_access_time,
int32_t FileIO::ReadValidated(int64_t offset,
char* buffer,
int32_t bytes_to_read,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Read(
kApiID, host_resource(), offset, bytes_to_read));
RegisterCallback(OPERATION_READ, callback, buffer, NULL);
@@ -156,7 +164,7 @@ int32_t FileIO::ReadValidated(int64_t offset,
int32_t FileIO::WriteValidated(int64_t offset,
const char* buffer,
int32_t bytes_to_write,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
// TODO(brettw) it would be nice to use a shared memory buffer for large
// writes rather than having to copy to a string (which will involve a number
// of extra copies to serialize over IPC).
@@ -167,14 +175,14 @@ int32_t FileIO::WriteValidated(int64_t offset,
}
int32_t FileIO::SetLengthValidated(int64_t length,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_SetLength(
kApiID, host_resource(), length));
RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL);
return PP_OK_COMPLETIONPENDING;
}
-int32_t FileIO::FlushValidated(PP_CompletionCallback callback) {
+int32_t FileIO::FlushValidated(scoped_refptr<TrackedCallback> callback) {
GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Flush(
kApiID, host_resource()));
RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL);
diff --git a/ppapi/proxy/ppb_file_ref_proxy.cc b/ppapi/proxy/ppb_file_ref_proxy.cc
index 26c3e15..d8ffde6 100644
--- a/ppapi/proxy/ppb_file_ref_proxy.cc
+++ b/ppapi/proxy/ppb_file_ref_proxy.cc
@@ -38,14 +38,15 @@ class FileRef : public PPB_FileRef_Shared {
// PPB_FileRef_API implementation (not provided by PPB_FileRef_Shared).
virtual PP_Resource GetParent() OVERRIDE;
- virtual int32_t MakeDirectory(PP_Bool make_ancestors,
- PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t MakeDirectory(
+ PP_Bool make_ancestors,
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t Touch(PP_Time last_access_time,
PP_Time last_modified_time,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t Delete(PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t Delete(scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t Rename(PP_Resource new_file_ref,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual PP_Var GetAbsolutePath() OVERRIDE;
// Executes the pending callback with the given ID. See pending_callbacks_.
@@ -56,9 +57,8 @@ class FileRef : public PPB_FileRef_Shared {
return PluginDispatcher::GetForResource(this);
}
- // Adds a callback to the list and returns its ID. Returns 0 if the callback
- // is invalid.
- int SendCallback(PP_CompletionCallback callback);
+ // Adds a callback to the list and returns its ID.
+ int SendCallback(scoped_refptr<TrackedCallback> callback);
// This class can have any number of out-standing requests with completion
// callbacks, in contrast to most resources which have one possible pending
@@ -66,9 +66,10 @@ class FileRef : public PPB_FileRef_Shared {
//
// To keep track of them, assign integer IDs to the callbacks, which is how
// the callback will be identified when it's passed to the host and then
- // back here.
- int next_callback_id_;
- typedef std::map<int, scoped_refptr<TrackedCallback> > PendingCallbackMap;
+ // back here. Use unsigned so that overflow is well-defined.
+ unsigned int next_callback_id_;
+ typedef std::map<unsigned int,
+ scoped_refptr<TrackedCallback> > PendingCallbackMap;
PendingCallbackMap pending_callbacks_;
DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef);
@@ -76,7 +77,7 @@ class FileRef : public PPB_FileRef_Shared {
FileRef::FileRef(const PPB_FileRef_CreateInfo& info)
: PPB_FileRef_Shared(OBJECT_IS_PROXY, info),
- next_callback_id_(1) {
+ next_callback_id_(0u) {
}
FileRef::~FileRef() {
@@ -97,45 +98,30 @@ PP_Resource FileRef::GetParent() {
}
int32_t FileRef::MakeDirectory(PP_Bool make_ancestors,
- PP_CompletionCallback callback) {
- int callback_id = SendCallback(callback);
- if (!callback_id)
- return PP_ERROR_BADARGUMENT;
-
+ scoped_refptr<TrackedCallback> callback) {
GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_MakeDirectory(
- API_ID_PPB_FILE_REF, host_resource(), make_ancestors, callback_id));
+ API_ID_PPB_FILE_REF, host_resource(), make_ancestors,
+ SendCallback(callback)));
return PP_OK_COMPLETIONPENDING;
}
int32_t FileRef::Touch(PP_Time last_access_time,
PP_Time last_modified_time,
- PP_CompletionCallback callback) {
- int callback_id = SendCallback(callback);
- if (!callback_id)
- return PP_ERROR_BADARGUMENT;
-
+ scoped_refptr<TrackedCallback> callback) {
GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Touch(
- API_ID_PPB_FILE_REF, host_resource(),
- last_access_time, last_modified_time, callback_id));
+ API_ID_PPB_FILE_REF, host_resource(), last_access_time,
+ last_modified_time, SendCallback(callback)));
return PP_OK_COMPLETIONPENDING;
}
-int32_t FileRef::Delete(PP_CompletionCallback callback) {
- int callback_id = SendCallback(callback);
- if (!callback_id)
- return PP_ERROR_BADARGUMENT;
-
+int32_t FileRef::Delete(scoped_refptr<TrackedCallback> callback) {
GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Delete(
- API_ID_PPB_FILE_REF, host_resource(), callback_id));
+ API_ID_PPB_FILE_REF, host_resource(), SendCallback(callback)));
return PP_OK_COMPLETIONPENDING;
}
int32_t FileRef::Rename(PP_Resource new_file_ref,
- PP_CompletionCallback callback) {
- int callback_id = SendCallback(callback);
- if (!callback_id)
- return PP_ERROR_BADARGUMENT;
-
+ scoped_refptr<TrackedCallback> callback) {
Resource* new_file_ref_object =
PpapiGlobals::Get()->GetResourceTracker()->GetResource(new_file_ref);
if (!new_file_ref_object ||
@@ -144,7 +130,7 @@ int32_t FileRef::Rename(PP_Resource new_file_ref,
GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Rename(
API_ID_PPB_FILE_REF, host_resource(),
- new_file_ref_object->host_resource(), callback_id));
+ new_file_ref_object->host_resource(), SendCallback(callback)));
return PP_OK_COMPLETIONPENDING;
}
@@ -170,15 +156,12 @@ void FileRef::ExecuteCallback(int callback_id, int32_t result) {
callback->Run(result);
}
-int FileRef::SendCallback(PP_CompletionCallback callback) {
- if (!callback.func)
- return 0;
-
+int FileRef::SendCallback(scoped_refptr<TrackedCallback> callback) {
// In extreme cases the IDs may wrap around, so avoid duplicates.
- while (pending_callbacks_.find(next_callback_id_) != pending_callbacks_.end())
- next_callback_id_++;
+ while (pending_callbacks_.count(next_callback_id_))
+ ++next_callback_id_;
- pending_callbacks_[next_callback_id_] = new TrackedCallback(this, callback);
+ pending_callbacks_[next_callback_id_] = callback;
return next_callback_id_++;
}
diff --git a/ppapi/proxy/ppb_file_system_proxy.cc b/ppapi/proxy/ppb_file_system_proxy.cc
index 370dcab..4619a1f 100644
--- a/ppapi/proxy/ppb_file_system_proxy.cc
+++ b/ppapi/proxy/ppb_file_system_proxy.cc
@@ -46,7 +46,7 @@ class FileSystem : public Resource, public PPB_FileSystem_API {
// PPB_FileSystem_APi implementation.
virtual int32_t Open(int64_t expected_size,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual PP_FileSystemType GetType() OVERRIDE;
// Called when the host has responded to our open request.
@@ -75,13 +75,13 @@ PPB_FileSystem_API* FileSystem::AsPPB_FileSystem_API() {
}
int32_t FileSystem::Open(int64_t expected_size,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
if (TrackedCallback::IsPending(current_open_callback_))
return PP_ERROR_INPROGRESS;
if (called_open_)
return PP_ERROR_FAILED;
- current_open_callback_ = new TrackedCallback(this, callback);
+ current_open_callback_ = callback;
called_open_ = true;
PluginDispatcher::GetForResource(this)->Send(
new PpapiHostMsg_PPBFileSystem_Open(
diff --git a/ppapi/proxy/ppb_flash_menu_proxy.cc b/ppapi/proxy/ppb_flash_menu_proxy.cc
index 276aaf8..1c919a6 100644
--- a/ppapi/proxy/ppb_flash_menu_proxy.cc
+++ b/ppapi/proxy/ppb_flash_menu_proxy.cc
@@ -30,7 +30,7 @@ class FlashMenu : public PPB_Flash_Menu_API, public Resource {
// PPB_Flash_Menu_API implementation.
virtual int32_t Show(const PP_Point* location,
int32_t* selected_id,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
void ShowACK(int32_t selected_id, int32_t result);
@@ -55,12 +55,12 @@ PPB_Flash_Menu_API* FlashMenu::AsPPB_Flash_Menu_API() {
int32_t FlashMenu::Show(const struct PP_Point* location,
int32_t* selected_id,
- struct PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
if (TrackedCallback::IsPending(callback_))
return PP_ERROR_INPROGRESS;
selected_id_ptr_ = selected_id;
- callback_ = new TrackedCallback(this, callback);
+ callback_ = callback;
PluginDispatcher::GetForResource(this)->Send(
new PpapiHostMsg_PPBFlashMenu_Show(
diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.cc b/ppapi/proxy/ppb_graphics_2d_proxy.cc
index 0cbd388..2fc34cc 100644
--- a/ppapi/proxy/ppb_graphics_2d_proxy.cc
+++ b/ppapi/proxy/ppb_graphics_2d_proxy.cc
@@ -43,7 +43,7 @@ class Graphics2D : public Resource, public thunk::PPB_Graphics2D_API {
void Scroll(const PP_Rect* clip_rect,
const PP_Point* amount);
void ReplaceContents(PP_Resource image_data);
- int32_t Flush(PP_CompletionCallback callback);
+ int32_t Flush(scoped_refptr<TrackedCallback> callback);
// Notification that the host has sent an ACK for a pending Flush.
void FlushACK(int32_t result_code);
@@ -126,15 +126,10 @@ void Graphics2D::ReplaceContents(PP_Resource image_data) {
kApiID, host_resource(), image_object->host_resource()));
}
-int32_t Graphics2D::Flush(PP_CompletionCallback callback) {
- // For now, disallow blocking calls. We'll need to add support for other
- // threads to this later.
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
-
+int32_t Graphics2D::Flush(scoped_refptr<TrackedCallback> callback) {
if (TrackedCallback::IsPending(current_flush_callback_))
return PP_ERROR_INPROGRESS; // Can't have >1 flush pending.
- current_flush_callback_ = new TrackedCallback(this, callback);
+ current_flush_callback_ = callback;
GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Flush(kApiID,
host_resource()));
diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc
index 4cbb5ca..c68b286 100644
--- a/ppapi/proxy/ppb_instance_proxy.cc
+++ b/ppapi/proxy/ppb_instance_proxy.cc
@@ -437,16 +437,13 @@ PP_Bool PPB_Instance_Proxy::SetCursor(PP_Instance instance,
}
int32_t PPB_Instance_Proxy::LockMouse(PP_Instance instance,
- PP_CompletionCallback callback) {
- if (!callback.func)
- return PP_ERROR_BADARGUMENT;
-
+ scoped_refptr<TrackedCallback> callback) {
// Save the mouse callback on the instance data.
InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())->
GetInstanceData(instance);
if (!data)
return PP_ERROR_BADARGUMENT;
- if (data->mouse_lock_callback.func)
+ if (TrackedCallback::IsPending(data->mouse_lock_callback))
return PP_ERROR_INPROGRESS; // Already have a pending callback.
data->mouse_lock_callback = callback;
@@ -654,7 +651,7 @@ void PPB_Instance_Proxy::OnHostMsgLockMouse(PP_Instance instance) {
return;
}
int32_t result = enter.functions()->LockMouse(instance,
- cb.pp_completion_callback());
+ enter.callback());
if (result != PP_OK_COMPLETIONPENDING)
cb.Run(result);
}
@@ -720,8 +717,9 @@ void PPB_Instance_Proxy::OnHostMsgDocumentCanAccessDocument(PP_Instance active,
*result = enter.functions()->DocumentCanAccessDocument(active, target);
}
-void PPB_Instance_Proxy::OnHostMsgGetDocumentURL(PP_Instance instance,
- SerializedVarReturnValue result) {
+void PPB_Instance_Proxy::OnHostMsgGetDocumentURL(
+ PP_Instance instance,
+ SerializedVarReturnValue result) {
EnterInstanceNoLock enter(instance);
if (enter.succeeded()) {
result.Return(dispatcher(),
@@ -794,11 +792,11 @@ void PPB_Instance_Proxy::OnPluginMsgMouseLockComplete(PP_Instance instance,
GetInstanceData(instance);
if (!data)
return; // Instance was probably deleted.
- if (!data->mouse_lock_callback.func) {
+ if (TrackedCallback::IsPending(data->mouse_lock_callback)) {
NOTREACHED();
return;
}
- PP_RunAndClearCompletionCallback(&data->mouse_lock_callback, result);
+ TrackedCallback::ClearAndRun(&(data->mouse_lock_callback), result);
}
void PPB_Instance_Proxy::MouseLockCompleteInHost(int32_t result,
diff --git a/ppapi/proxy/ppb_instance_proxy.h b/ppapi/proxy/ppb_instance_proxy.h
index 7a84ec8..20dd60d 100644
--- a/ppapi/proxy/ppb_instance_proxy.h
+++ b/ppapi/proxy/ppb_instance_proxy.h
@@ -85,7 +85,7 @@ class PPB_Instance_Proxy : public InterfaceProxy,
PP_Resource image,
const PP_Point* hot_spot) OVERRIDE;
virtual int32_t LockMouse(PP_Instance instance,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual void UnlockMouse(PP_Instance instance) OVERRIDE;
virtual PP_Bool GetDefaultPrintSettings(
PP_Instance instance,
diff --git a/ppapi/proxy/ppb_message_loop_proxy.cc b/ppapi/proxy/ppb_message_loop_proxy.cc
index 7a64b50..bcbb82a 100644
--- a/ppapi/proxy/ppb_message_loop_proxy.cc
+++ b/ppapi/proxy/ppb_message_loop_proxy.cc
@@ -13,6 +13,7 @@
#include "ppapi/c/pp_errors.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_globals.h"
+#include "ppapi/shared_impl/proxy_lock.h"
#include "ppapi/shared_impl/resource.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_message_loop_api.h"
@@ -140,10 +141,9 @@ int32_t MessageLoopResource::Run() {
// PP_ERROR_BLOCKS_MAIN_THREAD. Maybe have a special constructor for that
// one?
- // TODO(brettw) figure out how to release the lock. Can't run the message
- // loop while holding the lock.
nested_invocations_++;
- loop_->Run();
+ CallWhileUnlocked(base::Bind(&MessageLoop::Run,
+ base::Unretained(loop_.get())));
nested_invocations_--;
if (should_destroy_ && nested_invocations_ == 0) {
diff --git a/ppapi/proxy/ppb_network_monitor_private_proxy.cc b/ppapi/proxy/ppb_network_monitor_private_proxy.cc
index 865dc87..0d17cd4 100644
--- a/ppapi/proxy/ppb_network_monitor_private_proxy.cc
+++ b/ppapi/proxy/ppb_network_monitor_private_proxy.cc
@@ -7,6 +7,7 @@
#include "ppapi/proxy/enter_proxy.h"
#include "ppapi/proxy/plugin_proxy_delegate.h"
#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/shared_impl/proxy_lock.h"
#include "ppapi/thunk/ppb_network_monitor_private_api.h"
namespace ppapi {
@@ -39,7 +40,13 @@ class PPB_NetworkMonitor_Private_Proxy::NetworkMonitor
return this;
}
- void OnNetworkListReceived(const scoped_refptr<NetworkListStorage>& list) {
+ // This is invoked when a network list is received for this monitor (either
+ // initially or on a change). It acquires the ProxyLock inside because
+ // ObserverListThreadSafe does not support Bind/Closure, otherwise we would
+ // wrap the call with a lock using RunWhileLocked.
+ void OnNetworkListReceivedLocks(
+ const scoped_refptr<NetworkListStorage>& list) {
+ ProxyAutoLock lock;
PP_Resource list_resource =
PPB_NetworkList_Private_Shared::Create(
OBJECT_IS_PROXY, pp_instance(), list);
@@ -70,6 +77,8 @@ PP_Resource PPB_NetworkMonitor_Private_Proxy::CreateProxyResource(
PP_Instance instance,
PPB_NetworkMonitor_Callback callback,
void* user_data) {
+ // TODO(dmichael): Check that this thread has a valid message loop associated
+ // with it.
if (!callback)
return 0;
@@ -98,9 +107,9 @@ PP_Resource PPB_NetworkMonitor_Private_Proxy::CreateProxyResource(
// here.
proxy->current_list_ = NULL;
} else if (proxy->current_list_.get()) {
- MessageLoop::current()->PostTask(FROM_HERE, RunWhileLocked(base::Bind(
- &NetworkMonitor::OnNetworkListReceived,
- result->AsWeakPtr(), proxy->current_list_)));
+ MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
+ &NetworkMonitor::OnNetworkListReceivedLocks,
+ result->AsWeakPtr(), proxy->current_list_));
}
return result->GetReference();
@@ -122,7 +131,7 @@ void PPB_NetworkMonitor_Private_Proxy::OnPluginMsgNetworkList(
const ppapi::NetworkList& list) {
scoped_refptr<NetworkListStorage> list_storage(new NetworkListStorage(list));
current_list_ = list_storage;
- monitors_->Notify(&NetworkMonitor::OnNetworkListReceived, list_storage);
+ monitors_->Notify(&NetworkMonitor::OnNetworkListReceivedLocks, list_storage);
}
void PPB_NetworkMonitor_Private_Proxy::OnNetworkMonitorDeleted(
diff --git a/ppapi/proxy/ppb_network_monitor_private_proxy.h b/ppapi/proxy/ppb_network_monitor_private_proxy.h
index 3c420d8..e764b0c 100644
--- a/ppapi/proxy/ppb_network_monitor_private_proxy.h
+++ b/ppapi/proxy/ppb_network_monitor_private_proxy.h
@@ -47,6 +47,8 @@ class PPB_NetworkMonitor_Private_Proxy : public InterfaceProxy {
void OnNetworkMonitorDeleted(NetworkMonitor* monitor,
PP_Instance instance);
+ // We use ObserverListThreadSafe because we want to send notifications to the
+ // same thread that created the NetworkMonitor.
scoped_refptr<ObserverListThreadSafe<NetworkMonitor> > monitors_;
int monitors_count_;
diff --git a/ppapi/proxy/ppb_talk_private_proxy.cc b/ppapi/proxy/ppb_talk_private_proxy.cc
index 3b301f0..6297fa3 100644
--- a/ppapi/proxy/ppb_talk_private_proxy.cc
+++ b/ppapi/proxy/ppb_talk_private_proxy.cc
@@ -29,7 +29,7 @@ class Talk : public Resource, public thunk::PPB_Talk_Private_API {
thunk::PPB_Talk_Private_API* AsPPB_Talk_Private_API() { return this; }
// PPB_Talk_API implementation.
- int32_t GetPermission(const PP_CompletionCallback& callback) {
+ int32_t GetPermission(scoped_refptr<TrackedCallback> callback) {
if (TrackedCallback::IsPending(callback_))
return PP_ERROR_INPROGRESS;
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
@@ -37,7 +37,7 @@ class Talk : public Resource, public thunk::PPB_Talk_Private_API {
if (!dispatcher)
return PP_ERROR_FAILED;
- callback_ = new TrackedCallback(this, callback);
+ callback_ = callback;
if (PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser(
new PpapiHostMsg_PPBTalk_GetPermission(
diff --git a/ppapi/proxy/ppb_tcp_server_socket_private_proxy.cc b/ppapi/proxy/ppb_tcp_server_socket_private_proxy.cc
index ed5d5ad..5e6557b 100644
--- a/ppapi/proxy/ppb_tcp_server_socket_private_proxy.cc
+++ b/ppapi/proxy/ppb_tcp_server_socket_private_proxy.cc
@@ -22,9 +22,6 @@
namespace ppapi {
namespace proxy {
-typedef thunk::EnterResource<thunk::PPB_TCPServerSocket_Private_API>
- EnterTCPServerSocket;
-
namespace {
class TCPServerSocket : public PPB_TCPServerSocket_Shared {
@@ -164,7 +161,8 @@ void PPB_TCPServerSocket_Private_Proxy::OnMsgListenACK(
PP_Resource socket_resource,
uint32 socket_id,
int32_t status) {
- EnterTCPServerSocket enter(socket_resource, true);
+ thunk::EnterResourceNoLock<thunk::PPB_TCPServerSocket_Private_API>
+ enter(socket_resource, true);
if (enter.succeeded()) {
PPB_TCPServerSocket_Shared* server_socket =
static_cast<PPB_TCPServerSocket_Shared*>(enter.object());
diff --git a/ppapi/proxy/ppb_url_loader_proxy.cc b/ppapi/proxy/ppb_url_loader_proxy.cc
index 1eefe0c..bdeff84 100644
--- a/ppapi/proxy/ppb_url_loader_proxy.cc
+++ b/ppapi/proxy/ppb_url_loader_proxy.cc
@@ -91,19 +91,21 @@ class URLLoader : public Resource, public PPB_URLLoader_API {
// PPB_URLLoader_API implementation.
virtual int32_t Open(PP_Resource request_id,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t FollowRedirect(PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t FollowRedirect(
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual PP_Bool GetUploadProgress(int64_t* bytes_sent,
int64_t* total_bytes_to_be_sent) OVERRIDE;
virtual PP_Bool GetDownloadProgress(
int64_t* bytes_received,
int64_t* total_bytes_to_be_received) OVERRIDE;
virtual PP_Resource GetResponseInfo() OVERRIDE;
- virtual int32_t ReadResponseBody(void* buffer,
- int32_t bytes_to_read,
- PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t ReadResponseBody(
+ void* buffer,
+ int32_t bytes_to_read,
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t FinishStreamingToFile(
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual void Close() OVERRIDE;
virtual void GrantUniversalAccess() OVERRIDE;
virtual void SetStatusCallback(
@@ -178,7 +180,7 @@ PPB_URLLoader_API* URLLoader::AsPPB_URLLoader_API() {
}
int32_t URLLoader::Open(PP_Resource request_id,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
EnterResourceNoLock<thunk::PPB_URLRequestInfo_API> enter(request_id, true);
if (enter.failed()) {
Log(PP_LOGLEVEL_ERROR, "PPB_URLLoader.Open: The URL you're requesting is "
@@ -191,22 +193,18 @@ int32_t URLLoader::Open(PP_Resource request_id,
if (TrackedCallback::IsPending(current_callback_))
return PP_ERROR_INPROGRESS;
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
- current_callback_ = new TrackedCallback(this, callback);
+ current_callback_ = callback;
GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Open(
API_ID_PPB_URL_LOADER, host_resource(), enter.object()->GetData()));
return PP_OK_COMPLETIONPENDING;
}
-int32_t URLLoader::FollowRedirect(PP_CompletionCallback callback) {
+int32_t URLLoader::FollowRedirect(scoped_refptr<TrackedCallback> callback) {
if (TrackedCallback::IsPending(current_callback_))
return PP_ERROR_INPROGRESS;
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
- current_callback_ = new TrackedCallback(this, callback);
+ current_callback_ = callback;
GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect(
API_ID_PPB_URL_LOADER, host_resource()));
@@ -257,17 +255,12 @@ PP_Resource URLLoader::GetResponseInfo() {
int32_t URLLoader::ReadResponseBody(void* buffer,
int32_t bytes_to_read,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
if (!buffer || bytes_to_read <= 0)
return PP_ERROR_BADARGUMENT; // Must specify an output buffer.
if (TrackedCallback::IsPending(current_callback_))
return PP_ERROR_INPROGRESS; // Can only have one request pending.
- // Currently we don't support sync calls to read. We'll need to revisit
- // how this works when we allow blocking calls (from background threads).
- if (!callback.func)
- return PP_ERROR_BADARGUMENT;
-
if (static_cast<size_t>(bytes_to_read) <= buffer_.size()) {
// Special case: we've buffered enough data to be able to synchronously
// return data to the caller. Do so without making IPCs.
@@ -275,7 +268,7 @@ int32_t URLLoader::ReadResponseBody(void* buffer,
return bytes_to_read;
}
- current_callback_ = new TrackedCallback(this, callback);
+ current_callback_ = callback;
current_read_buffer_ = buffer;
current_read_buffer_size_ = bytes_to_read;
@@ -284,13 +277,12 @@ int32_t URLLoader::ReadResponseBody(void* buffer,
return PP_OK_COMPLETIONPENDING;
}
-int32_t URLLoader::FinishStreamingToFile(PP_CompletionCallback callback) {
+int32_t URLLoader::FinishStreamingToFile(
+ scoped_refptr<TrackedCallback> callback) {
if (TrackedCallback::IsPending(current_callback_))
return PP_ERROR_INPROGRESS;
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
- current_callback_ = new TrackedCallback(this, callback);
+ current_callback_ = callback;
GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FinishStreamingToFile(
API_ID_PPB_URL_LOADER, host_resource()));
diff --git a/ppapi/proxy/ppb_video_capture_proxy.cc b/ppapi/proxy/ppb_video_capture_proxy.cc
index 6a51299..badd40d 100644
--- a/ppapi/proxy/ppb_video_capture_proxy.cc
+++ b/ppapi/proxy/ppb_video_capture_proxy.cc
@@ -164,12 +164,12 @@ class VideoCapture : public PPB_VideoCapture_Shared {
// PPB_VideoCapture_Shared implementation.
virtual int32_t InternalEnumerateDevices(
PP_Resource* devices,
- const PP_CompletionCallback& callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t InternalOpen(
const std::string& device_id,
const PP_VideoCaptureDeviceInfo_Dev& requested_info,
uint32_t buffer_count,
- const PP_CompletionCallback& callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t InternalStartCapture() OVERRIDE;
virtual int32_t InternalReuseBuffer(uint32_t buffer) OVERRIDE;
virtual int32_t InternalStopCapture() OVERRIDE;
@@ -214,9 +214,10 @@ bool VideoCapture::OnStatus(PP_VideoCaptureStatus_Dev status) {
}
int32_t VideoCapture::InternalEnumerateDevices(
- PP_Resource* devices, const PP_CompletionCallback& callback) {
+ PP_Resource* devices,
+ scoped_refptr<TrackedCallback> callback) {
devices_ = devices;
- enumerate_devices_callback_ = new TrackedCallback(this, callback);
+ enumerate_devices_callback_ = callback;
GetDispatcher()->Send(new PpapiHostMsg_PPBVideoCapture_EnumerateDevices(
API_ID_PPB_VIDEO_CAPTURE_DEV, host_resource()));
return PP_OK_COMPLETIONPENDING;
@@ -226,12 +227,8 @@ int32_t VideoCapture::InternalOpen(
const std::string& device_id,
const PP_VideoCaptureDeviceInfo_Dev& requested_info,
uint32_t buffer_count,
- const PP_CompletionCallback& callback) {
- // Disallow blocking call. The base class doesn't check this.
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
-
- open_callback_ = new TrackedCallback(this, callback);
+ scoped_refptr<TrackedCallback> callback) {
+ open_callback_ = callback;
GetDispatcher()->Send(new PpapiHostMsg_PPBVideoCapture_Open(
API_ID_PPB_VIDEO_CAPTURE_DEV, host_resource(), device_id, requested_info,
buffer_count));
diff --git a/ppapi/proxy/ppb_video_decoder_proxy.cc b/ppapi/proxy/ppb_video_decoder_proxy.cc
index 3f5cdc4..2965fea 100644
--- a/ppapi/proxy/ppb_video_decoder_proxy.cc
+++ b/ppapi/proxy/ppb_video_decoder_proxy.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.
@@ -35,12 +35,12 @@ class VideoDecoder : public PPB_VideoDecoder_Shared {
// PPB_VideoDecoder_API implementation.
virtual int32_t Decode(const PP_VideoBitstreamBuffer_Dev* bitstream_buffer,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual void AssignPictureBuffers(
uint32_t no_of_buffers, const PP_PictureBuffer_Dev* buffers) OVERRIDE;
virtual void ReusePictureBuffer(int32_t picture_buffer_id) OVERRIDE;
- virtual int32_t Flush(PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t Reset(PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t Flush(scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t Reset(scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual void Destroy() OVERRIDE;
private:
@@ -65,7 +65,7 @@ VideoDecoder::~VideoDecoder() {
int32_t VideoDecoder::Decode(
const PP_VideoBitstreamBuffer_Dev* bitstream_buffer,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
EnterResourceNoLock<PPB_Buffer_API>
enter_buffer(bitstream_buffer->data, true);
if (enter_buffer.failed())
@@ -102,7 +102,7 @@ void VideoDecoder::ReusePictureBuffer(int32_t picture_buffer_id) {
API_ID_PPB_VIDEO_DECODER_DEV, host_resource(), picture_buffer_id));
}
-int32_t VideoDecoder::Flush(PP_CompletionCallback callback) {
+int32_t VideoDecoder::Flush(scoped_refptr<TrackedCallback> callback) {
if (!SetFlushCallback(callback))
return PP_ERROR_INPROGRESS;
@@ -112,7 +112,7 @@ int32_t VideoDecoder::Flush(PP_CompletionCallback callback) {
return PP_OK_COMPLETIONPENDING;
}
-int32_t VideoDecoder::Reset(PP_CompletionCallback callback) {
+int32_t VideoDecoder::Reset(scoped_refptr<TrackedCallback> callback) {
if (!SetResetCallback(callback))
return PP_ERROR_INPROGRESS;
diff --git a/ppapi/proxy/proxy_array_output.h b/ppapi/proxy/proxy_array_output.h
index d717909..6d15e0b 100644
--- a/ppapi/proxy/proxy_array_output.h
+++ b/ppapi/proxy/proxy_array_output.h
@@ -30,7 +30,7 @@
//
// callback = factory.NewOptionalCallback(&OnCallbackComplete, output);
// DoSomethingAsynchronously(output->pp_array_output(),
-// callback.PP_CompletionCallback());
+// callback.pp_completion_callback());
// ...
namespace ppapi {
namespace proxy {
diff --git a/ppapi/shared_impl/ppapi_globals.cc b/ppapi/shared_impl/ppapi_globals.cc
index c453ae2..80a4ee2 100644
--- a/ppapi/shared_impl/ppapi_globals.cc
+++ b/ppapi/shared_impl/ppapi_globals.cc
@@ -6,6 +6,7 @@
#include "base/lazy_instance.h" // For testing purposes only.
#include "base/logging.h"
+#include "base/message_loop_proxy.h"
#include "base/threading/thread_local.h" // For testing purposes only.
namespace ppapi {
@@ -41,6 +42,12 @@ void PpapiGlobals::SetPpapiGlobalsOnThreadForTest(PpapiGlobals* ptr) {
tls_ppapi_globals_for_test.Pointer()->Set(ptr);
}
+base::MessageLoopProxy* PpapiGlobals::GetMainThreadMessageLoop() {
+ CR_DEFINE_STATIC_LOCAL(scoped_refptr<base::MessageLoopProxy>, proxy,
+ (base::MessageLoopProxy::current()));
+ return proxy.get();
+}
+
bool PpapiGlobals::IsHostGlobals() const {
return false;
}
diff --git a/ppapi/shared_impl/ppapi_globals.h b/ppapi/shared_impl/ppapi_globals.h
index 8e2b94a..00fb9b1 100644
--- a/ppapi/shared_impl/ppapi_globals.h
+++ b/ppapi/shared_impl/ppapi_globals.h
@@ -17,6 +17,7 @@
namespace base {
class Lock;
+class MessageLoopProxy;
}
namespace ppapi {
@@ -101,6 +102,11 @@ class PPAPI_SHARED_EXPORT PpapiGlobals {
// failure.
virtual PP_Module GetModuleForInstance(PP_Instance instance) = 0;
+ // Returns the base::MessageLoopProxy for the main thread. Note that this must
+ // be called on the main thread the first time so that it can initialize
+ // its static data.
+ base::MessageLoopProxy* GetMainThreadMessageLoop();
+
// Returns the command line for the process.
virtual std::string GetCmdLine() = 0;
diff --git a/ppapi/shared_impl/ppb_audio_config_shared.cc b/ppapi/shared_impl/ppb_audio_config_shared.cc
index 6803c3c..1252de7 100644
--- a/ppapi/shared_impl/ppb_audio_config_shared.cc
+++ b/ppapi/shared_impl/ppb_audio_config_shared.cc
@@ -50,7 +50,7 @@ uint32_t PPB_AudioConfig_Shared::RecommendSampleFrameCount_1_1(
uint32_t sample_frame_count) {
// Version 1.1: Query the back-end hardware for sample rate and buffer size,
// and recommend a best fit based on request.
- thunk::EnterInstance enter(instance);
+ thunk::EnterInstanceNoLock enter(instance);
if (enter.failed())
return 0;
@@ -92,7 +92,7 @@ uint32_t PPB_AudioConfig_Shared::RecommendSampleFrameCount_1_1(
// static
PP_AudioSampleRate PPB_AudioConfig_Shared::RecommendSampleRate(
PP_Instance instance) {
- thunk::EnterInstance enter(instance);
+ thunk::EnterInstanceNoLock enter(instance);
if (enter.failed())
return PP_AUDIOSAMPLERATE_NONE;
PP_AudioSampleRate hardware_sample_rate = static_cast<PP_AudioSampleRate>(
diff --git a/ppapi/shared_impl/ppb_audio_input_shared.cc b/ppapi/shared_impl/ppb_audio_input_shared.cc
index ea2e685..4ea3e71 100644
--- a/ppapi/shared_impl/ppb_audio_input_shared.cc
+++ b/ppapi/shared_impl/ppb_audio_input_shared.cc
@@ -55,9 +55,7 @@ thunk::PPB_AudioInput_API* PPB_AudioInput_Shared::AsPPB_AudioInput_API() {
int32_t PPB_AudioInput_Shared::EnumerateDevices(
PP_Resource* devices,
- const PP_CompletionCallback& callback) {
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
+ scoped_refptr<TrackedCallback> callback) {
if (TrackedCallback::IsPending(enumerate_devices_callback_))
return PP_ERROR_INPROGRESS;
@@ -69,7 +67,7 @@ int32_t PPB_AudioInput_Shared::Open(
PP_Resource config,
PPB_AudioInput_Callback audio_input_callback,
void* user_data,
- const PP_CompletionCallback& callback) {
+ scoped_refptr<TrackedCallback> callback) {
if (!audio_input_callback)
return PP_ERROR_BADARGUMENT;
@@ -166,8 +164,11 @@ void PPB_AudioInput_Shared::OnOpenComplete(
}
// static
-PP_CompletionCallback PPB_AudioInput_Shared::MakeIgnoredCompletionCallback() {
- return PP_MakeCompletionCallback(&IgnoredCompletionCallback, NULL);
+scoped_refptr<TrackedCallback>
+PPB_AudioInput_Shared::MakeIgnoredCompletionCallback(
+ Resource* resource) {
+ return new TrackedCallback(resource,
+ PP_MakeCompletionCallback(&IgnoredCompletionCallback, NULL));
}
void PPB_AudioInput_Shared::SetStartCaptureState() {
@@ -254,7 +255,7 @@ int32_t PPB_AudioInput_Shared::CommonOpen(
PP_Resource config,
PPB_AudioInput_Callback audio_input_callback,
void* user_data,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
if (open_state_ != BEFORE_OPEN)
return PP_ERROR_FAILED;
@@ -263,9 +264,6 @@ int32_t PPB_AudioInput_Shared::CommonOpen(
if (enter_config.failed())
return PP_ERROR_BADARGUMENT;
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
-
if (TrackedCallback::IsPending(open_callback_))
return PP_ERROR_INPROGRESS;
diff --git a/ppapi/shared_impl/ppb_audio_input_shared.h b/ppapi/shared_impl/ppb_audio_input_shared.h
index 4da3940c..4dfdab9 100644
--- a/ppapi/shared_impl/ppb_audio_input_shared.h
+++ b/ppapi/shared_impl/ppb_audio_input_shared.h
@@ -41,12 +41,12 @@ class PPAPI_SHARED_EXPORT PPB_AudioInput_Shared
// Implementation of PPB_AudioInput_API non-trusted methods.
virtual int32_t EnumerateDevices(
PP_Resource* devices,
- const PP_CompletionCallback& callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t Open(const std::string& device_id,
PP_Resource config,
PPB_AudioInput_Callback audio_input_callback,
void* user_data,
- const PP_CompletionCallback& callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual PP_Resource GetCurrentConfig() OVERRIDE;
virtual PP_Bool StartCapture() OVERRIDE;
virtual PP_Bool StopCapture() OVERRIDE;
@@ -59,7 +59,8 @@ class PPAPI_SHARED_EXPORT PPB_AudioInput_Shared
size_t shared_memory_size,
base::SyncSocket::Handle socket_handle);
- static PP_CompletionCallback MakeIgnoredCompletionCallback();
+ static scoped_refptr<TrackedCallback> MakeIgnoredCompletionCallback(
+ Resource* resource);
protected:
enum OpenState {
@@ -70,12 +71,13 @@ class PPAPI_SHARED_EXPORT PPB_AudioInput_Shared
// Subclasses should implement these methods to do impl- and proxy-specific
// work.
- virtual int32_t InternalEnumerateDevices(PP_Resource* devices,
- PP_CompletionCallback callback) = 0;
+ virtual int32_t InternalEnumerateDevices(
+ PP_Resource* devices,
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t InternalOpen(const std::string& device_id,
PP_AudioSampleRate sample_rate,
uint32_t sample_frame_count,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual PP_Bool InternalStartCapture() = 0;
virtual PP_Bool InternalStopCapture() = 0;
virtual void InternalClose() = 0;
@@ -117,7 +119,7 @@ class PPAPI_SHARED_EXPORT PPB_AudioInput_Shared
PP_Resource config,
PPB_AudioInput_Callback audio_input_callback,
void* user_data,
- PP_CompletionCallback callback);
+ scoped_refptr<TrackedCallback> callback);
OpenState open_state_;
diff --git a/ppapi/shared_impl/ppb_file_io_shared.cc b/ppapi/shared_impl/ppb_file_io_shared.cc
index e54bd3c..b60e174 100644
--- a/ppapi/shared_impl/ppb_file_io_shared.cc
+++ b/ppapi/shared_impl/ppb_file_io_shared.cc
@@ -58,12 +58,12 @@ thunk::PPB_FileIO_API* PPB_FileIO_Shared::AsPPB_FileIO_API() {
int32_t PPB_FileIO_Shared::Open(PP_Resource file_ref,
int32_t open_flags,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, true);
if (enter.failed())
return PP_ERROR_BADRESOURCE;
- int32_t rv = CommonCallValidation(false, OPERATION_EXCLUSIVE, callback);
+ int32_t rv = CommonCallValidation(false, OPERATION_EXCLUSIVE);
if (rv != PP_OK)
return rv;
@@ -78,8 +78,8 @@ int32_t PPB_FileIO_Shared::Open(PP_Resource file_ref,
}
int32_t PPB_FileIO_Shared::Query(PP_FileInfo* info,
- PP_CompletionCallback callback) {
- int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE, callback);
+ scoped_refptr<TrackedCallback> callback) {
+ int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE);
if (rv != PP_OK)
return rv;
if (!info)
@@ -89,8 +89,8 @@ int32_t PPB_FileIO_Shared::Query(PP_FileInfo* info,
int32_t PPB_FileIO_Shared::Touch(PP_Time last_access_time,
PP_Time last_modified_time,
- PP_CompletionCallback callback) {
- int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE, callback);
+ scoped_refptr<TrackedCallback> callback) {
+ int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE);
if (rv != PP_OK)
return rv;
return TouchValidated(last_access_time, last_modified_time, callback);
@@ -99,8 +99,8 @@ int32_t PPB_FileIO_Shared::Touch(PP_Time last_access_time,
int32_t PPB_FileIO_Shared::Read(int64_t offset,
char* buffer,
int32_t bytes_to_read,
- PP_CompletionCallback callback) {
- int32_t rv = CommonCallValidation(true, OPERATION_READ, callback);
+ scoped_refptr<TrackedCallback> callback) {
+ int32_t rv = CommonCallValidation(true, OPERATION_READ);
if (rv != PP_OK)
return rv;
return ReadValidated(offset, buffer, bytes_to_read, callback);
@@ -109,23 +109,23 @@ int32_t PPB_FileIO_Shared::Read(int64_t offset,
int32_t PPB_FileIO_Shared::Write(int64_t offset,
const char* buffer,
int32_t bytes_to_write,
- PP_CompletionCallback callback) {
- int32_t rv = CommonCallValidation(true, OPERATION_WRITE, callback);
+ scoped_refptr<TrackedCallback> callback) {
+ int32_t rv = CommonCallValidation(true, OPERATION_WRITE);
if (rv != PP_OK)
return rv;
return WriteValidated(offset, buffer, bytes_to_write, callback);
}
int32_t PPB_FileIO_Shared::SetLength(int64_t length,
- PP_CompletionCallback callback) {
- int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE, callback);
+ scoped_refptr<TrackedCallback> callback) {
+ int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE);
if (rv != PP_OK)
return rv;
return SetLengthValidated(length, callback);
}
-int32_t PPB_FileIO_Shared::Flush(PP_CompletionCallback callback) {
- int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE, callback);
+int32_t PPB_FileIO_Shared::Flush(scoped_refptr<TrackedCallback> callback) {
+ int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE);
if (rv != PP_OK)
return rv;
return FlushValidated(callback);
@@ -169,14 +169,9 @@ void PPB_FileIO_Shared::ExecuteReadCallback(int32_t pp_error,
RunAndRemoveFirstPendingCallback(pp_error);
}
-int32_t PPB_FileIO_Shared::CommonCallValidation(
- bool should_be_open,
- OperationType new_op,
- PP_CompletionCallback callback) {
+int32_t PPB_FileIO_Shared::CommonCallValidation(bool should_be_open,
+ OperationType new_op) {
// Only asynchronous operation is supported.
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
-
if (should_be_open) {
if (!file_open_)
return PP_ERROR_FAILED;
@@ -193,16 +188,16 @@ int32_t PPB_FileIO_Shared::CommonCallValidation(
return PP_OK;
}
-void PPB_FileIO_Shared::RegisterCallback(OperationType op,
- PP_CompletionCallback callback,
- char* read_buffer,
- PP_FileInfo* info) {
- DCHECK(callback.func);
+void PPB_FileIO_Shared::RegisterCallback(
+ OperationType op,
+ scoped_refptr<TrackedCallback> callback,
+ char* read_buffer,
+ PP_FileInfo* info) {
DCHECK(pending_op_ == OPERATION_NONE ||
(pending_op_ != OPERATION_EXCLUSIVE && pending_op_ == op));
CallbackEntry entry;
- entry.callback = new TrackedCallback(this, callback);
+ entry.callback = callback;
entry.read_buffer = read_buffer;
entry.info = info;
callbacks_.push_back(entry);
diff --git a/ppapi/shared_impl/ppb_file_io_shared.h b/ppapi/shared_impl/ppb_file_io_shared.h
index 4470a94..a062497 100644
--- a/ppapi/shared_impl/ppb_file_io_shared.h
+++ b/ppapi/shared_impl/ppb_file_io_shared.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.
@@ -32,23 +32,23 @@ class PPAPI_SHARED_EXPORT PPB_FileIO_Shared : public Resource,
// PPB_FileIO_API implementation.
virtual int32_t Open(PP_Resource file_ref,
int32_t open_flags,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t Query(PP_FileInfo* info,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t Touch(PP_Time last_access_time,
PP_Time last_modified_time,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t Read(int64_t offset,
char* buffer,
int32_t bytes_to_read,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t Write(int64_t offset,
const char* buffer,
int32_t bytes_to_write,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t SetLength(int64_t length,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t Flush(PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t Flush(scoped_refptr<TrackedCallback> callback) OVERRIDE;
// Callback handler for different types of operations.
void ExecuteGeneralCallback(int32_t pp_error);
@@ -95,23 +95,24 @@ class PPAPI_SHARED_EXPORT PPB_FileIO_Shared : public Resource,
virtual int32_t OpenValidated(PP_Resource file_ref_resource,
thunk::PPB_FileRef_API* file_ref_api,
int32_t open_flags,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t QueryValidated(PP_FileInfo* info,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t TouchValidated(PP_Time last_access_time,
PP_Time last_modified_time,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t ReadValidated(int64_t offset,
char* buffer,
int32_t bytes_to_read,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t WriteValidated(int64_t offset,
const char* buffer,
int32_t bytes_to_write,
- PP_CompletionCallback callback) = 0;
- virtual int32_t SetLengthValidated(int64_t length,
- PP_CompletionCallback callback) = 0;
- virtual int32_t FlushValidated(PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
+ virtual int32_t SetLengthValidated(
+ int64_t length,
+ scoped_refptr<TrackedCallback> callback) = 0;
+ virtual int32_t FlushValidated(scoped_refptr<TrackedCallback> callback) = 0;
// Called for every "Validated" function.
//
@@ -121,9 +122,7 @@ class PPAPI_SHARED_EXPORT PPB_FileIO_Shared : public Resource,
//
// Returns |PP_OK| to indicate that everything is valid or |PP_ERROR_...| if
// the call should be aborted and that code returned to the plugin.
- int32_t CommonCallValidation(bool should_be_open,
- OperationType new_op,
- PP_CompletionCallback callback);
+ int32_t CommonCallValidation(bool should_be_open, OperationType new_op);
// Sets up a pending callback. This should only be called once it is certain
// that |PP_OK_COMPLETIONPENDING| will be returned.
@@ -131,7 +130,7 @@ class PPAPI_SHARED_EXPORT PPB_FileIO_Shared : public Resource,
// |read_buffer| is only used by read operations, |info| is used only by
// query operations.
void RegisterCallback(OperationType op,
- PP_CompletionCallback callback,
+ scoped_refptr<TrackedCallback> callback,
char* read_buffer,
PP_FileInfo* info);
diff --git a/ppapi/shared_impl/ppb_graphics_3d_shared.cc b/ppapi/shared_impl/ppb_graphics_3d_shared.cc
index 3a562f4..29a3339 100644
--- a/ppapi/shared_impl/ppb_graphics_3d_shared.cc
+++ b/ppapi/shared_impl/ppb_graphics_3d_shared.cc
@@ -55,19 +55,14 @@ int32_t PPB_Graphics3D_Shared::ResizeBuffers(int32_t width, int32_t height) {
return PP_OK;
}
-int32_t PPB_Graphics3D_Shared::SwapBuffers(PP_CompletionCallback callback) {
- if (!callback.func) {
- // Blocking SwapBuffers isn't supported (since we have to be on the main
- // thread).
- return PP_ERROR_BADARGUMENT;
- }
-
+int32_t PPB_Graphics3D_Shared::SwapBuffers(
+ scoped_refptr<TrackedCallback> callback) {
if (HasPendingSwap()) {
// Already a pending SwapBuffers that hasn't returned yet.
return PP_ERROR_INPROGRESS;
}
- swap_callback_ = new TrackedCallback(this, callback);
+ swap_callback_ = callback;
return DoSwapBuffers();
}
diff --git a/ppapi/shared_impl/ppb_graphics_3d_shared.h b/ppapi/shared_impl/ppb_graphics_3d_shared.h
index 3369f29..0860945 100644
--- a/ppapi/shared_impl/ppb_graphics_3d_shared.h
+++ b/ppapi/shared_impl/ppb_graphics_3d_shared.h
@@ -36,7 +36,7 @@ class PPAPI_SHARED_EXPORT PPB_Graphics3D_Shared
virtual int32_t SetAttribs(const int32_t attrib_list[]) OVERRIDE;
virtual int32_t GetError() OVERRIDE;
virtual int32_t ResizeBuffers(int32_t width, int32_t height) OVERRIDE;
- virtual int32_t SwapBuffers(PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t SwapBuffers(scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual void* MapTexSubImage2DCHROMIUM(GLenum target,
GLint level,
GLint xoffset,
diff --git a/ppapi/shared_impl/ppb_video_capture_shared.cc b/ppapi/shared_impl/ppb_video_capture_shared.cc
index 08f6bb2..962b060 100644
--- a/ppapi/shared_impl/ppb_video_capture_shared.cc
+++ b/ppapi/shared_impl/ppb_video_capture_shared.cc
@@ -37,9 +37,7 @@ thunk::PPB_VideoCapture_API* PPB_VideoCapture_Shared::AsPPB_VideoCapture_API() {
int32_t PPB_VideoCapture_Shared::EnumerateDevices(
PP_Resource* devices,
- const PP_CompletionCallback& callback) {
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
+ scoped_refptr<TrackedCallback> callback) {
if (TrackedCallback::IsPending(enumerate_devices_callback_))
return PP_ERROR_INPROGRESS;
@@ -50,7 +48,7 @@ int32_t PPB_VideoCapture_Shared::Open(
const std::string& device_id,
const PP_VideoCaptureDeviceInfo_Dev& requested_info,
uint32_t buffer_count,
- const PP_CompletionCallback& callback) {
+ scoped_refptr<TrackedCallback> callback) {
if (open_state_ != BEFORE_OPEN)
return PP_ERROR_FAILED;
diff --git a/ppapi/shared_impl/ppb_video_capture_shared.h b/ppapi/shared_impl/ppb_video_capture_shared.h
index b5c3385..80b29fe 100644
--- a/ppapi/shared_impl/ppb_video_capture_shared.h
+++ b/ppapi/shared_impl/ppb_video_capture_shared.h
@@ -29,11 +29,11 @@ class PPAPI_SHARED_EXPORT PPB_VideoCapture_Shared
// PPB_VideoCapture_API implementation.
virtual int32_t EnumerateDevices(
PP_Resource* devices,
- const PP_CompletionCallback& callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t Open(const std::string& device_id,
const PP_VideoCaptureDeviceInfo_Dev& requested_info,
uint32_t buffer_count,
- const PP_CompletionCallback& callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t StartCapture() OVERRIDE;
virtual int32_t ReuseBuffer(uint32_t buffer) OVERRIDE;
virtual int32_t StopCapture() OVERRIDE;
@@ -58,12 +58,12 @@ class PPAPI_SHARED_EXPORT PPB_VideoCapture_Shared
// work.
virtual int32_t InternalEnumerateDevices(
PP_Resource* devices,
- const PP_CompletionCallback& callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t InternalOpen(
const std::string& device_id,
const PP_VideoCaptureDeviceInfo_Dev& requested_info,
uint32_t buffer_count,
- const PP_CompletionCallback& callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t InternalStartCapture() = 0;
virtual int32_t InternalReuseBuffer(uint32_t buffer) = 0;
virtual int32_t InternalStopCapture() = 0;
diff --git a/ppapi/shared_impl/ppb_video_decoder_shared.cc b/ppapi/shared_impl/ppb_video_decoder_shared.cc
index b61567b..441b0d2 100644
--- a/ppapi/shared_impl/ppb_video_decoder_shared.cc
+++ b/ppapi/shared_impl/ppb_video_decoder_shared.cc
@@ -48,28 +48,27 @@ void PPB_VideoDecoder_Shared::Destroy() {
PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(graphics_context_);
}
-bool PPB_VideoDecoder_Shared::SetFlushCallback(PP_CompletionCallback callback) {
- CHECK(callback.func);
+bool PPB_VideoDecoder_Shared::SetFlushCallback(
+ scoped_refptr<TrackedCallback> callback) {
if (flush_callback_.get())
return false;
- flush_callback_ = new TrackedCallback(this, callback);
+ flush_callback_ = callback;
return true;
}
-bool PPB_VideoDecoder_Shared::SetResetCallback(PP_CompletionCallback callback) {
- CHECK(callback.func);
+bool PPB_VideoDecoder_Shared::SetResetCallback(
+ scoped_refptr<TrackedCallback> callback) {
if (TrackedCallback::IsPending(reset_callback_))
return false;
- reset_callback_ = new TrackedCallback(this, callback);
+ reset_callback_ = callback;
return true;
}
bool PPB_VideoDecoder_Shared::SetBitstreamBufferCallback(
int32 bitstream_buffer_id,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
return bitstream_buffer_callbacks_.insert(
- std::make_pair(bitstream_buffer_id,
- new TrackedCallback(this, callback))).second;
+ std::make_pair(bitstream_buffer_id, callback)).second;
}
void PPB_VideoDecoder_Shared::RunFlushCallback(int32 result) {
diff --git a/ppapi/shared_impl/ppb_video_decoder_shared.h b/ppapi/shared_impl/ppb_video_decoder_shared.h
index 9f1aa46..618b6d0 100644
--- a/ppapi/shared_impl/ppb_video_decoder_shared.h
+++ b/ppapi/shared_impl/ppb_video_decoder_shared.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.
@@ -40,10 +40,10 @@ class PPAPI_SHARED_EXPORT PPB_VideoDecoder_Shared
virtual void Destroy() OVERRIDE;
protected:
- bool SetFlushCallback(PP_CompletionCallback callback);
- bool SetResetCallback(PP_CompletionCallback callback);
- bool SetBitstreamBufferCallback(
- int32 bitstream_buffer_id, PP_CompletionCallback callback);
+ bool SetFlushCallback(scoped_refptr<TrackedCallback> callback);
+ bool SetResetCallback(scoped_refptr<TrackedCallback> callback);
+ bool SetBitstreamBufferCallback(int32 bitstream_buffer_id,
+ scoped_refptr<TrackedCallback> callback);
void RunFlushCallback(int32 result);
void RunResetCallback(int32 result);
diff --git a/ppapi/shared_impl/private/ppb_host_resolver_shared.cc b/ppapi/shared_impl/private/ppb_host_resolver_shared.cc
index 581055d..fb44ad2 100644
--- a/ppapi/shared_impl/private/ppb_host_resolver_shared.cc
+++ b/ppapi/shared_impl/private/ppb_host_resolver_shared.cc
@@ -53,15 +53,13 @@ int32_t PPB_HostResolver_Shared::Resolve(
const char* host,
uint16_t port,
const PP_HostResolver_Private_Hint* hint,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
if (!host)
return PP_ERROR_BADARGUMENT;
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
if (ResolveInProgress())
return PP_ERROR_INPROGRESS;
- resolve_callback_ = new TrackedCallback(this, callback);
+ resolve_callback_ = callback;
HostPortPair host_port;
host_port.host = host;
diff --git a/ppapi/shared_impl/private/ppb_host_resolver_shared.h b/ppapi/shared_impl/private/ppb_host_resolver_shared.h
index d915946..f4eb74a 100644
--- a/ppapi/shared_impl/private/ppb_host_resolver_shared.h
+++ b/ppapi/shared_impl/private/ppb_host_resolver_shared.h
@@ -50,7 +50,7 @@ class PPAPI_SHARED_EXPORT PPB_HostResolver_Shared
virtual int32_t Resolve(const char* host,
uint16_t port,
const PP_HostResolver_Private_Hint* hint,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual PP_Var GetCanonicalName() OVERRIDE;
virtual uint32_t GetSize() OVERRIDE;
virtual bool GetNetAddress(uint32_t index,
diff --git a/ppapi/shared_impl/private/ppb_tcp_server_socket_shared.cc b/ppapi/shared_impl/private/ppb_tcp_server_socket_shared.cc
index c919bf2..f057da6 100644
--- a/ppapi/shared_impl/private/ppb_tcp_server_socket_shared.cc
+++ b/ppapi/shared_impl/private/ppb_tcp_server_socket_shared.cc
@@ -34,30 +34,28 @@ PPB_TCPServerSocket_Shared::AsPPB_TCPServerSocket_Private_API() {
return this;
}
-int32_t PPB_TCPServerSocket_Shared::Listen(const PP_NetAddress_Private* addr,
- int32_t backlog,
- PP_CompletionCallback callback) {
+int32_t PPB_TCPServerSocket_Shared::Listen(
+ const PP_NetAddress_Private* addr,
+ int32_t backlog,
+ scoped_refptr<TrackedCallback> callback) {
if (!addr)
return PP_ERROR_BADARGUMENT;
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
if (state_ != BEFORE_LISTENING)
return PP_ERROR_FAILED;
if (TrackedCallback::IsPending(listen_callback_))
return PP_ERROR_INPROGRESS; // Can only have one pending request.
- listen_callback_ = new TrackedCallback(this, callback);
+ listen_callback_ = callback;
// Send the request, the browser will call us back via ListenACK
SendListen(*addr, backlog);
return PP_OK_COMPLETIONPENDING;
}
-int32_t PPB_TCPServerSocket_Shared::Accept(PP_Resource* tcp_socket,
- PP_CompletionCallback callback) {
+int32_t PPB_TCPServerSocket_Shared::Accept(
+ PP_Resource* tcp_socket,
+ scoped_refptr<TrackedCallback> callback) {
if (!tcp_socket)
return PP_ERROR_BADARGUMENT;
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
if (state_ != LISTENING)
return PP_ERROR_FAILED;
@@ -65,7 +63,7 @@ int32_t PPB_TCPServerSocket_Shared::Accept(PP_Resource* tcp_socket,
return PP_ERROR_INPROGRESS;
tcp_socket_buffer_ = tcp_socket;
- accept_callback_ = new TrackedCallback(this, callback);
+ accept_callback_ = callback;
SendAccept();
return PP_OK_COMPLETIONPENDING;
diff --git a/ppapi/shared_impl/private/ppb_tcp_server_socket_shared.h b/ppapi/shared_impl/private/ppb_tcp_server_socket_shared.h
index 6ce8044..03c22ab 100644
--- a/ppapi/shared_impl/private/ppb_tcp_server_socket_shared.h
+++ b/ppapi/shared_impl/private/ppb_tcp_server_socket_shared.h
@@ -35,9 +35,9 @@ class PPAPI_SHARED_EXPORT PPB_TCPServerSocket_Shared
// PPB_TCPServerSocket_Private_API implementation.
virtual int32_t Listen(const PP_NetAddress_Private* addr,
int32_t backlog,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t Accept(PP_Resource* tcp_socket,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual void StopListening() OVERRIDE;
void OnListenCompleted(uint32 socket_id, int32_t status);
diff --git a/ppapi/shared_impl/private/tcp_socket_private_impl.cc b/ppapi/shared_impl/private/tcp_socket_private_impl.cc
index a23066c..c4a9a17 100644
--- a/ppapi/shared_impl/private/tcp_socket_private_impl.cc
+++ b/ppapi/shared_impl/private/tcp_socket_private_impl.cc
@@ -50,17 +50,15 @@ TCPSocketPrivateImpl::AsPPB_TCPSocket_Private_API() {
int32_t TCPSocketPrivateImpl::Connect(const char* host,
uint16_t port,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
if (!host)
return PP_ERROR_BADARGUMENT;
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
if (connection_state_ != BEFORE_CONNECT)
return PP_ERROR_FAILED;
if (TrackedCallback::IsPending(connect_callback_))
return PP_ERROR_INPROGRESS; // Can only have one pending request.
- connect_callback_ = new TrackedCallback(this, callback);
+ connect_callback_ = callback;
// Send the request, the browser will call us back via ConnectACK.
SendConnect(host, port);
return PP_OK_COMPLETIONPENDING;
@@ -68,17 +66,15 @@ int32_t TCPSocketPrivateImpl::Connect(const char* host,
int32_t TCPSocketPrivateImpl::ConnectWithNetAddress(
const PP_NetAddress_Private* addr,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
if (!addr)
return PP_ERROR_BADARGUMENT;
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
if (connection_state_ != BEFORE_CONNECT)
return PP_ERROR_FAILED;
if (TrackedCallback::IsPending(connect_callback_))
return PP_ERROR_INPROGRESS; // Can only have one pending request.
- connect_callback_ = new TrackedCallback(this, callback);
+ connect_callback_ = callback;
// Send the request, the browser will call us back via ConnectACK.
SendConnectWithNetAddress(*addr);
return PP_OK_COMPLETIONPENDING;
@@ -102,13 +98,12 @@ PP_Bool TCPSocketPrivateImpl::GetRemoteAddress(
return PP_TRUE;
}
-int32_t TCPSocketPrivateImpl::SSLHandshake(const char* server_name,
- uint16_t server_port,
- PP_CompletionCallback callback) {
+int32_t TCPSocketPrivateImpl::SSLHandshake(
+ const char* server_name,
+ uint16_t server_port,
+ scoped_refptr<TrackedCallback> callback) {
if (!server_name)
return PP_ERROR_BADARGUMENT;
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
if (connection_state_ != CONNECTED)
return PP_ERROR_FAILED;
@@ -117,7 +112,7 @@ int32_t TCPSocketPrivateImpl::SSLHandshake(const char* server_name,
TrackedCallback::IsPending(write_callback_))
return PP_ERROR_INPROGRESS;
- ssl_handshake_callback_ = new TrackedCallback(this, callback);
+ ssl_handshake_callback_ = callback;
// Send the request, the browser will call us back via SSLHandshakeACK.
SendSSLHandshake(server_name, server_port, trusted_certificates_,
@@ -164,22 +159,18 @@ PP_Bool TCPSocketPrivateImpl::AddChainBuildingCertificate(
int32_t TCPSocketPrivateImpl::Read(char* buffer,
int32_t bytes_to_read,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
if (!buffer || bytes_to_read <= 0)
return PP_ERROR_BADARGUMENT;
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
if (!IsConnected())
return PP_ERROR_FAILED;
if (TrackedCallback::IsPending(read_callback_) ||
TrackedCallback::IsPending(ssl_handshake_callback_))
return PP_ERROR_INPROGRESS;
- // TODO(dmichael): use some other strategy for determining if an
- // operation is in progress
read_buffer_ = buffer;
bytes_to_read_ = std::min(bytes_to_read, kMaxReadSize);
- read_callback_ = new TrackedCallback(this, callback);
+ read_callback_ = callback;
// Send the request, the browser will call us back via ReadACK.
SendRead(bytes_to_read_);
@@ -188,11 +179,9 @@ int32_t TCPSocketPrivateImpl::Read(char* buffer,
int32_t TCPSocketPrivateImpl::Write(const char* buffer,
int32_t bytes_to_write,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
if (!buffer || bytes_to_write <= 0)
return PP_ERROR_BADARGUMENT;
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
if (!IsConnected())
return PP_ERROR_FAILED;
@@ -203,7 +192,7 @@ int32_t TCPSocketPrivateImpl::Write(const char* buffer,
if (bytes_to_write > kMaxWriteSize)
bytes_to_write = kMaxWriteSize;
- write_callback_ = new TrackedCallback(this, callback);
+ write_callback_ = callback;
// Send the request, the browser will call us back via WriteACK.
SendWrite(std::string(buffer, bytes_to_write));
diff --git a/ppapi/shared_impl/private/tcp_socket_private_impl.h b/ppapi/shared_impl/private/tcp_socket_private_impl.h
index 8038b5c..2792102 100644
--- a/ppapi/shared_impl/private/tcp_socket_private_impl.h
+++ b/ppapi/shared_impl/private/tcp_socket_private_impl.h
@@ -46,24 +46,25 @@ class PPAPI_SHARED_EXPORT TCPSocketPrivateImpl
// PPB_TCPSocket_Private_API implementation.
virtual int32_t Connect(const char* host,
uint16_t port,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t ConnectWithNetAddress(
const PP_NetAddress_Private* addr,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual PP_Bool GetLocalAddress(PP_NetAddress_Private* local_addr) OVERRIDE;
virtual PP_Bool GetRemoteAddress(PP_NetAddress_Private* remote_addr) OVERRIDE;
- virtual int32_t SSLHandshake(const char* server_name,
- uint16_t server_port,
- PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t SSLHandshake(
+ const char* server_name,
+ uint16_t server_port,
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual PP_Resource GetServerCertificate() OVERRIDE;
virtual PP_Bool AddChainBuildingCertificate(PP_Resource certificate,
PP_Bool trusted) OVERRIDE;
virtual int32_t Read(char* buffer,
int32_t bytes_to_read,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual int32_t Write(const char* buffer,
int32_t bytes_to_write,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual void Disconnect() OVERRIDE;
// Notifications on operations completion.
diff --git a/ppapi/shared_impl/private/udp_socket_private_impl.cc b/ppapi/shared_impl/private/udp_socket_private_impl.cc
index 3879b68..9b509e1 100644
--- a/ppapi/shared_impl/private/udp_socket_private_impl.cc
+++ b/ppapi/shared_impl/private/udp_socket_private_impl.cc
@@ -41,17 +41,15 @@ UDPSocketPrivateImpl::AsPPB_UDPSocket_Private_API() {
}
int32_t UDPSocketPrivateImpl::Bind(const PP_NetAddress_Private* addr,
- PP_CompletionCallback callback) {
- if (!addr || !callback.func)
+ scoped_refptr<TrackedCallback> callback) {
+ if (!addr)
return PP_ERROR_BADARGUMENT;
if (bound_ || closed_)
return PP_ERROR_FAILED;
if (TrackedCallback::IsPending(bind_callback_))
return PP_ERROR_INPROGRESS;
- // TODO(dmichael): use some other strategy for determining if an
- // operation is in progress
- bind_callback_ = new TrackedCallback(this, callback);
+ bind_callback_ = callback;
// Send the request, the browser will call us back via BindACK.
SendBind(*addr);
@@ -66,10 +64,11 @@ PP_Bool UDPSocketPrivateImpl::GetBoundAddress(PP_NetAddress_Private* addr) {
return PP_TRUE;
}
-int32_t UDPSocketPrivateImpl::RecvFrom(char* buffer,
- int32_t num_bytes,
- PP_CompletionCallback callback) {
- if (!buffer || num_bytes <= 0 || !callback.func)
+int32_t UDPSocketPrivateImpl::RecvFrom(
+ char* buffer,
+ int32_t num_bytes,
+ scoped_refptr<TrackedCallback> callback) {
+ if (!buffer || num_bytes <= 0)
return PP_ERROR_BADARGUMENT;
if (!bound_)
return PP_ERROR_FAILED;
@@ -78,7 +77,7 @@ int32_t UDPSocketPrivateImpl::RecvFrom(char* buffer,
read_buffer_ = buffer;
bytes_to_read_ = std::min(num_bytes, kMaxReadSize);
- recvfrom_callback_ = new TrackedCallback(this, callback);
+ recvfrom_callback_ = callback;
// Send the request, the browser will call us back via RecvFromACK.
SendRecvFrom(bytes_to_read_);
@@ -96,8 +95,8 @@ PP_Bool UDPSocketPrivateImpl::GetRecvFromAddress(PP_NetAddress_Private* addr) {
int32_t UDPSocketPrivateImpl::SendTo(const char* buffer,
int32_t num_bytes,
const PP_NetAddress_Private* addr,
- PP_CompletionCallback callback) {
- if (!buffer || num_bytes <= 0 || !addr || !callback.func)
+ scoped_refptr<TrackedCallback> callback) {
+ if (!buffer || num_bytes <= 0 || !addr)
return PP_ERROR_BADARGUMENT;
if (!bound_)
return PP_ERROR_FAILED;
@@ -107,7 +106,7 @@ int32_t UDPSocketPrivateImpl::SendTo(const char* buffer,
if (num_bytes > kMaxWriteSize)
num_bytes = kMaxWriteSize;
- sendto_callback_ = new TrackedCallback(this, callback);
+ sendto_callback_ = callback;
// Send the request, the browser will call us back via SendToACK.
SendSendTo(std::string(buffer, num_bytes), *addr);
diff --git a/ppapi/shared_impl/private/udp_socket_private_impl.h b/ppapi/shared_impl/private/udp_socket_private_impl.h
index bb8a80e..36d51ca 100644
--- a/ppapi/shared_impl/private/udp_socket_private_impl.h
+++ b/ppapi/shared_impl/private/udp_socket_private_impl.h
@@ -41,16 +41,16 @@ class PPAPI_SHARED_EXPORT UDPSocketPrivateImpl
// PPB_UDPSocket_Private_API implementation.
virtual int32_t Bind(const PP_NetAddress_Private* addr,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual PP_Bool GetBoundAddress(PP_NetAddress_Private* addr) OVERRIDE;
virtual int32_t RecvFrom(char* buffer,
int32_t num_bytes,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual PP_Bool GetRecvFromAddress(PP_NetAddress_Private* addr) OVERRIDE;
virtual int32_t SendTo(const char* buffer,
int32_t num_bytes,
const PP_NetAddress_Private* addr,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
virtual void Close() OVERRIDE;
// Notifications from the proxy.
diff --git a/ppapi/shared_impl/proxy_lock.cc b/ppapi/shared_impl/proxy_lock.cc
index 7ef652b..8d8d1e6 100644
--- a/ppapi/shared_impl/proxy_lock.cc
+++ b/ppapi/shared_impl/proxy_lock.cc
@@ -23,6 +23,11 @@ void ProxyLock::Release() {
lock->Release();
}
+void CallWhileUnlocked(const base::Closure& closure) {
+ ProxyAutoUnlock lock;
+ closure.Run();
+}
+
void CallWhileLocked(const base::Closure& closure) {
ProxyAutoLock lock;
closure.Run();
diff --git a/ppapi/shared_impl/proxy_lock.h b/ppapi/shared_impl/proxy_lock.h
index 20e907b..d0e20a5 100644
--- a/ppapi/shared_impl/proxy_lock.h
+++ b/ppapi/shared_impl/proxy_lock.h
@@ -126,6 +126,7 @@ ReturnType CallWhileUnlocked(ReturnType (*function)(P1, P2, P3, P4, P5),
ProxyAutoUnlock unlock;
return function(p1, p2, p3, p4, p5);
}
+void PPAPI_SHARED_EXPORT CallWhileUnlocked(const base::Closure& closure);
// CallWhileLocked locks the ProxyLock and runs the given closure immediately.
// The lock is released when CallWhileLocked returns. This function assumes the
diff --git a/ppapi/shared_impl/tracked_callback.cc b/ppapi/shared_impl/tracked_callback.cc
index f97acfd..3b9e25f 100644
--- a/ppapi/shared_impl/tracked_callback.cc
+++ b/ppapi/shared_impl/tracked_callback.cc
@@ -8,6 +8,8 @@
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/message_loop.h"
+#include "base/synchronization/lock.h"
+#include "ppapi/c/dev/ppb_message_loop_dev.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/shared_impl/callback_tracker.h"
@@ -23,14 +25,28 @@ namespace ppapi {
TrackedCallback::TrackedCallback(
Resource* resource,
const PP_CompletionCallback& callback)
- : ALLOW_THIS_IN_INITIALIZER_LIST(abort_impl_factory_(this)),
- resource_id_(resource->pp_resource()),
+ : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
+ resource_id_(resource ? resource->pp_resource() : 0),
completed_(false),
aborted_(false),
- callback_(callback) {
- tracker_ = PpapiGlobals::Get()->GetCallbackTrackerForInstance(
- resource->pp_instance()),
- tracker_->Add(make_scoped_refptr(this));
+ callback_(callback),
+ result_for_blocked_callback_(PP_OK) {
+ // We can only track this callback if the resource is valid. It can be NULL
+ // in error conditions in the Enter* classes and for callbacks associated with
+ // an instance.
+ // TODO(dmichael): Add tracking at the instance level, for callbacks that only
+ // have an instance (e.g. for MouseLock).
+ if (resource) {
+ tracker_ = PpapiGlobals::Get()->GetCallbackTrackerForInstance(
+ resource->pp_instance());
+ tracker_->Add(make_scoped_refptr(this));
+ }
+
+ base::Lock* proxy_lock = PpapiGlobals::Get()->GetProxyLock();
+ // We only need a ConditionVariable if the lock is valid (i.e., we're out-of-
+ // process) and the callback is blocking.
+ if (proxy_lock && is_blocking())
+ operation_completed_condvar_.reset(new base::ConditionVariable(proxy_lock));
}
TrackedCallback::~TrackedCallback() {
@@ -44,22 +60,25 @@ void TrackedCallback::Abort() {
}
void TrackedCallback::PostAbort() {
- if (!completed()) {
+ // It doesn't make sense to abort a callback that's not associated with a
+ // resource.
+ // TODO(dmichael): If we allow associating with an instance instead, we must
+ // allow for aborts in the case of the instance being destroyed.
+ DCHECK(resource_id_);
+
+ if (!completed() && !aborted_) {
aborted_ = true;
- // Post a task for the abort (only if necessary).
- if (!abort_impl_factory_.HasWeakPtrs()) {
- MessageLoop::current()->PostTask(
- FROM_HERE,
- RunWhileLocked(base::Bind(&TrackedCallback::Abort,
- abort_impl_factory_.GetWeakPtr())));
- }
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ RunWhileLocked(base::Bind(&TrackedCallback::Abort,
+ weak_ptr_factory_.GetWeakPtr())));
}
}
void TrackedCallback::Run(int32_t result) {
if (!completed()) {
// Cancel any pending calls.
- abort_impl_factory_.InvalidateWeakPtrs();
+ weak_ptr_factory_.InvalidateWeakPtrs();
// Copy |callback_| and look at |aborted()| now, since |MarkAsCompleted()|
// may delete us.
@@ -67,10 +86,63 @@ void TrackedCallback::Run(int32_t result) {
if (aborted())
result = PP_ERROR_ABORTED;
- // Do this before running the callback in case of reentrancy (which
- // shouldn't happen, but avoid strange failures).
- MarkAsCompleted();
- CallWhileUnlocked(PP_RunCompletionCallback, &callback, result);
+ if (is_blocking()) {
+ // If the condition variable is invalid, there are two possibilities. One,
+ // we're running in-process, in which case the call should have come in on
+ // the main thread and we should have returned PP_ERROR_BLOCKS_MAIN_THREAD
+ // well before this. Otherwise, this callback was not created as a
+ // blocking callback. Either way, there's some internal error.
+ if (!operation_completed_condvar_.get()) {
+ NOTREACHED();
+ return;
+ }
+ result_for_blocked_callback_ = result;
+ // Retain ourselves, since MarkAsCompleted will remove us from the
+ // tracker. Then MarkAsCompleted before waking up the blocked thread,
+ // which could potentially re-enter.
+ scoped_refptr<TrackedCallback> thiz(this);
+ MarkAsCompleted();
+ // Wake up the blocked thread. See BlockUntilComplete for where the thread
+ // Wait()s.
+ operation_completed_condvar_->Signal();
+ } else {
+ // Do this before running the callback in case of reentrancy (which
+ // shouldn't happen, but avoid strange failures).
+ MarkAsCompleted();
+ // TODO(dmichael): Associate a message loop with the callback; if it's not
+ // the same as the current thread's loop, then post it to the right loop.
+ CallWhileUnlocked(PP_RunCompletionCallback, &callback, result);
+ }
+ }
+}
+
+void TrackedCallback::PostRun(int32_t result) {
+ DCHECK(!completed());
+ if (!completed()) {
+ // There should be no pending calls.
+ DCHECK(!weak_ptr_factory_.HasWeakPtrs());
+ weak_ptr_factory_.InvalidateWeakPtrs();
+
+ if (resource_id_) {
+ // If it has a resource_id_, it's in the tracker, and may be aborted if
+ // the resource is destroyed.
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ RunWhileLocked(base::Bind(&TrackedCallback::Run,
+ weak_ptr_factory_.GetWeakPtr(),
+ result)));
+ } else {
+ // There is no resource_id_ associated with this callback, so it can't be
+ // aborted. We have the message loop retain the callback to make sure it
+ // gets run. This can happen when EnterBase is given an invalid resource,
+ // and in that case no resource or instance will retain this
+ // TrackedCallback.
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ RunWhileLocked(base::Bind(&TrackedCallback::Run,
+ this,
+ result)));
+ }
}
}
@@ -97,6 +169,24 @@ void TrackedCallback::ClearAndAbort(scoped_refptr<TrackedCallback>* callback) {
temp->Abort();
}
+int32_t TrackedCallback::BlockUntilComplete() {
+ // Note, we are already holding the proxy lock in all these methods, including
+ // this one (see ppapi/thunk/enter.cc for where it gets acquired).
+
+ // It doesn't make sense to wait on a non-blocking callback. Furthermore,
+ // BlockUntilComplete should never be called for in-process plugins, where
+ // blocking callbacks are not supported.
+ CHECK(operation_completed_condvar_.get());
+ if (!is_blocking() || !operation_completed_condvar_.get()) {
+ NOTREACHED();
+ return PP_ERROR_FAILED;
+ }
+
+ while (!completed())
+ operation_completed_condvar_->Wait();
+ return result_for_blocked_callback_;
+}
+
void TrackedCallback::MarkAsCompleted() {
DCHECK(!completed());
@@ -104,7 +194,9 @@ void TrackedCallback::MarkAsCompleted() {
// until we're done.
scoped_refptr<TrackedCallback> thiz = this;
completed_ = true;
- tracker_->Remove(thiz);
+ // We may not have a valid resource, in which case we're not in the tracker.
+ if (resource_id_)
+ tracker_->Remove(thiz);
tracker_ = NULL;
}
diff --git a/ppapi/shared_impl/tracked_callback.h b/ppapi/shared_impl/tracked_callback.h
index a75bded..5286b51 100644
--- a/ppapi/shared_impl/tracked_callback.h
+++ b/ppapi/shared_impl/tracked_callback.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.
@@ -10,8 +10,11 @@
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
+#include "base/synchronization/condition_variable.h"
#include "ppapi/c/pp_completion_callback.h"
+#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/shared_impl/ppapi_shared_export.h"
@@ -20,6 +23,13 @@ namespace ppapi {
class CallbackTracker;
class Resource;
+namespace thunk {
+namespace subtle {
+// For a friend declaration below.
+class EnterBase;
+}
+}
+
// |TrackedCallback| represents a tracked Pepper callback (from the browser to
// the plugin), typically still pending. Such callbacks have the standard Pepper
// callback semantics. Execution (i.e., completion) of callbacks happens through
@@ -51,9 +61,9 @@ class PPAPI_SHARED_EXPORT TrackedCallback
: public base::RefCountedThreadSafe<TrackedCallback> {
public:
// Create a tracked completion callback and register it with the tracker. The
- // resource pointer is not stored.
- TrackedCallback(Resource* resource,
- const PP_CompletionCallback& callback);
+ // resource pointer is not stored. If |resource| is NULL, this callback will
+ // not be added to the callback tracker.
+ TrackedCallback(Resource* resource, const PP_CompletionCallback& callback);
// These run the callback in an abortive manner, or post a task to do so (but
// immediately marking the callback as to be aborted).
@@ -66,6 +76,9 @@ class PPAPI_SHARED_EXPORT TrackedCallback
//
// See also ClearAndRun().
void Run(int32_t result);
+ void PostRun(int32_t result);
+
+ void BlockUntilRun();
// Returns the ID of the resource which "owns" the callback, or 0 if the
// callback is not associated with any resource.
@@ -88,7 +101,7 @@ class PPAPI_SHARED_EXPORT TrackedCallback
// Runs the given callback, clearing the given scoped_refptr before execution.
// This is useful for cases where there can be only one pending callback, and
- // the presence of the callback indicates is one is pending. Such code would
+ // the presence of the callback indicates one is pending. Such code would
// normally want to clear it before execution so the plugin can issue a new
// request.
static void ClearAndRun(scoped_refptr<TrackedCallback>* callback,
@@ -97,20 +110,43 @@ class PPAPI_SHARED_EXPORT TrackedCallback
// Same as ClearAndRun except it calls Abort().
static void ClearAndAbort(scoped_refptr<TrackedCallback>* callback);
+ protected:
+ bool is_blocking() {
+ return !callback_.func;
+ }
+ bool is_required() {
+ return (callback_.func &&
+ !(callback_.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL));
+ }
+ bool is_optional() {
+ return (callback_.func &&
+ (callback_.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL));
+ }
+
private:
- // This class is ref counted.
- friend class base::RefCountedThreadSafe<TrackedCallback>;
- virtual ~TrackedCallback();
+ // TrackedCallback and EnterBase manage dealing with how to invoke callbacks
+ // appropriately. Pepper interface implementations and proxies should not have
+ // to check the type of callback, block, or mark them complete explicitly.
+ friend class ppapi::thunk::subtle::EnterBase;
+
+ // Block until the associated operation has completed. Returns the result.
+ // This must only be called on a non-main thread on a blocking callback.
+ int32_t BlockUntilComplete();
// Mark this object as complete and remove it from the tracker. This must only
// be called once. Note that running this may result in this object being
// deleted (so keep a reference if it'll still be needed).
void MarkAsCompleted();
- // Factory used by |PostAbort()|. Note that it's safe to cancel any pending
- // posted aborts on destruction -- before it's destroyed, the "owning"
- // |CallbackTracker| must have gone through and done (synchronous) |Abort()|s.
- base::WeakPtrFactory<TrackedCallback> abort_impl_factory_;
+ // This class is ref counted.
+ friend class base::RefCountedThreadSafe<TrackedCallback>;
+ virtual ~TrackedCallback();
+
+ // Factory used by |PostAbort()| and |PostRun()|. Note that it's safe to
+ // cancel any pending posted tasks on destruction -- before it's destroyed,
+ // the "owning" |CallbackTracker| must have gone through and done
+ // (synchronous) |Abort()|s.
+ base::WeakPtrFactory<TrackedCallback> weak_ptr_factory_;
scoped_refptr<CallbackTracker> tracker_;
PP_Resource resource_id_;
@@ -118,6 +154,12 @@ class PPAPI_SHARED_EXPORT TrackedCallback
bool aborted_;
PP_CompletionCallback callback_;
+ int32_t result_for_blocked_callback_;
+ // Used for pausing/waking the blocked thread if this is a blocking completion
+ // callback. Note that in-process, there is no lock, blocking callbacks are
+ // not allowed, and therefore this pointer will be NULL.
+ scoped_ptr<base::ConditionVariable> operation_completed_condvar_;
+
DISALLOW_IMPLICIT_CONSTRUCTORS(TrackedCallback);
};
diff --git a/ppapi/tests/test_broker.cc b/ppapi/tests/test_broker.cc
index 478168b..ab27b0b 100644
--- a/ppapi/tests/test_broker.cc
+++ b/ppapi/tests/test_broker.cc
@@ -212,8 +212,8 @@ void TestBroker::RunTests(const std::string& filter) {
RUN_TEST(Create, filter);
RUN_TEST(Create, filter);
RUN_TEST(GetHandleFailure, filter);
- RUN_TEST(ConnectFailure, filter);
- RUN_TEST(ConnectAndPipe, filter);
+ RUN_TEST_FORCEASYNC_AND_NOT(ConnectFailure, filter);
+ RUN_TEST_FORCEASYNC_AND_NOT(ConnectAndPipe, filter);
}
std::string TestBroker::TestCreate() {
@@ -230,20 +230,11 @@ std::string TestBroker::TestCreate() {
// Test connection on invalid resource.
std::string TestBroker::TestConnectFailure() {
- // Callback NOT force async. Connect should fail. The callback will not be
- // posted so there's no need to wait for the callback to complete.
- TestCompletionCallback cb_1(instance_->pp_instance(), false);
- ASSERT_EQ(PP_ERROR_BADRESOURCE,
- broker_interface_->Connect(
- 0, pp::CompletionCallback(cb_1).pp_completion_callback()));
-
- // Callback force async. Connect will return PP_OK_COMPLETIONPENDING and the
- // callback will be posted. However, the callback should fail.
- TestCompletionCallback cb_2(instance_->pp_instance(), true);
- ASSERT_EQ(PP_OK_COMPLETIONPENDING,
- broker_interface_->Connect(
- 0, pp::CompletionCallback(cb_2).pp_completion_callback()));
- ASSERT_EQ(PP_ERROR_BADRESOURCE, cb_2.WaitForResult());
+ TestCompletionCallback callback(instance_->pp_instance(), callback_type());
+ callback.WaitForResult(broker_interface_->Connect(0,
+ callback.GetCallback().pp_completion_callback()));
+ CHECK_CALLBACK_BEHAVIOR(callback);
+ ASSERT_EQ(PP_ERROR_BADRESOURCE, callback.result());
PASS();
}
@@ -268,11 +259,11 @@ std::string TestBroker::TestConnectAndPipe() {
instance_->pp_instance());
ASSERT_TRUE(broker);
- TestCompletionCallback cb_3(instance_->pp_instance());
- ASSERT_EQ(PP_OK_COMPLETIONPENDING,
- broker_interface_->Connect(
- broker, pp::CompletionCallback(cb_3).pp_completion_callback()));
- ASSERT_EQ(PP_OK, cb_3.WaitForResult());
+ TestCompletionCallback callback(instance_->pp_instance(), callback_type());
+ callback.WaitForResult(broker_interface_->Connect(broker,
+ callback.GetCallback().pp_completion_callback()));
+ CHECK_CALLBACK_BEHAVIOR(callback);
+ ASSERT_EQ(PP_OK, callback.result());
int32_t handle = kInvalidHandle;
ASSERT_EQ(PP_OK, broker_interface_->GetHandle(broker, &handle));
diff --git a/ppapi/tests/test_case.cc b/ppapi/tests/test_case.cc
index 26f6d40..f6fb485 100644
--- a/ppapi/tests/test_case.cc
+++ b/ppapi/tests/test_case.cc
@@ -6,6 +6,7 @@
#include <sstream>
+#include "ppapi/tests/pp_thread.h"
#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"
@@ -107,8 +108,10 @@ bool TestCase::MatchesFilter(const std::string& test_name,
return filter.empty() || (test_name == filter);
}
-std::string TestCase::CheckResourcesAndVars() {
- std::string errors;
+std::string TestCase::CheckResourcesAndVars(std::string errors) {
+ if (!errors.empty())
+ return errors;
+
if (testing_interface_) {
// TODO(dmichael): Fix tests that leak resources and enable the following:
/*
@@ -143,4 +146,27 @@ std::string TestCase::CheckResourcesAndVars() {
return errors;
}
+// static
+void TestCase::QuitMainMessageLoop(PP_Instance instance) {
+ PP_Instance* heap_instance = new PP_Instance(instance);
+ pp::CompletionCallback callback(&DoQuitMainMessageLoop, heap_instance);
+ pp::Module::Get()->core()->CallOnMainThread(0, callback);
+}
+// static
+void TestCase::DoQuitMainMessageLoop(void* pp_instance, int32_t result) {
+ PP_Instance* instance = static_cast<PP_Instance*>(pp_instance);
+ GetTestingInterface()->QuitMessageLoop(*instance);
+ delete instance;
+}
+
+void TestCase::RunOnThreadInternal(void (*thread_func)(void*),
+ void* thread_param,
+ const PPB_Testing_Dev* testing_interface) {
+ PP_ThreadType thread;
+ PP_CreateThread(&thread, thread_func, thread_param);
+ // Run a message loop so pepper calls can be dispatched. The background
+ // thread will set result_ and make us Quit when it's done.
+ testing_interface->RunMessageLoop(instance_->pp_instance());
+ PP_JoinThread(thread);
+}
diff --git a/ppapi/tests/test_case.h b/ppapi/tests/test_case.h
index 2973084..2cf2ddf 100644
--- a/ppapi/tests/test_case.h
+++ b/ppapi/tests/test_case.h
@@ -12,9 +12,11 @@
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/dev/ppb_testing_dev.h"
+#include "ppapi/cpp/dev/message_loop_dev.h"
#include "ppapi/cpp/dev/scrollbar_dev.h"
#include "ppapi/cpp/view.h"
#include "ppapi/tests/test_utils.h"
+#include "ppapi/tests/testing_instance.h"
#if (defined __native_client__)
#include "ppapi/cpp/var.h"
@@ -78,6 +80,8 @@ class TestCase {
const PPB_Testing_Dev* testing_interface() { return testing_interface_; }
+ static void QuitMainMessageLoop(PP_Instance instance);
+
protected:
#if !(defined __native_client__)
// Overridden by each test to supply a ScriptableObject corresponding to the
@@ -104,12 +108,37 @@ class TestCase {
// Check for leaked resources and vars at the end of the test. If any exist,
// return a string with some information about the error. Otherwise, return
// an empty string.
- std::string CheckResourcesAndVars();
+ //
+ // You should pass the error string from the test so far; if it is non-empty,
+ // CheckResourcesAndVars will do nothing and return the same string.
+ std::string CheckResourcesAndVars(std::string errors);
+
+ // Run the given test method on a background thread and return the result.
+ template <class T>
+ std::string RunOnThread(std::string(T::*test_to_run)()) {
+#ifdef ENABLE_PEPPER_THREADING
+ if (!testing_interface_) {
+ return "Testing blocking callbacks requires the testing interface. In "
+ "Chrome, use the --enable-pepper-testing flag.";
+ }
+ // These tests are only valid if running out-of-process (threading is not
+ // supported in-process). Just consider it a pass.
+ if (!testing_interface_->IsOutOfProcess())
+ return std::string();
+ ThreadedTestRunner<T> runner(instance_->pp_instance(),
+ static_cast<T*>(this), test_to_run);
+ RunOnThreadInternal(&ThreadedTestRunner<T>::ThreadFunction, &runner,
+ testing_interface_);
+ return runner.result();
+#else
+ // If threading's not enabled, just treat it as success.
+ return std::string();
+#endif
+ }
// Pointer to the instance that owns us.
TestingInstance* instance_;
- protected:
// NULL unless InitTestingInterface is called.
const PPB_Testing_Dev* testing_interface_;
@@ -127,6 +156,49 @@ class TestCase {
}
private:
+ template <class T>
+ class ThreadedTestRunner {
+ public:
+ typedef std::string(T::*TestMethodType)();
+ ThreadedTestRunner(PP_Instance instance,
+ T* test_case,
+ TestMethodType test_to_run)
+ : instance_(instance),
+ test_case_(test_case),
+ test_to_run_(test_to_run) {
+ }
+ const std::string& result() { return result_; }
+ static void ThreadFunction(void* runner) {
+ static_cast<ThreadedTestRunner<T>*>(runner)->Run();
+ }
+
+ private:
+ void Run() {
+ // TODO(dmichael): Create and attach a pp::MessageLoop for this thread so
+ // nested loops work.
+ result_ = (test_case_->*test_to_run_)();
+ // Tell the main thread to quit its nested message loop, now that the test
+ // is complete.
+ TestCase::QuitMainMessageLoop(instance_);
+ }
+
+ std::string result_;
+ PP_Instance instance_;
+ T* test_case_;
+ TestMethodType test_to_run_;
+ };
+
+ // The internals for RunOnThread. This allows us to avoid including
+ // pp_thread.h in this header file, since it includes system headers like
+ // windows.h.
+ // RunOnThreadInternal launches a new thread to run |thread_func|, waits
+ // for it to complete using RunMessageLoop(), then joins.
+ void RunOnThreadInternal(void (*thread_func)(void*),
+ void* thread_param,
+ const PPB_Testing_Dev* testing_interface);
+
+ static void DoQuitMainMessageLoop(void* pp_instance, int32_t result);
+
// Passed when creating completion callbacks in some tests. This determines
// what kind of callback we use for the test.
CallbackType callback_type_;
@@ -184,12 +256,39 @@ class TestCaseFactory {
#define RUN_TEST(name, test_filter) \
if (MatchesFilter(#name, test_filter)) { \
set_callback_type(PP_OPTIONAL); \
- std::string error_message = Test##name(); \
- if (error_message.empty()) \
- error_message = CheckResourcesAndVars(); \
- instance_->LogTest(#name, error_message); \
+ instance_->LogTest(#name, CheckResourcesAndVars(Test##name())); \
+ }
+
+// Like RUN_TEST above but forces functions taking callbacks to complete
+// asynchronously on success or error.
+#define RUN_TEST_FORCEASYNC(name, test_filter) \
+ if (MatchesFilter(#name, test_filter)) { \
+ set_callback_type(PP_REQUIRED); \
+ instance_->LogTest(#name"ForceAsync", \
+ CheckResourcesAndVars(Test##name())); \
}
+#define RUN_TEST_BLOCKING(test_case, name, test_filter) \
+ if (MatchesFilter(#name, test_filter)) { \
+ set_callback_type(PP_BLOCKING); \
+ instance_->LogTest(#name"Blocking", \
+ CheckResourcesAndVars(RunOnThread(&test_case::Test##name))); \
+ }
+
+#define RUN_TEST_FORCEASYNC_AND_NOT(name, test_filter) \
+ do { \
+ RUN_TEST_FORCEASYNC(name, test_filter); \
+ RUN_TEST(name, test_filter); \
+ } while (false)
+
+// Run a test with all possible callback types.
+#define RUN_CALLBACK_TEST(test_case, name, test_filter) \
+ do { \
+ RUN_TEST_FORCEASYNC(name, test_filter); \
+ RUN_TEST(name, test_filter); \
+ RUN_TEST_BLOCKING(test_case, name, test_filter); \
+ } while (false)
+
#define RUN_TEST_WITH_REFERENCE_CHECK(name, test_filter) \
if (MatchesFilter(#name, test_filter)) { \
set_callback_type(PP_OPTIONAL); \
@@ -204,21 +303,6 @@ class TestCaseFactory {
instance_->LogTest(#name, error_message); \
}
-// Like RUN_TEST above but forces functions taking callbacks to complete
-// asynchronously on success or error.
-#define RUN_TEST_FORCEASYNC(name, test_filter) \
- if (MatchesFilter(#name"ForceAsync", test_filter)) { \
- set_callback_type(PP_REQUIRED); \
- instance_->LogTest(#name"ForceAsync", Test##name()); \
- }
-
-#define RUN_TEST_FORCEASYNC_AND_NOT(name, test_filter) \
- do { \
- RUN_TEST_FORCEASYNC(name, test_filter); \
- RUN_TEST(name, test_filter); \
- } while (false)
-
-
// Helper macros for checking values in tests, and returning a location
// description of the test fails.
#define ASSERT_TRUE(cmd) \
diff --git a/ppapi/tests/test_url_loader.cc b/ppapi/tests/test_url_loader.cc
index 15ea546..9024491 100644
--- a/ppapi/tests/test_url_loader.cc
+++ b/ppapi/tests/test_url_loader.cc
@@ -33,8 +33,9 @@ namespace {
int32_t WriteEntireBuffer(PP_Instance instance,
pp::FileIO* file_io,
int32_t offset,
- const std::string& data) {
- TestCompletionCallback callback(instance);
+ const std::string& data,
+ CallbackType callback_type) {
+ TestCompletionCallback callback(instance, callback_type);
int32_t write_offset = offset;
const char* buf = data.c_str();
int32_t size = data.size();
@@ -95,29 +96,29 @@ bool TestURLLoader::Init() {
}
void TestURLLoader::RunTests(const std::string& filter) {
- RUN_TEST_FORCEASYNC_AND_NOT(BasicGET, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(BasicPOST, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(BasicFilePOST, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(BasicFileRangePOST, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(CompoundBodyPOST, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(EmptyDataPOST, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(BinaryDataPOST, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(CustomRequestHeader, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(FailsBogusContentLength, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(StreamToFile, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(UntrustedSameOriginRestriction, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(TrustedSameOriginRestriction, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(UntrustedCrossOriginRequest, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(TrustedCrossOriginRequest, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(UntrustedJavascriptURLRestriction, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(TrustedJavascriptURLRestriction, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(UntrustedHttpRequests, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(TrustedHttpRequests, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(FollowURLRedirect, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(AuditURLRedirect, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(AbortCalls, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(UntendedLoad, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(PrefetchBufferThreshold, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, BasicGET, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, BasicPOST, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, BasicFilePOST, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, BasicFileRangePOST, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, CompoundBodyPOST, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, EmptyDataPOST, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, BinaryDataPOST, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, CustomRequestHeader, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, FailsBogusContentLength, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, StreamToFile, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, UntrustedSameOriginRestriction, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, TrustedSameOriginRestriction, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, UntrustedCrossOriginRequest, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, TrustedCrossOriginRequest, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, UntrustedJavascriptURLRestriction, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, TrustedJavascriptURLRestriction, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, UntrustedHttpRequests, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, TrustedHttpRequests, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, FollowURLRedirect, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, AuditURLRedirect, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, AbortCalls, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, UntendedLoad, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, PrefetchBufferThreshold, filter);
}
std::string TestURLLoader::ReadEntireFile(pp::FileIO* file_io,
@@ -222,7 +223,8 @@ int32_t TestURLLoader::PrepareFileForPost(
return callback.result();
}
- int32_t rv = WriteEntireBuffer(instance_->pp_instance(), &file_io, 0, data);
+ int32_t rv = WriteEntireBuffer(instance_->pp_instance(), &file_io, 0, data,
+ callback_type());
if (rv != PP_OK) {
message->assign("FileIO::Write failed.");
return rv;
@@ -787,8 +789,13 @@ std::string TestURLLoader::TestUntendedLoad() {
total_bytes_to_be_received);
if (bytes_received == total_bytes_to_be_received)
break;
- pp::Module::Get()->core()->CallOnMainThread(10, callback);
- callback.WaitForResult();
+ // TODO(dmichael): This should probably compare pp::MessageLoop::GetCurrent
+ // with GetForMainThread. We only need to yield on the main
+ // thread.
+ if (callback_type() != PP_BLOCKING) {
+ pp::Module::Get()->core()->CallOnMainThread(10, callback);
+ callback.WaitForResult();
+ }
}
// The loader should now have the data and have finished successfully.
diff --git a/ppapi/tests/test_utils.cc b/ppapi/tests/test_utils.cc
index 7405e93..cae96dc 100644
--- a/ppapi/tests/test_utils.cc
+++ b/ppapi/tests/test_utils.cc
@@ -97,6 +97,7 @@ TestCompletionCallback::TestCompletionCallback(PP_Instance instance)
// what the tests currently expect.
callback_type_(PP_OPTIONAL),
post_quit_task_(false),
+ run_count_(0), // TODO(dmichael): Remove when all tests are updated.
instance_(instance) {
}
@@ -172,10 +173,10 @@ void TestCompletionCallback::WaitForAbortResult(int32_t result) {
final_result));
return;
}
- } else if (result != PP_OK) {
+ } else if (result < PP_OK) {
errors_.assign(
- ReportError("TestCompletionCallback: Expected PP_ERROR_ABORTED or"
- "PP_OK. Ran synchronously.",
+ ReportError("TestCompletionCallback: Expected PP_ERROR_ABORTED or "
+ "non-error response. Ran synchronously.",
result));
return;
}
@@ -198,6 +199,7 @@ void TestCompletionCallback::Reset() {
result_ = PP_OK_COMPLETIONPENDING;
have_result_ = false;
post_quit_task_ = false;
+ run_count_ = 0; // TODO(dmichael): Remove when all tests are updated.
errors_.clear();
}
@@ -205,9 +207,12 @@ void TestCompletionCallback::Reset() {
void TestCompletionCallback::Handler(void* user_data, int32_t result) {
TestCompletionCallback* callback =
static_cast<TestCompletionCallback*>(user_data);
+ // If this check fails, it means that the callback was invoked twice or that
+ // the PPAPI call completed synchronously, but also ran the callback.
PP_DCHECK(!callback->have_result_);
callback->result_ = result;
callback->have_result_ = true;
+ callback->run_count_++; // TODO(dmichael): Remove when all tests are updated.
if (callback->post_quit_task_) {
callback->post_quit_task_ = false;
GetTestingInterface()->QuitMessageLoop(callback->instance_);
diff --git a/ppapi/thunk/enter.cc b/ppapi/thunk/enter.cc
index a511711..dcfe2aa 100644
--- a/ppapi/thunk/enter.cc
+++ b/ppapi/thunk/enter.cc
@@ -8,84 +8,151 @@
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/stringprintf.h"
+#include "base/synchronization/lock.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/shared_impl/ppapi_globals.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/ppb_instance_api.h"
#include "ppapi/thunk/resource_creation_api.h"
namespace ppapi {
+namespace {
+
+bool IsMainThread() {
+ return
+ PpapiGlobals::Get()->GetMainThreadMessageLoop()->BelongsToCurrentThread();
+}
+
+} // namespace
+
namespace thunk {
namespace subtle {
-bool CallbackIsRequired(const PP_CompletionCallback& callback) {
- return callback.func != NULL &&
- (callback.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL) == 0;
+void AssertLockHeld() {
+ base::Lock* proxy_lock = PpapiGlobals::Get()->GetProxyLock();
+ // The lock is only valid in the plugin side of the proxy, so it only makes
+ // sense to assert there. Otherwise, silently succeed.
+ if (proxy_lock)
+ proxy_lock->AssertAcquired();
}
EnterBase::EnterBase()
- : callback_(PP_BlockUntilComplete()),
+ : resource_(NULL),
+ retval_(PP_OK) {
+ // TODO(dmichael) validate that threads have an associated message loop.
+}
+
+EnterBase::EnterBase(PP_Resource resource)
+ : resource_(GetResource(resource)),
retval_(PP_OK) {
- // TODO(brettw) validate threads.
+ // TODO(dmichael) validate that threads have an associated message loop.
}
-EnterBase::EnterBase(const PP_CompletionCallback& callback)
- : callback_(CallbackIsRequired(callback) ? callback
- : PP_BlockUntilComplete()),
+EnterBase::EnterBase(PP_Resource resource,
+ const PP_CompletionCallback& callback)
+ : resource_(GetResource(resource)),
retval_(PP_OK) {
- // TODO(brettw) validate threads.
+ callback_ = new TrackedCallback(resource_, callback);
+
+ // TODO(dmichael) validate that threads have an associated message loop.
}
EnterBase::~EnterBase() {
- if (callback_.func) {
- // All async completions should have cleared the callback in SetResult().
- DCHECK(retval_ != PP_OK_COMPLETIONPENDING && retval_ != PP_OK);
- MessageLoop::current()->PostTask(FROM_HERE, RunWhileLocked(base::Bind(
- callback_.func, callback_.user_data, retval_)));
- }
+ // callback_ is cleared any time it is run, scheduled to be run, or once we
+ // know it will be completed asynchronously. So by this point it should be
+ // NULL.
+ DCHECK(!callback_);
}
int32_t EnterBase::SetResult(int32_t result) {
- if (!callback_.func || result == PP_OK_COMPLETIONPENDING) {
- // Easy case, we don't need to issue the callback (either none is
- // required, or the implementation will asynchronously issue it
- // for us), just store the result.
- callback_ = PP_BlockUntilComplete();
+ if (!callback_) {
+ // It doesn't make sense to call SetResult if there is no callback.
+ NOTREACHED();
retval_ = result;
- return retval_;
+ return result;
}
-
- // This is a required callback, asynchronously issue it.
- // TODO(brettw) make this work on different threads, etc.
- MessageLoop::current()->PostTask(FROM_HERE, RunWhileLocked(base::Bind(
- callback_.func, callback_.user_data, result)));
-
- // Now that the callback will be issued in the future, we should return
- // "pending" to the caller, and not issue the callback again.
- callback_ = PP_BlockUntilComplete();
- retval_ = PP_OK_COMPLETIONPENDING;
+ if (result == PP_OK_COMPLETIONPENDING) {
+ retval_ = result;
+ if (callback_->is_blocking()) {
+ DCHECK(!IsMainThread()); // We should have returned an error before this.
+ retval_ = callback_->BlockUntilComplete();
+ } else {
+ // The callback is not blocking and the operation will complete
+ // asynchronously, so there's nothing to do.
+ retval_ = result;
+ }
+ } else {
+ // The function completed synchronously.
+ if (callback_->is_required()) {
+ // This is a required callback, so we must issue it asynchronously.
+ // TODO(dmichael) make this work so that a call from a background thread
+ // goes back to that thread.
+ callback_->PostRun(result);
+ retval_ = PP_OK_COMPLETIONPENDING;
+ } else {
+ // The callback is blocking or optional, so all we need to do is mark
+ // the callback as completed so that it won't be issued later.
+ callback_->MarkAsCompleted();
+ retval_ = result;
+ }
+ }
+ callback_ = NULL;
return retval_;
}
-Resource* EnterBase::GetResource(PP_Resource resource) const {
+// static
+Resource* EnterBase::GetResource(PP_Resource resource) {
return PpapiGlobals::Get()->GetResourceTracker()->GetResource(resource);
}
+void EnterBase::SetStateForCallbackError(bool report_error) {
+ if (!CallbackIsValid()) {
+ callback_->MarkAsCompleted();
+ callback_ = NULL;
+ retval_ = PP_ERROR_BLOCKS_MAIN_THREAD;
+ if (report_error) {
+ std::string message(
+ "Blocking callbacks are not allowed on the main thread.");
+ PpapiGlobals::Get()->BroadcastLogWithSource(0, PP_LOGLEVEL_ERROR,
+ std::string(), message);
+ }
+ }
+}
+
+bool EnterBase::CallbackIsValid() const {
+ // A callback is only considered invalid if it is blocking and we're on the
+ // main thread.
+ return !callback_ || !callback_->is_blocking() || !IsMainThread();
+}
+
+void EnterBase::ClearCallback() {
+ callback_ = NULL;
+}
+
void EnterBase::SetStateForResourceError(PP_Resource pp_resource,
Resource* resource_base,
void* object,
bool report_error) {
+ // Check for callback errors. If we get any, SetStateForCallbackError will
+ // emit a log message. But we also want to check for resource errors. If there
+ // are both kinds of errors, we'll emit two log messages and return
+ // PP_ERROR_BADRESOURCE.
+ SetStateForCallbackError(report_error);
+
if (object)
return; // Everything worked.
- if (callback_.func) {
- // Required callback, issue the async completion.
- MessageLoop::current()->PostTask(FROM_HERE, RunWhileLocked(base::Bind(
- callback_.func, callback_.user_data,
- static_cast<int32_t>(PP_ERROR_BADRESOURCE))));
- callback_ = PP_BlockUntilComplete();
+ if (callback_ && callback_->is_required()) {
+ // TODO(dmichael) make this work so that a call from a background thread
+ // goes back to that thread.
+ callback_->PostRun(static_cast<int32_t>(PP_ERROR_BADRESOURCE));
+ callback_ = NULL;
retval_ = PP_OK_COMPLETIONPENDING;
} else {
+ if (callback_)
+ callback_->MarkAsCompleted();
+ callback_ = NULL;
retval_ = PP_ERROR_BADRESOURCE;
}
@@ -111,17 +178,23 @@ void EnterBase::SetStateForResourceError(PP_Resource pp_resource,
void EnterBase::SetStateForFunctionError(PP_Instance pp_instance,
void* object,
bool report_error) {
+ // Check for callback errors. If we get any, SetStateForCallbackError will
+ // emit a log message. But we also want to check for instance errors. If there
+ // are both kinds of errors, we'll emit two log messages and return
+ // PP_ERROR_BADARGUMENT.
+ SetStateForCallbackError(report_error);
+
if (object)
return; // Everything worked.
- if (callback_.func) {
- // Required callback, issue the async completion.
- MessageLoop::current()->PostTask(FROM_HERE, RunWhileLocked(base::Bind(
- callback_.func, callback_.user_data,
- static_cast<int32_t>(PP_ERROR_BADARGUMENT))));
- callback_ = PP_BlockUntilComplete();
+ if (callback_ && callback_->is_required()) {
+ callback_->PostRun(static_cast<int32_t>(PP_ERROR_BADARGUMENT));
+ callback_ = NULL;
retval_ = PP_OK_COMPLETIONPENDING;
} else {
+ if (callback_)
+ callback_->MarkAsCompleted();
+ callback_ = NULL;
retval_ = PP_ERROR_BADARGUMENT;
}
@@ -147,7 +220,10 @@ EnterInstance::EnterInstance(PP_Instance instance)
EnterInstance::EnterInstance(PP_Instance instance,
const PP_CompletionCallback& callback)
- : EnterBase(callback),
+ : EnterBase(0 /* resource */, callback),
+ // TODO(dmichael): This means that the callback_ we get is not associated
+ // even with the instance, but we should handle that for
+ // MouseLock (maybe others?).
functions_(PpapiGlobals::Get()->GetInstanceAPI(instance)) {
SetStateForFunctionError(instance, functions_, true);
}
diff --git a/ppapi/thunk/enter.h b/ppapi/thunk/enter.h
index 1693977..098a2a8 100644
--- a/ppapi/thunk/enter.h
+++ b/ppapi/thunk/enter.h
@@ -5,13 +5,18 @@
#ifndef PPAPI_THUNK_ENTER_H_
#define PPAPI_THUNK_ENTER_H_
+#include <string>
+
#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/shared_impl/api_id.h"
#include "ppapi/shared_impl/ppapi_globals.h"
#include "ppapi/shared_impl/proxy_lock.h"
#include "ppapi/shared_impl/resource.h"
#include "ppapi/shared_impl/resource_tracker.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/ppapi_thunk_export.h"
#include "ppapi/thunk/ppb_instance_api.h"
#include "ppapi/thunk/resource_creation_api.h"
@@ -38,6 +43,9 @@ namespace thunk {
namespace subtle {
+// Assert that we are holding the proxy lock.
+PPAPI_THUNK_EXPORT void AssertLockHeld();
+
// This helps us define our RAII Enter classes easily. To make an RAII class
// which locks the proxy lock on construction and unlocks on destruction,
// inherit from |LockOnEntry<true>|. For cases where you don't want to lock,
@@ -48,7 +56,17 @@ struct LockOnEntry;
template <>
struct LockOnEntry<false> {
-// TODO(dmichael) assert the lock is held.
+#if (!NDEBUG)
+ LockOnEntry() {
+ // You must already hold the lock to use Enter*NoLock.
+ AssertLockHeld();
+ }
+ ~LockOnEntry() {
+ // You must not release the lock before leaving the scope of the
+ // Enter*NoLock.
+ AssertLockHeld();
+ }
+#endif
};
template <>
@@ -65,10 +83,15 @@ struct LockOnEntry<true> {
class PPAPI_THUNK_EXPORT EnterBase {
public:
EnterBase();
- explicit EnterBase(const PP_CompletionCallback& callback);
+ explicit EnterBase(PP_Resource resource);
+ EnterBase(PP_Resource resource, const PP_CompletionCallback& callback);
virtual ~EnterBase();
- // Sets the result.
+ // Sets the result for calls that use a completion callback. It handles making
+ // sure that "Required" callbacks are scheduled to run asynchronously and
+ // "Blocking" callbacks cause the caller to block. (Interface implementations,
+ // therefore, should not do any special casing based on the type of the
+ // callback.)
//
// Returns the "retval()". This is to support the typical usage of
// return enter.SetResult(...);
@@ -78,18 +101,27 @@ class PPAPI_THUNK_EXPORT EnterBase {
// Use this value as the return value for the function.
int32_t retval() const { return retval_; }
+ // All failure conditions cause retval_ to be set to an appropriate error
+ // code.
+ bool succeeded() const { return retval_ == PP_OK; }
+ bool failed() const { return !succeeded(); }
+
+ const scoped_refptr<TrackedCallback>& callback() { return callback_; }
+
protected:
// Helper function to return a Resource from a PP_Resource. Having this
// code be in the non-templatized base keeps us from having to instantiate
// it in every template.
- Resource* GetResource(PP_Resource resource) const;
+ static Resource* GetResource(PP_Resource resource);
+
+ void ClearCallback();
// Does error handling associated with entering a resource. The resource_base
// is the result of looking up the given pp_resource. The object is the
- // result of converting the base to the desired object (converted back to a
- // Resource* so this function doesn't have to be templatized). The reason for
- // passing both resource_base and object is that we can differentiate "bad
- // resource ID" from "valid resource ID not of the currect type."
+ // result of converting the base to the desired object (converted to a void*
+ // so this function doesn't have to be templatized). The reason for passing
+ // both resource_base and object is that we can differentiate "bad resource
+ // ID" from "valid resource ID not of the correct type."
//
// This will set retval_ = PP_ERROR_BADRESOURCE if the object is invalid, and
// if report_error is set, log a message to the programmer.
@@ -103,11 +135,23 @@ class PPAPI_THUNK_EXPORT EnterBase {
void* object,
bool report_error);
+ // For Enter objects that need a resource, we'll store a pointer to the
+ // Resource object so that we don't need to look it up more than once. For
+ // Enter objects with no resource, this will be NULL.
+ Resource* resource_;
+
private:
- // Holds the callback. The function will only be non-NULL when the
- // callback is requried. Optional callbacks don't require any special
- // handling from us at this layer.
- PP_CompletionCallback callback_;
+ bool CallbackIsValid() const;
+
+ // Checks whether the callback is valid (i.e., if it is either non-blocking,
+ // or blocking and we're on a background thread). If the callback is invalid,
+ // this will set retval_ = PP_ERROR_BLOCKS_MAIN_THREAD, and if report_error is
+ // set, it will log a message to the programmer.
+ void SetStateForCallbackError(bool report_error);
+
+ // Holds the callback. For Enter objects that aren't given a callback, this
+ // will be NULL.
+ scoped_refptr<TrackedCallback> callback_;
int32_t retval_;
};
@@ -121,34 +165,30 @@ class EnterResource : public subtle::EnterBase,
public subtle::LockOnEntry<lock_on_entry> {
public:
EnterResource(PP_Resource resource, bool report_error)
- : EnterBase() {
+ : EnterBase(resource) {
Init(resource, report_error);
}
- EnterResource(PP_Resource resource,
- const PP_CompletionCallback& callback,
+ EnterResource(PP_Resource resource, const PP_CompletionCallback& callback,
bool report_error)
- : EnterBase(callback) {
+ : EnterBase(resource, callback) {
Init(resource, report_error);
}
~EnterResource() {}
- bool succeeded() const { return !!object_; }
- bool failed() const { return !object_; }
-
ResourceT* object() { return object_; }
Resource* resource() { return resource_; }
private:
void Init(PP_Resource resource, bool report_error) {
- resource_ = GetResource(resource);
if (resource_)
object_ = resource_->GetAs<ResourceT>();
else
object_ = NULL;
+ // Validate the resource (note, if both are wrong, we will return
+ // PP_ERROR_BADRESOURCE; last in wins).
SetStateForResourceError(resource, resource_, object_, report_error);
}
- Resource* resource_;
ResourceT* object_;
DISALLOW_COPY_AND_ASSIGN(EnterResource);
@@ -163,6 +203,10 @@ class EnterResourceNoLock : public EnterResource<ResourceT, false> {
EnterResourceNoLock(PP_Resource resource, bool report_error)
: EnterResource<ResourceT, false>(resource, report_error) {
}
+ EnterResourceNoLock(PP_Resource resource, PP_CompletionCallback callback,
+ bool report_error)
+ : EnterResource<ResourceT, false>(resource, callback, report_error) {
+ }
};
// EnterInstance ---------------------------------------------------------------
@@ -190,13 +234,10 @@ class PPAPI_THUNK_EXPORT EnterInstanceNoLock
public subtle::LockOnEntry<false> {
public:
EnterInstanceNoLock(PP_Instance instance);
- //EnterInstanceNoLock(PP_Instance instance,
- // const PP_CompletionCallback& callback);
+ EnterInstanceNoLock(PP_Instance instance,
+ const PP_CompletionCallback& callback);
~EnterInstanceNoLock();
- bool succeeded() const { return !!functions_; }
- bool failed() const { return !functions_; }
-
PPB_Instance_API* functions() { return functions_; }
private:
@@ -212,9 +253,6 @@ class PPAPI_THUNK_EXPORT EnterResourceCreation
EnterResourceCreation(PP_Instance instance);
~EnterResourceCreation();
- bool succeeded() const { return !!functions_; }
- bool failed() const { return !functions_; }
-
ResourceCreationAPI* functions() { return functions_; }
private:
@@ -228,9 +266,6 @@ class PPAPI_THUNK_EXPORT EnterResourceCreationNoLock
EnterResourceCreationNoLock(PP_Instance instance);
~EnterResourceCreationNoLock();
- bool succeeded() const { return !!functions_; }
- bool failed() const { return !functions_; }
-
ResourceCreationAPI* functions() { return functions_; }
private:
diff --git a/ppapi/thunk/ppb_audio_api.h b/ppapi/thunk/ppb_audio_api.h
index 3c9c274..f6377994 100644
--- a/ppapi/thunk/ppb_audio_api.h
+++ b/ppapi/thunk/ppb_audio_api.h
@@ -1,15 +1,19 @@
-// 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.
#ifndef PPAPI_THUNK_PPB_AUDIO_API_H_
#define PPAPI_THUNK_PPB_AUDIO_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/ppb_audio.h"
#include "ppapi/thunk/ppapi_thunk_export.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPAPI_THUNK_EXPORT PPB_Audio_API {
@@ -21,8 +25,9 @@ class PPAPI_THUNK_EXPORT PPB_Audio_API {
virtual PP_Bool StopPlayback() = 0;
// Trusted API.
- virtual int32_t OpenTrusted(PP_Resource config_id,
- PP_CompletionCallback create_callback) = 0;
+ virtual int32_t OpenTrusted(
+ PP_Resource config_id,
+ scoped_refptr<TrackedCallback> create_callback) = 0;
virtual int32_t GetSyncSocket(int* sync_socket) = 0;
virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) = 0;
};
diff --git a/ppapi/thunk/ppb_audio_input_api.h b/ppapi/thunk/ppb_audio_input_api.h
index 38e94ef..545f982 100644
--- a/ppapi/thunk/ppb_audio_input_api.h
+++ b/ppapi/thunk/ppb_audio_input_api.h
@@ -8,6 +8,7 @@
#include <string>
#include <vector>
+#include "base/memory/ref_counted.h"
#include "ppapi/c/dev/ppb_audio_input_dev.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/thunk/ppapi_thunk_export.h"
@@ -15,6 +16,7 @@
namespace ppapi {
struct DeviceRefData;
+class TrackedCallback;
namespace thunk {
@@ -22,14 +24,13 @@ class PPAPI_THUNK_EXPORT PPB_AudioInput_API {
public:
virtual ~PPB_AudioInput_API() {}
- virtual int32_t EnumerateDevices(
- PP_Resource* devices,
- const PP_CompletionCallback& callback) = 0;
+ virtual int32_t EnumerateDevices(PP_Resource* devices,
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t Open(const std::string& device_id,
PP_Resource config,
PPB_AudioInput_Callback audio_input_callback,
void* user_data,
- const PP_CompletionCallback& callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual PP_Resource GetCurrentConfig() = 0;
virtual PP_Bool StartCapture() = 0;
virtual PP_Bool StopCapture() = 0;
@@ -39,7 +40,7 @@ class PPAPI_THUNK_EXPORT PPB_AudioInput_API {
virtual int32_t OpenTrusted(
const std::string& device_id,
PP_Resource config,
- const PP_CompletionCallback& create_callback) = 0;
+ scoped_refptr<TrackedCallback> create_callback) = 0;
virtual int32_t GetSyncSocket(int* sync_socket) = 0;
virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) = 0;
virtual const std::vector<DeviceRefData>& GetDeviceRefData() const = 0;
diff --git a/ppapi/thunk/ppb_audio_input_thunk.cc b/ppapi/thunk/ppb_audio_input_thunk.cc
index 9102dc5..f3cd13a 100644
--- a/ppapi/thunk/ppb_audio_input_thunk.cc
+++ b/ppapi/thunk/ppb_audio_input_thunk.cc
@@ -4,6 +4,7 @@
#include "ppapi/c/pp_errors.h"
#include "ppapi/shared_impl/ppb_device_ref_shared.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_device_ref_api.h"
#include "ppapi/thunk/ppb_audio_input_api.h"
@@ -49,7 +50,8 @@ int32_t EnumerateDevices(PP_Resource audio_input,
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->EnumerateDevices(devices, callback));
+ return enter.SetResult(enter.object()->EnumerateDevices(devices,
+ enter.callback()));
}
int32_t Open(PP_Resource audio_input,
@@ -73,7 +75,7 @@ int32_t Open(PP_Resource audio_input,
}
return enter.SetResult(enter.object()->Open(
- device_id, config, audio_input_callback, user_data, callback));
+ device_id, config, audio_input_callback, user_data, enter.callback()));
}
PP_Resource GetCurrentConfig(PP_Resource audio_input) {
diff --git a/ppapi/thunk/ppb_audio_input_trusted_thunk.cc b/ppapi/thunk/ppb_audio_input_trusted_thunk.cc
index f1f1ef9..0b1631a 100644
--- a/ppapi/thunk/ppb_audio_input_trusted_thunk.cc
+++ b/ppapi/thunk/ppb_audio_input_trusted_thunk.cc
@@ -4,6 +4,7 @@
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/trusted/ppb_audio_input_trusted_dev.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_audio_input_api.h"
#include "ppapi/thunk/resource_creation_api.h"
@@ -29,7 +30,8 @@ int32_t Open(PP_Resource audio_id,
EnterAudioInput enter(audio_id, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->OpenTrusted("", config_id, callback));
+ return enter.SetResult(enter.object()->OpenTrusted("", config_id,
+ enter.callback()));
}
int32_t GetSyncSocket(PP_Resource audio_id, int* sync_socket) {
diff --git a/ppapi/thunk/ppb_audio_trusted_thunk.cc b/ppapi/thunk/ppb_audio_trusted_thunk.cc
index d87d84d..9484d69 100644
--- a/ppapi/thunk/ppb_audio_trusted_thunk.cc
+++ b/ppapi/thunk/ppb_audio_trusted_thunk.cc
@@ -4,6 +4,7 @@
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/trusted/ppb_audio_trusted.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
#include "ppapi/thunk/ppb_audio_api.h"
@@ -29,7 +30,8 @@ int32_t Open(PP_Resource audio_id,
EnterAudio enter(audio_id, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->OpenTrusted(config_id, callback));
+ return enter.SetResult(enter.object()->OpenTrusted(config_id,
+ enter.callback()));
}
int32_t GetSyncSocket(PP_Resource audio_id, int* sync_socket) {
diff --git a/ppapi/thunk/ppb_broker_api.h b/ppapi/thunk/ppb_broker_api.h
index 8703a7b..803c99e 100644
--- a/ppapi/thunk/ppb_broker_api.h
+++ b/ppapi/thunk/ppb_broker_api.h
@@ -1,21 +1,25 @@
-// 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.
#ifndef PPAPI_THUNK_PPB_BROKER_API_H_
#define PPAPI_THUNK_PPB_BROKER_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_stdint.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPB_Broker_API {
public:
virtual ~PPB_Broker_API() {}
- virtual int32_t Connect(PP_CompletionCallback connect_callback) = 0;
+ virtual int32_t Connect(scoped_refptr<TrackedCallback> connect_callback) = 0;
virtual int32_t GetHandle(int32_t* handle) = 0;
};
diff --git a/ppapi/thunk/ppb_broker_thunk.cc b/ppapi/thunk/ppb_broker_thunk.cc
index 9fb115f..fa192b6 100644
--- a/ppapi/thunk/ppb_broker_thunk.cc
+++ b/ppapi/thunk/ppb_broker_thunk.cc
@@ -4,6 +4,7 @@
#include "ppapi/c/trusted/ppb_broker_trusted.h"
#include "ppapi/c/pp_errors.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
#include "ppapi/thunk/ppb_broker_api.h"
@@ -31,7 +32,7 @@ int32_t Connect(PP_Resource resource,
EnterResource<PPB_Broker_API> enter(resource, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Connect(callback));
+ return enter.SetResult(enter.object()->Connect(enter.callback()));
}
int32_t GetHandle(PP_Resource resource, int32_t* handle) {
diff --git a/ppapi/thunk/ppb_directory_reader_api.h b/ppapi/thunk/ppb_directory_reader_api.h
index b9a18e9..6a32934 100644
--- a/ppapi/thunk/ppb_directory_reader_api.h
+++ b/ppapi/thunk/ppb_directory_reader_api.h
@@ -1,13 +1,17 @@
-// 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.
#ifndef PPAPI_THUNK_DIRECTORY_READER_API_H_
#define PPAPI_THUNK_DIRECTORY_READER_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/dev/ppb_directory_reader_dev.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPB_DirectoryReader_API {
@@ -15,7 +19,7 @@ class PPB_DirectoryReader_API {
virtual ~PPB_DirectoryReader_API() {}
virtual int32_t GetNextEntry(PP_DirectoryEntry_Dev* entry,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
};
} // namespace thunk
diff --git a/ppapi/thunk/ppb_directory_reader_thunk.cc b/ppapi/thunk/ppb_directory_reader_thunk.cc
index eb58684..8ff54e9 100644
--- a/ppapi/thunk/ppb_directory_reader_thunk.cc
+++ b/ppapi/thunk/ppb_directory_reader_thunk.cc
@@ -5,6 +5,7 @@
#include "ppapi/c/dev/ppb_directory_reader_dev.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
#include "ppapi/thunk/ppb_directory_reader_api.h"
@@ -38,7 +39,7 @@ int32_t GetNextEntry(PP_Resource directory_reader,
directory_reader, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->GetNextEntry(entry, callback));
+ return enter.SetResult(enter.object()->GetNextEntry(entry, enter.callback()));
}
const PPB_DirectoryReader_Dev g_ppb_directory_reader_thunk = {
diff --git a/ppapi/thunk/ppb_file_chooser_api.h b/ppapi/thunk/ppb_file_chooser_api.h
index ed94782..15cc9e4 100644
--- a/ppapi/thunk/ppb_file_chooser_api.h
+++ b/ppapi/thunk/ppb_file_chooser_api.h
@@ -1,13 +1,17 @@
-// 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.
#ifndef PPAPI_THUNK_PPB_FILE_CHOOSER_API_H_
#define PPAPI_THUNK_PPB_FILE_CHOOSER_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/dev/ppb_file_chooser_dev.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPB_FileChooser_API {
@@ -15,24 +19,24 @@ class PPB_FileChooser_API {
virtual ~PPB_FileChooser_API() {}
virtual int32_t Show(const PP_ArrayOutput& output,
- const PP_CompletionCallback& callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
// Trusted API.
virtual int32_t ShowWithoutUserGesture(
PP_Bool save_as,
PP_Var suggested_file_name,
const PP_ArrayOutput& output,
- const PP_CompletionCallback& callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
// Version 0.5 API.
- virtual int32_t Show0_5(const PP_CompletionCallback& callback) = 0;
+ virtual int32_t Show0_5(scoped_refptr<TrackedCallback> callback) = 0;
virtual PP_Resource GetNextChosenFile() = 0;
// Trusted version 0.5 API.
virtual int32_t ShowWithoutUserGesture0_5(
PP_Bool save_as,
PP_Var suggested_file_name,
- const PP_CompletionCallback& callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
};
} // namespace thunk
diff --git a/ppapi/thunk/ppb_file_chooser_thunk.cc b/ppapi/thunk/ppb_file_chooser_thunk.cc
index 8db1b50..c52125a 100644
--- a/ppapi/thunk/ppb_file_chooser_thunk.cc
+++ b/ppapi/thunk/ppb_file_chooser_thunk.cc
@@ -6,6 +6,7 @@
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/trusted/ppb_file_chooser_trusted.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/shared_impl/var.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
@@ -38,7 +39,7 @@ int32_t Show0_5(PP_Resource chooser, PP_CompletionCallback callback) {
EnterResource<PPB_FileChooser_API> enter(chooser, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Show0_5(callback));
+ return enter.SetResult(enter.object()->Show0_5(enter.callback()));
}
PP_Resource GetNextChosenFile0_5(PP_Resource chooser) {
@@ -54,7 +55,7 @@ int32_t Show(PP_Resource chooser,
EnterResource<PPB_FileChooser_API> enter(chooser, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Show(output, callback));
+ return enter.SetResult(enter.object()->Show(output, enter.callback()));
}
int32_t ShowWithoutUserGesture0_5(PP_Resource chooser,
@@ -65,7 +66,7 @@ int32_t ShowWithoutUserGesture0_5(PP_Resource chooser,
if (enter.failed())
return enter.retval();
return enter.SetResult(enter.object()->ShowWithoutUserGesture0_5(
- save_as, suggested_file_name, callback));
+ save_as, suggested_file_name, enter.callback()));
}
int32_t ShowWithoutUserGesture0_6(PP_Resource chooser,
@@ -77,7 +78,7 @@ int32_t ShowWithoutUserGesture0_6(PP_Resource chooser,
if (enter.failed())
return enter.retval();
return enter.SetResult(enter.object()->ShowWithoutUserGesture(
- save_as, suggested_file_name, output, callback));
+ save_as, suggested_file_name, output, enter.callback()));
}
const PPB_FileChooser_Dev_0_5 g_ppb_file_chooser_0_5_thunk = {
diff --git a/ppapi/thunk/ppb_file_io_api.h b/ppapi/thunk/ppb_file_io_api.h
index f49e809..1e6e3ad 100644
--- a/ppapi/thunk/ppb_file_io_api.h
+++ b/ppapi/thunk/ppb_file_io_api.h
@@ -1,14 +1,18 @@
-// 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.
#ifndef PPAPI_THUNK_PPB_FILE_IO_API_H_
#define PPAPI_THUNK_PPB_FILE_IO_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/ppb_file_io.h"
#include "ppapi/thunk/ppapi_thunk_export.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPAPI_THUNK_EXPORT PPB_FileIO_API {
@@ -17,32 +21,32 @@ class PPAPI_THUNK_EXPORT PPB_FileIO_API {
virtual int32_t Open(PP_Resource file_ref,
int32_t open_flags,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t Query(PP_FileInfo* info,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t Touch(PP_Time last_access_time,
PP_Time last_modified_time,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t Read(int64_t offset,
char* buffer,
int32_t bytes_to_read,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t Write(int64_t offset,
const char* buffer,
int32_t bytes_to_write,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t SetLength(int64_t length,
- PP_CompletionCallback callback) = 0;
- virtual int32_t Flush(PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
+ virtual int32_t Flush(scoped_refptr<TrackedCallback> callback) = 0;
virtual void Close() = 0;
// Trusted API.
virtual int32_t GetOSFileDescriptor() = 0;
virtual int32_t WillWrite(int64_t offset,
int32_t bytes_to_write,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t WillSetLength(int64_t length,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
};
} // namespace thunk
diff --git a/ppapi/thunk/ppb_file_io_thunk.cc b/ppapi/thunk/ppb_file_io_thunk.cc
index a129a62..8fcfa52 100644
--- a/ppapi/thunk/ppb_file_io_thunk.cc
+++ b/ppapi/thunk/ppb_file_io_thunk.cc
@@ -4,6 +4,7 @@
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
#include "ppapi/thunk/ppb_file_io_api.h"
@@ -35,7 +36,8 @@ int32_t Open(PP_Resource file_io,
EnterFileIO enter(file_io, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Open(file_ref, open_flags, callback));
+ return enter.SetResult(enter.object()->Open(file_ref, open_flags,
+ enter.callback()));
}
int32_t Query(PP_Resource file_io,
@@ -44,7 +46,7 @@ int32_t Query(PP_Resource file_io,
EnterFileIO enter(file_io, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Query(info, callback));
+ return enter.SetResult(enter.object()->Query(info, enter.callback()));
}
int32_t Touch(PP_Resource file_io,
@@ -55,7 +57,7 @@ int32_t Touch(PP_Resource file_io,
if (enter.failed())
return enter.retval();
return enter.SetResult(enter.object()->Touch(
- last_access_time, last_modified_time, callback));
+ last_access_time, last_modified_time, enter.callback()));
}
int32_t Read(PP_Resource file_io,
@@ -67,7 +69,7 @@ int32_t Read(PP_Resource file_io,
if (enter.failed())
return enter.retval();
return enter.SetResult(enter.object()->Read(offset, buffer, bytes_to_read,
- callback));
+ enter.callback()));
}
int32_t Write(PP_Resource file_io,
@@ -79,7 +81,7 @@ int32_t Write(PP_Resource file_io,
if (enter.failed())
return enter.retval();
return enter.SetResult(enter.object()->Write(offset, buffer, bytes_to_write,
- callback));
+ enter.callback()));
}
int32_t SetLength(PP_Resource file_io,
@@ -88,7 +90,7 @@ int32_t SetLength(PP_Resource file_io,
EnterFileIO enter(file_io, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->SetLength(length, callback));
+ return enter.SetResult(enter.object()->SetLength(length, enter.callback()));
}
int32_t Flush(PP_Resource file_io,
@@ -96,7 +98,7 @@ int32_t Flush(PP_Resource file_io,
EnterFileIO enter(file_io, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Flush(callback));
+ return enter.SetResult(enter.object()->Flush(enter.callback()));
}
void Close(PP_Resource file_io) {
diff --git a/ppapi/thunk/ppb_file_io_trusted_thunk.cc b/ppapi/thunk/ppb_file_io_trusted_thunk.cc
index c291ec8..3336026 100644
--- a/ppapi/thunk/ppb_file_io_trusted_thunk.cc
+++ b/ppapi/thunk/ppb_file_io_trusted_thunk.cc
@@ -5,6 +5,7 @@
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/trusted/ppb_file_io_trusted.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
#include "ppapi/thunk/ppb_file_io_api.h"
@@ -21,7 +22,7 @@ int32_t GetOSFileDescriptor(PP_Resource file_io) {
EnterFileIO enter(file_io, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->GetOSFileDescriptor());
+ return enter.object()->GetOSFileDescriptor();
}
int32_t WillWrite(PP_Resource file_io,
@@ -32,7 +33,7 @@ int32_t WillWrite(PP_Resource file_io,
if (enter.failed())
return enter.retval();
return enter.SetResult(enter.object()->WillWrite(offset, bytes_to_write,
- callback));
+ enter.callback()));
}
int32_t WillSetLength(PP_Resource file_io,
@@ -41,7 +42,8 @@ int32_t WillSetLength(PP_Resource file_io,
EnterFileIO enter(file_io, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->WillSetLength(length, callback));
+ return enter.SetResult(enter.object()->WillSetLength(length,
+ enter.callback()));
}
const PPB_FileIOTrusted g_ppb_file_io_trusted_thunk = {
diff --git a/ppapi/thunk/ppb_file_ref_api.h b/ppapi/thunk/ppb_file_ref_api.h
index ca74003..ed46098 100644
--- a/ppapi/thunk/ppb_file_ref_api.h
+++ b/ppapi/thunk/ppb_file_ref_api.h
@@ -1,16 +1,18 @@
-// 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.
#ifndef PPAPI_THUNK_PPB_FILE_REF_API_H_
#define PPAPI_THUNK_PPB_FILE_REF_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/ppb_file_ref.h"
#include "ppapi/thunk/ppapi_thunk_export.h"
namespace ppapi {
struct PPB_FileRef_CreateInfo;
+class TrackedCallback;
namespace thunk {
@@ -23,13 +25,13 @@ class PPAPI_THUNK_EXPORT PPB_FileRef_API {
virtual PP_Var GetPath() const = 0;
virtual PP_Resource GetParent() = 0;
virtual int32_t MakeDirectory(PP_Bool make_ancestors,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t Touch(PP_Time last_access_time,
PP_Time last_modified_time,
- PP_CompletionCallback callback) = 0;
- virtual int32_t Delete(PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
+ virtual int32_t Delete(scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t Rename(PP_Resource new_file_ref,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
// Intermal function for use in proxying. Returns the internal CreateInfo
// (the contained resource does not carry a ref on behalf of the caller).
diff --git a/ppapi/thunk/ppb_file_ref_thunk.cc b/ppapi/thunk/ppb_file_ref_thunk.cc
index d2a2a53..15122db 100644
--- a/ppapi/thunk/ppb_file_ref_thunk.cc
+++ b/ppapi/thunk/ppb_file_ref_thunk.cc
@@ -7,6 +7,7 @@
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_file_ref_private.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
#include "ppapi/thunk/ppb_file_ref_api.h"
@@ -70,7 +71,7 @@ int32_t MakeDirectory(PP_Resource directory_ref,
if (enter.failed())
return enter.retval();
return enter.SetResult(enter.object()->MakeDirectory(make_ancestors,
- callback));
+ enter.callback()));
}
int32_t Touch(PP_Resource file_ref,
@@ -81,7 +82,7 @@ int32_t Touch(PP_Resource file_ref,
if (enter.failed())
return enter.retval();
return enter.SetResult(enter.object()->Touch(
- last_access_time, last_modified_time, callback));
+ last_access_time, last_modified_time, enter.callback()));
}
int32_t Delete(PP_Resource file_ref,
@@ -89,7 +90,7 @@ int32_t Delete(PP_Resource file_ref,
EnterFileRef enter(file_ref, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Delete(callback));
+ return enter.SetResult(enter.object()->Delete(enter.callback()));
}
int32_t Rename(PP_Resource file_ref,
@@ -98,7 +99,8 @@ int32_t Rename(PP_Resource file_ref,
EnterFileRef enter(file_ref, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Rename(new_file_ref, callback));
+ return enter.SetResult(enter.object()->Rename(new_file_ref,
+ enter.callback()));
}
PP_Var GetAbsolutePath(PP_Resource file_ref) {
diff --git a/ppapi/thunk/ppb_file_system_api.h b/ppapi/thunk/ppb_file_system_api.h
index 096d072..f9524dc 100644
--- a/ppapi/thunk/ppb_file_system_api.h
+++ b/ppapi/thunk/ppb_file_system_api.h
@@ -1,13 +1,17 @@
-// 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.
#ifndef PPAPI_THUNK_PPB_FILE_SYSTEM_API_H_
#define PPAPI_THUNK_PPB_FILE_SYSTEM_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/ppb_file_system.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPB_FileSystem_API {
@@ -15,7 +19,7 @@ class PPB_FileSystem_API {
virtual ~PPB_FileSystem_API() {}
virtual int32_t Open(int64_t expected_size,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual PP_FileSystemType GetType() = 0;
};
diff --git a/ppapi/thunk/ppb_file_system_thunk.cc b/ppapi/thunk/ppb_file_system_thunk.cc
index d0d41f8..327594c 100644
--- a/ppapi/thunk/ppb_file_system_thunk.cc
+++ b/ppapi/thunk/ppb_file_system_thunk.cc
@@ -5,6 +5,7 @@
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/ppb_file_system.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
#include "ppapi/thunk/ppb_file_system_api.h"
@@ -35,7 +36,7 @@ int32_t Open(PP_Resource file_system,
EnterFileSystem enter(file_system, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Open(expected_size, callback));
+ return enter.SetResult(enter.object()->Open(expected_size, enter.callback()));
}
PP_FileSystemType GetType(PP_Resource file_system) {
diff --git a/ppapi/thunk/ppb_flash_menu_api.h b/ppapi/thunk/ppb_flash_menu_api.h
index a6d99c2..410bda5 100644
--- a/ppapi/thunk/ppb_flash_menu_api.h
+++ b/ppapi/thunk/ppb_flash_menu_api.h
@@ -1,13 +1,17 @@
-// 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.
#ifndef PPAPI_THUNK_PPB_FLASH_MENU_API_H_
#define PPAPI_THUNK_PPB_FLASH_MENU_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/private/ppb_flash_menu.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPB_Flash_Menu_API {
@@ -16,7 +20,7 @@ class PPB_Flash_Menu_API {
virtual int32_t Show(const PP_Point* location,
int32_t* selected_id,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
};
} // namespace thunk
diff --git a/ppapi/thunk/ppb_flash_menu_thunk.cc b/ppapi/thunk/ppb_flash_menu_thunk.cc
index 68c9b50..e0d190d 100644
--- a/ppapi/thunk/ppb_flash_menu_thunk.cc
+++ b/ppapi/thunk/ppb_flash_menu_thunk.cc
@@ -5,6 +5,7 @@
#include "ppapi/c/private/ppb_flash_menu.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
#include "ppapi/thunk/ppb_flash_menu_api.h"
@@ -34,7 +35,8 @@ int32_t Show(PP_Resource resource,
EnterResource<PPB_Flash_Menu_API> enter(resource, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Show(location, selected_id, callback));
+ return enter.SetResult(enter.object()->Show(location, selected_id,
+ enter.callback()));
}
const PPB_Flash_Menu g_ppb_flash_menu_thunk = {
diff --git a/ppapi/thunk/ppb_graphics_2d_api.h b/ppapi/thunk/ppb_graphics_2d_api.h
index 7b74cb3..320297b 100644
--- a/ppapi/thunk/ppb_graphics_2d_api.h
+++ b/ppapi/thunk/ppb_graphics_2d_api.h
@@ -1,7 +1,8 @@
-// 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 "base/memory/ref_counted.h"
#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_point.h"
@@ -10,6 +11,9 @@
#include "ppapi/c/pp_size.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPB_Graphics2D_API {
@@ -23,7 +27,7 @@ class PPB_Graphics2D_API {
virtual void Scroll(const PP_Rect* clip_rect,
const PP_Point* amount) = 0;
virtual void ReplaceContents(PP_Resource image_data) = 0;
- virtual int32_t Flush(PP_CompletionCallback callback) = 0;
+ virtual int32_t Flush(scoped_refptr<TrackedCallback> callback) = 0;
};
} // namespace thunk
diff --git a/ppapi/thunk/ppb_graphics_2d_thunk.cc b/ppapi/thunk/ppb_graphics_2d_thunk.cc
index 393b4c6..1d76bba 100644
--- a/ppapi/thunk/ppb_graphics_2d_thunk.cc
+++ b/ppapi/thunk/ppb_graphics_2d_thunk.cc
@@ -5,6 +5,7 @@
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/ppb_graphics_2d.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_graphics_2d_api.h"
#include "ppapi/thunk/resource_creation_api.h"
@@ -70,12 +71,11 @@ void ReplaceContents(PP_Resource graphics_2d, PP_Resource image_data) {
enter.object()->ReplaceContents(image_data);
}
-int32_t Flush(PP_Resource graphics_2d,
- PP_CompletionCallback callback) {
+int32_t Flush(PP_Resource graphics_2d, PP_CompletionCallback callback) {
EnterGraphics2D enter(graphics_2d, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Flush(callback));
+ return enter.SetResult(enter.object()->Flush(enter.callback()));
}
const PPB_Graphics2D g_ppb_graphics_2d_thunk = {
diff --git a/ppapi/thunk/ppb_graphics_3d_api.h b/ppapi/thunk/ppb_graphics_3d_api.h
index 84dc829..76197b1 100644
--- a/ppapi/thunk/ppb_graphics_3d_api.h
+++ b/ppapi/thunk/ppb_graphics_3d_api.h
@@ -5,12 +5,16 @@
#ifndef PPAPI_THUNK_PPB_GRAPHICS_3D_API_H_
#define PPAPI_THUNK_PPB_GRAPHICS_3D_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/ppb_graphics_3d.h"
#include "ppapi/c/trusted/ppb_graphics_3d_trusted.h"
#include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h"
#include "ppapi/thunk/ppapi_thunk_export.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPAPI_THUNK_EXPORT PPB_Graphics3D_API {
@@ -22,7 +26,7 @@ class PPAPI_THUNK_EXPORT PPB_Graphics3D_API {
virtual int32_t SetAttribs(const int32_t attrib_list[]) = 0;
virtual int32_t GetError() = 0;
virtual int32_t ResizeBuffers(int32_t width, int32_t height) = 0;
- virtual int32_t SwapBuffers(PP_CompletionCallback callback) = 0;
+ virtual int32_t SwapBuffers(scoped_refptr<TrackedCallback> callback) = 0;
// Graphics3DTrusted API.
virtual PP_Bool InitCommandBuffer() = 0;
diff --git a/ppapi/thunk/ppb_graphics_3d_thunk.cc b/ppapi/thunk/ppb_graphics_3d_thunk.cc
index edc19ca..eb079bb 100644
--- a/ppapi/thunk/ppb_graphics_3d_thunk.cc
+++ b/ppapi/thunk/ppb_graphics_3d_thunk.cc
@@ -4,6 +4,7 @@
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
#include "ppapi/thunk/ppb_graphics_3d_api.h"
@@ -70,7 +71,7 @@ int32_t SwapBuffers(PP_Resource graphics_3d, PP_CompletionCallback callback) {
EnterGraphics3D enter(graphics_3d, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->SwapBuffers(callback));
+ return enter.SetResult(enter.object()->SwapBuffers(enter.callback()));
}
const PPB_Graphics3D g_ppb_graphics_3d_thunk = {
diff --git a/ppapi/thunk/ppb_host_resolver_private_api.h b/ppapi/thunk/ppb_host_resolver_private_api.h
index 367e0c3..446ab20 100644
--- a/ppapi/thunk/ppb_host_resolver_private_api.h
+++ b/ppapi/thunk/ppb_host_resolver_private_api.h
@@ -5,10 +5,14 @@
#ifndef PPAPI_THUNK_PPB_HOST_RESOLVER_PRIVATE_API_H_
#define PPAPI_THUNK_PPB_HOST_RESOLVER_PRIVATE_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/private/ppb_host_resolver_private.h"
#include "ppapi/thunk/ppapi_thunk_export.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPAPI_THUNK_EXPORT PPB_HostResolver_Private_API {
@@ -18,7 +22,7 @@ class PPAPI_THUNK_EXPORT PPB_HostResolver_Private_API {
virtual int32_t Resolve(const char* host,
uint16_t port,
const PP_HostResolver_Private_Hint* hint,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual PP_Var GetCanonicalName() = 0;
virtual uint32_t GetSize() = 0;
virtual bool GetNetAddress(uint32_t index,
diff --git a/ppapi/thunk/ppb_host_resolver_private_thunk.cc b/ppapi/thunk/ppb_host_resolver_private_thunk.cc
index 2de4dd0..9da6656 100644
--- a/ppapi/thunk/ppb_host_resolver_private_thunk.cc
+++ b/ppapi/thunk/ppb_host_resolver_private_thunk.cc
@@ -4,6 +4,7 @@
#include "ppapi/c/pp_var.h"
#include "ppapi/c/private/ppb_host_resolver_private.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_host_resolver_private_api.h"
#include "ppapi/thunk/resource_creation_api.h"
@@ -36,7 +37,8 @@ int32_t Resolve(PP_Resource host_resolver,
EnterHostResolver enter(host_resolver, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Resolve(host, port, hint, callback));
+ return enter.SetResult(enter.object()->Resolve(host, port, hint,
+ enter.callback()));
}
PP_Var GetCanonicalName(PP_Resource host_resolver) {
diff --git a/ppapi/thunk/ppb_instance_api.h b/ppapi/thunk/ppb_instance_api.h
index 97fd0b6..9b4e644 100644
--- a/ppapi/thunk/ppb_instance_api.h
+++ b/ppapi/thunk/ppb_instance_api.h
@@ -5,6 +5,8 @@
#ifndef PPAPI_THUNK_INSTANCE_API_H_
#define PPAPI_THUNK_INSTANCE_API_H_
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "ppapi/c/dev/pp_print_settings_dev.h"
#include "ppapi/c/dev/ppb_console_dev.h"
#include "ppapi/c/dev/ppb_text_input_dev.h"
@@ -27,6 +29,7 @@
namespace ppapi {
+class TrackedCallback;
struct ViewData;
namespace thunk {
@@ -109,7 +112,7 @@ class PPB_Instance_API {
// MouseLock.
virtual int32_t LockMouse(PP_Instance instance,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual void UnlockMouse(PP_Instance instance) = 0;
// Printing.
diff --git a/ppapi/thunk/ppb_layer_compositor_api.h b/ppapi/thunk/ppb_layer_compositor_api.h
index 8d72760..883334f 100644
--- a/ppapi/thunk/ppb_layer_compositor_api.h
+++ b/ppapi/thunk/ppb_layer_compositor_api.h
@@ -1,13 +1,17 @@
-// 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.
#ifndef PPAPI_THUNK_PPB_LAYER_COMPOSITOR_API_H_
#define PPAPI_THUNK_PPB_LAYER_COMPOSITOR_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/dev/ppb_layer_compositor_dev.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPB_LayerCompositor_API {
@@ -20,7 +24,7 @@ class PPB_LayerCompositor_API {
virtual void SetRect(PP_Resource layer, const PP_Rect* rect) = 0;
virtual void SetDisplay(PP_Resource layer, PP_Bool is_displayed) = 0;
virtual void MarkAsDirty(PP_Resource layer) = 0;
- virtual int32_t SwapBuffers(PP_CompletionCallback callback) = 0;
+ virtual int32_t SwapBuffers(scoped_refptr<TrackedCallback> callback) = 0;
};
} // namespace thunk
diff --git a/ppapi/thunk/ppb_message_loop_api.h b/ppapi/thunk/ppb_message_loop_api.h
index 36f2f1a..52660ca 100644
--- a/ppapi/thunk/ppb_message_loop_api.h
+++ b/ppapi/thunk/ppb_message_loop_api.h
@@ -5,7 +5,15 @@
#ifndef PPAPI_THUNK_PPB_MESSAGE_LOOP_API_H_
#define PPAPI_THUNK_PPB_MESSAGE_LOOP_API_H_
+#include "base/memory/ref_counted.h"
+#include "ppapi/c/pp_bool.h"
+#include "ppapi/c/pp_completion_callback.h"
+#include "ppapi/c/pp_stdint.h"
+
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPB_MessageLoop_API {
@@ -14,6 +22,10 @@ class PPB_MessageLoop_API {
virtual int32_t AttachToCurrentThread() = 0;
virtual int32_t Run() = 0;
+ // Note: Most interfaces should use scoped_refptr<TrackedCallback>, in order
+ // to track callbacks and support things like blocking or optional callbacks.
+ // In this case, the callback is really just a way to pass a function pointer,
+ // and those options don't make sense.
virtual int32_t PostWork(PP_CompletionCallback callback,
int64_t delay_ms) = 0;
virtual int32_t PostQuit(PP_Bool should_destroy) = 0;
diff --git a/ppapi/thunk/ppb_mouse_lock_thunk.cc b/ppapi/thunk/ppb_mouse_lock_thunk.cc
index d884ab0..cf2530f 100644
--- a/ppapi/thunk/ppb_mouse_lock_thunk.cc
+++ b/ppapi/thunk/ppb_mouse_lock_thunk.cc
@@ -4,6 +4,7 @@
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/ppb_mouse_lock.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_instance_api.h"
#include "ppapi/thunk/thunk.h"
@@ -17,7 +18,8 @@ int32_t LockMouse(PP_Instance instance, PP_CompletionCallback callback) {
EnterInstance enter(instance, callback);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.functions()->LockMouse(instance, callback));
+ return enter.SetResult(enter.functions()->LockMouse(instance,
+ enter.callback()));
}
void UnlockMouse(PP_Instance instance) {
diff --git a/ppapi/thunk/ppb_talk_private_api.h b/ppapi/thunk/ppb_talk_private_api.h
index 8f5244d..5a4f06c 100644
--- a/ppapi/thunk/ppb_talk_private_api.h
+++ b/ppapi/thunk/ppb_talk_private_api.h
@@ -5,16 +5,20 @@
#ifndef PPAPI_THUNK_PPB_TALK_PRIVATE_API_H_
#define PPAPI_THUNK_PPB_TALK_PRIVATE_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/thunk/ppapi_thunk_export.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPAPI_THUNK_EXPORT PPB_Talk_Private_API {
public:
virtual ~PPB_Talk_Private_API() {}
- virtual int32_t GetPermission(const PP_CompletionCallback& callback) = 0;
+ virtual int32_t GetPermission(scoped_refptr<TrackedCallback> callback) = 0;
};
} // namespace thunk
diff --git a/ppapi/thunk/ppb_talk_private_thunk.cc b/ppapi/thunk/ppb_talk_private_thunk.cc
index 3e3775c..2785688 100644
--- a/ppapi/thunk/ppb_talk_private_thunk.cc
+++ b/ppapi/thunk/ppb_talk_private_thunk.cc
@@ -4,6 +4,7 @@
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_talk_private.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_talk_private_api.h"
#include "ppapi/thunk/thunk.h"
@@ -25,7 +26,7 @@ int32_t GetPermission(PP_Resource resource,
EnterResource<PPB_Talk_Private_API> enter(resource, true);
if (enter.failed())
return PP_ERROR_BADRESOURCE;
- return enter.object()->GetPermission(callback);
+ return enter.SetResult(enter.object()->GetPermission(enter.callback()));
}
const PPB_Talk_Private_1_0 g_ppb_talk_private_thunk = {
diff --git a/ppapi/thunk/ppb_tcp_server_socket_private_api.h b/ppapi/thunk/ppb_tcp_server_socket_private_api.h
index b88dfc8..8563bef 100644
--- a/ppapi/thunk/ppb_tcp_server_socket_private_api.h
+++ b/ppapi/thunk/ppb_tcp_server_socket_private_api.h
@@ -5,10 +5,14 @@
#ifndef PPAPI_THUNK_PPB_TCP_SERVER_SOCKET_PRIVATE_API_H_
#define PPAPI_THUNK_PPB_TCP_SERVER_SOCKET_PRIVATE_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/private/ppb_tcp_server_socket_private.h"
#include "ppapi/thunk/ppapi_thunk_export.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPAPI_THUNK_EXPORT PPB_TCPServerSocket_Private_API {
@@ -17,9 +21,9 @@ public:
virtual int32_t Listen(const PP_NetAddress_Private* addr,
int32_t backlog,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t Accept(PP_Resource* tcp_socket,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual void StopListening() = 0;
};
diff --git a/ppapi/thunk/ppb_tcp_server_socket_private_thunk.cc b/ppapi/thunk/ppb_tcp_server_socket_private_thunk.cc
index fcff45e..a9fcb14 100644
--- a/ppapi/thunk/ppb_tcp_server_socket_private_thunk.cc
+++ b/ppapi/thunk/ppb_tcp_server_socket_private_thunk.cc
@@ -4,6 +4,7 @@
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_tcp_server_socket_private.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_tcp_server_socket_private_api.h"
#include "ppapi/thunk/resource_creation_api.h"
@@ -35,7 +36,8 @@ int32_t Listen(PP_Resource tcp_server_socket,
EnterTCPServer enter(tcp_server_socket, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Listen(addr, backlog, callback));
+ return enter.SetResult(enter.object()->Listen(addr, backlog,
+ enter.callback()));
}
int32_t Accept(PP_Resource tcp_server_socket,
@@ -44,7 +46,7 @@ int32_t Accept(PP_Resource tcp_server_socket,
EnterTCPServer enter(tcp_server_socket, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Accept(tcp_socket, callback));
+ return enter.SetResult(enter.object()->Accept(tcp_socket, enter.callback()));
}
void StopListening(PP_Resource tcp_server_socket) {
diff --git a/ppapi/thunk/ppb_tcp_socket_private_api.h b/ppapi/thunk/ppb_tcp_socket_private_api.h
index 689f590f..1311a20 100644
--- a/ppapi/thunk/ppb_tcp_socket_private_api.h
+++ b/ppapi/thunk/ppb_tcp_socket_private_api.h
@@ -5,10 +5,14 @@
#ifndef PPAPI_THUNK_PPB_TCP_SOCKET_PRIVATE_API_H_
#define PPAPI_THUNK_PPB_TCP_SOCKET_PRIVATE_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/private/ppb_tcp_socket_private.h"
#include "ppapi/thunk/ppapi_thunk_export.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPAPI_THUNK_EXPORT PPB_TCPSocket_Private_API {
@@ -17,23 +21,24 @@ class PPAPI_THUNK_EXPORT PPB_TCPSocket_Private_API {
virtual int32_t Connect(const char* host,
uint16_t port,
- PP_CompletionCallback callback) = 0;
- virtual int32_t ConnectWithNetAddress(const PP_NetAddress_Private* addr,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
+ virtual int32_t ConnectWithNetAddress(
+ const PP_NetAddress_Private* addr,
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual PP_Bool GetLocalAddress(PP_NetAddress_Private* local_addr) = 0;
virtual PP_Bool GetRemoteAddress(PP_NetAddress_Private* remote_addr) = 0;
virtual int32_t SSLHandshake(const char* server_name,
uint16_t server_port,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual PP_Resource GetServerCertificate() = 0;
virtual PP_Bool AddChainBuildingCertificate(PP_Resource certificate,
PP_Bool trusted) = 0;
virtual int32_t Read(char* buffer,
int32_t bytes_to_read,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t Write(const char* buffer,
int32_t bytes_to_write,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual void Disconnect() = 0;
};
diff --git a/ppapi/thunk/ppb_tcp_socket_private_thunk.cc b/ppapi/thunk/ppb_tcp_socket_private_thunk.cc
index fe01e66..425f5ad 100644
--- a/ppapi/thunk/ppb_tcp_socket_private_thunk.cc
+++ b/ppapi/thunk/ppb_tcp_socket_private_thunk.cc
@@ -5,6 +5,7 @@
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_tcp_socket_private.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
#include "ppapi/thunk/ppb_tcp_socket_private_api.h"
@@ -36,7 +37,7 @@ int32_t Connect(PP_Resource tcp_socket,
EnterTCP enter(tcp_socket, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Connect(host, port, callback));
+ return enter.SetResult(enter.object()->Connect(host, port, enter.callback()));
}
int32_t ConnectWithNetAddress(PP_Resource tcp_socket,
@@ -45,7 +46,8 @@ int32_t ConnectWithNetAddress(PP_Resource tcp_socket,
EnterTCP enter(tcp_socket, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->ConnectWithNetAddress(addr, callback));
+ return enter.SetResult(
+ enter.object()->ConnectWithNetAddress(addr, enter.callback()));
}
PP_Bool GetLocalAddress(PP_Resource tcp_socket,
@@ -72,7 +74,7 @@ int32_t SSLHandshake(PP_Resource tcp_socket,
if (enter.failed())
return enter.retval();
return enter.SetResult(enter.object()->SSLHandshake(server_name, server_port,
- callback));
+ enter.callback()));
}
PP_Resource GetServerCertificate(PP_Resource tcp_socket) {
@@ -98,7 +100,8 @@ int32_t Read(PP_Resource tcp_socket,
EnterTCP enter(tcp_socket, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Read(buffer, bytes_to_read, callback));
+ return enter.SetResult(enter.object()->Read(buffer, bytes_to_read,
+ enter.callback()));
}
int32_t Write(PP_Resource tcp_socket,
@@ -109,7 +112,7 @@ int32_t Write(PP_Resource tcp_socket,
if (enter.failed())
return enter.retval();
return enter.SetResult(enter.object()->Write(buffer, bytes_to_write,
- callback));
+ enter.callback()));
}
void Disconnect(PP_Resource tcp_socket) {
diff --git a/ppapi/thunk/ppb_udp_socket_private_api.h b/ppapi/thunk/ppb_udp_socket_private_api.h
index ee5ac8e..0b2a3c6 100644
--- a/ppapi/thunk/ppb_udp_socket_private_api.h
+++ b/ppapi/thunk/ppb_udp_socket_private_api.h
@@ -5,10 +5,14 @@
#ifndef PPAPI_THUNK_PPB_UDP_SOCKET_PRIVATE_API_H_
#define PPAPI_THUNK_PPB_UDP_SOCKET_PRIVATE_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/private/ppb_udp_socket_private.h"
#include "ppapi/thunk/ppapi_thunk_export.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPAPI_THUNK_EXPORT PPB_UDPSocket_Private_API {
@@ -16,16 +20,16 @@ class PPAPI_THUNK_EXPORT PPB_UDPSocket_Private_API {
virtual ~PPB_UDPSocket_Private_API() {}
virtual int32_t Bind(const PP_NetAddress_Private* addr,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual PP_Bool GetBoundAddress(PP_NetAddress_Private* addr) = 0;
virtual int32_t RecvFrom(char* buffer,
int32_t num_bytes,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual PP_Bool GetRecvFromAddress(PP_NetAddress_Private* addr) = 0;
virtual int32_t SendTo(const char* buffer,
int32_t num_bytes,
const PP_NetAddress_Private* addr,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual void Close() = 0;
};
diff --git a/ppapi/thunk/ppb_udp_socket_private_thunk.cc b/ppapi/thunk/ppb_udp_socket_private_thunk.cc
index d0452c0..0c0801a 100644
--- a/ppapi/thunk/ppb_udp_socket_private_thunk.cc
+++ b/ppapi/thunk/ppb_udp_socket_private_thunk.cc
@@ -5,6 +5,7 @@
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_udp_socket_private.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_udp_socket_private_api.h"
#include "ppapi/thunk/resource_creation_api.h"
@@ -35,7 +36,7 @@ int32_t Bind(PP_Resource udp_socket,
EnterUDP enter(udp_socket, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Bind(addr, callback));
+ return enter.SetResult(enter.object()->Bind(addr, enter.callback()));
}
PP_Bool GetBoundAddress(PP_Resource udp_socket,
@@ -53,7 +54,8 @@ int32_t RecvFrom(PP_Resource udp_socket,
EnterUDP enter(udp_socket, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->RecvFrom(buffer, num_bytes, callback));
+ return enter.SetResult(enter.object()->RecvFrom(buffer, num_bytes,
+ enter.callback()));
}
PP_Bool GetRecvFromAddress(PP_Resource udp_socket,
@@ -73,7 +75,7 @@ int32_t SendTo(PP_Resource udp_socket,
if (enter.failed())
return enter.retval();
return enter.SetResult(enter.object()->SendTo(buffer, num_bytes, addr,
- callback));
+ enter.callback()));
}
void Close(PP_Resource udp_socket) {
diff --git a/ppapi/thunk/ppb_url_loader_api.h b/ppapi/thunk/ppb_url_loader_api.h
index 5f9e58d..be61166 100644
--- a/ppapi/thunk/ppb_url_loader_api.h
+++ b/ppapi/thunk/ppb_url_loader_api.h
@@ -1,14 +1,18 @@
-// 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.
#ifndef PPAPI_THUNK_URL_LOADER_API_H_
#define PPAPI_THUNK_URL_LOADER_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/ppb_url_loader.h"
#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPB_URLLoader_API {
@@ -16,8 +20,8 @@ class PPB_URLLoader_API {
virtual ~PPB_URLLoader_API() {}
virtual int32_t Open(PP_Resource request_id,
- PP_CompletionCallback callback) = 0;
- virtual int32_t FollowRedirect(PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
+ virtual int32_t FollowRedirect(scoped_refptr<TrackedCallback> callback) = 0;
virtual PP_Bool GetUploadProgress(int64_t* bytes_sent,
int64_t* total_bytes_to_be_sent) = 0;
virtual PP_Bool GetDownloadProgress(int64_t* bytes_received,
@@ -25,8 +29,9 @@ class PPB_URLLoader_API {
virtual PP_Resource GetResponseInfo() = 0;
virtual int32_t ReadResponseBody(void* buffer,
int32_t bytes_to_read,
- PP_CompletionCallback callback) = 0;
- virtual int32_t FinishStreamingToFile(PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
+ virtual int32_t FinishStreamingToFile(
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual void Close() = 0;
// Trusted API.
diff --git a/ppapi/thunk/ppb_url_loader_thunk.cc b/ppapi/thunk/ppb_url_loader_thunk.cc
index 71dbdad..23113cd 100644
--- a/ppapi/thunk/ppb_url_loader_thunk.cc
+++ b/ppapi/thunk/ppb_url_loader_thunk.cc
@@ -4,6 +4,7 @@
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
#include "ppapi/thunk/ppb_url_loader_api.h"
@@ -34,7 +35,7 @@ int32_t Open(PP_Resource loader,
EnterURLLoader enter(loader, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Open(request_id, callback));
+ return enter.SetResult(enter.object()->Open(request_id, enter.callback()));
}
int32_t FollowRedirect(PP_Resource loader,
@@ -42,7 +43,7 @@ int32_t FollowRedirect(PP_Resource loader,
EnterURLLoader enter(loader, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->FollowRedirect(callback));
+ return enter.SetResult(enter.object()->FollowRedirect(enter.callback()));
}
PP_Bool GetUploadProgress(PP_Resource loader,
@@ -86,7 +87,7 @@ int32_t ReadResponseBody(PP_Resource loader,
if (enter.failed())
return enter.retval();
return enter.SetResult(enter.object()->ReadResponseBody(buffer, bytes_to_read,
- callback));
+ enter.callback()));
}
int32_t FinishStreamingToFile(PP_Resource loader,
@@ -94,7 +95,8 @@ int32_t FinishStreamingToFile(PP_Resource loader,
EnterURLLoader enter(loader, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->FinishStreamingToFile(callback));
+ return enter.SetResult(
+ enter.object()->FinishStreamingToFile(enter.callback()));
}
void Close(PP_Resource loader) {
diff --git a/ppapi/thunk/ppb_video_capture_api.h b/ppapi/thunk/ppb_video_capture_api.h
index a792ff3..117b495 100644
--- a/ppapi/thunk/ppb_video_capture_api.h
+++ b/ppapi/thunk/ppb_video_capture_api.h
@@ -8,11 +8,13 @@
#include <string>
#include <vector>
+#include "base/memory/ref_counted.h"
#include "ppapi/c/dev/ppb_video_capture_dev.h"
namespace ppapi {
struct DeviceRefData;
+class TrackedCallback;
namespace thunk {
@@ -21,11 +23,11 @@ class PPB_VideoCapture_API {
virtual ~PPB_VideoCapture_API() {}
virtual int32_t EnumerateDevices(PP_Resource* devices,
- const PP_CompletionCallback& callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t Open(const std::string& device_id,
const PP_VideoCaptureDeviceInfo_Dev& requested_info,
uint32_t buffer_count,
- const PP_CompletionCallback& callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual int32_t StartCapture() = 0;
virtual int32_t ReuseBuffer(uint32_t buffer) = 0;
virtual int32_t StopCapture() = 0;
diff --git a/ppapi/thunk/ppb_video_capture_thunk.cc b/ppapi/thunk/ppb_video_capture_thunk.cc
index 2471446..54cb68c 100644
--- a/ppapi/thunk/ppb_video_capture_thunk.cc
+++ b/ppapi/thunk/ppb_video_capture_thunk.cc
@@ -4,6 +4,7 @@
#include "ppapi/c/pp_errors.h"
#include "ppapi/shared_impl/ppb_device_ref_shared.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_device_ref_api.h"
#include "ppapi/thunk/ppb_video_capture_api.h"
@@ -36,7 +37,8 @@ int32_t EnumerateDevices(PP_Resource video_capture,
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->EnumerateDevices(devices, callback));
+ return enter.SetResult(enter.object()->EnumerateDevices(devices,
+ enter.callback()));
}
int32_t Open(PP_Resource video_capture,
@@ -59,7 +61,7 @@ int32_t Open(PP_Resource video_capture,
}
return enter.SetResult(enter.object()->Open(
- device_id, *requested_info, buffer_count, callback));
+ device_id, *requested_info, buffer_count, enter.callback()));
}
int32_t StartCapture(PP_Resource video_capture) {
diff --git a/ppapi/thunk/ppb_video_decoder_api.h b/ppapi/thunk/ppb_video_decoder_api.h
index e17d22b..e26c887 100644
--- a/ppapi/thunk/ppb_video_decoder_api.h
+++ b/ppapi/thunk/ppb_video_decoder_api.h
@@ -1,13 +1,17 @@
-// 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.
#ifndef PPAPI_THUNK_VIDEO_DECODER_API_H_
#define PPAPI_THUNK_VIDEO_DECODER_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/dev/ppb_video_decoder_dev.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
class PPB_VideoDecoder_API {
@@ -15,12 +19,12 @@ class PPB_VideoDecoder_API {
virtual ~PPB_VideoDecoder_API() {}
virtual int32_t Decode(const PP_VideoBitstreamBuffer_Dev* bitstream_buffer,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
virtual void AssignPictureBuffers(uint32_t no_of_buffers,
const PP_PictureBuffer_Dev* buffers) = 0;
virtual void ReusePictureBuffer(int32_t picture_buffer_id) = 0;
- virtual int32_t Flush(PP_CompletionCallback callback) = 0;
- virtual int32_t Reset(PP_CompletionCallback callback) = 0;
+ virtual int32_t Flush(scoped_refptr<TrackedCallback> callback) = 0;
+ virtual int32_t Reset(scoped_refptr<TrackedCallback> callback) = 0;
virtual void Destroy() = 0;
};
diff --git a/ppapi/thunk/ppb_video_decoder_thunk.cc b/ppapi/thunk/ppb_video_decoder_thunk.cc
index 594b336..2472d8a 100644
--- a/ppapi/thunk/ppb_video_decoder_thunk.cc
+++ b/ppapi/thunk/ppb_video_decoder_thunk.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "ppapi/c/pp_errors.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
#include "ppapi/thunk/ppb_video_decoder_api.h"
@@ -35,7 +36,8 @@ int32_t Decode(PP_Resource video_decoder,
EnterVideoDecoder enter(video_decoder, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Decode(bitstream_buffer, callback));
+ return enter.SetResult(enter.object()->Decode(bitstream_buffer,
+ enter.callback()));
}
void AssignPictureBuffers(PP_Resource video_decoder,
@@ -56,7 +58,7 @@ int32_t Flush(PP_Resource video_decoder, PP_CompletionCallback callback) {
EnterVideoDecoder enter(video_decoder, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Flush(callback));
+ return enter.SetResult(enter.object()->Flush(enter.callback()));
}
int32_t Reset(PP_Resource video_decoder,
@@ -64,7 +66,7 @@ int32_t Reset(PP_Resource video_decoder,
EnterVideoDecoder enter(video_decoder, callback, true);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Reset(callback));
+ return enter.SetResult(enter.object()->Reset(enter.callback()));
}
void Destroy(PP_Resource video_decoder) {
diff --git a/ppapi/thunk/ppb_websocket_api.h b/ppapi/thunk/ppb_websocket_api.h
index 04fc960..e5b7791 100644
--- a/ppapi/thunk/ppb_websocket_api.h
+++ b/ppapi/thunk/ppb_websocket_api.h
@@ -5,10 +5,14 @@
#ifndef PPAPI_THUNK_WEBSOCKET_API_H_
#define PPAPI_THUNK_WEBSOCKET_API_H_
+#include "base/memory/ref_counted.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/ppb_websocket.h"
namespace ppapi {
+
+class TrackedCallback;
+
namespace thunk {
// Some arguments and attributes are based on The WebSocket Protocol and The
@@ -25,19 +29,19 @@ class PPB_WebSocket_API {
virtual int32_t Connect(PP_Var url,
const PP_Var protocols[],
uint32_t protocol_count,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
// Closes the established connection with specified |code| and |reason|.
// Returns an int32_t error code from pp_errors.h.
virtual int32_t Close(uint16_t code,
PP_Var reason,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
// Receives a message from the WebSocket server. Caller must keep specified
// |message| object as valid until completion callback is invoked. Returns an
// int32_t error code from pp_errors.h.
virtual int32_t ReceiveMessage(PP_Var* message,
- PP_CompletionCallback callback) = 0;
+ scoped_refptr<TrackedCallback> callback) = 0;
// Sends a message to the WebSocket server. Returns an int32_t error code
// from pp_errors.h.
diff --git a/ppapi/thunk/ppb_websocket_thunk.cc b/ppapi/thunk/ppb_websocket_thunk.cc
index e83293c..3e127b8 100644
--- a/ppapi/thunk/ppb_websocket_thunk.cc
+++ b/ppapi/thunk/ppb_websocket_thunk.cc
@@ -4,6 +4,7 @@
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_var.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/thunk.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_websocket_api.h"
@@ -37,7 +38,7 @@ int32_t Connect(PP_Resource resource,
if (enter.failed())
return enter.retval();
return enter.SetResult(enter.object()->Connect(
- url, protocols, protocol_count, callback));
+ url, protocols, protocol_count, enter.callback()));
}
int32_t Close(PP_Resource resource,
@@ -47,7 +48,7 @@ int32_t Close(PP_Resource resource,
EnterWebSocket enter(resource, callback, false);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->Close(code, reason, callback));
+ return enter.SetResult(enter.object()->Close(code, reason, enter.callback()));
}
int32_t ReceiveMessage(PP_Resource resource,
@@ -56,7 +57,8 @@ int32_t ReceiveMessage(PP_Resource resource,
EnterWebSocket enter(resource, callback, false);
if (enter.failed())
return enter.retval();
- return enter.SetResult(enter.object()->ReceiveMessage(message, callback));
+ return enter.SetResult(enter.object()->ReceiveMessage(message,
+ enter.callback()));
}
int32_t SendMessage(PP_Resource resource, PP_Var message) {
diff --git a/webkit/plugins/ppapi/file_callbacks.cc b/webkit/plugins/ppapi/file_callbacks.cc
index e9e1aee..0ab4453 100644
--- a/webkit/plugins/ppapi/file_callbacks.cc
+++ b/webkit/plugins/ppapi/file_callbacks.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.
@@ -25,11 +25,11 @@ namespace ppapi {
FileCallbacks::FileCallbacks(
Resource* resource,
- PP_CompletionCallback callback,
+ scoped_refptr<TrackedCallback> callback,
PP_FileInfo* info,
scoped_refptr<PPB_FileSystem_Impl> file_system,
scoped_refptr<PPB_DirectoryReader_Impl> directory_reader)
- : callback_(new TrackedCallback(resource, callback)),
+ : callback_(callback),
info_(info),
file_system_(file_system),
directory_reader_(directory_reader) {
diff --git a/webkit/plugins/ppapi/file_callbacks.h b/webkit/plugins/ppapi/file_callbacks.h
index 8c00336..c254dab 100644
--- a/webkit/plugins/ppapi/file_callbacks.h
+++ b/webkit/plugins/ppapi/file_callbacks.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.
@@ -36,7 +36,7 @@ class PPB_FileSystem_Impl;
class FileCallbacks : public fileapi::FileSystemCallbackDispatcher {
public:
FileCallbacks(::ppapi::Resource* resource,
- PP_CompletionCallback callback,
+ scoped_refptr< ::ppapi::TrackedCallback> callback,
PP_FileInfo* info,
scoped_refptr<PPB_FileSystem_Impl> file_system,
scoped_refptr<PPB_DirectoryReader_Impl> directory_reader);
diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc
index 423209f..7098f70 100644
--- a/webkit/plugins/ppapi/plugin_module.cc
+++ b/webkit/plugins/ppapi/plugin_module.cc
@@ -154,12 +154,6 @@ PluginModuleSet* GetLivePluginSet() {
return &live_plugin_libs;
}
-base::MessageLoopProxy* GetMainThreadMessageLoop() {
- CR_DEFINE_STATIC_LOCAL(scoped_refptr<base::MessageLoopProxy>, proxy,
- (base::MessageLoopProxy::current()));
- return proxy.get();
-}
-
// PPB_Core --------------------------------------------------------------------
void AddRefResource(PP_Resource resource) {
@@ -182,7 +176,7 @@ void CallOnMainThread(int delay_in_msec,
PP_CompletionCallback callback,
int32_t result) {
if (callback.func) {
- GetMainThreadMessageLoop()->PostDelayedTask(
+ PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostDelayedTask(
FROM_HERE,
base::Bind(callback.func, callback.user_data, result),
base::TimeDelta::FromMilliseconds(delay_in_msec));
@@ -190,7 +184,8 @@ void CallOnMainThread(int delay_in_msec,
}
PP_Bool IsMainThread() {
- return BoolToPPBool(GetMainThreadMessageLoop()->BelongsToCurrentThread());
+ return BoolToPPBool(PpapiGlobals::Get()->
+ GetMainThreadMessageLoop()->BelongsToCurrentThread());
}
const PPB_Core core_interface = {
@@ -427,7 +422,8 @@ PluginModule::PluginModule(const std::string& name,
memset(&entry_points_, 0, sizeof(entry_points_));
pp_module_ = HostGlobals::Get()->AddModule(this);
- GetMainThreadMessageLoop(); // Initialize the main thread message loop.
+ // Initialize the main thread message loop.
+ PpapiGlobals::Get()->GetMainThreadMessageLoop();
GetLivePluginSet()->insert(this);
}
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index 3b6f263..96a08ad 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -107,6 +107,7 @@ using ppapi::PPB_View_Shared;
using ppapi::PPP_Instance_Combined;
using ppapi::ScopedPPResource;
using ppapi::StringVar;
+using ppapi::TrackedCallback;
using ppapi::thunk::EnterResourceNoLock;
using ppapi::thunk::PPB_Buffer_API;
using ppapi::thunk::PPB_Graphics2D_API;
@@ -350,7 +351,6 @@ PluginInstance::PluginInstance(
text_input_caret_set_(false),
selection_caret_(0),
selection_anchor_(0),
- lock_mouse_callback_(PP_BlockUntilComplete()),
pending_user_gesture_(0.0),
flash_impl_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
pp_instance_ = HostGlobals::Get()->AddInstance(this);
@@ -378,8 +378,8 @@ PluginInstance::~PluginInstance() {
i != plugin_object_copy.end(); ++i)
delete *i;
- if (lock_mouse_callback_.func)
- PP_RunAndClearCompletionCallback(&lock_mouse_callback_, PP_ERROR_ABORTED);
+ if (lock_mouse_callback_)
+ TrackedCallback::ClearAndAbort(&lock_mouse_callback_);
delegate_->InstanceDeleted(this);
module_->InstanceDeleted(this);
@@ -1595,12 +1595,12 @@ bool PluginInstance::IsProcessingUserGesture() {
}
void PluginInstance::OnLockMouseACK(bool succeeded) {
- if (!lock_mouse_callback_.func) {
+ if (TrackedCallback::IsPending(lock_mouse_callback_)) {
NOTREACHED();
return;
}
- PP_RunAndClearCompletionCallback(&lock_mouse_callback_,
- succeeded ? PP_OK : PP_ERROR_FAILED);
+ TrackedCallback::ClearAndRun(&lock_mouse_callback_,
+ succeeded ? PP_OK : PP_ERROR_FAILED);
}
void PluginInstance::OnMouseLockLost() {
@@ -1954,12 +1954,8 @@ PP_Bool PluginInstance::SetCursor(PP_Instance instance,
}
int32_t PluginInstance::LockMouse(PP_Instance instance,
- PP_CompletionCallback callback) {
- if (!callback.func) {
- // Don't support synchronous call.
- return PP_ERROR_BLOCKS_MAIN_THREAD;
- }
- if (lock_mouse_callback_.func) // A lock is pending.
+ scoped_refptr<TrackedCallback> callback) {
+ if (TrackedCallback::IsPending(lock_mouse_callback_))
return PP_ERROR_INPROGRESS;
if (delegate()->IsMouseLocked(this))
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h
index 7ae152a..7250e88 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.h
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h
@@ -37,6 +37,7 @@
#include "ppapi/c/private/ppp_instance_private.h"
#include "ppapi/shared_impl/ppb_instance_shared.h"
#include "ppapi/shared_impl/ppb_view_shared.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCanvas.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
@@ -371,8 +372,9 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance :
PP_MouseCursor_Type type,
PP_Resource image,
const PP_Point* hot_spot) OVERRIDE;
- virtual int32_t LockMouse(PP_Instance instance,
- PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t LockMouse(
+ PP_Instance instance,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
virtual void UnlockMouse(PP_Instance instance) OVERRIDE;
virtual PP_Bool GetDefaultPrintSettings(
PP_Instance instance,
@@ -646,7 +648,7 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance :
size_t selection_caret_;
size_t selection_anchor_;
- PP_CompletionCallback lock_mouse_callback_;
+ scoped_refptr< ::ppapi::TrackedCallback> lock_mouse_callback_;
// Track pending user gestures so out-of-process plugins can respond to
// a user gesture after it has been processed.
diff --git a/webkit/plugins/ppapi/ppb_audio_impl.cc b/webkit/plugins/ppapi/ppb_audio_impl.cc
index f5b64ad..7024aea 100644
--- a/webkit/plugins/ppapi/ppb_audio_impl.cc
+++ b/webkit/plugins/ppapi/ppb_audio_impl.cc
@@ -112,8 +112,9 @@ PP_Bool PPB_Audio_Impl::StopPlayback() {
return PP_TRUE;
}
-int32_t PPB_Audio_Impl::OpenTrusted(PP_Resource config,
- PP_CompletionCallback create_callback) {
+int32_t PPB_Audio_Impl::OpenTrusted(
+ PP_Resource config,
+ scoped_refptr<TrackedCallback> create_callback) {
// Validate the config and keep a reference to it.
EnterResourceNoLock<PPB_AudioConfig_API> enter(config, true);
if (enter.failed())
@@ -135,7 +136,7 @@ int32_t PPB_Audio_Impl::OpenTrusted(PP_Resource config,
// At this point, we are guaranteeing ownership of the completion
// callback. Audio promises to fire the completion callback
// once and only once.
- SetCreateCallback(new TrackedCallback(this, create_callback));
+ SetCreateCallback(create_callback);
return PP_OK_COMPLETIONPENDING;
}
diff --git a/webkit/plugins/ppapi/ppb_audio_impl.h b/webkit/plugins/ppapi/ppb_audio_impl.h
index 19acfc3..be41e36 100644
--- a/webkit/plugins/ppapi/ppb_audio_impl.h
+++ b/webkit/plugins/ppapi/ppb_audio_impl.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.
@@ -57,8 +57,9 @@ class PPB_Audio_Impl : public ::ppapi::Resource,
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 OpenTrusted(
+ PP_Resource config_id,
+ scoped_refptr< ::ppapi::TrackedCallback> create_callback) OVERRIDE;
virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE;
virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE;
diff --git a/webkit/plugins/ppapi/ppb_audio_input_impl.cc b/webkit/plugins/ppapi/ppb_audio_input_impl.cc
index fe1036d..3b4d609 100644
--- a/webkit/plugins/ppapi/ppb_audio_input_impl.cc
+++ b/webkit/plugins/ppapi/ppb_audio_input_impl.cc
@@ -42,7 +42,7 @@ PP_Resource PPB_AudioInput_Impl::Create0_1(
audio_input(new PPB_AudioInput_Impl(instance));
int32_t result = audio_input->Open(
"", config, audio_input_callback, user_data,
- MakeIgnoredCompletionCallback());
+ MakeIgnoredCompletionCallback(audio_input.get()));
if (result != PP_OK && result != PP_OK_COMPLETIONPENDING)
return 0;
return audio_input->GetReference();
@@ -51,7 +51,7 @@ PP_Resource PPB_AudioInput_Impl::Create0_1(
int32_t PPB_AudioInput_Impl::OpenTrusted(
const std::string& device_id,
PP_Resource config,
- const PP_CompletionCallback& create_callback) {
+ scoped_refptr<TrackedCallback> create_callback) {
return CommonOpen(device_id, config, NULL, NULL, create_callback);
}
@@ -104,13 +104,13 @@ void PPB_AudioInput_Impl::StreamCreationFailed() {
int32_t PPB_AudioInput_Impl::InternalEnumerateDevices(
PP_Resource* devices,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
if (!plugin_delegate)
return PP_ERROR_FAILED;
devices_ = devices;
- enumerate_devices_callback_ = new TrackedCallback(this, callback);
+ enumerate_devices_callback_ = callback;
plugin_delegate->EnumerateDevices(
PP_DEVICETYPE_DEV_AUDIOCAPTURE,
base::Bind(&PPB_AudioInput_Impl::EnumerateDevicesCallbackFunc,
@@ -118,10 +118,11 @@ int32_t PPB_AudioInput_Impl::InternalEnumerateDevices(
return PP_OK_COMPLETIONPENDING;
}
-int32_t PPB_AudioInput_Impl::InternalOpen(const std::string& device_id,
- PP_AudioSampleRate sample_rate,
- uint32_t sample_frame_count,
- PP_CompletionCallback callback) {
+int32_t PPB_AudioInput_Impl::InternalOpen(
+ const std::string& device_id,
+ PP_AudioSampleRate sample_rate,
+ uint32_t sample_frame_count,
+ scoped_refptr<TrackedCallback> callback) {
PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
if (!plugin_delegate)
return PP_ERROR_FAILED;
@@ -131,7 +132,7 @@ int32_t PPB_AudioInput_Impl::InternalOpen(const std::string& device_id,
audio_input_ = plugin_delegate->CreateAudioInput(
device_id, sample_rate, sample_frame_count, this);
if (audio_input_) {
- open_callback_ = new TrackedCallback(this, callback);
+ open_callback_ = callback;
return PP_OK_COMPLETIONPENDING;
} else {
return PP_ERROR_FAILED;
diff --git a/webkit/plugins/ppapi/ppb_audio_input_impl.h b/webkit/plugins/ppapi/ppb_audio_input_impl.h
index 186a148..d7a1e0c 100644
--- a/webkit/plugins/ppapi/ppb_audio_input_impl.h
+++ b/webkit/plugins/ppapi/ppb_audio_input_impl.h
@@ -39,7 +39,7 @@ class PPB_AudioInput_Impl : public ::ppapi::PPB_AudioInput_Shared,
virtual int32_t OpenTrusted(
const std::string& device_id,
PP_Resource config,
- const PP_CompletionCallback& create_callback) OVERRIDE;
+ scoped_refptr< ::ppapi::TrackedCallback> create_callback) OVERRIDE;
virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE;
virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE;
virtual const DeviceRefDataVector& GetDeviceRefData() const OVERRIDE;
@@ -54,11 +54,12 @@ class PPB_AudioInput_Impl : public ::ppapi::PPB_AudioInput_Shared,
// PPB_AudioInput_Shared implementation.
virtual int32_t InternalEnumerateDevices(
PP_Resource* devices,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t InternalOpen(const std::string& device_id,
- PP_AudioSampleRate sample_rate,
- uint32_t sample_frame_count,
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
+ virtual int32_t InternalOpen(
+ const std::string& device_id,
+ PP_AudioSampleRate sample_rate,
+ uint32_t sample_frame_count,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
virtual PP_Bool InternalStartCapture() OVERRIDE;
virtual PP_Bool InternalStopCapture() OVERRIDE;
virtual void InternalClose() OVERRIDE;
diff --git a/webkit/plugins/ppapi/ppb_broker_impl.cc b/webkit/plugins/ppapi/ppb_broker_impl.cc
index 289b173..2386e0d 100644
--- a/webkit/plugins/ppapi/ppb_broker_impl.cc
+++ b/webkit/plugins/ppapi/ppb_broker_impl.cc
@@ -40,12 +40,8 @@ PPB_Broker_API* PPB_Broker_Impl::AsPPB_Broker_API() {
return this;
}
-int32_t PPB_Broker_Impl::Connect(PP_CompletionCallback connect_callback) {
- if (!connect_callback.func) {
- // Synchronous calls are not supported.
- return PP_ERROR_BLOCKS_MAIN_THREAD;
- }
-
+int32_t PPB_Broker_Impl::Connect(
+ scoped_refptr<TrackedCallback> connect_callback) {
// TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process.
if (broker_) {
@@ -61,7 +57,7 @@ int32_t PPB_Broker_Impl::Connect(PP_CompletionCallback connect_callback) {
// and BrokerConnected is called before ConnectToBroker returns.
// Because it must be created now, it must be aborted and cleared if
// ConnectToBroker fails.
- connect_callback_ = new TrackedCallback(this, connect_callback);
+ connect_callback_ = connect_callback;
broker_ = plugin_instance->delegate()->ConnectToBroker(this);
if (!broker_) {
diff --git a/webkit/plugins/ppapi/ppb_broker_impl.h b/webkit/plugins/ppapi/ppb_broker_impl.h
index 51b5f00..6799c4f 100644
--- a/webkit/plugins/ppapi/ppb_broker_impl.h
+++ b/webkit/plugins/ppapi/ppb_broker_impl.h
@@ -32,7 +32,8 @@ class WEBKIT_PLUGINS_EXPORT PPB_Broker_Impl
virtual ::ppapi::thunk::PPB_Broker_API* AsPPB_Broker_API() OVERRIDE;
// PPB_BrokerTrusted implementation.
- virtual int32_t Connect(PP_CompletionCallback connect_callback) OVERRIDE;
+ virtual int32_t Connect(
+ scoped_refptr< ::ppapi::TrackedCallback> connect_callback) OVERRIDE;
virtual int32_t GetHandle(int32_t* handle) OVERRIDE;
void BrokerConnected(int32_t handle, int32_t result);
diff --git a/webkit/plugins/ppapi/ppb_directory_reader_impl.cc b/webkit/plugins/ppapi/ppb_directory_reader_impl.cc
index 2f38121..ec1315e 100644
--- a/webkit/plugins/ppapi/ppb_directory_reader_impl.cc
+++ b/webkit/plugins/ppapi/ppb_directory_reader_impl.cc
@@ -23,6 +23,7 @@
#include "webkit/plugins/ppapi/resource_helper.h"
using ::ppapi::PpapiGlobals;
+using ::ppapi::TrackedCallback;
using ::ppapi::thunk::EnterResourceNoLock;
using ::ppapi::thunk::PPB_DirectoryReader_API;
using ::ppapi::thunk::PPB_FileRef_API;
@@ -80,9 +81,7 @@ PPB_DirectoryReader_API* PPB_DirectoryReader_Impl::AsPPB_DirectoryReader_API() {
int32_t PPB_DirectoryReader_Impl::GetNextEntry(
PP_DirectoryEntry_Dev* entry,
- PP_CompletionCallback callback) {
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
+ scoped_refptr<TrackedCallback> callback) {
if (directory_ref_->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL)
return PP_ERROR_FAILED;
diff --git a/webkit/plugins/ppapi/ppb_directory_reader_impl.h b/webkit/plugins/ppapi/ppb_directory_reader_impl.h
index b7cae31..10d567a 100644
--- a/webkit/plugins/ppapi/ppb_directory_reader_impl.h
+++ b/webkit/plugins/ppapi/ppb_directory_reader_impl.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.
@@ -12,7 +12,6 @@
#include "ppapi/shared_impl/resource.h"
#include "ppapi/thunk/ppb_directory_reader_api.h"
-struct PP_CompletionCallback;
struct PP_DirectoryEntry_Dev;
namespace webkit {
@@ -34,8 +33,9 @@ class PPB_DirectoryReader_Impl
OVERRIDE;
// PPB_DirectoryReader_API implementation.
- virtual int32_t GetNextEntry(PP_DirectoryEntry_Dev* entry,
- PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t GetNextEntry(
+ PP_DirectoryEntry_Dev* entry,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
void AddNewEntries(const std::vector<base::FileUtilProxy::Entry>& entries,
bool has_more);
diff --git a/webkit/plugins/ppapi/ppb_file_chooser_impl.cc b/webkit/plugins/ppapi/ppb_file_chooser_impl.cc
index a40d694..40ef147 100644
--- a/webkit/plugins/ppapi/ppb_file_chooser_impl.cc
+++ b/webkit/plugins/ppapi/ppb_file_chooser_impl.cc
@@ -165,11 +165,7 @@ void PPB_FileChooser_Impl::StoreChosenFiles(
}
int32_t PPB_FileChooser_Impl::ValidateCallback(
- const PP_CompletionCallback& callback) {
- // We only support non-blocking calls.
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
-
+ scoped_refptr<TrackedCallback> callback) {
if (TrackedCallback::IsPending(callback_))
return PP_ERROR_INPROGRESS;
@@ -177,15 +173,14 @@ int32_t PPB_FileChooser_Impl::ValidateCallback(
}
void PPB_FileChooser_Impl::RegisterCallback(
- const PP_CompletionCallback& callback) {
- DCHECK(callback.func);
+ scoped_refptr<TrackedCallback> callback) {
DCHECK(!TrackedCallback::IsPending(callback_));
PluginModule* plugin_module = ResourceHelper::GetPluginModule(this);
if (!plugin_module)
return;
- callback_ = new TrackedCallback(this, callback);
+ callback_ = callback;
}
void PPB_FileChooser_Impl::RunCallback(int32_t result) {
@@ -193,7 +188,7 @@ void PPB_FileChooser_Impl::RunCallback(int32_t result) {
}
int32_t PPB_FileChooser_Impl::Show(const PP_ArrayOutput& output,
- const PP_CompletionCallback& callback) {
+ scoped_refptr<TrackedCallback> callback) {
int32_t result = Show0_5(callback);
if (result == PP_OK_COMPLETIONPENDING)
output_.set_pp_array_output(output);
@@ -204,7 +199,7 @@ int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture(
PP_Bool save_as,
PP_Var suggested_file_name,
const PP_ArrayOutput& output,
- const PP_CompletionCallback& callback) {
+ scoped_refptr<TrackedCallback> callback) {
int32_t result = ShowWithoutUserGesture0_5(save_as, suggested_file_name,
callback);
if (result == PP_OK_COMPLETIONPENDING)
@@ -212,7 +207,7 @@ int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture(
return result;
}
-int32_t PPB_FileChooser_Impl::Show0_5(const PP_CompletionCallback& callback) {
+int32_t PPB_FileChooser_Impl::Show0_5(scoped_refptr<TrackedCallback> callback) {
PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
if (!plugin_instance)
return PP_ERROR_FAILED;
@@ -224,7 +219,7 @@ int32_t PPB_FileChooser_Impl::Show0_5(const PP_CompletionCallback& callback) {
int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture0_5(
PP_Bool save_as,
PP_Var suggested_file_name,
- const PP_CompletionCallback& callback) {
+ scoped_refptr<TrackedCallback> callback) {
int32_t rv = ValidateCallback(callback);
if (rv != PP_OK)
return rv;
diff --git a/webkit/plugins/ppapi/ppb_file_chooser_impl.h b/webkit/plugins/ppapi/ppb_file_chooser_impl.h
index 396c583..59de2ac 100644
--- a/webkit/plugins/ppapi/ppb_file_chooser_impl.h
+++ b/webkit/plugins/ppapi/ppb_file_chooser_impl.h
@@ -16,8 +16,6 @@
#include "ppapi/thunk/ppb_file_chooser_api.h"
#include "webkit/plugins/webkit_plugins_export.h"
-struct PP_CompletionCallback;
-
namespace ppapi {
class TrackedCallback;
}
@@ -63,28 +61,30 @@ class PPB_FileChooser_Impl : public ::ppapi::Resource,
// Check that |callback| is valid (only non-blocking operation is supported)
// and that no callback is already pending. Returns |PP_OK| if okay, else
// |PP_ERROR_...| to be returned to the plugin.
- int32_t ValidateCallback(const PP_CompletionCallback& callback);
+ int32_t ValidateCallback(scoped_refptr< ::ppapi::TrackedCallback> callback);
// Sets up |callback| as the pending callback. This should only be called once
// it is certain that |PP_OK_COMPLETIONPENDING| will be returned.
- void RegisterCallback(const PP_CompletionCallback& callback);
+ void RegisterCallback(scoped_refptr< ::ppapi::TrackedCallback> callback);
void RunCallback(int32_t result);
// PPB_FileChooser_API implementation.
- virtual int32_t Show(const PP_ArrayOutput& output,
- const PP_CompletionCallback& callback) OVERRIDE;
+ virtual int32_t Show(
+ const PP_ArrayOutput& output,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
virtual int32_t ShowWithoutUserGesture(
PP_Bool save_as,
PP_Var suggested_file_name,
const PP_ArrayOutput& output,
- const PP_CompletionCallback& callback);
- virtual int32_t Show0_5(const PP_CompletionCallback& callback) OVERRIDE;
+ scoped_refptr< ::ppapi::TrackedCallback> callback);
+ virtual int32_t Show0_5(
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
virtual PP_Resource GetNextChosenFile() OVERRIDE;
virtual int32_t ShowWithoutUserGesture0_5(
PP_Bool save_as,
PP_Var suggested_file_name,
- const PP_CompletionCallback& callback) OVERRIDE;
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
// Splits a comma-separated MIME type/extension list |accept_types|, trims the
// resultant split types, makes them lowercase, and returns them.
diff --git a/webkit/plugins/ppapi/ppb_file_io_impl.cc b/webkit/plugins/ppapi/ppb_file_io_impl.cc
index 7fa69bc..d102270 100644
--- a/webkit/plugins/ppapi/ppb_file_io_impl.cc
+++ b/webkit/plugins/ppapi/ppb_file_io_impl.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.
@@ -29,6 +29,7 @@
using ppapi::PPTimeToTime;
using ppapi::TimeToPPTime;
+using ppapi::TrackedCallback;
using ppapi::thunk::PPB_FileRef_API;
namespace webkit {
@@ -44,10 +45,11 @@ PPB_FileIO_Impl::~PPB_FileIO_Impl() {
Close();
}
-int32_t PPB_FileIO_Impl::OpenValidated(PP_Resource file_ref_resource,
- PPB_FileRef_API* file_ref_api,
- int32_t open_flags,
- PP_CompletionCallback callback) {
+int32_t PPB_FileIO_Impl::OpenValidated(
+ PP_Resource file_ref_resource,
+ PPB_FileRef_API* file_ref_api,
+ int32_t open_flags,
+ scoped_refptr<TrackedCallback> callback) {
PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api);
int flags = 0;
@@ -79,8 +81,9 @@ int32_t PPB_FileIO_Impl::OpenValidated(PP_Resource file_ref_resource,
return PP_OK_COMPLETIONPENDING;
}
-int32_t PPB_FileIO_Impl::QueryValidated(PP_FileInfo* info,
- PP_CompletionCallback callback) {
+int32_t PPB_FileIO_Impl::QueryValidated(
+ PP_FileInfo* info,
+ scoped_refptr<TrackedCallback> callback) {
PluginDelegate* plugin_delegate = GetPluginDelegate();
if (!plugin_delegate)
return PP_ERROR_FAILED;
@@ -95,9 +98,10 @@ int32_t PPB_FileIO_Impl::QueryValidated(PP_FileInfo* info,
return PP_OK_COMPLETIONPENDING;
}
-int32_t PPB_FileIO_Impl::TouchValidated(PP_Time last_access_time,
- PP_Time last_modified_time,
- PP_CompletionCallback callback) {
+int32_t PPB_FileIO_Impl::TouchValidated(
+ PP_Time last_access_time,
+ PP_Time last_modified_time,
+ scoped_refptr<TrackedCallback> callback) {
PluginDelegate* plugin_delegate = GetPluginDelegate();
if (!plugin_delegate)
return PP_ERROR_FAILED;
@@ -114,10 +118,11 @@ int32_t PPB_FileIO_Impl::TouchValidated(PP_Time last_access_time,
return PP_OK_COMPLETIONPENDING;
}
-int32_t PPB_FileIO_Impl::ReadValidated(int64_t offset,
- char* buffer,
- int32_t bytes_to_read,
- PP_CompletionCallback callback) {
+int32_t PPB_FileIO_Impl::ReadValidated(
+ int64_t offset,
+ char* buffer,
+ int32_t bytes_to_read,
+ scoped_refptr<TrackedCallback> callback) {
PluginDelegate* plugin_delegate = GetPluginDelegate();
if (!plugin_delegate)
return PP_ERROR_FAILED;
@@ -133,10 +138,11 @@ int32_t PPB_FileIO_Impl::ReadValidated(int64_t offset,
return PP_OK_COMPLETIONPENDING;
}
-int32_t PPB_FileIO_Impl::WriteValidated(int64_t offset,
- const char* buffer,
- int32_t bytes_to_write,
- PP_CompletionCallback callback) {
+int32_t PPB_FileIO_Impl::WriteValidated(
+ int64_t offset,
+ const char* buffer,
+ int32_t bytes_to_write,
+ scoped_refptr<TrackedCallback> callback) {
PluginDelegate* plugin_delegate = GetPluginDelegate();
if (!plugin_delegate)
return PP_ERROR_FAILED;
@@ -160,8 +166,9 @@ int32_t PPB_FileIO_Impl::WriteValidated(int64_t offset,
return PP_OK_COMPLETIONPENDING;
}
-int32_t PPB_FileIO_Impl::SetLengthValidated(int64_t length,
- PP_CompletionCallback callback) {
+int32_t PPB_FileIO_Impl::SetLengthValidated(
+ int64_t length,
+ scoped_refptr<TrackedCallback> callback) {
PluginDelegate* plugin_delegate = GetPluginDelegate();
if (!plugin_delegate)
return PP_ERROR_FAILED;
@@ -184,7 +191,8 @@ int32_t PPB_FileIO_Impl::SetLengthValidated(int64_t length,
return PP_OK_COMPLETIONPENDING;
}
-int32_t PPB_FileIO_Impl::FlushValidated(PP_CompletionCallback callback) {
+int32_t PPB_FileIO_Impl::FlushValidated(
+ scoped_refptr<TrackedCallback> callback) {
PluginDelegate* plugin_delegate = GetPluginDelegate();
if (!plugin_delegate)
return PP_ERROR_FAILED;
@@ -222,8 +230,8 @@ int32_t PPB_FileIO_Impl::GetOSFileDescriptor() {
int32_t PPB_FileIO_Impl::WillWrite(int64_t offset,
int32_t bytes_to_write,
- PP_CompletionCallback callback) {
- int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE, callback);
+ scoped_refptr<TrackedCallback> callback) {
+ int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE);
if (rv != PP_OK)
return rv;
@@ -240,9 +248,10 @@ int32_t PPB_FileIO_Impl::WillWrite(int64_t offset,
return PP_OK_COMPLETIONPENDING;
}
-int32_t PPB_FileIO_Impl::WillSetLength(int64_t length,
- PP_CompletionCallback callback) {
- int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE, callback);
+int32_t PPB_FileIO_Impl::WillSetLength(
+ int64_t length,
+ scoped_refptr<TrackedCallback> callback) {
+ int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE);
if (rv != PP_OK)
return rv;
diff --git a/webkit/plugins/ppapi/ppb_file_io_impl.h b/webkit/plugins/ppapi/ppb_file_io_impl.h
index 27353c6..2298d87 100644
--- a/webkit/plugins/ppapi/ppb_file_io_impl.h
+++ b/webkit/plugins/ppapi/ppb_file_io_impl.h
@@ -13,8 +13,6 @@
#include "ppapi/shared_impl/ppb_file_io_shared.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"
-struct PP_CompletionCallback;
-
namespace webkit {
namespace ppapi {
@@ -29,34 +27,43 @@ class PPB_FileIO_Impl : public ::ppapi::PPB_FileIO_Shared {
// as the "Validated" versions below).
virtual void Close() OVERRIDE;
virtual int32_t GetOSFileDescriptor() OVERRIDE;
- virtual int32_t WillWrite(int64_t offset,
- int32_t bytes_to_write,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t WillSetLength(int64_t length,
- PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t WillWrite(
+ int64_t offset,
+ int32_t bytes_to_write,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
+ virtual int32_t WillSetLength(
+ int64_t length,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
private:
// FileIOImpl overrides.
- virtual int32_t OpenValidated(PP_Resource file_ref_resource,
- ::ppapi::thunk::PPB_FileRef_API* file_ref_api,
- int32_t open_flags,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t QueryValidated(PP_FileInfo* info,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t TouchValidated(PP_Time last_access_time,
- PP_Time last_modified_time,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t ReadValidated(int64_t offset,
- char* buffer,
- int32_t bytes_to_read,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t WriteValidated(int64_t offset,
- const char* buffer,
- int32_t bytes_to_write,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t SetLengthValidated(int64_t length,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t FlushValidated(PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t OpenValidated(
+ PP_Resource file_ref_resource,
+ ::ppapi::thunk::PPB_FileRef_API* file_ref_api,
+ int32_t open_flags,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
+ virtual int32_t QueryValidated(
+ PP_FileInfo* info,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
+ virtual int32_t TouchValidated(
+ PP_Time last_access_time,
+ PP_Time last_modified_time,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
+ virtual int32_t ReadValidated(
+ int64_t offset,
+ char* buffer,
+ int32_t bytes_to_read,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
+ virtual int32_t WriteValidated(
+ int64_t offset,
+ const char* buffer,
+ int32_t bytes_to_write,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
+ virtual int32_t SetLengthValidated(
+ int64_t length,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
+ virtual int32_t FlushValidated(
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
// Returns the plugin delegate for this resource if it exists, or NULL if it
// doesn't. Calling code should always check for NULL.
diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.cc b/webkit/plugins/ppapi/ppb_file_ref_impl.cc
index 48115e5..a3864f8 100644
--- a/webkit/plugins/ppapi/ppb_file_ref_impl.cc
+++ b/webkit/plugins/ppapi/ppb_file_ref_impl.cc
@@ -25,6 +25,7 @@ using ppapi::HostResource;
using ppapi::PPB_FileRef_CreateInfo;
using ppapi::PPTimeToTime;
using ppapi::StringVar;
+using ppapi::TrackedCallback;
using ppapi::thunk::EnterResourceNoLock;
using ppapi::thunk::PPB_FileRef_API;
using ppapi::thunk::PPB_FileSystem_API;
@@ -165,10 +166,9 @@ PP_Resource PPB_FileRef_Impl::GetParent() {
return parent_ref->GetReference();
}
-int32_t PPB_FileRef_Impl::MakeDirectory(PP_Bool make_ancestors,
- PP_CompletionCallback callback) {
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
+int32_t PPB_FileRef_Impl::MakeDirectory(
+ PP_Bool make_ancestors,
+ scoped_refptr<TrackedCallback> callback) {
if (!IsValidNonExternalFileSystem())
return PP_ERROR_NOACCESS;
@@ -184,9 +184,7 @@ int32_t PPB_FileRef_Impl::MakeDirectory(PP_Bool make_ancestors,
int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time,
PP_Time last_modified_time,
- PP_CompletionCallback callback) {
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
+ scoped_refptr<TrackedCallback> callback) {
if (!IsValidNonExternalFileSystem())
return PP_ERROR_NOACCESS;
@@ -202,9 +200,7 @@ int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time,
return PP_OK_COMPLETIONPENDING;
}
-int32_t PPB_FileRef_Impl::Delete(PP_CompletionCallback callback) {
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
+int32_t PPB_FileRef_Impl::Delete(scoped_refptr<TrackedCallback> callback) {
if (!IsValidNonExternalFileSystem())
return PP_ERROR_NOACCESS;
@@ -219,9 +215,7 @@ int32_t PPB_FileRef_Impl::Delete(PP_CompletionCallback callback) {
}
int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref,
- PP_CompletionCallback callback) {
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
+ scoped_refptr<TrackedCallback> callback) {
EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true);
if (enter.failed())
return PP_ERROR_BADRESOURCE;
diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.h b/webkit/plugins/ppapi/ppb_file_ref_impl.h
index 91d1551..9b33758 100644
--- a/webkit/plugins/ppapi/ppb_file_ref_impl.h
+++ b/webkit/plugins/ppapi/ppb_file_ref_impl.h
@@ -39,14 +39,18 @@ class PPB_FileRef_Impl : public ::ppapi::PPB_FileRef_Shared {
// PPB_FileRef_API implementation (not provided by PPB_FileRef_Shared).
virtual PP_Resource GetParent() OVERRIDE;
- virtual int32_t MakeDirectory(PP_Bool make_ancestors,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t Touch(PP_Time last_access_time,
- PP_Time last_modified_time,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t Delete(PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t Rename(PP_Resource new_file_ref,
- PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t MakeDirectory(
+ PP_Bool make_ancestors,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
+ virtual int32_t Touch(
+ PP_Time last_access_time,
+ PP_Time last_modified_time,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
+ virtual int32_t Delete(
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
+ virtual int32_t Rename(
+ PP_Resource new_file_ref,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
virtual PP_Var GetAbsolutePath();
PPB_FileSystem_Impl* file_system() const { return file_system_.get(); }
diff --git a/webkit/plugins/ppapi/ppb_file_system_impl.cc b/webkit/plugins/ppapi/ppb_file_system_impl.cc
index 9428e3a..ae9edeb 100644
--- a/webkit/plugins/ppapi/ppb_file_system_impl.cc
+++ b/webkit/plugins/ppapi/ppb_file_system_impl.cc
@@ -21,6 +21,7 @@
#include "webkit/plugins/ppapi/resource_helper.h"
using ppapi::thunk::PPB_FileSystem_API;
+using ppapi::TrackedCallback;
namespace webkit {
namespace ppapi {
@@ -52,10 +53,7 @@ PPB_FileSystem_API* PPB_FileSystem_Impl::AsPPB_FileSystem_API() {
}
int32_t PPB_FileSystem_Impl::Open(int64_t expected_size,
- PP_CompletionCallback callback) {
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
-
+ scoped_refptr<TrackedCallback> callback) {
// Should not allow multiple opens.
if (called_open_)
return PP_ERROR_INPROGRESS;
@@ -81,10 +79,10 @@ int32_t PPB_FileSystem_Impl::Open(int64_t expected_size,
return PP_ERROR_FAILED;
if (!plugin_instance->delegate()->OpenFileSystem(
- plugin_instance->container()->element().document().url(),
- file_system_type, expected_size,
- new FileCallbacks(this, callback, NULL,
- scoped_refptr<PPB_FileSystem_Impl>(this), NULL)))
+ plugin_instance->container()->element().document().url(),
+ file_system_type, expected_size,
+ new FileCallbacks(this, callback, NULL,
+ scoped_refptr<PPB_FileSystem_Impl>(this), NULL)))
return PP_ERROR_FAILED;
return PP_OK_COMPLETIONPENDING;
}
diff --git a/webkit/plugins/ppapi/ppb_file_system_impl.h b/webkit/plugins/ppapi/ppb_file_system_impl.h
index c963ce3..7864989 100644
--- a/webkit/plugins/ppapi/ppb_file_system_impl.h
+++ b/webkit/plugins/ppapi/ppb_file_system_impl.h
@@ -33,8 +33,9 @@ class PPB_FileSystem_Impl : public ::ppapi::Resource,
void set_opened(bool opened) { opened_ = opened; }
// PPB_FileSystem_API implementation.
- virtual int32_t Open(int64_t expected_size,
- PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t Open(
+ int64_t expected_size,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
virtual PP_FileSystemType GetType() OVERRIDE;
private:
diff --git a/webkit/plugins/ppapi/ppb_flash_menu_impl.cc b/webkit/plugins/ppapi/ppb_flash_menu_impl.cc
index aa3f768..e0c405e 100644
--- a/webkit/plugins/ppapi/ppb_flash_menu_impl.cc
+++ b/webkit/plugins/ppapi/ppb_flash_menu_impl.cc
@@ -130,15 +130,12 @@ PPB_Flash_Menu_API* PPB_Flash_Menu_Impl::AsPPB_Flash_Menu_API() {
int32_t PPB_Flash_Menu_Impl::Show(const PP_Point* location,
int32_t* selected_id_out,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
// |location| is not (currently) optional.
// TODO(viettrungluu): Make it optional and default to the current mouse pos?
if (!location)
return PP_ERROR_BADARGUMENT;
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
-
if (TrackedCallback::IsPending(callback_))
return PP_ERROR_INPROGRESS;
@@ -150,16 +147,13 @@ int32_t PPB_Flash_Menu_Impl::Show(const PP_Point* location,
plugin_instance, this, gfx::Point(location->x, location->y));
if (rv == PP_OK_COMPLETIONPENDING) {
// Record callback and output buffers.
- callback_ = new TrackedCallback(this, callback);
+ callback_ = callback;
selected_id_out_ = selected_id_out;
} else {
// This should never be completed synchronously successfully.
DCHECK_NE(rv, PP_OK);
}
return rv;
-
- NOTIMPLEMENTED();
- return PP_ERROR_FAILED;
}
void PPB_Flash_Menu_Impl::CompleteShow(int32_t result,
diff --git a/webkit/plugins/ppapi/ppb_flash_menu_impl.h b/webkit/plugins/ppapi/ppb_flash_menu_impl.h
index 92daa64..33ce588 100644
--- a/webkit/plugins/ppapi/ppb_flash_menu_impl.h
+++ b/webkit/plugins/ppapi/ppb_flash_menu_impl.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.
@@ -34,9 +34,10 @@ class PPB_Flash_Menu_Impl : public ::ppapi::Resource,
virtual ::ppapi::thunk::PPB_Flash_Menu_API* AsPPB_Flash_Menu_API() OVERRIDE;
// PPB_Flash_Menu implementation.
- virtual int32_t Show(const PP_Point* location,
- int32_t* selected_id_out,
- PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t Show(
+ const PP_Point* location,
+ int32_t* selected_id_out,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
// Called to complete |Show()|.
WEBKIT_PLUGINS_EXPORT void CompleteShow(int32_t result, unsigned action);
diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
index 3a6a1a8..69ac176 100644
--- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
+++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
@@ -314,11 +314,8 @@ void PPB_Graphics2D_Impl::ReplaceContents(PP_Resource image_data) {
queued_operations_.push_back(operation);
}
-int32_t PPB_Graphics2D_Impl::Flush(PP_CompletionCallback callback) {
+int32_t PPB_Graphics2D_Impl::Flush(scoped_refptr<TrackedCallback> callback) {
TRACE_EVENT0("pepper", "PPB_Graphics2D_Impl::Flush");
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
-
// Don't allow more than one pending flush at a time.
if (HasPendingFlush())
return PP_ERROR_INPROGRESS;
@@ -374,11 +371,9 @@ int32_t PPB_Graphics2D_Impl::Flush(PP_CompletionCallback callback) {
if (nothing_visible) {
// There's nothing visible to invalidate so just schedule the callback to
// execute in the next round of the message loop.
- ScheduleOffscreenCallback(FlushCallbackData(
- scoped_refptr<TrackedCallback>(new TrackedCallback(this, callback))));
+ ScheduleOffscreenCallback(FlushCallbackData(callback));
} else {
- unpainted_flush_callback_.Set(
- scoped_refptr<TrackedCallback>(new TrackedCallback(this, callback)));
+ unpainted_flush_callback_.Set(callback);
}
return PP_OK_COMPLETIONPENDING;
}
diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.h b/webkit/plugins/ppapi/ppb_graphics_2d_impl.h
index 3b8ce9a..69e0f96 100644
--- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.h
+++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.h
@@ -49,7 +49,8 @@ class PPB_Graphics2D_Impl : public ::ppapi::Resource,
virtual void Scroll(const PP_Rect* clip_rect,
const PP_Point* amount) OVERRIDE;
virtual void ReplaceContents(PP_Resource image_data) OVERRIDE;
- virtual int32_t Flush(PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t Flush(
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
bool ReadImageData(PP_Resource image, const PP_Point* top_left);
diff --git a/webkit/plugins/ppapi/ppb_layer_compositor_impl.cc b/webkit/plugins/ppapi/ppb_layer_compositor_impl.cc
index 542feb1..32b859a 100644
--- a/webkit/plugins/ppapi/ppb_layer_compositor_impl.cc
+++ b/webkit/plugins/ppapi/ppb_layer_compositor_impl.cc
@@ -5,8 +5,10 @@
#include "webkit/plugins/ppapi/ppb_layer_compositor_impl.h"
#include "ppapi/c/pp_errors.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "webkit/plugins/ppapi/common.h"
+using ppapi::TrackedCallback;
using ppapi::thunk::PPB_LayerCompositor_API;
namespace webkit {
@@ -45,7 +47,8 @@ void PPB_LayerCompositor_Impl::SetDisplay(PP_Resource layer,
void PPB_LayerCompositor_Impl::MarkAsDirty(PP_Resource layer) {
}
-int32_t PPB_LayerCompositor_Impl::SwapBuffers(PP_CompletionCallback callback) {
+int32_t PPB_LayerCompositor_Impl::SwapBuffers(
+ scoped_refptr<TrackedCallback> callback) {
return PP_ERROR_FAILED;
}
diff --git a/webkit/plugins/ppapi/ppb_layer_compositor_impl.h b/webkit/plugins/ppapi/ppb_layer_compositor_impl.h
index b1e4cac..1ec1c0d 100644
--- a/webkit/plugins/ppapi/ppb_layer_compositor_impl.h
+++ b/webkit/plugins/ppapi/ppb_layer_compositor_impl.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.
@@ -33,7 +33,8 @@ class PPB_LayerCompositor_Impl
virtual void SetRect(PP_Resource layer, const PP_Rect* rect) OVERRIDE;
virtual void SetDisplay(PP_Resource layer, PP_Bool is_displayed) OVERRIDE;
virtual void MarkAsDirty(PP_Resource layer) OVERRIDE;
- virtual int32_t SwapBuffers(PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t SwapBuffers(
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(PPB_LayerCompositor_Impl);
diff --git a/webkit/plugins/ppapi/ppb_url_loader_impl.cc b/webkit/plugins/ppapi/ppb_url_loader_impl.cc
index 7e4fdef..efb36cc 100644
--- a/webkit/plugins/ppapi/ppb_url_loader_impl.cc
+++ b/webkit/plugins/ppapi/ppb_url_loader_impl.cc
@@ -96,7 +96,7 @@ void PPB_URLLoader_Impl::InstanceWasDeleted() {
}
int32_t PPB_URLLoader_Impl::Open(PP_Resource request_id,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
// Main document loads are already open, so don't allow people to open them
// again.
if (main_document_loader_)
@@ -172,7 +172,8 @@ int32_t PPB_URLLoader_Impl::Open(PP_Resource request_id,
return PP_OK_COMPLETIONPENDING;
}
-int32_t PPB_URLLoader_Impl::FollowRedirect(PP_CompletionCallback callback) {
+int32_t PPB_URLLoader_Impl::FollowRedirect(
+ scoped_refptr<TrackedCallback> callback) {
int32_t rv = ValidateCallback(callback);
if (rv != PP_OK)
return rv;
@@ -215,9 +216,10 @@ PP_Resource PPB_URLLoader_Impl::GetResponseInfo() {
return response_info_->GetReference();
}
-int32_t PPB_URLLoader_Impl::ReadResponseBody(void* buffer,
- int32_t bytes_to_read,
- PP_CompletionCallback callback) {
+int32_t PPB_URLLoader_Impl::ReadResponseBody(
+ void* buffer,
+ int32_t bytes_to_read,
+ scoped_refptr<TrackedCallback> callback) {
int32_t rv = ValidateCallback(callback);
if (rv != PP_OK)
return rv;
@@ -244,7 +246,7 @@ int32_t PPB_URLLoader_Impl::ReadResponseBody(void* buffer,
}
int32_t PPB_URLLoader_Impl::FinishStreamingToFile(
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
int32_t rv = ValidateCallback(callback);
if (rv != PP_OK)
return rv;
@@ -395,10 +397,9 @@ void PPB_URLLoader_Impl::FinishLoading(int32_t done_status) {
RunCallback(done_status_);
}
-int32_t PPB_URLLoader_Impl::ValidateCallback(PP_CompletionCallback callback) {
- // We only support non-blocking calls.
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
+int32_t PPB_URLLoader_Impl::ValidateCallback(
+ scoped_refptr<TrackedCallback> callback) {
+ DCHECK(callback);
if (TrackedCallback::IsPending(pending_callback_))
return PP_ERROR_INPROGRESS;
@@ -406,15 +407,15 @@ int32_t PPB_URLLoader_Impl::ValidateCallback(PP_CompletionCallback callback) {
return PP_OK;
}
-void PPB_URLLoader_Impl::RegisterCallback(PP_CompletionCallback callback) {
- DCHECK(callback.func);
+void PPB_URLLoader_Impl::RegisterCallback(
+ scoped_refptr<TrackedCallback> callback) {
DCHECK(!TrackedCallback::IsPending(pending_callback_));
PluginModule* plugin_module = ResourceHelper::GetPluginModule(this);
if (!plugin_module)
return;
- pending_callback_ = new TrackedCallback(this, callback);
+ pending_callback_ = callback;
}
void PPB_URLLoader_Impl::RunCallback(int32_t result) {
diff --git a/webkit/plugins/ppapi/ppb_url_loader_impl.h b/webkit/plugins/ppapi/ppb_url_loader_impl.h
index 948f928..38a1b52 100644
--- a/webkit/plugins/ppapi/ppb_url_loader_impl.h
+++ b/webkit/plugins/ppapi/ppb_url_loader_impl.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.
@@ -39,20 +39,23 @@ class PPB_URLLoader_Impl : public ::ppapi::Resource,
virtual void InstanceWasDeleted() OVERRIDE;
// PPB_URLLoader_API implementation.
- virtual int32_t Open(PP_Resource request_id,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t FollowRedirect(PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t Open(
+ PP_Resource request_id,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
+ virtual int32_t FollowRedirect(
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
virtual PP_Bool GetUploadProgress(int64_t* bytes_sent,
int64_t* total_bytes_to_be_sent) OVERRIDE;
virtual PP_Bool GetDownloadProgress(
int64_t* bytes_received,
int64_t* total_bytes_to_be_received) OVERRIDE;
virtual PP_Resource GetResponseInfo() OVERRIDE;
- virtual int32_t ReadResponseBody(void* buffer,
- int32_t bytes_to_read,
- PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t ReadResponseBody(
+ void* buffer,
+ int32_t bytes_to_read,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
virtual int32_t FinishStreamingToFile(
- PP_CompletionCallback callback) OVERRIDE;
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
virtual void Close() OVERRIDE;
virtual void GrantUniversalAccess() OVERRIDE;
virtual void SetStatusCallback(
@@ -89,11 +92,11 @@ class PPB_URLLoader_Impl : public ::ppapi::Resource,
// Check that |callback| is valid (only non-blocking operation is supported)
// and that no callback is already pending. Returns |PP_OK| if okay, else
// |PP_ERROR_...| to be returned to the plugin.
- int32_t ValidateCallback(PP_CompletionCallback callback);
+ int32_t ValidateCallback(scoped_refptr< ::ppapi::TrackedCallback> callback);
// Sets up |callback| as the pending callback. This should only be called once
// it is certain that |PP_OK_COMPLETIONPENDING| will be returned.
- void RegisterCallback(PP_CompletionCallback callback);
+ void RegisterCallback(scoped_refptr< ::ppapi::TrackedCallback> callback);
void RunCallback(int32_t result);
diff --git a/webkit/plugins/ppapi/ppb_video_capture_impl.cc b/webkit/plugins/ppapi/ppb_video_capture_impl.cc
index 9a00155..40612f0 100644
--- a/webkit/plugins/ppapi/ppb_video_capture_impl.cc
+++ b/webkit/plugins/ppapi/ppb_video_capture_impl.cc
@@ -173,13 +173,13 @@ void PPB_VideoCapture_Impl::OnInitialized(media::VideoCapture* capture,
int32_t PPB_VideoCapture_Impl::InternalEnumerateDevices(
PP_Resource* devices,
- const PP_CompletionCallback& callback) {
+ scoped_refptr<TrackedCallback> callback) {
PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
if (!instance)
return PP_ERROR_FAILED;
devices_ = devices;
- enumerate_devices_callback_ = new TrackedCallback(this, callback);
+ enumerate_devices_callback_ = callback;
instance->delegate()->EnumerateDevices(
PP_DEVICETYPE_DEV_VIDEOCAPTURE,
base::Bind(&PPB_VideoCapture_Impl::EnumerateDevicesCallbackFunc,
@@ -191,13 +191,10 @@ int32_t PPB_VideoCapture_Impl::InternalOpen(
const std::string& device_id,
const PP_VideoCaptureDeviceInfo_Dev& requested_info,
uint32_t buffer_count,
- const PP_CompletionCallback& callback) {
+ scoped_refptr<TrackedCallback> callback) {
// It is able to complete synchronously if the default device is used.
bool sync_completion = device_id.empty();
- if (!callback.func && !sync_completion)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
-
PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
if (!instance)
return PP_ERROR_FAILED;
@@ -212,7 +209,7 @@ int32_t PPB_VideoCapture_Impl::InternalOpen(
OnInitialized(platform_video_capture_.get(), true);
return PP_OK;
} else {
- open_callback_ = new TrackedCallback(this, callback);
+ open_callback_ = callback;
return PP_OK_COMPLETIONPENDING;
}
}
diff --git a/webkit/plugins/ppapi/ppb_video_capture_impl.h b/webkit/plugins/ppapi/ppb_video_capture_impl.h
index 8c77138..06e63aa 100644
--- a/webkit/plugins/ppapi/ppb_video_capture_impl.h
+++ b/webkit/plugins/ppapi/ppb_video_capture_impl.h
@@ -54,12 +54,12 @@ class PPB_VideoCapture_Impl
// PPB_VideoCapture_Shared implementation.
virtual int32_t InternalEnumerateDevices(
PP_Resource* devices,
- const PP_CompletionCallback& callback) OVERRIDE;
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
virtual int32_t InternalOpen(
const std::string& device_id,
const PP_VideoCaptureDeviceInfo_Dev& requested_info,
uint32_t buffer_count,
- const PP_CompletionCallback& callback) OVERRIDE;
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
virtual int32_t InternalStartCapture() OVERRIDE;
virtual int32_t InternalReuseBuffer(uint32_t buffer) OVERRIDE;
virtual int32_t InternalStopCapture() OVERRIDE;
diff --git a/webkit/plugins/ppapi/ppb_video_decoder_impl.cc b/webkit/plugins/ppapi/ppb_video_decoder_impl.cc
index ab0773c..9c63e13 100644
--- a/webkit/plugins/ppapi/ppb_video_decoder_impl.cc
+++ b/webkit/plugins/ppapi/ppb_video_decoder_impl.cc
@@ -24,6 +24,7 @@
#include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h"
#include "webkit/plugins/ppapi/resource_helper.h"
+using ppapi::TrackedCallback;
using ppapi::thunk::EnterResourceNoLock;
using ppapi::thunk::PPB_Buffer_API;
using ppapi::thunk::PPB_Graphics3D_API;
@@ -126,10 +127,7 @@ bool PPB_VideoDecoder_Impl::Init(
int32_t PPB_VideoDecoder_Impl::Decode(
const PP_VideoBitstreamBuffer_Dev* bitstream_buffer,
- PP_CompletionCallback callback) {
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
-
+ scoped_refptr<TrackedCallback> callback) {
if (!platform_video_decoder_)
return PP_ERROR_BADRESOURCE;
@@ -178,10 +176,7 @@ void PPB_VideoDecoder_Impl::ReusePictureBuffer(int32_t picture_buffer_id) {
platform_video_decoder_->ReusePictureBuffer(picture_buffer_id);
}
-int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) {
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
-
+int32_t PPB_VideoDecoder_Impl::Flush(scoped_refptr<TrackedCallback> callback) {
if (!platform_video_decoder_)
return PP_ERROR_BADRESOURCE;
@@ -193,10 +188,7 @@ int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) {
return PP_OK_COMPLETIONPENDING;
}
-int32_t PPB_VideoDecoder_Impl::Reset(PP_CompletionCallback callback) {
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
-
+int32_t PPB_VideoDecoder_Impl::Reset(scoped_refptr<TrackedCallback> callback) {
if (!platform_video_decoder_)
return PP_ERROR_BADRESOURCE;
diff --git a/webkit/plugins/ppapi/ppb_video_decoder_impl.h b/webkit/plugins/ppapi/ppb_video_decoder_impl.h
index 895874b3..f82f702 100644
--- a/webkit/plugins/ppapi/ppb_video_decoder_impl.h
+++ b/webkit/plugins/ppapi/ppb_video_decoder_impl.h
@@ -39,13 +39,16 @@ class PPB_VideoDecoder_Impl : public ::ppapi::PPB_VideoDecoder_Shared,
PP_VideoDecoder_Profile profile);
// PPB_VideoDecoder_API implementation.
- virtual int32_t Decode(const PP_VideoBitstreamBuffer_Dev* bitstream_buffer,
- PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t Decode(
+ const PP_VideoBitstreamBuffer_Dev* bitstream_buffer,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
virtual void AssignPictureBuffers(
uint32_t no_of_buffers, const PP_PictureBuffer_Dev* buffers) OVERRIDE;
virtual void ReusePictureBuffer(int32_t picture_buffer_id) OVERRIDE;
- virtual int32_t Flush(PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t Reset(PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t Flush(
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
+ virtual int32_t Reset(
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
virtual void Destroy() OVERRIDE;
// media::VideoDecodeAccelerator::Client implementation.
diff --git a/webkit/plugins/ppapi/ppb_websocket_impl.cc b/webkit/plugins/ppapi/ppb_websocket_impl.cc
index 8cdada8..bc9fae4 100644
--- a/webkit/plugins/ppapi/ppb_websocket_impl.cc
+++ b/webkit/plugins/ppapi/ppb_websocket_impl.cc
@@ -107,7 +107,7 @@ PPB_WebSocket_API* PPB_WebSocket_Impl::AsPPB_WebSocket_API() {
int32_t PPB_WebSocket_Impl::Connect(PP_Var url,
const PP_Var protocols[],
uint32_t protocol_count,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
// Check mandatory interfaces.
PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
DCHECK(plugin_instance);
@@ -181,10 +181,6 @@ int32_t PPB_WebSocket_Impl::Connect(PP_Var url,
}
WebString web_protocols = WebString::fromUTF8(protocol_string);
- // Validate |callback| (Doesn't support blocking callback)
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
-
// Create WebKit::WebSocket object and connect.
WebDocument document = plugin_instance->container()->element().document();
websocket_.reset(WebSocket::create(document, this));
@@ -199,14 +195,14 @@ int32_t PPB_WebSocket_Impl::Connect(PP_Var url,
state_ = PP_WEBSOCKETREADYSTATE_CONNECTING;
// Install callback.
- connect_callback_ = new TrackedCallback(this, callback);
+ connect_callback_ = callback;
return PP_OK_COMPLETIONPENDING;
}
int32_t PPB_WebSocket_Impl::Close(uint16_t code,
PP_Var reason,
- PP_CompletionCallback callback) {
+ scoped_refptr<TrackedCallback> callback) {
// Check mandarory interfaces.
if (!websocket_.get())
return PP_ERROR_FAILED;
@@ -248,12 +244,8 @@ int32_t PPB_WebSocket_Impl::Close(uint16_t code,
if (state_ == PP_WEBSOCKETREADYSTATE_CLOSED)
return PP_OK;
- // Validate |callback| (Doesn't support blocking callback)
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
-
// Install |callback|.
- close_callback_ = new TrackedCallback(this, callback);
+ close_callback_ = callback;
// Abort ongoing connect.
if (state_ == PP_WEBSOCKETREADYSTATE_CONNECTING) {
@@ -283,8 +275,9 @@ int32_t PPB_WebSocket_Impl::Close(uint16_t code,
return PP_OK_COMPLETIONPENDING;
}
-int32_t PPB_WebSocket_Impl::ReceiveMessage(PP_Var* message,
- PP_CompletionCallback callback) {
+int32_t PPB_WebSocket_Impl::ReceiveMessage(
+ PP_Var* message,
+ scoped_refptr<TrackedCallback> callback) {
// Check state.
if (state_ == PP_WEBSOCKETREADYSTATE_INVALID ||
state_ == PP_WEBSOCKETREADYSTATE_CONNECTING)
@@ -305,14 +298,10 @@ int32_t PPB_WebSocket_Impl::ReceiveMessage(PP_Var* message,
if (error_was_received_)
return PP_ERROR_FAILED;
- // Validate |callback| (Doesn't support blocking callback)
- if (!callback.func)
- return PP_ERROR_BLOCKS_MAIN_THREAD;
-
// Or retain |message| as buffer to store and install |callback|.
wait_for_receive_ = true;
receive_callback_var_ = message;
- receive_callback_ = new TrackedCallback(this, callback);
+ receive_callback_ = callback;
return PP_OK_COMPLETIONPENDING;
}
diff --git a/webkit/plugins/ppapi/ppb_websocket_impl.h b/webkit/plugins/ppapi/ppb_websocket_impl.h
index 765e6c9..0bdaf4b 100644
--- a/webkit/plugins/ppapi/ppb_websocket_impl.h
+++ b/webkit/plugins/ppapi/ppb_websocket_impl.h
@@ -39,15 +39,18 @@ class PPB_WebSocket_Impl : public ::ppapi::Resource,
virtual ::ppapi::thunk::PPB_WebSocket_API* AsPPB_WebSocket_API() OVERRIDE;
// PPB_WebSocket_API implementation.
- virtual int32_t Connect(PP_Var url,
- const PP_Var protocols[],
- uint32_t protocol_count,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t Close(uint16_t code,
- PP_Var reason,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t ReceiveMessage(PP_Var* message,
- PP_CompletionCallback callback) OVERRIDE;
+ virtual int32_t Connect(
+ PP_Var url,
+ const PP_Var protocols[],
+ uint32_t protocol_count,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
+ virtual int32_t Close(
+ uint16_t code,
+ PP_Var reason,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
+ virtual int32_t ReceiveMessage(
+ PP_Var* message,
+ scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
virtual int32_t SendMessage(PP_Var message) OVERRIDE;
virtual uint64_t GetBufferedAmount() OVERRIDE;
virtual uint16_t GetCloseCode() OVERRIDE;