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

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

Issue 10909138: Convert the async device ID getter to a chrome resource host (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 months 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 aa9799071cd2460ab1fc02226121d90321348fe8..622a7fbb85516f8dda9e5c19965698b047ba2fb3 100644
--- a/content/public/browser/browser_ppapi_host.h
+++ b/content/public/browser/browser_ppapi_host.h
@@ -5,8 +5,12 @@
#ifndef CONTENT_PUBLIC_BROWSER_BROWSER_PPAPI_HOST_H_
#define CONTENT_PUBLIC_BROWSER_BROWSER_PPAPI_HOST_H_
+#include "base/callback_forward.h"
#include "base/process.h"
#include "content/common/content_export.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_view_host.h"
+#include "ppapi/c/pp_instance.h"
namespace ppapi {
namespace host {
@@ -23,14 +27,73 @@ namespace content {
// lives entirely on the I/O thread.
class CONTENT_EXPORT BrowserPpapiHost {
public:
+ struct RenderViewIDs {
jam 2012/09/10 16:22:21 nit: we've avoied a struct for these two so far af
brettw 2012/09/11 20:25:20 I insert these into a map. I can use a pair but th
+ int process_id;
+ int view_id;
+ };
+
// Returns the PpapiHost object.
virtual ppapi::host::PpapiHost* GetPpapiHost() = 0;
// Returns the handle to the plugin process.
virtual base::ProcessHandle GetPluginProcessHandle() const = 0;
+ // Returns true if the given PP_Instance is valid.
+ virtual bool IsValidInstance(PP_Instance instance) const = 0;
+
+ // Returns the process/view Ids associated with the RenderView containing the
+ // given instance. If the instance is invalid, the ids will be 0.
+ //
+ // The PP_Instance should be already validated by the host before creating
yzshen1 2012/09/11 00:53:17 I don't understand this comment. Is it out-dated o
brettw 2012/09/11 20:25:20 I clarified this a bit. I just didn't want everybo
+ // any resources with the PP_Instance, so you should not generally need to
+ // check for errors.
+ virtual RenderViewIDs GetRenderViewIDsForInstance(
+ PP_Instance instance) const = 0;
+
+ // Schedules the given callback to execute on the UI thread of the browser,
+ // passing the RenderView 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>
+ void PostOnUIThreadWithRenderViewAndReply(
yzshen1 2012/09/11 00:53:17 This method is not used in this CL. Is it obsolete
brettw 2012/09/11 20:25:20 Yeah, I removed this and stashed it for when we ne
+ const tracked_objects::Location& from_here,
+ PP_Instance instance,
+ const base::Callback<ReturnType(RenderViewHost*)>& task,
+ const base::Callback<void(ReturnType)>& reply) const {
+ BrowserThread::PostTaskAndReplyWithResult(
+ BrowserThread::UI,
+ from_here,
+ base::Bind(&CallWithRenderViewHost,
+ GetRenderViewIDsForInstance(instance), task),
+ reply);
+ }
+
protected:
virtual ~BrowserPpapiHost() {}
+
+ // 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(
+ const RenderViewIDs& ids,
+ const base::Callback<ReturnType(RenderViewHost*)>& task) {
+ RenderViewHost* render_view_host =
+ RenderViewHost::FromID(ids.process_id, ids.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