OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_VAR_SERIALIZATION_RULES_H_ | 5 #ifndef PPAPI_PROXY_VAR_SERIALIZATION_RULES_H_ |
6 #define PPAPI_PROXY_VAR_SERIALIZATION_RULES_H_ | 6 #define PPAPI_PROXY_VAR_SERIALIZATION_RULES_H_ |
7 | 7 |
8 #include "ppapi/c/pp_var.h" | 8 #include "ppapi/c/pp_var.h" |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 namespace pp { | 12 namespace pp { |
13 namespace proxy { | 13 namespace proxy { |
14 | 14 |
| 15 class Dispatcher; |
| 16 |
15 // Encapsulates the rules for serializing and deserializing vars to and from | 17 // Encapsulates the rules for serializing and deserializing vars to and from |
16 // the local process. The renderer and the plugin process each have separate | 18 // the local process. The renderer and the plugin process each have separate |
17 // bookkeeping rules. | 19 // bookkeeping rules. |
18 class VarSerializationRules { | 20 class VarSerializationRules { |
19 public: | 21 public: |
20 virtual ~VarSerializationRules() {} | 22 virtual ~VarSerializationRules() {} |
21 | 23 |
22 // Caller-owned calls -------------------------------------------------------- | 24 // Caller-owned calls -------------------------------------------------------- |
23 // | 25 // |
24 // A caller-owned call is when doing a function call with a "normal" input | 26 // A caller-owned call is when doing a function call with a "normal" input |
25 // argument. The caller has a reference to the var, and the caller is | 27 // argument. The caller has a reference to the var, and the caller is |
26 // responsible for freeing that reference. | 28 // responsible for freeing that reference. |
27 | 29 |
28 // Prepares the given var for sending to the callee. If the var is a string, | 30 // Prepares the given var for sending to the callee. If the var is a string, |
29 // the value of that string will be placed in *str_val. If the var is not | 31 // the value of that string will be placed in *str_val. If the var is not |
30 // a string, str_val will be untouched and may be NULL. | 32 // a string, str_val will be untouched and may be NULL. The return value will |
31 virtual void SendCallerOwned(const PP_Var& var, std::string* str_val) = 0; | 33 // be the var valid for the host process. |
| 34 virtual PP_Var SendCallerOwned(const PP_Var& var, std::string* str_val) = 0; |
32 | 35 |
33 // When receiving a caller-owned variable, normally we don't have to do | 36 // When receiving a caller-owned variable, normally we don't have to do |
34 // anything. However, in the case of strings, we need to deserialize the | 37 // anything. However, in the case of strings, we need to deserialize the |
35 // string from IPC, create a new PP_Var string in the local process, call the | 38 // string from IPC, create a new PP_Var string in the local process, call the |
36 // function, and then destroy the temporary string. These two functions | 39 // function, and then destroy the temporary string. These two functions |
37 // handle that process | 40 // handle that process |
38 // | 41 // |
39 // BeginReceiveCallerOwned takes a var from IPC and an optional pointer to | 42 // BeginReceiveCallerOwned takes a var from IPC and an optional pointer to |
40 // the deserialized string (which will be used only when var is a | 43 // the deserialized string (which will be used only when var is a |
41 // VARTYPE_STRING and may be NULL otherwise) and returns a new var | 44 // VARTYPE_STRING and may be NULL otherwise) and returns a new var |
42 // representing the input in the local process. The output will be the same | 45 // representing the input in the local process. |
43 // as the input except for strings. | |
44 // | 46 // |
45 // EndReceiveCallerOwned destroys the string created by Begin* and does | 47 // EndReceiveCallerOwned destroys the string created by Begin* and does |
46 // nothing otherwise. It should be called with the result of Begin*. | 48 // nothing otherwise. It should be called with the result of Begin*. |
47 virtual PP_Var BeginReceiveCallerOwned(const PP_Var& var, | 49 virtual PP_Var BeginReceiveCallerOwned(const PP_Var& var, |
48 const std::string* str_val) = 0; | 50 const std::string* str_val, |
| 51 Dispatcher* dispatcher) = 0; |
49 virtual void EndReceiveCallerOwned(const PP_Var& var) = 0; | 52 virtual void EndReceiveCallerOwned(const PP_Var& var) = 0; |
50 | 53 |
51 // Passinag refs ------------------------------------------------------------- | 54 // Passinag refs ------------------------------------------------------------- |
52 // | 55 // |
53 // A pass-ref transfer is when ownership of a reference is passed from | 56 // A pass-ref transfer is when ownership of a reference is passed from |
54 // onen side to the other. Normally, this happens via return values and | 57 // onen side to the other. Normally, this happens via return values and |
55 // output arguments, as for exceptions. The code generating the value | 58 // output arguments, as for exceptions. The code generating the value |
56 // (the function returning it in the case of a return value) will AddRef | 59 // (the function returning it in the case of a return value) will AddRef |
57 // the var on behalf of the consumer of the value. Responsibility for | 60 // the var on behalf of the consumer of the value. Responsibility for |
58 // Release is on the consumer (the caller of the function in the case of a | 61 // Release is on the consumer (the caller of the function in the case of a |
59 // return value). | 62 // return value). |
60 | 63 |
61 // Creates a var in the context of the local process from the given | 64 // Creates a var in the context of the local process from the given |
62 // deserialized var and deserialized string (which will be used only when var | 65 // deserialized var and deserialized string (which will be used only when var |
63 // is a VARTYPE_STRING and may be NULL otherwise). The input var/string | 66 // is a VARTYPE_STRING and may be NULL otherwise). The input var/string |
64 // should be the result of calling SendPassRef in the remote process. | 67 // should be the result of calling SendPassRef in the remote process. The |
| 68 // return value is the var valid in the plugin process. |
65 virtual PP_Var ReceivePassRef(const PP_Var& var, | 69 virtual PP_Var ReceivePassRef(const PP_Var& var, |
66 const std::string& str_val) = 0; | 70 const std::string& str_val, |
| 71 Dispatcher* dispatcher) = 0; |
67 | 72 |
68 // Prepares a var to be sent to the remote side. One local reference will | 73 // Prepares a var to be sent to the remote side. One local reference will |
69 // be passed to the remote side. Call Begin* before doing the send and End* | 74 // be passed to the remote side. Call Begin* before doing the send and End* |
70 // after doing the send. See SendCallerOwned for a description of the string. | 75 // after doing the send. See SendCallerOwned for a description of the string. |
71 virtual void BeginSendPassRef(const PP_Var& var, std::string* str_val) = 0; | 76 // The return value from BeginSendPassRef will be the var valid for the host |
| 77 // process. |
| 78 virtual PP_Var BeginSendPassRef(const PP_Var& var, std::string* str_val) = 0; |
72 virtual void EndSendPassRef(const PP_Var& var) = 0; | 79 virtual void EndSendPassRef(const PP_Var& var) = 0; |
73 | 80 |
74 // --------------------------------------------------------------------------- | 81 // --------------------------------------------------------------------------- |
75 | 82 |
76 virtual void ReleaseObjectRef(const PP_Var& var) = 0; | 83 virtual void ReleaseObjectRef(const PP_Var& var) = 0; |
77 | 84 |
78 protected: | 85 protected: |
79 VarSerializationRules() {} | 86 VarSerializationRules() {} |
80 }; | 87 }; |
81 | 88 |
82 } // namespace proxy | 89 } // namespace proxy |
83 } // namespace pp | 90 } // namespace pp |
84 | 91 |
85 #endif // PPAPI_PROXY_VAR_SERIALIZATION_RULES_H_ | 92 #endif // PPAPI_PROXY_VAR_SERIALIZATION_RULES_H_ |
OLD | NEW |