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

Side by Side Diff: ppapi/proxy/host_var_serialization_rules.cc

Issue 9034035: Make it possible to have 1 PpapiGlobals per thread. Update unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove SHARED; contaminated from another CL Created 8 years, 11 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 #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"
10 #include "ppapi/shared_impl/var.h"
11 #include "ppapi/shared_impl/var_tracker.h"
12
13 using ppapi::PpapiGlobals;
14 using ppapi::StringVar;
15 using ppapi::VarTracker;
9 16
10 namespace ppapi { 17 namespace ppapi {
11 namespace proxy { 18 namespace proxy {
12 19
13 HostVarSerializationRules::HostVarSerializationRules( 20 HostVarSerializationRules::HostVarSerializationRules(PP_Module pp_module)
14 const PPB_Var* var_interface, 21 : pp_module_(pp_module) {
15 PP_Module pp_module)
16 : var_interface_(var_interface),
17 pp_module_(pp_module) {
18 } 22 }
19 23
20 HostVarSerializationRules::~HostVarSerializationRules() { 24 HostVarSerializationRules::~HostVarSerializationRules() {
21 } 25 }
22 26
23 PP_Var HostVarSerializationRules::SendCallerOwned(const PP_Var& var, 27 PP_Var HostVarSerializationRules::SendCallerOwned(const PP_Var& var,
24 std::string* str_val) { 28 std::string* str_val) {
25 if (var.type == PP_VARTYPE_STRING) 29 if (var.type == PP_VARTYPE_STRING)
26 VarToString(var, str_val); 30 VarToString(var, str_val);
27 return var; 31 return var;
28 } 32 }
29 33
30 PP_Var HostVarSerializationRules::BeginReceiveCallerOwned( 34 PP_Var HostVarSerializationRules::BeginReceiveCallerOwned(
31 const PP_Var& var, 35 const PP_Var& var,
32 const std::string* str_val, 36 const std::string* str_val,
33 Dispatcher* /* dispatcher */) { 37 Dispatcher* /* dispatcher */) {
34 if (var.type == PP_VARTYPE_STRING) { 38 if (var.type == PP_VARTYPE_STRING) {
brettw 2012/01/05 23:41:20 Can you remove the {} here for consistency?
dmichael (off chromium) 2012/01/06 18:18:45 Done.
35 // Convert the string to the context of the current process. 39 return StringVar::StringToPPVar(*str_val);
36 return var_interface_->VarFromUtf8(str_val->c_str(),
37 static_cast<uint32_t>(str_val->size()));
38 } 40 }
39 return var; 41 return var;
40 } 42 }
41 43
42 void HostVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) { 44 void HostVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) {
43 if (var.type == PP_VARTYPE_STRING) { 45 if (var.type == PP_VARTYPE_STRING) {
44 // Destroy the string BeginReceiveCallerOwned created above. 46 // Destroy the string BeginReceiveCallerOwned created above.
45 var_interface_->Release(var); 47 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var);
46 } 48 }
47 } 49 }
48 50
49 PP_Var HostVarSerializationRules::ReceivePassRef(const PP_Var& var, 51 PP_Var HostVarSerializationRules::ReceivePassRef(const PP_Var& var,
50 const std::string& str_val, 52 const std::string& str_val,
51 Dispatcher* /* dispatcher */) { 53 Dispatcher* /* dispatcher */) {
52 if (var.type == PP_VARTYPE_STRING) { 54 if (var.type == PP_VARTYPE_STRING) {
53 // Convert the string to the context of the current process. 55 // Convert the string to the context of the current process.
54 return var_interface_->VarFromUtf8(str_val.c_str(), 56 return StringVar::StringToPPVar(str_val);
55 static_cast<uint32_t>(str_val.size()));
56 } 57 }
57 58
58 // See PluginVarSerialization::BeginSendPassRef for an example. 59 // See PluginVarSerialization::BeginSendPassRef for an example.
59 if (var.type == PP_VARTYPE_OBJECT) 60 if (var.type == PP_VARTYPE_OBJECT)
60 var_interface_->AddRef(var); 61 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var);
61 return var; 62 return var;
62 } 63 }
63 64
64 PP_Var HostVarSerializationRules::BeginSendPassRef(const PP_Var& var, 65 PP_Var HostVarSerializationRules::BeginSendPassRef(const PP_Var& var,
65 std::string* str_val) { 66 std::string* str_val) {
66 // See PluginVarSerialization::ReceivePassRef for an example. We don't need 67 // See PluginVarSerialization::ReceivePassRef for an example. We don't need
67 // to do anything here other than convert the string. 68 // to do anything here other than convert the string.
68 if (var.type == PP_VARTYPE_STRING) 69 if (var.type == PP_VARTYPE_STRING)
69 VarToString(var, str_val); 70 VarToString(var, str_val);
70 return var; 71 return var;
71 } 72 }
72 73
73 void HostVarSerializationRules::EndSendPassRef(const PP_Var& /* var */, 74 void HostVarSerializationRules::EndSendPassRef(const PP_Var& /* var */,
74 Dispatcher* /* dispatcher */) { 75 Dispatcher* /* dispatcher */) {
75 // See PluginVarSerialization::ReceivePassRef for an example. We don't need 76 // See PluginVarSerialization::ReceivePassRef for an example. We don't need
76 // to do anything here. 77 // to do anything here.
77 } 78 }
78 79
79 void HostVarSerializationRules::VarToString(const PP_Var& var, 80 void HostVarSerializationRules::VarToString(const PP_Var& var,
80 std::string* str) { 81 std::string* str) {
81 DCHECK(var.type == PP_VARTYPE_STRING); 82 DCHECK(var.type == PP_VARTYPE_STRING);
82 83
83 // This could be optimized to avoid an extra string copy by going to a lower 84 // This could be optimized to avoid an extra string copy by going to a lower
84 // level of the browser's implementation of strings where we already have 85 // level of the browser's implementation of strings where we already have
85 // a std::string. 86 // a std::string.
86 uint32_t len = 0; 87 StringVar* string_var = StringVar::FromPPVar(var);
87 const char* data = var_interface_->VarToUtf8(var, &len); 88 if (string_var)
88 str->assign(data, len); 89 *str = string_var->value();
89 } 90 }
90 91
91 void HostVarSerializationRules::ReleaseObjectRef(const PP_Var& var) { 92 void HostVarSerializationRules::ReleaseObjectRef(const PP_Var& var) {
92 var_interface_->Release(var); 93 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var);
93 } 94 }
94 95
95 } // namespace proxy 96 } // namespace proxy
96 } // namespace ppapi 97 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698