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

Unified Diff: ppapi/proxy/ppb_url_loader_proxy.cc

Issue 10081020: PPAPI: Make blocking completion callbacks work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated TestURLLoader to test blocking callbacks. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ppapi/proxy/ppb_url_loader_proxy.cc
diff --git a/ppapi/proxy/ppb_url_loader_proxy.cc b/ppapi/proxy/ppb_url_loader_proxy.cc
index c300bb98cee69941eb2f05f35e0a9e8a077daea4..575e130b166c3ff964b99fe8e3a84dea5df8936a 100644
--- a/ppapi/proxy/ppb_url_loader_proxy.cc
+++ b/ppapi/proxy/ppb_url_loader_proxy.cc
@@ -92,8 +92,8 @@ 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;
+ ApiCallbackType callback) OVERRIDE;
+ virtual int32_t FollowRedirect(ApiCallbackType callback) OVERRIDE;
virtual PP_Bool GetUploadProgress(int64_t* bytes_sent,
int64_t* total_bytes_to_be_sent) OVERRIDE;
virtual PP_Bool GetDownloadProgress(
@@ -102,9 +102,9 @@ class URLLoader : public Resource, public PPB_URLLoader_API {
virtual PP_Resource GetResponseInfo() OVERRIDE;
virtual int32_t ReadResponseBody(void* buffer,
int32_t bytes_to_read,
- PP_CompletionCallback callback) OVERRIDE;
+ ApiCallbackType callback) OVERRIDE;
virtual int32_t FinishStreamingToFile(
- PP_CompletionCallback callback) OVERRIDE;
+ ApiCallbackType callback) OVERRIDE;
virtual void Close() OVERRIDE;
virtual void GrantUniversalAccess() OVERRIDE;
virtual void SetStatusCallback(
@@ -179,7 +179,7 @@ PPB_URLLoader_API* URLLoader::AsPPB_URLLoader_API() {
}
int32_t URLLoader::Open(PP_Resource request_id,
- PP_CompletionCallback callback) {
+ ApiCallbackType 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 "
@@ -192,22 +192,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(ApiCallbackType 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()));
@@ -258,17 +254,12 @@ PP_Resource URLLoader::GetResponseInfo() {
int32_t URLLoader::ReadResponseBody(void* buffer,
int32_t bytes_to_read,
- PP_CompletionCallback callback) {
+ ApiCallbackType 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.
@@ -276,7 +267,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;
@@ -285,13 +276,11 @@ int32_t URLLoader::ReadResponseBody(void* buffer,
return PP_OK_COMPLETIONPENDING;
}
-int32_t URLLoader::FinishStreamingToFile(PP_CompletionCallback callback) {
+int32_t URLLoader::FinishStreamingToFile(ApiCallbackType 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()));

Powered by Google App Engine
This is Rietveld 408576698