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

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

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

Powered by Google App Engine
This is Rietveld 408576698