Chromium Code Reviews| Index: content/public/browser/browser_ppapi_host.h |
| diff --git a/content/public/browser/browser_ppapi_host.h b/content/public/browser/browser_ppapi_host.h |
| index 08c5f074af2be597174809b09f6525b353b8ceda..8e7a208490f5ce5b4cbd5fff43130df5ff32b1f2 100644 |
| --- a/content/public/browser/browser_ppapi_host.h |
| +++ b/content/public/browser/browser_ppapi_host.h |
| @@ -9,6 +9,7 @@ |
| #include "base/process.h" |
| #include "content/common/content_export.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/render_process_host.h" |
| #include "content/public/browser/render_view_host.h" |
| #include "googleurl/src/gurl.h" |
| #include "ppapi/c/pp_instance.h" |
| @@ -83,6 +84,58 @@ class CONTENT_EXPORT BrowserPpapiHost { |
| // Get the Document/Plugin URLs for the given PP_Instance. |
| virtual GURL GetDocumentURLForInstance(PP_Instance instance) = 0; |
| virtual GURL GetPluginURLForInstance(PP_Instance instance) = 0; |
| + |
| + |
| + // Schedules the given callback to execute on the UI thread of the browser, |
| + // passing the RenderProcess 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 RenderView 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 PostOnUIThreadWithRenderProcessAndReply( |
|
yzshen1
2012/12/20 20:00:20
Is it possible to be done using ResourceMessageFil
|
| + const tracked_objects::Location& from_here, |
| + PP_Instance instance, |
| + const base::Callback<ReturnType(RenderProcessHost*)>& task, |
| + const base::Callback<void(ReturnType)>& reply) const { |
| + int render_process_id, render_view_id; |
| + bool success = 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; |
| + } |
| + |
| + protected: |
| + // Backend for PostOnUIThreadWithRenderViewAndReply. This converts the IDs |
| + // to a RenderProcessHost and calls the function, or returns a |
| + // defaultconstructed return value on error. |
| + template<typename ReturnType> |
| + static 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(); |
| + } |
| }; |
| } // namespace content |