| 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 2dbdfe30205d346f14047f97086d13396dda7a90..e387ac02f6951a2b2cdf8a0b247cf01f71fb0713 100644
|
| --- a/content/public/browser/browser_ppapi_host.h
|
| +++ b/content/public/browser/browser_ppapi_host.h
|
| @@ -9,7 +9,9 @@
|
| #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 "content/public/common/process_type.h"
|
| #include "ppapi/c/pp_instance.h"
|
|
|
| namespace IPC {
|
| @@ -45,6 +47,7 @@ class CONTENT_EXPORT BrowserPpapiHost {
|
| ppapi::PpapiPermissions permissions,
|
| base::ProcessHandle plugin_child_process,
|
| int plugin_child_process_id,
|
| + ProcessType process_type,
|
| IPC::ChannelProxy* channel,
|
| net::HostResolver* host_resolver,
|
| int render_process_id,
|
| @@ -81,6 +84,58 @@ class CONTENT_EXPORT BrowserPpapiHost {
|
|
|
| // Returns the unique id of the child plugin process (this is NOT the pid).
|
| virtual int GetPluginProcessID() = 0;
|
| +
|
| + // Schedules the given callback to execute on the UI thread of the browser,
|
| + // passing the RenderViewHost 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
|
| + // default-constructed |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
|
| + // default-constructed result.
|
| + template<typename ReturnType>
|
| + bool PostOnUIThreadWithRenderViewHostAndReply(
|
| + const tracked_objects::Location& from_here,
|
| + PP_Instance instance,
|
| + const base::Callback<ReturnType(RenderViewHost*)>& 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(&CallWithRenderViewHost<ReturnType>,
|
| + render_process_id, render_view_id, task),
|
| + reply);
|
| + return true;
|
| + }
|
| +
|
| + protected:
|
| + // Backend for PostOnUIThreadWithRenderViewAndReply. This converts the IDs
|
| + // to a RenderViewHost and calls the function, or returns a
|
| + // default-constructed return value on error.
|
| + template<typename ReturnType>
|
| + static ReturnType CallWithRenderViewHost(
|
| + int render_process_id,
|
| + int render_view_id,
|
| + const base::Callback<ReturnType(RenderViewHost*)>& task) {
|
| + RenderViewHost* render_view_host = RenderViewHost::FromID(render_process_id,
|
| + render_view_id);
|
| + if (render_view_host)
|
| + return task.Run(render_view_host);
|
| + return ReturnType();
|
| + }
|
| };
|
|
|
| } // namespace content
|
|
|