| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_PROXY_RAW_VAR_DATA_H_ | 5 #ifndef PPAPI_PROXY_RAW_VAR_DATA_H_ |
| 6 #define PPAPI_PROXY_RAW_VAR_DATA_H_ | 6 #define PPAPI_PROXY_RAW_VAR_DATA_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "ppapi/c/pp_instance.h" | 13 #include "ppapi/c/pp_instance.h" |
| 14 #include "ppapi/c/pp_var.h" | 14 #include "ppapi/c/pp_var.h" |
| 15 #include "ppapi/proxy/ppapi_param_traits.h" | 15 #include "ppapi/proxy/ppapi_param_traits.h" |
| 16 #include "ppapi/proxy/ppapi_proxy_export.h" | 16 #include "ppapi/proxy/ppapi_proxy_export.h" |
| 17 #include "ppapi/proxy/serialized_handle.h" | 17 #include "ppapi/proxy/serialized_handle.h" |
| 18 | 18 |
| 19 namespace base { |
| 20 class Pickle; |
| 19 class PickleIterator; | 21 class PickleIterator; |
| 22 } |
| 20 | 23 |
| 21 namespace IPC { | 24 namespace IPC { |
| 22 class Message; | 25 class Message; |
| 23 } | 26 } |
| 24 | 27 |
| 25 namespace ppapi { | 28 namespace ppapi { |
| 26 namespace proxy { | 29 namespace proxy { |
| 27 | 30 |
| 28 class RawVarData; | 31 class RawVarData; |
| 29 | 32 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // the returned PP_Var are also constructed. Each PP_Var created has a | 64 // the returned PP_Var are also constructed. Each PP_Var created has a |
| 62 // ref-count equal to the number of references it has in the graph of vars. | 65 // ref-count equal to the number of references it has in the graph of vars. |
| 63 // The returned var (the "root") has one additional reference. | 66 // The returned var (the "root") has one additional reference. |
| 64 PP_Var CreatePPVar(PP_Instance instance); | 67 PP_Var CreatePPVar(PP_Instance instance); |
| 65 | 68 |
| 66 // Write the graph to a message using the given HandleWriter. | 69 // Write the graph to a message using the given HandleWriter. |
| 67 void Write(IPC::Message* m, const HandleWriter& handle_writer); | 70 void Write(IPC::Message* m, const HandleWriter& handle_writer); |
| 68 | 71 |
| 69 // Create a RawVarDataGraph from the given message. | 72 // Create a RawVarDataGraph from the given message. |
| 70 static scoped_ptr<RawVarDataGraph> Read(const IPC::Message* m, | 73 static scoped_ptr<RawVarDataGraph> Read(const IPC::Message* m, |
| 71 PickleIterator* iter); | 74 base::PickleIterator* iter); |
| 72 | 75 |
| 73 // Returns a vector of SerializedHandles associated with this RawVarDataGraph. | 76 // Returns a vector of SerializedHandles associated with this RawVarDataGraph. |
| 74 // Ownership of the pointers remains with the elements of the RawVarDataGraph. | 77 // Ownership of the pointers remains with the elements of the RawVarDataGraph. |
| 75 std::vector<SerializedHandle*> GetHandles(); | 78 std::vector<SerializedHandle*> GetHandles(); |
| 76 | 79 |
| 77 // Sets the threshold size at which point we switch from transmitting | 80 // Sets the threshold size at which point we switch from transmitting |
| 78 // array buffers in IPC messages to using shared memory. This is only used | 81 // array buffers in IPC messages to using shared memory. This is only used |
| 79 // for testing purposes where we need to transmit small buffers using shmem | 82 // for testing purposes where we need to transmit small buffers using shmem |
| 80 // (in order to have fast tests). | 83 // (in order to have fast tests). |
| 81 static void SetMinimumArrayBufferSizeForShmemForTest(uint32 threshold); | 84 static void SetMinimumArrayBufferSizeForShmemForTest(uint32 threshold); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 106 // along with the graph it is a part of to be initialized. | 109 // along with the graph it is a part of to be initialized. |
| 107 virtual void PopulatePPVar(const PP_Var& var, | 110 virtual void PopulatePPVar(const PP_Var& var, |
| 108 const std::vector<PP_Var>& graph) = 0; | 111 const std::vector<PP_Var>& graph) = 0; |
| 109 | 112 |
| 110 // Writes the RawVarData to a message. | 113 // Writes the RawVarData to a message. |
| 111 virtual void Write(IPC::Message* m, | 114 virtual void Write(IPC::Message* m, |
| 112 const HandleWriter& handle_writer) = 0; | 115 const HandleWriter& handle_writer) = 0; |
| 113 // Reads the RawVarData from a message. Returns true on success. | 116 // Reads the RawVarData from a message. Returns true on success. |
| 114 virtual bool Read(PP_VarType type, | 117 virtual bool Read(PP_VarType type, |
| 115 const IPC::Message* m, | 118 const IPC::Message* m, |
| 116 PickleIterator* iter) = 0; | 119 base::PickleIterator* iter) = 0; |
| 117 | 120 |
| 118 // Returns a SerializedHandle associated with this RawVarData or NULL if none | 121 // Returns a SerializedHandle associated with this RawVarData or NULL if none |
| 119 // exists. Ownership of the pointer remains with the RawVarData. | 122 // exists. Ownership of the pointer remains with the RawVarData. |
| 120 virtual SerializedHandle* GetHandle(); | 123 virtual SerializedHandle* GetHandle(); |
| 121 | 124 |
| 122 bool initialized() { return initialized_; } | 125 bool initialized() { return initialized_; } |
| 123 | 126 |
| 124 protected: | 127 protected: |
| 125 bool initialized_; | 128 bool initialized_; |
| 126 }; | 129 }; |
| 127 | 130 |
| 128 // A RawVarData class for PP_Vars which are value types. | 131 // A RawVarData class for PP_Vars which are value types. |
| 129 class BasicRawVarData : public RawVarData { | 132 class BasicRawVarData : public RawVarData { |
| 130 public: | 133 public: |
| 131 BasicRawVarData(); | 134 BasicRawVarData(); |
| 132 ~BasicRawVarData() override; | 135 ~BasicRawVarData() override; |
| 133 | 136 |
| 134 // RawVarData implementation. | 137 // RawVarData implementation. |
| 135 PP_VarType Type() override; | 138 PP_VarType Type() override; |
| 136 bool Init(const PP_Var& var, PP_Instance instance) override; | 139 bool Init(const PP_Var& var, PP_Instance instance) override; |
| 137 PP_Var CreatePPVar(PP_Instance instance) override; | 140 PP_Var CreatePPVar(PP_Instance instance) override; |
| 138 void PopulatePPVar(const PP_Var& var, | 141 void PopulatePPVar(const PP_Var& var, |
| 139 const std::vector<PP_Var>& graph) override; | 142 const std::vector<PP_Var>& graph) override; |
| 140 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; | 143 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; |
| 141 bool Read(PP_VarType type, | 144 bool Read(PP_VarType type, |
| 142 const IPC::Message* m, | 145 const IPC::Message* m, |
| 143 PickleIterator* iter) override; | 146 base::PickleIterator* iter) override; |
| 144 | 147 |
| 145 private: | 148 private: |
| 146 PP_Var var_; | 149 PP_Var var_; |
| 147 }; | 150 }; |
| 148 | 151 |
| 149 // A RawVarData class for string PP_Vars. | 152 // A RawVarData class for string PP_Vars. |
| 150 class StringRawVarData : public RawVarData { | 153 class StringRawVarData : public RawVarData { |
| 151 public: | 154 public: |
| 152 StringRawVarData(); | 155 StringRawVarData(); |
| 153 ~StringRawVarData() override; | 156 ~StringRawVarData() override; |
| 154 | 157 |
| 155 // RawVarData implementation. | 158 // RawVarData implementation. |
| 156 PP_VarType Type() override; | 159 PP_VarType Type() override; |
| 157 bool Init(const PP_Var& var, PP_Instance instance) override; | 160 bool Init(const PP_Var& var, PP_Instance instance) override; |
| 158 PP_Var CreatePPVar(PP_Instance instance) override; | 161 PP_Var CreatePPVar(PP_Instance instance) override; |
| 159 void PopulatePPVar(const PP_Var& var, | 162 void PopulatePPVar(const PP_Var& var, |
| 160 const std::vector<PP_Var>& graph) override; | 163 const std::vector<PP_Var>& graph) override; |
| 161 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; | 164 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; |
| 162 bool Read(PP_VarType type, | 165 bool Read(PP_VarType type, |
| 163 const IPC::Message* m, | 166 const IPC::Message* m, |
| 164 PickleIterator* iter) override; | 167 base::PickleIterator* iter) override; |
| 165 | 168 |
| 166 private: | 169 private: |
| 167 // The data in the string. | 170 // The data in the string. |
| 168 std::string data_; | 171 std::string data_; |
| 169 }; | 172 }; |
| 170 | 173 |
| 171 // A RawVarData class for array buffer PP_Vars. | 174 // A RawVarData class for array buffer PP_Vars. |
| 172 class ArrayBufferRawVarData : public RawVarData { | 175 class ArrayBufferRawVarData : public RawVarData { |
| 173 public: | 176 public: |
| 174 // Enum for array buffer message types. | 177 // Enum for array buffer message types. |
| 175 enum ShmemType { | 178 enum ShmemType { |
| 176 ARRAY_BUFFER_NO_SHMEM, | 179 ARRAY_BUFFER_NO_SHMEM, |
| 177 ARRAY_BUFFER_SHMEM_HOST, | 180 ARRAY_BUFFER_SHMEM_HOST, |
| 178 ARRAY_BUFFER_SHMEM_PLUGIN, | 181 ARRAY_BUFFER_SHMEM_PLUGIN, |
| 179 }; | 182 }; |
| 180 | 183 |
| 181 ArrayBufferRawVarData(); | 184 ArrayBufferRawVarData(); |
| 182 ~ArrayBufferRawVarData() override; | 185 ~ArrayBufferRawVarData() override; |
| 183 | 186 |
| 184 // RawVarData implementation. | 187 // RawVarData implementation. |
| 185 PP_VarType Type() override; | 188 PP_VarType Type() override; |
| 186 bool Init(const PP_Var& var, PP_Instance instance) override; | 189 bool Init(const PP_Var& var, PP_Instance instance) override; |
| 187 PP_Var CreatePPVar(PP_Instance instance) override; | 190 PP_Var CreatePPVar(PP_Instance instance) override; |
| 188 void PopulatePPVar(const PP_Var& var, | 191 void PopulatePPVar(const PP_Var& var, |
| 189 const std::vector<PP_Var>& graph) override; | 192 const std::vector<PP_Var>& graph) override; |
| 190 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; | 193 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; |
| 191 bool Read(PP_VarType type, | 194 bool Read(PP_VarType type, |
| 192 const IPC::Message* m, | 195 const IPC::Message* m, |
| 193 PickleIterator* iter) override; | 196 base::PickleIterator* iter) override; |
| 194 SerializedHandle* GetHandle() override; | 197 SerializedHandle* GetHandle() override; |
| 195 | 198 |
| 196 private: | 199 private: |
| 197 // The type of the storage underlying the array buffer. | 200 // The type of the storage underlying the array buffer. |
| 198 ShmemType type_; | 201 ShmemType type_; |
| 199 // The data in the buffer. Valid for |type_| == ARRAY_BUFFER_NO_SHMEM. | 202 // The data in the buffer. Valid for |type_| == ARRAY_BUFFER_NO_SHMEM. |
| 200 std::string data_; | 203 std::string data_; |
| 201 // Host shmem handle. Valid for |type_| == ARRAY_BUFFER_SHMEM_HOST. | 204 // Host shmem handle. Valid for |type_| == ARRAY_BUFFER_SHMEM_HOST. |
| 202 int host_shm_handle_id_; | 205 int host_shm_handle_id_; |
| 203 // Plugin shmem handle. Valid for |type_| == ARRAY_BUFFER_SHMEM_PLUGIN. | 206 // Plugin shmem handle. Valid for |type_| == ARRAY_BUFFER_SHMEM_PLUGIN. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 214 | 217 |
| 215 // RawVarData implementation. | 218 // RawVarData implementation. |
| 216 PP_VarType Type() override; | 219 PP_VarType Type() override; |
| 217 bool Init(const PP_Var& var, PP_Instance instance) override; | 220 bool Init(const PP_Var& var, PP_Instance instance) override; |
| 218 PP_Var CreatePPVar(PP_Instance instance) override; | 221 PP_Var CreatePPVar(PP_Instance instance) override; |
| 219 void PopulatePPVar(const PP_Var& var, | 222 void PopulatePPVar(const PP_Var& var, |
| 220 const std::vector<PP_Var>& graph) override; | 223 const std::vector<PP_Var>& graph) override; |
| 221 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; | 224 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; |
| 222 bool Read(PP_VarType type, | 225 bool Read(PP_VarType type, |
| 223 const IPC::Message* m, | 226 const IPC::Message* m, |
| 224 PickleIterator* iter) override; | 227 base::PickleIterator* iter) override; |
| 225 | 228 |
| 226 private: | 229 private: |
| 227 std::vector<size_t> children_; | 230 std::vector<size_t> children_; |
| 228 }; | 231 }; |
| 229 | 232 |
| 230 // A RawVarData class for dictionary PP_Vars. | 233 // A RawVarData class for dictionary PP_Vars. |
| 231 class DictionaryRawVarData : public RawVarData { | 234 class DictionaryRawVarData : public RawVarData { |
| 232 public: | 235 public: |
| 233 DictionaryRawVarData(); | 236 DictionaryRawVarData(); |
| 234 ~DictionaryRawVarData() override; | 237 ~DictionaryRawVarData() override; |
| 235 | 238 |
| 236 void AddChild(const std::string& key, size_t value); | 239 void AddChild(const std::string& key, size_t value); |
| 237 | 240 |
| 238 // RawVarData implementation. | 241 // RawVarData implementation. |
| 239 PP_VarType Type() override; | 242 PP_VarType Type() override; |
| 240 bool Init(const PP_Var& var, PP_Instance instance) override; | 243 bool Init(const PP_Var& var, PP_Instance instance) override; |
| 241 PP_Var CreatePPVar(PP_Instance instance) override; | 244 PP_Var CreatePPVar(PP_Instance instance) override; |
| 242 void PopulatePPVar(const PP_Var& var, | 245 void PopulatePPVar(const PP_Var& var, |
| 243 const std::vector<PP_Var>& graph) override; | 246 const std::vector<PP_Var>& graph) override; |
| 244 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; | 247 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; |
| 245 bool Read(PP_VarType type, | 248 bool Read(PP_VarType type, |
| 246 const IPC::Message* m, | 249 const IPC::Message* m, |
| 247 PickleIterator* iter) override; | 250 base::PickleIterator* iter) override; |
| 248 | 251 |
| 249 private: | 252 private: |
| 250 std::vector<std::pair<std::string, size_t> > children_; | 253 std::vector<std::pair<std::string, size_t> > children_; |
| 251 }; | 254 }; |
| 252 | 255 |
| 253 // A RawVarData class for resource PP_Vars. | 256 // A RawVarData class for resource PP_Vars. |
| 254 // This class does not hold a reference on the PP_Resource that is being | 257 // This class does not hold a reference on the PP_Resource that is being |
| 255 // serialized. If sending a resource from the plugin to the host, the plugin | 258 // serialized. If sending a resource from the plugin to the host, the plugin |
| 256 // should not release the ResourceVar before sending the serialized message to | 259 // should not release the ResourceVar before sending the serialized message to |
| 257 // the host, and the host should immediately consume the ResourceVar before | 260 // the host, and the host should immediately consume the ResourceVar before |
| 258 // processing further messages. | 261 // processing further messages. |
| 259 class ResourceRawVarData : public RawVarData { | 262 class ResourceRawVarData : public RawVarData { |
| 260 public: | 263 public: |
| 261 ResourceRawVarData(); | 264 ResourceRawVarData(); |
| 262 ~ResourceRawVarData() override; | 265 ~ResourceRawVarData() override; |
| 263 | 266 |
| 264 // RawVarData implementation. | 267 // RawVarData implementation. |
| 265 PP_VarType Type() override; | 268 PP_VarType Type() override; |
| 266 bool Init(const PP_Var& var, PP_Instance instance) override; | 269 bool Init(const PP_Var& var, PP_Instance instance) override; |
| 267 PP_Var CreatePPVar(PP_Instance instance) override; | 270 PP_Var CreatePPVar(PP_Instance instance) override; |
| 268 void PopulatePPVar(const PP_Var& var, | 271 void PopulatePPVar(const PP_Var& var, |
| 269 const std::vector<PP_Var>& graph) override; | 272 const std::vector<PP_Var>& graph) override; |
| 270 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; | 273 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; |
| 271 bool Read(PP_VarType type, | 274 bool Read(PP_VarType type, |
| 272 const IPC::Message* m, | 275 const IPC::Message* m, |
| 273 PickleIterator* iter) override; | 276 base::PickleIterator* iter) override; |
| 274 | 277 |
| 275 private: | 278 private: |
| 276 // Resource ID in the plugin. If one has not yet been created, this is 0. | 279 // Resource ID in the plugin. If one has not yet been created, this is 0. |
| 277 // This is a borrowed reference; the resource's refcount is not incremented. | 280 // This is a borrowed reference; the resource's refcount is not incremented. |
| 278 PP_Resource pp_resource_; | 281 PP_Resource pp_resource_; |
| 279 | 282 |
| 280 // Pending resource host ID in the renderer. | 283 // Pending resource host ID in the renderer. |
| 281 int pending_renderer_host_id_; | 284 int pending_renderer_host_id_; |
| 282 | 285 |
| 283 // Pending resource host ID in the browser. | 286 // Pending resource host ID in the browser. |
| 284 int pending_browser_host_id_; | 287 int pending_browser_host_id_; |
| 285 | 288 |
| 286 // A message containing information about how to create a plugin-side | 289 // A message containing information about how to create a plugin-side |
| 287 // resource. The message type will vary based on the resource type, and will | 290 // resource. The message type will vary based on the resource type, and will |
| 288 // usually contain a pending resource host ID, and other required information. | 291 // usually contain a pending resource host ID, and other required information. |
| 289 // If the resource was created directly, this is NULL. | 292 // If the resource was created directly, this is NULL. |
| 290 scoped_ptr<IPC::Message> creation_message_; | 293 scoped_ptr<IPC::Message> creation_message_; |
| 291 }; | 294 }; |
| 292 | 295 |
| 293 } // namespace proxy | 296 } // namespace proxy |
| 294 } // namespace ppapi | 297 } // namespace ppapi |
| 295 | 298 |
| 296 #endif // PPAPI_PROXY_RAW_VAR_DATA_H_ | 299 #endif // PPAPI_PROXY_RAW_VAR_DATA_H_ |
| OLD | NEW |