Chromium Code Reviews| Index: content/browser/renderer_host/pepper/pepper_socket_utils.h |
| diff --git a/content/browser/renderer_host/pepper/pepper_socket_utils.h b/content/browser/renderer_host/pepper/pepper_socket_utils.h |
| index 3861eb687408b6c34d581cf3ea78a30a0ff34dc0..f934fc363c67c6fe48a2047a4a195d91dbefa7c9 100644 |
| --- a/content/browser/renderer_host/pepper/pepper_socket_utils.h |
| +++ b/content/browser/renderer_host/pepper/pepper_socket_utils.h |
| @@ -89,6 +89,58 @@ bool PostOnUIThreadWithRenderViewHostAndReply( |
| return true; |
| } |
| +// Backend for PostOnUIThreadWithRenderProcessHostAndReply. |
| +// This converts the IDs to a RenderProcessHost and calls the function, |
| +// or returns a defaultconstructed value on error. |
| +template<typename ReturnType> |
| +ReturnType CallWithRenderProcessHost( |
| + int render_process_id, |
| + const base::Callback<ReturnType(RenderProcessHost*)>& task) { |
| + RenderProcessHost* render_process_host = |
| + RenderProcessHost::FromID(render_process_id); |
| + if (render_process_host) |
| + return task.Run(render_process_host); |
| + return ReturnType(); |
| +} |
| + |
| +// Schedules the given callback to execute on the UI thread of the browser, |
| +// passing the RenderProcessHost associated with the given instance as a |
| +// parameter. |
| +// |
| +// Normally this would be called from a ResourceHost with the reply using |
| +// a weak pointer to itself. |
| +// |
| +// Importantly, the task will not be run if the RenderProcessHost is |
| +// destroyed by the time we get to the UI thread, or if the PP_Instance is |
| +// invalid, but the reply will still be run. The return type in this case |
| +// will be a defaultconstructed |ReturnType|. |
| +// |
| +// So you may want to make sure you don't do silly things in the reply |
| +// handler if the task on the UI thread is never run and you get a |
| +// defaultconstructed result. |
| +template<typename ReturnType> |
| +bool PostOnUIThreadWithRenderProcessHostAndReply( |
|
yzshen1
2013/01/24 18:45:03
Is this going to be used by other callers other th
ygorshenin1
2013/02/05 12:45:31
PostOnUIThreadWithRenderProcessHostAndReply is nee
|
| + const BrowserPpapiHost* browser_ppapi_host, |
| + const tracked_objects::Location& from_here, |
| + PP_Instance instance, |
| + const base::Callback<ReturnType(RenderProcessHost*)>& task, |
| + const base::Callback<void(ReturnType)>& reply) { |
| + int render_process_id, render_view_id; |
| + bool success = browser_ppapi_host->GetRenderViewIDsForInstance( |
| + instance, |
| + &render_process_id, |
| + &render_view_id); |
| + if (!success) |
| + return false; |
| + BrowserThread::PostTaskAndReplyWithResult( |
| + BrowserThread::UI, |
| + from_here, |
| + base::Bind(&CallWithRenderProcessHost<ReturnType>, |
| + render_process_id, task), |
| + reply); |
| + return true; |
| +} |
| + |
| } // namespace pepper_socket_utils |
| } // namespace content |