OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ppapi/proxy/host_var_serialization_rules.h" | 5 #include "ppapi/proxy/host_var_serialization_rules.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ppapi/c/ppb_var.h" | 8 #include "ppapi/c/ppb_var.h" |
9 #include "ppapi/shared_impl/ppapi_globals.h" | 9 #include "ppapi/shared_impl/ppapi_globals.h" |
10 #include "ppapi/shared_impl/var.h" | 10 #include "ppapi/shared_impl/var.h" |
11 #include "ppapi/shared_impl/var_tracker.h" | 11 #include "ppapi/shared_impl/var_tracker.h" |
12 | 12 |
13 using ppapi::PpapiGlobals; | 13 using ppapi::PpapiGlobals; |
14 using ppapi::StringVar; | 14 using ppapi::StringVar; |
15 using ppapi::VarTracker; | 15 using ppapi::VarTracker; |
16 | 16 |
17 namespace ppapi { | 17 namespace ppapi { |
18 namespace proxy { | 18 namespace proxy { |
19 | 19 |
20 HostVarSerializationRules::HostVarSerializationRules(PP_Module pp_module) | 20 HostVarSerializationRules::HostVarSerializationRules(PP_Module pp_module) |
21 : pp_module_(pp_module) { | 21 : pp_module_(pp_module) { |
22 } | 22 } |
23 | 23 |
24 HostVarSerializationRules::~HostVarSerializationRules() { | 24 HostVarSerializationRules::~HostVarSerializationRules() { |
25 } | 25 } |
26 | 26 |
27 PP_Var HostVarSerializationRules::SendCallerOwned( | 27 PP_Var HostVarSerializationRules::SendCallerOwned(const PP_Var& var) { |
28 const PP_Var& var, | |
29 const std::string** str_ptr_out) { | |
30 if (var.type == PP_VARTYPE_STRING) | |
31 VarToStringPtr(var, str_ptr_out); | |
32 return var; | 28 return var; |
33 } | 29 } |
34 | 30 |
35 PP_Var HostVarSerializationRules::BeginReceiveCallerOwned( | 31 PP_Var HostVarSerializationRules::BeginReceiveCallerOwned( |
36 const PP_Var& var, | 32 const PP_Var& var, |
37 scoped_ptr<std::string> str, | |
38 Dispatcher* /* dispatcher */) { | 33 Dispatcher* /* dispatcher */) { |
39 if (var.type == PP_VARTYPE_STRING) { | |
40 // Put the string in to the VarTracker (transferring ownership, since we | |
41 // would otherwise just delete the one we received from IPC). This allows | |
42 // us to avoid unnecessary copying of the string. | |
43 return StringVar::StringToPPVar(str.Pass()); | |
44 } | |
45 return var; | 34 return var; |
46 } | 35 } |
47 | 36 |
48 void HostVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) { | 37 void HostVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) { |
49 if (var.type == PP_VARTYPE_STRING) { | 38 if (var.type == PP_VARTYPE_STRING) { |
50 // Destroy the string BeginReceiveCallerOwned created above. | 39 // Destroy the string. |
51 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var); | 40 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var); |
52 } | 41 } |
53 } | 42 } |
54 | 43 |
55 PP_Var HostVarSerializationRules::ReceivePassRef( | 44 PP_Var HostVarSerializationRules::ReceivePassRef( |
56 const PP_Var& var, | 45 const PP_Var& var, |
57 scoped_ptr<std::string> str, | |
58 Dispatcher* /* dispatcher */) { | 46 Dispatcher* /* dispatcher */) { |
59 if (var.type == PP_VARTYPE_STRING) { | |
60 // Put the string in to the tracker, transferring ownership. | |
61 return StringVar::StringToPPVar(str.Pass()); | |
62 } | |
63 | |
64 // See PluginVarSerialization::BeginSendPassRef for an example. | 47 // See PluginVarSerialization::BeginSendPassRef for an example. |
65 if (var.type == PP_VARTYPE_OBJECT) | 48 if (var.type == PP_VARTYPE_OBJECT) |
66 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var); | 49 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var); |
67 return var; | 50 return var; |
68 } | 51 } |
69 | 52 |
70 PP_Var HostVarSerializationRules::BeginSendPassRef( | 53 PP_Var HostVarSerializationRules::BeginSendPassRef(const PP_Var& var) { |
71 const PP_Var& var, | |
72 const std::string** str_ptr_out) { | |
73 // See PluginVarSerialization::ReceivePassRef for an example. We don't need | |
74 // to do anything here other than convert the string. | |
75 if (var.type == PP_VARTYPE_STRING) | |
76 VarToStringPtr(var, str_ptr_out); | |
77 return var; | 54 return var; |
78 } | 55 } |
79 | 56 |
80 void HostVarSerializationRules::EndSendPassRef(const PP_Var& /* var */, | 57 void HostVarSerializationRules::EndSendPassRef(const PP_Var& /* var */, |
81 Dispatcher* /* dispatcher */) { | 58 Dispatcher* /* dispatcher */) { |
82 // See PluginVarSerialization::ReceivePassRef for an example. We don't need | 59 // See PluginVarSerialization::ReceivePassRef for an example. We don't need |
83 // to do anything here. | 60 // to do anything here. |
84 } | 61 } |
85 | 62 |
86 void HostVarSerializationRules::VarToStringPtr( | |
87 const PP_Var& var, | |
88 const std::string** str_ptr_out) { | |
89 DCHECK(var.type == PP_VARTYPE_STRING); | |
90 *str_ptr_out = NULL; | |
91 StringVar* string_var = StringVar::FromPPVar(var); | |
92 if (string_var) | |
93 *str_ptr_out = string_var->ptr(); | |
94 } | |
95 | |
96 void HostVarSerializationRules::ReleaseObjectRef(const PP_Var& var) { | 63 void HostVarSerializationRules::ReleaseObjectRef(const PP_Var& var) { |
97 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var); | 64 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var); |
98 } | 65 } |
99 | 66 |
100 } // namespace proxy | 67 } // namespace proxy |
101 } // namespace ppapi | 68 } // namespace ppapi |
OLD | NEW |