Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: ppapi/proxy/var_serialization_rules.h

Issue 9138027: PPAPI: Reduce string copying in SerializedVar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: small comment tweak Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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. The return value will be the var valid for the
34 virtual PP_Var SendCallerOwned(const PP_Var& var, std::string* str_val) = 0; 35 // local process.
36 virtual PP_Var SendCallerOwned(const PP_Var& var,
37 const std::string** str_ptr_out) = 0;
35 38
36 // When receiving a caller-owned variable, normally we don't have to do 39 // 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 40 // 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 41 // 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 42 // function, and then destroy the temporary string. These two functions
40 // handle that process 43 // handle that process.
41 // 44 //
42 // BeginReceiveCallerOwned takes a var from IPC and an optional pointer to 45 // BeginReceiveCallerOwned takes a var from IPC and an optional pointer to
43 // the deserialized string (which will be used only when var is a 46 // 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 47 // VARTYPE_STRING and may be NULL otherwise) and returns a new var
45 // representing the input in the local process. 48 // representing the input in the local process.
46 // 49 //
47 // EndReceiveCallerOwned destroys the string created by Begin* and does 50 // EndReceiveCallerOwned releases the reference count in the Var tracker for
48 // nothing otherwise. It should be called with the result of Begin*. 51 // the object or string that was added to the tracker. (Note, if the recipient
52 // took a reference to the Var, it will remain in the tracker after
53 // EndReceiveCallerOwned).
49 virtual PP_Var BeginReceiveCallerOwned(const PP_Var& var, 54 virtual PP_Var BeginReceiveCallerOwned(const PP_Var& var,
50 const std::string* str_val, 55 scoped_ptr<std::string> str,
51 Dispatcher* dispatcher) = 0; 56 Dispatcher* dispatcher) = 0;
52 virtual void EndReceiveCallerOwned(const PP_Var& var) = 0; 57 virtual void EndReceiveCallerOwned(const PP_Var& var) = 0;
53 58
54 // Passing refs ------------------------------------------------------------- 59 // Passing refs -------------------------------------------------------------
55 // 60 //
56 // A pass-ref transfer is when ownership of a reference is passed from 61 // 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 62 // one side to the other. Normally, this happens via return values and
58 // output arguments, as for exceptions. The code generating the value 63 // output arguments, as for exceptions. The code generating the value
59 // (the function returning it in the case of a return value) will AddRef 64 // (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 65 // 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 66 // Release is on the consumer (the caller of the function in the case of a
62 // return value). 67 // return value).
63 68
64 // Creates a var in the context of the local process from the given 69 // 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 70 // 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 71 // 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 72 // should be the result of calling SendPassRef in the remote process. The
68 // return value is the var valid in the plugin process. 73 // return value is the var valid in the host process for object vars.
74 // Otherwise, the return value is a var which is valid in the local process.
69 virtual PP_Var ReceivePassRef(const PP_Var& var, 75 virtual PP_Var ReceivePassRef(const PP_Var& var,
70 const std::string& str_val, 76 scoped_ptr<std::string> str,
71 Dispatcher* dispatcher) = 0; 77 Dispatcher* dispatcher) = 0;
72 78
73 // Prepares a var to be sent to the remote side. One local reference will 79 // 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* 80 // 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. 81 // after doing the send. See SendCallerOwned for a description of the string.
76 // 82 //
77 // The return value from BeginSendPassRef will be the var valid for the host 83 // For object vars, the return value from BeginSendPassRef will be the var
78 // process. This same value must be passed to EndSendPassRef. 84 // 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; 85 // local process. This same var must be passed to EndSendPassRef.
86 virtual PP_Var BeginSendPassRef(const PP_Var& var,
87 const std::string** str_ptr_out) = 0;
80 virtual void EndSendPassRef(const PP_Var& var, Dispatcher* dispatcher) = 0; 88 virtual void EndSendPassRef(const PP_Var& var, Dispatcher* dispatcher) = 0;
81 89
82 // --------------------------------------------------------------------------- 90 // ---------------------------------------------------------------------------
83 91
84 virtual void ReleaseObjectRef(const PP_Var& var) = 0; 92 virtual void ReleaseObjectRef(const PP_Var& var) = 0;
85 93
86 protected: 94 protected:
87 VarSerializationRules() {} 95 VarSerializationRules() {}
88 }; 96 };
89 97
90 } // namespace proxy 98 } // namespace proxy
91 } // namespace ppapi 99 } // namespace ppapi
92 100
93 #endif // PPAPI_PROXY_VAR_SERIALIZATION_RULES_H_ 101 #endif // PPAPI_PROXY_VAR_SERIALIZATION_RULES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698