summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-05 18:17:05 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-05 18:17:05 +0000
commita78956be12c7d66aeacdb371cfe957014e6e0fff (patch)
tree7cc23f63df2090b2be8b27a9959bf54e34acf8f9
parent09c37bac05f382080e064d0bf96c7387f5f00c4b (diff)
downloadchromium_src-a78956be12c7d66aeacdb371cfe957014e6e0fff.zip
chromium_src-a78956be12c7d66aeacdb371cfe957014e6e0fff.tar.gz
chromium_src-a78956be12c7d66aeacdb371cfe957014e6e0fff.tar.bz2
Convert proxy callbacks to use TrackedCallback.
This converts all free-standing refs of PP_CompletionCallback to use the new TrackedCallback. BUG= TEST= Review URL: http://codereview.chromium.org/9003009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116509 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ppapi/proxy/ppb_broker_proxy.cc24
-rw-r--r--ppapi/proxy/ppb_file_chooser_proxy.cc22
-rw-r--r--ppapi/proxy/ppb_file_ref_proxy.cc18
-rw-r--r--ppapi/proxy/ppb_file_system_proxy.cc23
-rw-r--r--ppapi/proxy/ppb_flash_menu_proxy.cc10
-rw-r--r--ppapi/proxy/ppb_flash_net_connector_proxy.cc20
-rw-r--r--ppapi/proxy/ppb_graphics_2d_proxy.cc14
-rw-r--r--ppapi/proxy/ppb_url_loader_proxy.cc37
8 files changed, 57 insertions, 111 deletions
diff --git a/ppapi/proxy/ppb_broker_proxy.cc b/ppapi/proxy/ppb_broker_proxy.cc
index 657c5f5..18065bb 100644
--- a/ppapi/proxy/ppb_broker_proxy.cc
+++ b/ppapi/proxy/ppb_broker_proxy.cc
@@ -11,6 +11,7 @@
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/shared_impl/platform_file.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/ppb_broker_api.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/resource_creation_api.h"
@@ -41,7 +42,7 @@ class Broker : public PPB_Broker_API, public Resource {
private:
bool called_connect_;
- PP_CompletionCallback current_connect_callback_;
+ scoped_refptr<TrackedCallback> current_connect_callback_;
// The plugin module owns the handle.
// The host side transfers ownership of the handle to the plugin side when it
@@ -52,22 +53,13 @@ class Broker : public PPB_Broker_API, public Resource {
DISALLOW_COPY_AND_ASSIGN(Broker);
};
-Broker::Broker(const HostResource& resource) : Resource(resource),
+Broker::Broker(const HostResource& resource)
+ : Resource(resource),
called_connect_(false),
- current_connect_callback_(PP_MakeCompletionCallback(NULL, NULL)),
socket_handle_(base::kInvalidPlatformFileValue) {
}
Broker::~Broker() {
- // Ensure the callback is always fired.
- if (current_connect_callback_.func) {
- // TODO(brettw) the callbacks at this level should be refactored with a
- // more automatic tracking system like we have in the renderer.
- MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
- current_connect_callback_.func, current_connect_callback_.user_data,
- static_cast<int32_t>(PP_ERROR_ABORTED)));
- }
-
socket_handle_ = base::kInvalidPlatformFileValue;
}
@@ -81,12 +73,12 @@ int32_t Broker::Connect(PP_CompletionCallback connect_callback) {
return PP_ERROR_BLOCKS_MAIN_THREAD;
}
- if (current_connect_callback_.func)
+ if (TrackedCallback::IsPending(current_connect_callback_))
return PP_ERROR_INPROGRESS;
else if (called_connect_)
return PP_ERROR_FAILED;
- current_connect_callback_ = connect_callback;
+ current_connect_callback_ = new TrackedCallback(this, connect_callback);
called_connect_ = true;
bool success = PluginDispatcher::GetForResource(this)->Send(
@@ -115,12 +107,12 @@ void Broker::ConnectComplete(IPC::PlatformFileForTransit socket_handle,
IPC::PlatformFileForTransitToPlatformFile(socket_handle));
}
- if (!current_connect_callback_.func) {
+ if (!TrackedCallback::IsPending(current_connect_callback_)) {
// The handle might leak if the plugin never calls GetHandle().
return;
}
- PP_RunAndClearCompletionCallback(&current_connect_callback_, result);
+ TrackedCallback::ClearAndRun(&current_connect_callback_, result);
}
PPB_Broker_Proxy::PPB_Broker_Proxy(Dispatcher* dispatcher)
diff --git a/ppapi/proxy/ppb_file_chooser_proxy.cc b/ppapi/proxy/ppb_file_chooser_proxy.cc
index 7361835..c3914ef 100644
--- a/ppapi/proxy/ppb_file_chooser_proxy.cc
+++ b/ppapi/proxy/ppb_file_chooser_proxy.cc
@@ -19,6 +19,7 @@
#include "ppapi/proxy/serialized_var.h"
#include "ppapi/shared_impl/ppapi_globals.h"
#include "ppapi/shared_impl/resource_tracker.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/shared_impl/var.h"
#include "ppapi/thunk/resource_creation_api.h"
#include "ppapi/thunk/thunk.h"
@@ -61,7 +62,7 @@ class FileChooser : public Resource,
const char* suggested_file_name,
const PP_CompletionCallback& callback);
- PP_CompletionCallback current_show_callback_;
+ scoped_refptr<TrackedCallback> current_show_callback_;
// All files returned by the current show callback that haven't yet been
// given to the plugin. The plugin will repeatedly call us to get the next
@@ -72,21 +73,10 @@ class FileChooser : public Resource,
DISALLOW_COPY_AND_ASSIGN(FileChooser);
};
-FileChooser::FileChooser(const HostResource& resource)
- : Resource(resource),
- current_show_callback_(PP_MakeCompletionCallback(NULL, NULL)) {
+FileChooser::FileChooser(const HostResource& resource) : Resource(resource) {
}
FileChooser::~FileChooser() {
- // Always need to fire completion callbacks to prevent a leak in the plugin.
- if (current_show_callback_.func) {
- // TODO(brettw) the callbacks at this level should be refactored with a
- // more automatic tracking system like we have in the renderer.
- MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
- current_show_callback_.func, current_show_callback_.user_data,
- static_cast<int32_t>(PP_ERROR_ABORTED)));
- }
-
// Any existing files we haven't transferred ownership to the plugin need
// to be freed.
ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
@@ -118,10 +108,10 @@ int32_t FileChooser::Show(bool require_user_gesture,
if (!callback.func)
return PP_ERROR_BLOCKS_MAIN_THREAD;
- if (current_show_callback_.func)
+ if (TrackedCallback::IsPending(current_show_callback_))
return PP_ERROR_INPROGRESS; // Can't show more than once.
- current_show_callback_ = callback;
+ current_show_callback_ = new TrackedCallback(this, callback);
PluginDispatcher::GetForResource(this)->Send(
new PpapiHostMsg_PPBFileChooser_Show(
API_ID_PPB_FILE_CHOOSER,
@@ -154,7 +144,7 @@ void FileChooser::ChooseComplete(
file_queue_.push(PPB_FileRef_Proxy::DeserializeFileRef(chosen_files[i]));
// Notify the plugin of the new data.
- PP_RunAndClearCompletionCallback(&current_show_callback_, result_code);
+ TrackedCallback::ClearAndRun(&current_show_callback_, result_code);
// DANGER: May delete |this|!
}
diff --git a/ppapi/proxy/ppb_file_ref_proxy.cc b/ppapi/proxy/ppb_file_ref_proxy.cc
index e481f86..7c12ea3 100644
--- a/ppapi/proxy/ppb_file_ref_proxy.cc
+++ b/ppapi/proxy/ppb_file_ref_proxy.cc
@@ -17,6 +17,7 @@
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/serialized_var.h"
#include "ppapi/shared_impl/ppb_file_ref_shared.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/resource_creation_api.h"
#include "ppapi/thunk/thunk.h"
@@ -68,7 +69,7 @@ class FileRef : public PPB_FileRef_Shared {
// the callback will be identified when it's passed to the host and then
// back here.
int next_callback_id_;
- typedef std::map<int, PP_CompletionCallback> PendingCallbackMap;
+ typedef std::map<int, scoped_refptr<TrackedCallback> > PendingCallbackMap;
PendingCallbackMap pending_callbacks_;
DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef);
@@ -85,14 +86,7 @@ FileRef::~FileRef() {
}
void FileRef::LastPluginRefWasDeleted() {
- // Abort all pending callbacks. Do this by posting a task to avoid reentering
- // the plugin's Release() call that probably deleted this object.
- for (PendingCallbackMap::iterator i = pending_callbacks_.begin();
- i != pending_callbacks_.end(); ++i) {
- MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
- i->second.func, i->second.user_data,
- static_cast<int32_t>(PP_ERROR_ABORTED)));
- }
+ // The callback tracker will abort our callbacks for us.
pending_callbacks_.clear();
}
@@ -172,9 +166,9 @@ void FileRef::ExecuteCallback(int callback_id, int32_t result) {
}
// Executing the callback may mutate the callback list.
- PP_CompletionCallback callback = found->second;
+ scoped_refptr<TrackedCallback> callback = found->second;
pending_callbacks_.erase(found);
- PP_RunCompletionCallback(&callback, result);
+ callback->Run(result);
}
int FileRef::SendCallback(PP_CompletionCallback callback) {
@@ -185,7 +179,7 @@ int FileRef::SendCallback(PP_CompletionCallback callback) {
while (pending_callbacks_.find(next_callback_id_) != pending_callbacks_.end())
next_callback_id_++;
- pending_callbacks_[next_callback_id_] = callback;
+ pending_callbacks_[next_callback_id_] = new TrackedCallback(this, callback);
return next_callback_id_++;
}
diff --git a/ppapi/proxy/ppb_file_system_proxy.cc b/ppapi/proxy/ppb_file_system_proxy.cc
index 32aff7c..d25452d 100644
--- a/ppapi/proxy/ppb_file_system_proxy.cc
+++ b/ppapi/proxy/ppb_file_system_proxy.cc
@@ -14,6 +14,7 @@
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/serialized_var.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_file_system_api.h"
#include "ppapi/thunk/resource_creation_api.h"
@@ -56,7 +57,7 @@ class FileSystem : public Resource, public PPB_FileSystem_API {
private:
PP_FileSystemType type_;
bool called_open_;
- PP_CompletionCallback current_open_callback_;
+ scoped_refptr<TrackedCallback> current_open_callback_;
DISALLOW_COPY_AND_ASSIGN(FileSystem);
};
@@ -65,22 +66,10 @@ FileSystem::FileSystem(const HostResource& host_resource,
PP_FileSystemType type)
: Resource(host_resource),
type_(type),
- called_open_(false),
- current_open_callback_(PP_MakeCompletionCallback(NULL, NULL)) {
+ called_open_(false) {
}
-// TODO(brettw) this logic is duplicated with some other resource objects
-// like FileChooser. It would be nice to look at all of the different resources
-// that need callback tracking and design something that they can all re-use.
FileSystem::~FileSystem() {
- // Ensure the callback is always fired.
- if (current_open_callback_.func) {
- // TODO(brettw) the callbacks at this level should be refactored with a
- // more automatic tracking system like we have in the renderer.
- MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
- current_open_callback_.func, current_open_callback_.user_data,
- static_cast<int32_t>(PP_ERROR_ABORTED)));
- }
}
PPB_FileSystem_API* FileSystem::AsPPB_FileSystem_API() {
@@ -89,12 +78,12 @@ PPB_FileSystem_API* FileSystem::AsPPB_FileSystem_API() {
int32_t FileSystem::Open(int64_t expected_size,
PP_CompletionCallback callback) {
- if (current_open_callback_.func)
+ if (TrackedCallback::IsPending(current_open_callback_))
return PP_ERROR_INPROGRESS;
if (called_open_)
return PP_ERROR_FAILED;
- current_open_callback_ = callback;
+ current_open_callback_ = new TrackedCallback(this, callback);
called_open_ = true;
PluginDispatcher::GetForResource(this)->Send(
new PpapiHostMsg_PPBFileSystem_Open(
@@ -107,7 +96,7 @@ PP_FileSystemType FileSystem::GetType() {
}
void FileSystem::OpenComplete(int32_t result) {
- PP_RunAndClearCompletionCallback(&current_open_callback_, result);
+ TrackedCallback::ClearAndRun(&current_open_callback_, result);
}
PPB_FileSystem_Proxy::PPB_FileSystem_Proxy(Dispatcher* dispatcher)
diff --git a/ppapi/proxy/ppb_flash_menu_proxy.cc b/ppapi/proxy/ppb_flash_menu_proxy.cc
index 31681e7..d2ef2a3 100644
--- a/ppapi/proxy/ppb_flash_menu_proxy.cc
+++ b/ppapi/proxy/ppb_flash_menu_proxy.cc
@@ -8,6 +8,7 @@
#include "ppapi/c/private/ppb_flash_menu.h"
#include "ppapi/proxy/enter_proxy.h"
#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_flash_menu_api.h"
#include "ppapi/thunk/resource_creation_api.h"
@@ -35,7 +36,7 @@ class FlashMenu : public PPB_Flash_Menu_API, public Resource {
void ShowACK(int32_t selected_id, int32_t result);
private:
- PP_CompletionCallback callback_;
+ scoped_refptr<TrackedCallback> callback_;
int32_t* selected_id_ptr_;
DISALLOW_COPY_AND_ASSIGN(FlashMenu);
@@ -43,7 +44,6 @@ class FlashMenu : public PPB_Flash_Menu_API, public Resource {
FlashMenu::FlashMenu(const HostResource& resource)
: Resource(resource),
- callback_(PP_BlockUntilComplete()),
selected_id_ptr_(NULL) {
}
@@ -57,11 +57,11 @@ 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) {
- if (callback_.func)
+ if (TrackedCallback::IsPending(callback_))
return PP_ERROR_INPROGRESS;
selected_id_ptr_ = selected_id;
- callback_ = callback;
+ callback_ = new TrackedCallback(this, callback);
PluginDispatcher::GetForResource(this)->Send(
new PpapiHostMsg_PPBFlashMenu_Show(
@@ -71,7 +71,7 @@ int32_t FlashMenu::Show(const struct PP_Point* location,
void FlashMenu::ShowACK(int32_t selected_id, int32_t result) {
*selected_id_ptr_ = selected_id;
- PP_RunAndClearCompletionCallback(&callback_, result);
+ TrackedCallback::ClearAndRun(&callback_, result);
}
PPB_Flash_Menu_Proxy::PPB_Flash_Menu_Proxy(Dispatcher* dispatcher)
diff --git a/ppapi/proxy/ppb_flash_net_connector_proxy.cc b/ppapi/proxy/ppb_flash_net_connector_proxy.cc
index 60855c9..feaba6a 100644
--- a/ppapi/proxy/ppb_flash_net_connector_proxy.cc
+++ b/ppapi/proxy/ppb_flash_net_connector_proxy.cc
@@ -13,6 +13,7 @@
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/serialized_var.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_flash_net_connector_api.h"
#include "ppapi/thunk/resource_creation_api.h"
@@ -35,10 +36,6 @@ void StringToNetAddress(const std::string& str, PP_NetAddress_Private* addr) {
memcpy(addr->data, str.data(), addr->size);
}
-void AbortCallback(PP_CompletionCallback callback) {
- PP_RunCompletionCallback(&callback, PP_ERROR_ABORTED);
-}
-
class FlashNetConnector : public PPB_Flash_NetConnector_API,
public Resource {
public:
@@ -75,7 +72,7 @@ class FlashNetConnector : public PPB_Flash_NetConnector_API,
PP_NetAddress_Private* remote_addr_out,
PP_CompletionCallback callback);
- PP_CompletionCallback callback_;
+ scoped_refptr<TrackedCallback> callback_;
PP_FileHandle* socket_out_;
PP_NetAddress_Private* local_addr_out_;
PP_NetAddress_Private* remote_addr_out_;
@@ -83,17 +80,12 @@ class FlashNetConnector : public PPB_Flash_NetConnector_API,
FlashNetConnector::FlashNetConnector(const HostResource& resource)
: Resource(resource),
- callback_(PP_BlockUntilComplete()),
socket_out_(NULL),
local_addr_out_(NULL),
remote_addr_out_(NULL) {
}
FlashNetConnector::~FlashNetConnector() {
- if (callback_.func) {
- MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(&AbortCallback, callback_));
- }
}
PPB_Flash_NetConnector_API* FlashNetConnector::AsPPB_Flash_NetConnector_API() {
@@ -131,7 +123,7 @@ void FlashNetConnector::ConnectComplete(
base::PlatformFile file,
const std::string& local_addr_as_string,
const std::string& remote_addr_as_string) {
- if (!callback_.func) {
+ if (TrackedCallback::IsPending(callback_)) {
base::ClosePlatformFile(file);
return;
}
@@ -140,7 +132,7 @@ void FlashNetConnector::ConnectComplete(
StringToNetAddress(local_addr_as_string, local_addr_out_);
StringToNetAddress(remote_addr_as_string, remote_addr_out_);
- PP_RunAndClearCompletionCallback(&callback_, result);
+ TrackedCallback::ClearAndRun(&callback_, result);
}
int32_t FlashNetConnector::ConnectWithMessage(
@@ -150,13 +142,13 @@ int32_t FlashNetConnector::ConnectWithMessage(
PP_NetAddress_Private* remote_addr_out,
PP_CompletionCallback callback) {
scoped_ptr<IPC::Message> msg_deletor(msg);
- if (callback_.func != NULL)
+ if (TrackedCallback::IsPending(callback_))
return PP_ERROR_INPROGRESS; // Can only have one pending request.
// Send the request, it will call us back via ConnectACK.
PluginDispatcher::GetForResource(this)->Send(msg_deletor.release());
- callback_ = callback;
+ callback_ = new TrackedCallback(this, callback);
socket_out_ = socket_out;
local_addr_out_ = local_addr_out;
remote_addr_out_ = remote_addr_out;
diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.cc b/ppapi/proxy/ppb_graphics_2d_proxy.cc
index 59659e7..0788361 100644
--- a/ppapi/proxy/ppb_graphics_2d_proxy.cc
+++ b/ppapi/proxy/ppb_graphics_2d_proxy.cc
@@ -15,6 +15,7 @@
#include "ppapi/proxy/enter_proxy.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_graphics_2d_api.h"
#include "ppapi/thunk/thunk.h"
@@ -58,8 +59,8 @@ class Graphics2D : public Resource, public thunk::PPB_Graphics2D_API {
PP_Bool is_always_opaque_;
// In the plugin, this is the current callback set for Flushes. When the
- // callback function pointer is non-NULL, we're waiting for a flush ACK.
- PP_CompletionCallback current_flush_callback_;
+ // pointer is non-NULL, we're waiting for a flush ACK.
+ scoped_refptr<TrackedCallback> current_flush_callback_;
DISALLOW_COPY_AND_ASSIGN(Graphics2D);
};
@@ -69,8 +70,7 @@ Graphics2D::Graphics2D(const HostResource& host_resource,
PP_Bool is_always_opaque)
: Resource(host_resource),
size_(size),
- is_always_opaque_(is_always_opaque),
- current_flush_callback_(PP_BlockUntilComplete()) {
+ is_always_opaque_(is_always_opaque) {
}
Graphics2D::~Graphics2D() {
@@ -126,9 +126,9 @@ int32_t Graphics2D::Flush(PP_CompletionCallback callback) {
if (!callback.func)
return PP_ERROR_BLOCKS_MAIN_THREAD;
- if (current_flush_callback_.func)
+ if (TrackedCallback::IsPending(current_flush_callback_))
return PP_ERROR_INPROGRESS; // Can't have >1 flush pending.
- current_flush_callback_ = callback;
+ current_flush_callback_ = new TrackedCallback(this, callback);
GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Flush(kApiID,
host_resource()));
@@ -136,7 +136,7 @@ int32_t Graphics2D::Flush(PP_CompletionCallback callback) {
}
void Graphics2D::FlushACK(int32_t result_code) {
- PP_RunAndClearCompletionCallback(&current_flush_callback_, result_code);
+ TrackedCallback::ClearAndRun(&current_flush_callback_, result_code);
}
PPB_Graphics2D_Proxy::PPB_Graphics2D_Proxy(Dispatcher* dispatcher)
diff --git a/ppapi/proxy/ppb_url_loader_proxy.cc b/ppapi/proxy/ppb_url_loader_proxy.cc
index a09799b..de74318 100644
--- a/ppapi/proxy/ppb_url_loader_proxy.cc
+++ b/ppapi/proxy/ppb_url_loader_proxy.cc
@@ -24,6 +24,7 @@
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/ppb_url_response_info_proxy.h"
#include "ppapi/shared_impl/scoped_pp_resource.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_url_loader_api.h"
#include "ppapi/thunk/resource_creation_api.h"
@@ -136,7 +137,7 @@ class URLLoader : public Resource, public PPB_URLLoader_API {
// Current completion callback for the current phase of loading. We have only
// one thing (open, follow redirect, read, etc.) outstanding at once.
- PP_CompletionCallback current_callback_;
+ scoped_refptr<TrackedCallback> current_callback_;
// When an asynchronous read is pending, this will contain the buffer to put
// the data. The current_callback_ will identify the read callback.
@@ -161,22 +162,12 @@ URLLoader::URLLoader(const HostResource& resource)
total_bytes_to_be_sent_(-1),
bytes_received_(-1),
total_bytes_to_be_received_(-1),
- current_callback_(PP_MakeCompletionCallback(NULL, NULL)),
current_read_buffer_(NULL),
current_read_buffer_size_(0),
response_info_(0) {
}
URLLoader::~URLLoader() {
- // Always need to fire completion callbacks to prevent a leak in the plugin.
- if (current_callback_.func) {
- // TODO(brettw) the callbacks at this level should be refactored with a
- // more automatic tracking system like we have in the renderer.
- MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
- current_callback_.func, current_callback_.user_data,
- static_cast<int32_t>(PP_ERROR_ABORTED)));
- }
-
if (response_info_)
PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(response_info_);
}
@@ -191,12 +182,12 @@ int32_t URLLoader::Open(PP_Resource request_id,
if (enter.failed())
return PP_ERROR_BADRESOURCE;
- if (current_callback_.func)
+ if (TrackedCallback::IsPending(current_callback_))
return PP_ERROR_INPROGRESS;
if (!callback.func)
return PP_ERROR_BLOCKS_MAIN_THREAD;
- current_callback_ = callback;
+ current_callback_ = new TrackedCallback(this, callback);
GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Open(
API_ID_PPB_URL_LOADER, host_resource(), enter.object()->GetData()));
@@ -204,12 +195,12 @@ int32_t URLLoader::Open(PP_Resource request_id,
}
int32_t URLLoader::FollowRedirect(PP_CompletionCallback callback) {
- if (current_callback_.func)
+ if (TrackedCallback::IsPending(current_callback_))
return PP_ERROR_INPROGRESS;
if (!callback.func)
return PP_ERROR_BLOCKS_MAIN_THREAD;
- current_callback_ = callback;
+ current_callback_ = new TrackedCallback(this, callback);
GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect(
API_ID_PPB_URL_LOADER, host_resource()));
@@ -263,7 +254,7 @@ int32_t URLLoader::ReadResponseBody(void* buffer,
PP_CompletionCallback callback) {
if (!buffer || bytes_to_read <= 0)
return PP_ERROR_BADARGUMENT; // Must specify an output buffer.
- if (current_callback_.func)
+ 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
@@ -278,7 +269,7 @@ int32_t URLLoader::ReadResponseBody(void* buffer,
return bytes_to_read;
}
- current_callback_ = callback;
+ current_callback_ = new TrackedCallback(this, callback);
current_read_buffer_ = buffer;
current_read_buffer_size_ = bytes_to_read;
@@ -288,12 +279,12 @@ int32_t URLLoader::ReadResponseBody(void* buffer,
}
int32_t URLLoader::FinishStreamingToFile(PP_CompletionCallback callback) {
- if (current_callback_.func)
+ if (TrackedCallback::IsPending(current_callback_))
return PP_ERROR_INPROGRESS;
if (!callback.func)
return PP_ERROR_BLOCKS_MAIN_THREAD;
- current_callback_ = callback;
+ current_callback_ = new TrackedCallback(this, callback);
GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FinishStreamingToFile(
API_ID_PPB_URL_LOADER, host_resource()));
@@ -326,7 +317,7 @@ void URLLoader::UpdateProgress(
}
void URLLoader::ReadResponseBodyAck(int32 result, const std::string& data) {
- if (!current_callback_.func || !current_read_buffer_) {
+ if (!TrackedCallback::IsPending(current_callback_) || !current_read_buffer_) {
NOTREACHED();
return;
}
@@ -345,13 +336,11 @@ void URLLoader::ReadResponseBodyAck(int32 result, const std::string& data) {
result = bytes_to_return;
}
- // The plugin should be able to make a new request from their callback, so
- // we have to clear our copy first.
- PP_RunAndClearCompletionCallback(&current_callback_, result);
+ TrackedCallback::ClearAndRun(&current_callback_, result);
}
void URLLoader::CallbackComplete(int32_t result) {
- PP_RunAndClearCompletionCallback(&current_callback_, result);
+ TrackedCallback::ClearAndRun(&current_callback_, result);
}
void URLLoader::PopBuffer(void* output_buffer, int32_t output_size) {