[email protected] | d8f868a6 | 2012-02-04 16:44:37 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 6608531 | 2010-11-05 22:14:25 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef PPAPI_PROXY_VAR_SERIALIZATION_RULES_H_ |
| 6 | #define PPAPI_PROXY_VAR_SERIALIZATION_RULES_H_ |
| 7 | |
[email protected] | 67600b9 | 2012-03-10 06:51:48 | [diff] [blame] | 8 | #include "base/memory/ref_counted.h" |
[email protected] | 6608531 | 2010-11-05 22:14:25 | [diff] [blame] | 9 | #include "ppapi/c/pp_var.h" |
| 10 | |
| 11 | #include <string> |
| 12 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 13 | namespace ppapi { |
[email protected] | 6608531 | 2010-11-05 22:14:25 | [diff] [blame] | 14 | namespace proxy { |
| 15 | |
| 16 | // Encapsulates the rules for serializing and deserializing vars to and from |
| 17 | // the local process. The renderer and the plugin process each have separate |
| 18 | // bookkeeping rules. |
[email protected] | 67600b9 | 2012-03-10 06:51:48 | [diff] [blame] | 19 | class VarSerializationRules : public base::RefCounted<VarSerializationRules> { |
[email protected] | 6608531 | 2010-11-05 22:14:25 | [diff] [blame] | 20 | public: |
[email protected] | 6608531 | 2010-11-05 22:14:25 | [diff] [blame] | 21 | // Caller-owned calls -------------------------------------------------------- |
| 22 | // |
| 23 | // A caller-owned call is when doing a function call with a "normal" input |
| 24 | // argument. The caller has a reference to the var, and the caller is |
| 25 | // responsible for freeing that reference. |
| 26 | |
[email protected] | 2d449b3 | 2012-02-07 05:38:00 | [diff] [blame] | 27 | // Prepares the given var for sending to the remote process. For object vars, |
| 28 | // the returned var will contain the id valid for the host process. |
| 29 | // Otherwise, the returned var is valid in the local process. |
| 30 | virtual PP_Var SendCallerOwned(const PP_Var& var) = 0; |
[email protected] | 6608531 | 2010-11-05 22:14:25 | [diff] [blame] | 31 | |
| 32 | // When receiving a caller-owned variable, normally we don't have to do |
| 33 | // anything. However, in the case of strings, we need to deserialize the |
[email protected] | 2d449b3 | 2012-02-07 05:38:00 | [diff] [blame] | 34 | // string from IPC, call the function, and then destroy the temporary string. |
| 35 | // These two functions handle that process. |
[email protected] | 6608531 | 2010-11-05 22:14:25 | [diff] [blame] | 36 | // |
[email protected] | 2d449b3 | 2012-02-07 05:38:00 | [diff] [blame] | 37 | // BeginReceiveCallerOwned takes a var from IPC and returns a new var |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 38 | // representing the input in the local process. |
[email protected] | 6608531 | 2010-11-05 22:14:25 | [diff] [blame] | 39 | // |
[email protected] | d8f868a6 | 2012-02-04 16:44:37 | [diff] [blame] | 40 | // EndReceiveCallerOwned releases the reference count in the Var tracker for |
| 41 | // the object or string that was added to the tracker. (Note, if the recipient |
| 42 | // took a reference to the Var, it will remain in the tracker after |
| 43 | // EndReceiveCallerOwned). |
[email protected] | 67600b9 | 2012-03-10 06:51:48 | [diff] [blame] | 44 | virtual PP_Var BeginReceiveCallerOwned(const PP_Var& var) = 0; |
[email protected] | 6608531 | 2010-11-05 22:14:25 | [diff] [blame] | 45 | virtual void EndReceiveCallerOwned(const PP_Var& var) = 0; |
| 46 | |
[email protected] | b20df1c | 2011-08-03 14:38:24 | [diff] [blame] | 47 | // Passing refs ------------------------------------------------------------- |
[email protected] | 6608531 | 2010-11-05 22:14:25 | [diff] [blame] | 48 | // |
| 49 | // A pass-ref transfer is when ownership of a reference is passed from |
[email protected] | b20df1c | 2011-08-03 14:38:24 | [diff] [blame] | 50 | // one side to the other. Normally, this happens via return values and |
[email protected] | 6608531 | 2010-11-05 22:14:25 | [diff] [blame] | 51 | // output arguments, as for exceptions. The code generating the value |
| 52 | // (the function returning it in the case of a return value) will AddRef |
| 53 | // the var on behalf of the consumer of the value. Responsibility for |
| 54 | // Release is on the consumer (the caller of the function in the case of a |
| 55 | // return value). |
| 56 | |
| 57 | // Creates a var in the context of the local process from the given |
[email protected] | 2d449b3 | 2012-02-07 05:38:00 | [diff] [blame] | 58 | // deserialized var. The input var should be the result of calling |
| 59 | // SendPassRef in the remote process. The return value is the var valid in |
| 60 | // the host process for object vars. Otherwise, the return value is a var |
| 61 | // which is valid in the local process. |
[email protected] | 67600b9 | 2012-03-10 06:51:48 | [diff] [blame] | 62 | virtual PP_Var ReceivePassRef(const PP_Var& var) = 0; |
[email protected] | 6608531 | 2010-11-05 22:14:25 | [diff] [blame] | 63 | |
| 64 | // Prepares a var to be sent to the remote side. One local reference will |
| 65 | // be passed to the remote side. Call Begin* before doing the send and End* |
[email protected] | 2d449b3 | 2012-02-07 05:38:00 | [diff] [blame] | 66 | // after doing the send |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 67 | // |
[email protected] | d8f868a6 | 2012-02-04 16:44:37 | [diff] [blame] | 68 | // For object vars, the return value from BeginSendPassRef will be the var |
| 69 | // valid for the host process. Otherwise, it is a var that is valid in the |
| 70 | // local process. This same var must be passed to EndSendPassRef. |
[email protected] | 2d449b3 | 2012-02-07 05:38:00 | [diff] [blame] | 71 | virtual PP_Var BeginSendPassRef(const PP_Var& var) = 0; |
[email protected] | 67600b9 | 2012-03-10 06:51:48 | [diff] [blame] | 72 | virtual void EndSendPassRef(const PP_Var& var) = 0; |
[email protected] | 6608531 | 2010-11-05 22:14:25 | [diff] [blame] | 73 | |
| 74 | // --------------------------------------------------------------------------- |
| 75 | |
| 76 | virtual void ReleaseObjectRef(const PP_Var& var) = 0; |
| 77 | |
| 78 | protected: |
| 79 | VarSerializationRules() {} |
[email protected] | 95bbcc7 | 2012-07-11 00:07:54 | [diff] [blame] | 80 | virtual ~VarSerializationRules() {} |
| 81 | |
| 82 | private: |
| 83 | friend class base::RefCounted<VarSerializationRules>; |
[email protected] | 6608531 | 2010-11-05 22:14:25 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | } // namespace proxy |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 87 | } // namespace ppapi |
[email protected] | 6608531 | 2010-11-05 22:14:25 | [diff] [blame] | 88 | |
| 89 | #endif // PPAPI_PROXY_VAR_SERIALIZATION_RULES_H_ |