diff options
author | dmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-05 20:08:24 +0000 |
---|---|---|
committer | dmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-05 20:08:24 +0000 |
commit | c9eb5058727792d807a475026f33e428813fdd0c (patch) | |
tree | adcc38af58d1203e89ef556f3510f15cb2946011 /ppapi/shared_impl/private | |
parent | 02506d484620d02edead710dc856ab8a28813c3b (diff) | |
download | chromium_src-c9eb5058727792d807a475026f33e428813fdd0c.zip chromium_src-c9eb5058727792d807a475026f33e428813fdd0c.tar.gz chromium_src-c9eb5058727792d807a475026f33e428813fdd0c.tar.bz2 |
PPAPI: Get TrackedCallback ready for running on non-main threads.
When CompletionCallbacks can run on background threads, ClearAndRun doesn't make sense anymore. Because the call may bounce to a different thread, we can't guarantee we'll run it right away, so setting the callback pointer to NULL is no longer a good way to indicate the callback has been run. Instead, callers should just use Run(), and rely on IsPending() to tell them if the call is still pending.
TrackedCallback also can not use WeakPtrs, because those DCHECK if they are dereferenced on a different thread than they were created on. In particular, if a PPB implementation calls callback_->Run(PP_OK), that almost always happens on the main thread, and creates a WeakPtr<TrackedCallback> there. But Run will sometimes have to schedule a task on a non-main thread, and the WeakPtr will fail there. Note that because all this happens behind the proxy lock, it actually would be safe. But I just went with a bool flag to do the same checking as before, rather than try to subvert the WeakPtr checks.
The CL for the Callbacks-on-background-threads feature is basically working and is here:
https://chromiumcodereview.appspot.com/10910099
BUG=92909
Review URL: https://chromiumcodereview.appspot.com/10909244
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166009 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/shared_impl/private')
4 files changed, 14 insertions, 20 deletions
diff --git a/ppapi/shared_impl/private/ppb_host_resolver_shared.cc b/ppapi/shared_impl/private/ppb_host_resolver_shared.cc index 543b1c0..ba026dc 100644 --- a/ppapi/shared_impl/private/ppb_host_resolver_shared.cc +++ b/ppapi/shared_impl/private/ppb_host_resolver_shared.cc @@ -84,8 +84,7 @@ void PPB_HostResolver_Shared::OnResolveCompleted( net_address_list_.clear(); } - TrackedCallback::ClearAndRun(&resolve_callback_, - succeeded ? PP_OK : PP_ERROR_FAILED); + resolve_callback_->Run(succeeded ? PP_OK : PP_ERROR_FAILED); } uint32 PPB_HostResolver_Shared::GenerateHostResolverID() { 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 f057da6..f816c62 100644 --- a/ppapi/shared_impl/private/ppb_tcp_server_socket_shared.cc +++ b/ppapi/shared_impl/private/ppb_tcp_server_socket_shared.cc @@ -78,9 +78,9 @@ void PPB_TCPServerSocket_Shared::StopListening() { SendStopListening(); socket_id_ = 0; - if (listen_callback_.get()) + if (TrackedCallback::IsPending(listen_callback_)) listen_callback_->PostAbort(); - if (accept_callback_.get()) + if (TrackedCallback::IsPending(accept_callback_)) accept_callback_->PostAbort(); tcp_socket_buffer_ = NULL; } @@ -98,7 +98,7 @@ void PPB_TCPServerSocket_Shared::OnListenCompleted(uint32 socket_id, state_ = LISTENING; } - TrackedCallback::ClearAndRun(&listen_callback_, status); + listen_callback_->Run(status); } } // namespace ppapi diff --git a/ppapi/shared_impl/private/tcp_socket_private_impl.cc b/ppapi/shared_impl/private/tcp_socket_private_impl.cc index c4a9a17..e2c645f0 100644 --- a/ppapi/shared_impl/private/tcp_socket_private_impl.cc +++ b/ppapi/shared_impl/private/tcp_socket_private_impl.cc @@ -232,8 +232,7 @@ void TCPSocketPrivateImpl::OnConnectCompleted( remote_addr_ = remote_addr; connection_state_ = CONNECTED; } - TrackedCallback::ClearAndRun(&connect_callback_, - succeeded ? PP_OK : PP_ERROR_FAILED); + connect_callback_->Run(succeeded ? PP_OK : PP_ERROR_FAILED); } void TCPSocketPrivateImpl::OnSSLHandshakeCompleted( @@ -251,12 +250,12 @@ void TCPSocketPrivateImpl::OnSSLHandshakeCompleted( resource_type_, pp_instance(), certificate_fields); - TrackedCallback::ClearAndRun(&ssl_handshake_callback_, PP_OK); + ssl_handshake_callback_->Run(PP_OK); } else { // The resource might be released in the callback so we need to hold // a reference so we can Disconnect() first. AddRef(); - TrackedCallback::ClearAndRun(&ssl_handshake_callback_, PP_ERROR_FAILED); + ssl_handshake_callback_->Run(PP_ERROR_FAILED); Disconnect(); Release(); } @@ -277,8 +276,7 @@ void TCPSocketPrivateImpl::OnReadCompleted(bool succeeded, read_buffer_ = NULL; bytes_to_read_ = -1; - TrackedCallback::ClearAndRun( - &read_callback_, + read_callback_->Run( succeeded ? static_cast<int32_t>(data.size()) : static_cast<int32_t>(PP_ERROR_FAILED)); } @@ -291,8 +289,7 @@ void TCPSocketPrivateImpl::OnWriteCompleted(bool succeeded, return; } - TrackedCallback::ClearAndRun( - &write_callback_, + write_callback_->Run( succeeded ? bytes_written : static_cast<int32_t>(PP_ERROR_FAILED)); } @@ -317,7 +314,7 @@ bool TCPSocketPrivateImpl::IsConnected() const { void TCPSocketPrivateImpl::PostAbortIfNecessary( scoped_refptr<TrackedCallback>* callback) { - if (callback->get()) + if (TrackedCallback::IsPending(*callback)) (*callback)->PostAbort(); } diff --git a/ppapi/shared_impl/private/udp_socket_private_impl.cc b/ppapi/shared_impl/private/udp_socket_private_impl.cc index d3e94c1..288c38f 100644 --- a/ppapi/shared_impl/private/udp_socket_private_impl.cc +++ b/ppapi/shared_impl/private/udp_socket_private_impl.cc @@ -162,8 +162,7 @@ void UDPSocketPrivateImpl::OnBindCompleted( bound_addr_ = addr; - TrackedCallback::ClearAndRun(&bind_callback_, - succeeded ? PP_OK : PP_ERROR_FAILED); + bind_callback_->Run(succeeded ? PP_OK : PP_ERROR_FAILED); } void UDPSocketPrivateImpl::OnRecvFromCompleted( @@ -184,8 +183,7 @@ void UDPSocketPrivateImpl::OnRecvFromCompleted( bytes_to_read_ = -1; recvfrom_addr_ = addr; - TrackedCallback::ClearAndRun(&recvfrom_callback_, - succeeded ? static_cast<int32_t>(data.size()) : + recvfrom_callback_->Run(succeeded ? static_cast<int32_t>(data.size()) : static_cast<int32_t>(PP_ERROR_FAILED)); } @@ -196,7 +194,7 @@ void UDPSocketPrivateImpl::OnSendToCompleted(bool succeeded, return; } - TrackedCallback::ClearAndRun(&sendto_callback_, + sendto_callback_->Run( succeeded ? bytes_written : static_cast<int32_t>(PP_ERROR_FAILED)); } @@ -218,7 +216,7 @@ void UDPSocketPrivateImpl::Init(uint32 socket_id) { void UDPSocketPrivateImpl::PostAbortIfNecessary( scoped_refptr<TrackedCallback>* callback) { - if (callback->get()) + if (TrackedCallback::IsPending(*callback)) (*callback)->PostAbort(); } |