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