Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2036)

Unified Diff: content/public/browser/browser_ppapi_host.h

Issue 11441012: PPB_UDPSocket_Private is switched to the new Pepper proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: PPB_UDPSocket_Shared is merged to UDPSocketPrivateResource. PepperUDPSocketPrivateShared is merged … Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..06fe4bbf2d96217433a39f9b463431bac1ab1f9f 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 "googleurl/src/gurl.h"
#include "ppapi/c/pp_instance.h"
@@ -45,6 +47,7 @@ class CONTENT_EXPORT BrowserPpapiHost {
IPC::Sender* sender,
ppapi::PpapiPermissions permissions,
base::ProcessHandle plugin_child_process,
+ ProcessType process_type,
IPC::ChannelProxy* channel,
net::HostResolver* host_resolver,
int render_process_id,
@@ -83,6 +86,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 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
dmichael (off chromium) 2013/01/10 17:30:47 nit: PostOnUIThreadWithRenderView+Host+AndReply
ygorshenin1 2013/01/11 11:42:45 Done.
+ // 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

Powered by Google App Engine
This is Rietveld 408576698