Chromium Code Reviews| Index: ppapi/shared_impl/resource_var.h |
| diff --git a/ppapi/shared_impl/resource_var.h b/ppapi/shared_impl/resource_var.h |
| index 70eabc6cfb56ab426618ea14ba3ed1ae4595e62b..af78b0d6b6f2fac648b906efc4fc060abe295653 100644 |
| --- a/ppapi/shared_impl/resource_var.h |
| +++ b/ppapi/shared_impl/resource_var.h |
| @@ -9,47 +9,71 @@ |
| #include "ppapi/c/pp_resource.h" |
| #include "ppapi/c/pp_var.h" |
| #include "ppapi/shared_impl/ppapi_shared_export.h" |
| +#include "ppapi/shared_impl/scoped_pp_resource.h" |
| #include "ppapi/shared_impl/var.h" |
| namespace ppapi { |
| +class HostResourceVar; |
| + |
| // Represents a resource Var. |
| class PPAPI_SHARED_EXPORT ResourceVar : public Var { |
| public: |
| - // Makes a null resource var. |
| + // Gets the resource ID associated with this var. |
| + // This is 0 if a resource is still pending (only possible on the host side). |
| + virtual PP_Resource pp_resource() const = 0; |
| + |
| + // Determines whether this is a pending resource. |
| + // This is true if, on the host side, the pp_resource is 0 and there is a |
| + // non-empty creation_message. |
| + virtual bool IsPending() const = 0; |
| + |
| + // Safely down-cast to HostResourceVar, for access to creation_message. |
| + // If this is not a HostResourceVar, returns NULL. |
| + // Always succeeds if IsPending returns true. |
| + virtual HostResourceVar* AsHostResourceVar(); |
| + |
| + // Var override. |
| + virtual ResourceVar* AsResourceVar() OVERRIDE; |
| + virtual PP_VarType GetType() const OVERRIDE; |
| + |
| + // Helper function that converts a PP_Var to a ResourceVar. This will |
| + // return NULL if the PP_Var is not of Resource type. |
| + static ResourceVar* FromPPVar(PP_Var var); |
| + |
| + protected: |
| ResourceVar(); |
|
dmichael (off chromium)
2013/09/13 17:29:03
you also need to define a virtual destructor.
Matt Giuca
2013/09/17 00:24:52
Done.
|
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ResourceVar); |
| +}; |
| + |
| +// Represents a resource Var, usable on the host side. |
|
raymes
2013/09/13 17:41:33
Nit: please fill the line to 80chars with comments
Matt Giuca
2013/09/17 00:24:52
Done.
|
| +// Can either have a plugin-side resource or a pending resource host. |
| +class PPAPI_SHARED_EXPORT HostResourceVar : public ResourceVar { |
|
dmichael (off chromium)
2013/09/13 17:29:03
Should this live in content/renderer/pepper instea
Matt Giuca
2013/09/17 01:26:28
Done.
|
| + public: |
| + // Makes a null resource var. |
| + HostResourceVar(); |
| + |
| // Makes a resource var with an existing plugin-side resource. |
| - explicit ResourceVar(PP_Resource pp_resource); |
| + explicit HostResourceVar(PP_Resource pp_resource); |
| // Makes a resource var with a pending resource host. |
| // The |creation_message| contains instructions on how to create the |
|
dmichael (off chromium)
2013/09/13 17:29:03
s/"instruction on how to"/"data needed to"?
Matt Giuca
2013/09/17 00:24:52
Done.
|
| // plugin-side resource. Its type depends on the type of resource. |
| - explicit ResourceVar(const IPC::Message& creation_message); |
| + explicit HostResourceVar(const IPC::Message& creation_message); |
| - virtual ~ResourceVar(); |
| + virtual ~HostResourceVar(); |
| - // Gets the resource ID associated with this var. |
| - // This is 0 if a resource is still pending. |
| - PP_Resource pp_resource() const { return pp_resource_; } |
| + // ResourceVar override. |
| + virtual PP_Resource pp_resource() const OVERRIDE; |
| + virtual bool IsPending() const OVERRIDE; |
| + virtual HostResourceVar* AsHostResourceVar() OVERRIDE; |
| // Gets the message for creating a plugin-side resource. |
| // May be an empty message. |
|
dmichael (off chromium)
2013/09/13 17:29:03
Would it be better to own a scoped_ptr instead, an
Matt Giuca
2013/09/17 00:24:52
Done.
|
| const IPC::Message& creation_message() const { return creation_message_; } |
| - // Determines whether this is a pending resource. |
| - // This is true if the pp_resource is 0 and there is a non-empty |
| - // creation_message. |
| - bool IsPending() const; |
| - |
| - // Var override. |
| - virtual ResourceVar* AsResourceVar() OVERRIDE; |
| - virtual PP_VarType GetType() const OVERRIDE; |
| - |
| - // Helper function that converts a PP_Var to a ResourceVar. This will |
| - // return NULL if the PP_Var is not of Resource type. |
| - static ResourceVar* FromPPVar(PP_Var var); |
| - |
| private: |
| // Real resource ID in the plugin. 0 if one has not yet been created |
| // (indicating that there is a pending host resource). |
| @@ -60,7 +84,30 @@ class PPAPI_SHARED_EXPORT ResourceVar : public Var { |
| // Otherwise, carries an empty message. |
| IPC::Message creation_message_; |
| - DISALLOW_COPY_AND_ASSIGN(ResourceVar); |
| + DISALLOW_COPY_AND_ASSIGN(HostResourceVar); |
| +}; |
| + |
| +// Represents a resource Var, usable on the plugin side. |
|
raymes
2013/09/13 17:41:33
nit: Var -> var for consistency
Matt Giuca
2013/09/17 00:24:52
Done.
|
| +class PPAPI_SHARED_EXPORT PluginResourceVar : public ResourceVar { |
|
dmichael (off chromium)
2013/09/13 17:29:03
This should probably live in ppapi/proxy
(Note, I
Matt Giuca
2013/09/17 01:26:28
Done.
|
| + public: |
| + // Makes a null resource var. |
| + PluginResourceVar(); |
| + |
| + // Makes a resource var with an existing resource. |
| + // Takes one reference to the given resource. |
| + explicit PluginResourceVar(PP_Resource pp_resource); |
| + |
| + virtual ~PluginResourceVar(); |
| + |
| + // ResourceVar override. |
| + virtual PP_Resource pp_resource() const OVERRIDE; |
|
raymes
2013/09/13 17:41:33
nit: pp_resource() style naming is usually for sim
Matt Giuca
2013/09/17 00:24:52
Done.
|
| + virtual bool IsPending() const OVERRIDE; |
| + |
| + private: |
| + // Resource ID. |
| + ScopedPPResource pp_resource_; |
|
dmichael (off chromium)
2013/09/13 17:29:03
If possible, I think scoped_refptr<Resource> would
Matt Giuca
2013/09/17 00:24:52
I had a long chat with Yuzhu about this. First, we
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(PluginResourceVar); |
| }; |
| } // namespace ppapi |