diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-16 20:10:55 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-16 20:10:55 +0000 |
commit | e655a951994dcafb7203d6824b90dfef6e445dca (patch) | |
tree | 18b9126b21efd9e63f74149263753031ec393ae8 /ppapi | |
parent | c96312d46205ea82764aba6255ecbb8dd5f57d11 (diff) | |
download | chromium_src-e655a951994dcafb7203d6824b90dfef6e445dca.zip chromium_src-e655a951994dcafb7203d6824b90dfef6e445dca.tar.gz chromium_src-e655a951994dcafb7203d6824b90dfef6e445dca.tar.bz2 |
Add a new error code for a null callback on the main thread.
Convert the NaCl and ChromeIPC proxies to use the new value.
Review URL: http://codereview.chromium.org/7885014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101556 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
16 files changed, 93 insertions, 34 deletions
diff --git a/ppapi/api/pp_errors.idl b/ppapi/api/pp_errors.idl index 950b77b..bd49081 100644 --- a/ppapi/api/pp_errors.idl +++ b/ppapi/api/pp_errors.idl @@ -9,7 +9,10 @@ /** * This enumeration contains enumerators of all PPAPI error codes. - * Errors are negative valued. + * + * Errors are negative valued. Callers should treat all negative values as a + * failure, even if it's not in the list, since the possible errors are likely + * to expand and change over time. */ [unnamed] enum PP_Error { /** @@ -26,11 +29,20 @@ */ PP_OK_COMPLETIONPENDING = -1, - /** This value indicates failure for unspecified reasons. */ + /**This value indicates failure for unspecified reasons. */ PP_ERROR_FAILED = -2, + /** * This value indicates failure due to an asynchronous operation being - * interrupted, typically as a result of user action. + * interrupted. The most common cause of this error code is destroying a + * resource that still has a callback pending. All callbacks are guaranteed + * to execute, so any callbacks pending on a destroyed resource will be + * issued with PP_ERROR_ABORTED. + * + * If you get an aborted notification that you aren't expecting, check to + * make sure that the resource you're using is still in scope. A common + * mistake is to create a resource on the stack, which will destroy the + * resource as soon as the function returns. */ PP_ERROR_ABORTED = -3, @@ -67,6 +79,20 @@ */ PP_ERROR_NOTSUPPORTED = -12, + /** + * Returned if you try to use a null completion callback to "block until + * complete" on the main thread. Blocking the main thread is not permitted + * to keep the browser responsive (otherwise, you may not be able to handle + * input events, and there are reentrancy and deadlock issues). + * + * The goal is to provide blocking calls from background threads, but PPAPI + * calls on background threads are not currently supported. Until this + * support is complete, you must either do asynchronous operations on the + * main thread, or provide an adaptor for a blocking background thread to + * execute the operaitions on the main thread. + */ + PP_ERROR_BLOCKS_MAIN_THREAD = -13, + PP_ERROR_FILENOTFOUND = -20, /** This value indicates failure due to a file that already exists. */ PP_ERROR_FILEEXISTS = -21, diff --git a/ppapi/c/pp_errors.h b/ppapi/c/pp_errors.h index 1394aa7..724ff9b 100644 --- a/ppapi/c/pp_errors.h +++ b/ppapi/c/pp_errors.h @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -/* From pp_errors.idl modified Sat Jul 16 16:50:26 2011. */ +/* From pp_errors.idl modified Wed Sep 14 08:34:03 2011. */ #ifndef PPAPI_C_PP_ERRORS_H_ #define PPAPI_C_PP_ERRORS_H_ @@ -22,7 +22,10 @@ */ /** * This enumeration contains enumerators of all PPAPI error codes. - * Errors are negative valued. + * + * Errors are negative valued. Callers should treat all negative values as a + * failure, even if it's not in the list, since the possible errors are likely + * to expand and change over time. */ enum { /** @@ -38,11 +41,19 @@ enum { * available. */ PP_OK_COMPLETIONPENDING = -1, - /** This value indicates failure for unspecified reasons. */ + /**This value indicates failure for unspecified reasons. */ PP_ERROR_FAILED = -2, /** * This value indicates failure due to an asynchronous operation being - * interrupted, typically as a result of user action. + * interrupted. The most common cause of this error code is destroying a + * resource that still has a callback pending. All callbacks are guaranteed + * to execute, so any callbacks pending on a destroyed resource will be + * issued with PP_ERROR_ABORTED. + * + * If you get an aborted notification that you aren't expecting, check to + * make sure that the resource you're using is still in scope. A common + * mistake is to create a resource on the stack, which will destroy the + * resource as soon as the function returns. */ PP_ERROR_ABORTED = -3, /** This value indicates failure due to an invalid argument. */ @@ -69,6 +80,19 @@ enum { * The requested command is not supported by the browser. */ PP_ERROR_NOTSUPPORTED = -12, + /** + * Returned if you try to use a null completion callback to "block until + * complete" on the main thread. Blocking the main thread is not permitted + * to keep the browser responsive (otherwise, you may not be able to handle + * input events, and there are reentrancy and deadlock issues). + * + * The goal is to provide blocking calls from background threads, but PPAPI + * calls on background threads are not currently supported. Until this + * support is complete, you must either do asynchronous operations on the + * main thread, or provide an adaptor for a blocking background thread to + * execute the operaitions on the main thread. + */ + PP_ERROR_BLOCKS_MAIN_THREAD = -13, PP_ERROR_FILENOTFOUND = -20, /** This value indicates failure due to a file that already exists. */ PP_ERROR_FILEEXISTS = -21, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_nacl_file.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_nacl_file.cc index 1099ec1..4c8758c 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_nacl_file.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_nacl_file.cc @@ -24,10 +24,10 @@ int32_t StreamAsFile(PP_Instance instance, int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback); if (callback_id == 0) - return PP_ERROR_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; NaClSrpcError srpc_result = NaClFileRpcClient::StreamAsFile( - GetMainSrpcChannel(), instance, const_cast<char*>(url), callback_id); + GetMainSrpcChannel(), instance, const_cast<char*>(url), callback_id); DebugPrintf("NaClFile::StreamAsFile: %s\n", NaClSrpcErrorString(srpc_result)); if (srpc_result == NACL_SRPC_RESULT_OK) diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_file_io.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_file_io.cc index 848b1ee..9f4851e 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_file_io.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_file_io.cc @@ -66,7 +66,7 @@ int32_t Open(PP_Resource file_io, int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback); if (callback_id == 0) // Just like Chrome, for now disallow blocking calls. - return PP_ERROR_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; int32_t pp_error; NaClSrpcError srpc_result = @@ -90,7 +90,7 @@ int32_t Query(PP_Resource file_io, struct PP_CompletionCallback callback) { DebugPrintf("PPB_FileIO::Query: file_io=%"NACL_PRIu32"\n", file_io); if (callback.func == 0) // Just like Chrome, for now disallow blocking calls. - return PP_ERROR_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; int32_t callback_id = CompletionCallbackTable::Get()->AddCallback( callback, reinterpret_cast<char*>(info)); @@ -130,7 +130,7 @@ int32_t Touch(PP_Resource file_io, int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback); if (callback_id == 0) // Just like Chrome, for now disallow blocking calls. - return PP_ERROR_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; int32_t pp_error = PP_ERROR_FAILED; @@ -165,7 +165,7 @@ int32_t Read(PP_Resource file_io, int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback, buffer); if (callback_id == 0) // Just like Chrome, for now disallow blocking calls. - return PP_ERROR_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; int32_t pp_error_or_bytes; NaClSrpcError srpc_result = @@ -202,7 +202,7 @@ int32_t Write(PP_Resource file_io, int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback); if (callback_id == 0) // Just like Chrome, for now disallow blocking calls. - return PP_ERROR_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; int32_t pp_error_or_bytes = PP_ERROR_FAILED; NaClSrpcError srpc_result = PpbFileIORpcClient::PPB_FileIO_Write( @@ -231,7 +231,7 @@ int32_t SetLength(PP_Resource file_io, int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback); if (callback_id == 0) // Just like Chrome, for now disallow blocking calls. - return PP_ERROR_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; int32_t pp_error = PP_ERROR_FAILED; NaClSrpcError srpc_result = PpbFileIORpcClient::PPB_FileIO_SetLength( @@ -256,7 +256,7 @@ int32_t Flush(PP_Resource file_io, int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback); if (callback_id == 0) // Just like Chrome, for now disallow blocking calls. - return PP_ERROR_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; int32_t pp_error = PP_ERROR_FAILED; NaClSrpcError srpc_result = PpbFileIORpcClient::PPB_FileIO_Flush( diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_file_system.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_file_system.cc index 64ebaf5..fb4fa40 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_file_system.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_file_system.cc @@ -57,8 +57,8 @@ int32_t Open(PP_Resource file_system, DebugPrintf("PPB_FileSystem::Open: file_system=%"NACL_PRIu32"\n", file_system); int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback); - if (callback_id == 0) - return PP_ERROR_BADARGUMENT; + if (callback_id == 0) // Just like Chrome, for now disallow blocking calls. + return PP_ERROR_BLOCKS_MAIN_THREAD; int32_t pp_error; NaClSrpcError srpc_result = diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_2d.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_2d.cc index 3bab6d1..2bf2797 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_2d.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_2d.cc @@ -153,7 +153,7 @@ int32_t Flush(PP_Resource graphics_2d, int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback); if (callback_id == 0) // Just like Chrome, for now disallow blocking calls. - return PP_ERROR_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; int32_t pp_error; NaClSrpcError srpc_result = diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_3d.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_3d.cc index 974563a..736eee2 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_3d.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_3d.cc @@ -238,7 +238,7 @@ int32_t PluginGraphics3D::SwapBuffers(PP_Resource graphics3d_id, int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback); if (callback_id == 0) // Just like Chrome, for now disallow blocking calls. - return PP_ERROR_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; int32_t pp_error; NaClSrpcError retval = diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_url_loader.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_url_loader.cc index 2118e90..be7a639 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_url_loader.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_url_loader.cc @@ -60,7 +60,7 @@ int32_t Open(PP_Resource loader, int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback); if (callback_id == 0) // Just like Chrome, for now disallow blocking calls. - return PP_ERROR_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; int32_t pp_error; NaClSrpcError srpc_result = @@ -80,7 +80,7 @@ int32_t FollowRedirect(PP_Resource loader, int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback); if (callback_id == 0) // Just like Chrome, for now disallow blocking calls. - return PP_ERROR_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; int32_t pp_error; NaClSrpcError srpc_result = @@ -167,7 +167,7 @@ int32_t ReadResponseBody(PP_Resource loader, int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback, buffer); if (callback_id == 0) // Just like Chrome, for now disallow blocking calls. - return PP_ERROR_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; int32_t pp_error_or_bytes; NaClSrpcError srpc_result = @@ -195,7 +195,7 @@ int32_t FinishStreamingToFile(PP_Resource loader, int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback); if (callback_id == 0) // Just like Chrome, for now disallow blocking calls. - return PP_ERROR_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; int32_t pp_error; NaClSrpcError srpc_result = diff --git a/ppapi/native_client/tests/ppapi_browser/ppb_file_system/ppapi_ppb_file_system.cc b/ppapi/native_client/tests/ppapi_browser/ppb_file_system/ppapi_ppb_file_system.cc index 5d17cde..ebf8128 100644 --- a/ppapi/native_client/tests/ppapi_browser/ppb_file_system/ppapi_ppb_file_system.cc +++ b/ppapi/native_client/tests/ppapi_browser/ppb_file_system/ppapi_ppb_file_system.cc @@ -134,7 +134,7 @@ void TestOpen() { pp_error = ppb_file_system->Open(file_system, kSize, PP_BlockUntilComplete()); ppb_core->ReleaseResource(file_system); - EXPECT(pp_error == PP_ERROR_BADARGUMENT); + EXPECT(pp_error == PP_ERROR_BLOCKS_MAIN_THREAD); #endif // Test success for asynchronous open. diff --git a/ppapi/native_client/tests/ppapi_browser/ppb_graphics2d/ppapi_ppb_graphics2d.cc b/ppapi/native_client/tests/ppapi_browser/ppb_graphics2d/ppapi_ppb_graphics2d.cc index cedeead..c8b4007 100644 --- a/ppapi/native_client/tests/ppapi_browser/ppb_graphics2d/ppapi_ppb_graphics2d.cc +++ b/ppapi/native_client/tests/ppapi_browser/ppb_graphics2d/ppapi_ppb_graphics2d.cc @@ -486,7 +486,7 @@ void TestFlush() { // Invalid args -> PP_ERROR_BAD..., no callback. EXPECT(PP_ERROR_BADRESOURCE == PPBGraphics2D()->Flush(kInvalidResource, cc)); EXPECT(PP_ERROR_BADRESOURCE == PPBGraphics2D()->Flush(kNotAResource, cc)); - EXPECT(PP_ERROR_BADARGUMENT == + EXPECT(PP_ERROR_BLOCKS_MAIN_THREAD == PPBGraphics2D()->Flush(graphics2d, PP_BlockUntilComplete())); // Valid args -> PP_OK_COMPLETIONPENDING, expect callback. diff --git a/ppapi/native_client/tests/ppapi_browser/ppb_url_loader/ppapi_ppb_url_loader.cc b/ppapi/native_client/tests/ppapi_browser/ppb_url_loader/ppapi_ppb_url_loader.cc index 1c5d30f..70d4d93 100644 --- a/ppapi/native_client/tests/ppapi_browser/ppb_url_loader/ppapi_ppb_url_loader.cc +++ b/ppapi/native_client/tests/ppapi_browser/ppb_url_loader/ppapi_ppb_url_loader.cc @@ -407,7 +407,7 @@ void TestOpenSimple() { loader = PPBURLLoader()->Create(pp_instance()); // We are on the main thread, performing a sync call should fail rv = PPBURLLoader()->Open(loader, request, PP_BlockUntilComplete()); - EXPECT(PP_ERROR_BADARGUMENT == rv); + EXPECT(PP_ERROR_BLOCKS_MAIN_THREAD == rv); PPBCore()->ReleaseResource(loader); LOG_TO_BROWSER("open (asynchronous) normal"); diff --git a/ppapi/proxy/ppb_broker_proxy.cc b/ppapi/proxy/ppb_broker_proxy.cc index ff06759..f584cf0 100644 --- a/ppapi/proxy/ppb_broker_proxy.cc +++ b/ppapi/proxy/ppb_broker_proxy.cc @@ -98,7 +98,7 @@ PPB_Broker_API* Broker::AsPPB_Broker_API() { int32_t Broker::Connect(PP_CompletionCallback connect_callback) { if (!connect_callback.func) { // Synchronous calls are not supported. - return PP_ERROR_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; } if (current_connect_callback_.func) diff --git a/ppapi/proxy/ppb_file_chooser_proxy.cc b/ppapi/proxy/ppb_file_chooser_proxy.cc index 73f7a6a..c74ba4f 100644 --- a/ppapi/proxy/ppb_file_chooser_proxy.cc +++ b/ppapi/proxy/ppb_file_chooser_proxy.cc @@ -83,6 +83,9 @@ PPB_FileChooser_API* FileChooser::AsPPB_FileChooser_API() { } int32_t FileChooser::Show(const PP_CompletionCallback& callback) { + if (!callback.func) + return PP_ERROR_BLOCKS_MAIN_THREAD; + if (current_show_callback_.func) return PP_ERROR_INPROGRESS; // Can't show more than once. diff --git a/ppapi/proxy/ppb_flash_tcp_socket_proxy.cc b/ppapi/proxy/ppb_flash_tcp_socket_proxy.cc index 7ff2ce3..020cf28 100644 --- a/ppapi/proxy/ppb_flash_tcp_socket_proxy.cc +++ b/ppapi/proxy/ppb_flash_tcp_socket_proxy.cc @@ -209,8 +209,10 @@ PP_Bool FlashTCPSocket::GetRemoteAddress(PP_Flash_NetAddress* remote_addr) { int32_t FlashTCPSocket::SSLHandshake(const char* server_name, uint16_t server_port, PP_CompletionCallback callback) { - if (!server_name || !callback.func) + if (!server_name) return PP_ERROR_BADARGUMENT; + if (!callback.func) + return PP_ERROR_BLOCKS_MAIN_THREAD; if (connection_state_ != CONNECTED) return PP_ERROR_FAILED; @@ -230,8 +232,10 @@ int32_t FlashTCPSocket::SSLHandshake(const char* server_name, int32_t FlashTCPSocket::Read(char* buffer, int32_t bytes_to_read, PP_CompletionCallback callback) { - if (!buffer || bytes_to_read <= 0 || !callback.func) + 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; @@ -251,8 +255,10 @@ int32_t FlashTCPSocket::Read(char* buffer, int32_t FlashTCPSocket::Write(const char* buffer, int32_t bytes_to_write, PP_CompletionCallback callback) { - if (!buffer || bytes_to_write <= 0 || !callback.func) + 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; @@ -365,7 +371,7 @@ int32_t FlashTCPSocket::ConnectWithMessage(IPC::Message* msg, PP_CompletionCallback callback) { scoped_ptr<IPC::Message> msg_deletor(msg); if (!callback.func) - return PP_ERROR_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; if (connection_state_ != BEFORE_CONNECT) return PP_ERROR_FAILED; if (connect_callback_.func) diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.cc b/ppapi/proxy/ppb_graphics_2d_proxy.cc index 232e1fe..dcf8d26 100644 --- a/ppapi/proxy/ppb_graphics_2d_proxy.cc +++ b/ppapi/proxy/ppb_graphics_2d_proxy.cc @@ -124,7 +124,7 @@ 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_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; if (current_flush_callback_.func) return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. diff --git a/ppapi/proxy/ppb_surface_3d_proxy.cc b/ppapi/proxy/ppb_surface_3d_proxy.cc index 70809da..c46f01b 100644 --- a/ppapi/proxy/ppb_surface_3d_proxy.cc +++ b/ppapi/proxy/ppb_surface_3d_proxy.cc @@ -62,7 +62,7 @@ int32_t Surface3D::SwapBuffers(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_BADARGUMENT; + return PP_ERROR_BLOCKS_MAIN_THREAD; if (is_flush_pending()) return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. |