Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef PPAPI_SHARED_IMPL_RESOURCE_VAR_H_ | 5 #ifndef PPAPI_SHARED_IMPL_RESOURCE_VAR_H_ |
| 6 #define PPAPI_SHARED_IMPL_RESOURCE_VAR_H_ | 6 #define PPAPI_SHARED_IMPL_RESOURCE_VAR_H_ |
| 7 | 7 |
| 8 #include "ipc/ipc_message.h" | 8 #include "ipc/ipc_message.h" |
| 9 #include "ppapi/c/pp_resource.h" | 9 #include "ppapi/c/pp_resource.h" |
| 10 #include "ppapi/c/pp_var.h" | 10 #include "ppapi/c/pp_var.h" |
| 11 #include "ppapi/shared_impl/ppapi_shared_export.h" | 11 #include "ppapi/shared_impl/ppapi_shared_export.h" |
| 12 #include "ppapi/shared_impl/scoped_pp_resource.h" | |
| 12 #include "ppapi/shared_impl/var.h" | 13 #include "ppapi/shared_impl/var.h" |
| 13 | 14 |
| 14 namespace ppapi { | 15 namespace ppapi { |
| 15 | 16 |
| 17 class HostResourceVar; | |
| 18 | |
| 16 // Represents a resource Var. | 19 // Represents a resource Var. |
| 17 class PPAPI_SHARED_EXPORT ResourceVar : public Var { | 20 class PPAPI_SHARED_EXPORT ResourceVar : public Var { |
| 18 public: | 21 public: |
| 19 // Makes a null resource var. | |
| 20 ResourceVar(); | |
| 21 | |
| 22 // Makes a resource var with an existing plugin-side resource. | |
| 23 explicit ResourceVar(PP_Resource pp_resource); | |
| 24 | |
| 25 // Makes a resource var with a pending resource host. | |
| 26 // The |creation_message| contains instructions on how to create the | |
| 27 // plugin-side resource. Its type depends on the type of resource. | |
| 28 explicit ResourceVar(const IPC::Message& creation_message); | |
| 29 | |
| 30 virtual ~ResourceVar(); | |
| 31 | |
| 32 // Gets the resource ID associated with this var. | 22 // Gets the resource ID associated with this var. |
| 33 // This is 0 if a resource is still pending. | 23 // This is 0 if a resource is still pending (only possible on the host side). |
| 34 PP_Resource pp_resource() const { return pp_resource_; } | 24 virtual PP_Resource pp_resource() const = 0; |
| 35 | |
| 36 // Gets the message for creating a plugin-side resource. | |
| 37 // May be an empty message. | |
| 38 const IPC::Message& creation_message() const { return creation_message_; } | |
| 39 | 25 |
| 40 // Determines whether this is a pending resource. | 26 // Determines whether this is a pending resource. |
| 41 // This is true if the pp_resource is 0 and there is a non-empty | 27 // This is true if, on the host side, the pp_resource is 0 and there is a |
| 42 // creation_message. | 28 // non-empty creation_message. |
| 43 bool IsPending() const; | 29 virtual bool IsPending() const = 0; |
| 30 | |
| 31 // Safely down-cast to HostResourceVar, for access to creation_message. | |
| 32 // If this is not a HostResourceVar, returns NULL. | |
| 33 // Always succeeds if IsPending returns true. | |
| 34 virtual HostResourceVar* AsHostResourceVar(); | |
| 44 | 35 |
| 45 // Var override. | 36 // Var override. |
| 46 virtual ResourceVar* AsResourceVar() OVERRIDE; | 37 virtual ResourceVar* AsResourceVar() OVERRIDE; |
| 47 virtual PP_VarType GetType() const OVERRIDE; | 38 virtual PP_VarType GetType() const OVERRIDE; |
| 48 | 39 |
| 49 // Helper function that converts a PP_Var to a ResourceVar. This will | 40 // Helper function that converts a PP_Var to a ResourceVar. This will |
| 50 // return NULL if the PP_Var is not of Resource type. | 41 // return NULL if the PP_Var is not of Resource type. |
| 51 static ResourceVar* FromPPVar(PP_Var var); | 42 static ResourceVar* FromPPVar(PP_Var var); |
| 52 | 43 |
| 44 protected: | |
| 45 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.
| |
| 46 | |
| 47 private: | |
| 48 DISALLOW_COPY_AND_ASSIGN(ResourceVar); | |
| 49 }; | |
| 50 | |
| 51 // 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.
| |
| 52 // Can either have a plugin-side resource or a pending resource host. | |
| 53 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.
| |
| 54 public: | |
| 55 // Makes a null resource var. | |
| 56 HostResourceVar(); | |
| 57 | |
| 58 // Makes a resource var with an existing plugin-side resource. | |
| 59 explicit HostResourceVar(PP_Resource pp_resource); | |
| 60 | |
| 61 // Makes a resource var with a pending resource host. | |
| 62 // 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.
| |
| 63 // plugin-side resource. Its type depends on the type of resource. | |
| 64 explicit HostResourceVar(const IPC::Message& creation_message); | |
| 65 | |
| 66 virtual ~HostResourceVar(); | |
| 67 | |
| 68 // ResourceVar override. | |
| 69 virtual PP_Resource pp_resource() const OVERRIDE; | |
| 70 virtual bool IsPending() const OVERRIDE; | |
| 71 virtual HostResourceVar* AsHostResourceVar() OVERRIDE; | |
| 72 | |
| 73 // Gets the message for creating a plugin-side resource. | |
| 74 // 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.
| |
| 75 const IPC::Message& creation_message() const { return creation_message_; } | |
| 76 | |
| 53 private: | 77 private: |
| 54 // Real resource ID in the plugin. 0 if one has not yet been created | 78 // Real resource ID in the plugin. 0 if one has not yet been created |
| 55 // (indicating that there is a pending host resource). | 79 // (indicating that there is a pending host resource). |
| 56 PP_Resource pp_resource_; | 80 PP_Resource pp_resource_; |
| 57 | 81 |
| 58 // If the plugin-side resource has not yet been created, carries a message to | 82 // If the plugin-side resource has not yet been created, carries a message to |
| 59 // create a resource of the specific type on the plugin side. | 83 // create a resource of the specific type on the plugin side. |
| 60 // Otherwise, carries an empty message. | 84 // Otherwise, carries an empty message. |
| 61 IPC::Message creation_message_; | 85 IPC::Message creation_message_; |
| 62 | 86 |
| 63 DISALLOW_COPY_AND_ASSIGN(ResourceVar); | 87 DISALLOW_COPY_AND_ASSIGN(HostResourceVar); |
| 88 }; | |
| 89 | |
| 90 // 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.
| |
| 91 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.
| |
| 92 public: | |
| 93 // Makes a null resource var. | |
| 94 PluginResourceVar(); | |
| 95 | |
| 96 // Makes a resource var with an existing resource. | |
| 97 // Takes one reference to the given resource. | |
| 98 explicit PluginResourceVar(PP_Resource pp_resource); | |
| 99 | |
| 100 virtual ~PluginResourceVar(); | |
| 101 | |
| 102 // ResourceVar override. | |
| 103 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.
| |
| 104 virtual bool IsPending() const OVERRIDE; | |
| 105 | |
| 106 private: | |
| 107 // Resource ID. | |
| 108 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
| |
| 109 | |
| 110 DISALLOW_COPY_AND_ASSIGN(PluginResourceVar); | |
| 64 }; | 111 }; |
| 65 | 112 |
| 66 } // namespace ppapi | 113 } // namespace ppapi |
| 67 | 114 |
| 68 #endif // PPAPI_SHARED_IMPL_RESOURCE_VAR_H_ | 115 #endif // PPAPI_SHARED_IMPL_RESOURCE_VAR_H_ |
| OLD | NEW |