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

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

Issue 9138027: PPAPI: Reduce string copying in SerializedVar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Duh 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) 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(const PP_Var& var, 27 PP_Var HostVarSerializationRules::SendCallerOwned(
28 std::string* str_val) { 28 const PP_Var& var,
29 const std::string** str_ptr_out) {
29 if (var.type == PP_VARTYPE_STRING) 30 if (var.type == PP_VARTYPE_STRING)
30 VarToString(var, str_val); 31 VarToStringPtr(var, str_ptr_out);
31 return var; 32 return var;
32 } 33 }
33 34
34 PP_Var HostVarSerializationRules::BeginReceiveCallerOwned( 35 PP_Var HostVarSerializationRules::BeginReceiveCallerOwned(
35 const PP_Var& var, 36 const PP_Var& var,
36 const std::string* str_val, 37 scoped_ptr<std::string> str,
37 Dispatcher* /* dispatcher */) { 38 Dispatcher* /* dispatcher */) {
38 if (var.type == PP_VARTYPE_STRING) 39 if (var.type == PP_VARTYPE_STRING) {
39 return StringVar::StringToPPVar(*str_val); 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 }
40 return var; 45 return var;
41 } 46 }
42 47
43 void HostVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) { 48 void HostVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) {
44 if (var.type == PP_VARTYPE_STRING) { 49 if (var.type == PP_VARTYPE_STRING) {
45 // Destroy the string BeginReceiveCallerOwned created above. 50 // Destroy the string BeginReceiveCallerOwned created above.
46 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var); 51 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var);
47 } 52 }
48 } 53 }
49 54
50 PP_Var HostVarSerializationRules::ReceivePassRef(const PP_Var& var, 55 PP_Var HostVarSerializationRules::ReceivePassRef(
51 const std::string& str_val, 56 const PP_Var& var,
52 Dispatcher* /* dispatcher */) { 57 scoped_ptr<std::string> str,
58 Dispatcher* /* dispatcher */) {
53 if (var.type == PP_VARTYPE_STRING) { 59 if (var.type == PP_VARTYPE_STRING) {
54 // Convert the string to the context of the current process. 60 // Put the string in to the tracker, transferring ownership.
55 return StringVar::StringToPPVar(str_val); 61 return StringVar::StringToPPVar(str.Pass());
56 } 62 }
57 63
58 // See PluginVarSerialization::BeginSendPassRef for an example. 64 // See PluginVarSerialization::BeginSendPassRef for an example.
59 if (var.type == PP_VARTYPE_OBJECT) 65 if (var.type == PP_VARTYPE_OBJECT)
60 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var); 66 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var);
61 return var; 67 return var;
62 } 68 }
63 69
64 PP_Var HostVarSerializationRules::BeginSendPassRef(const PP_Var& var, 70 PP_Var HostVarSerializationRules::BeginSendPassRef(
65 std::string* str_val) { 71 const PP_Var& var,
72 const std::string** str_ptr_out) {
66 // See PluginVarSerialization::ReceivePassRef for an example. We don't need 73 // See PluginVarSerialization::ReceivePassRef for an example. We don't need
67 // to do anything here other than convert the string. 74 // to do anything here other than convert the string.
68 if (var.type == PP_VARTYPE_STRING) 75 if (var.type == PP_VARTYPE_STRING)
69 VarToString(var, str_val); 76 VarToStringPtr(var, str_ptr_out);
70 return var; 77 return var;
71 } 78 }
72 79
73 void HostVarSerializationRules::EndSendPassRef(const PP_Var& /* var */, 80 void HostVarSerializationRules::EndSendPassRef(const PP_Var& /* var */,
74 Dispatcher* /* dispatcher */) { 81 Dispatcher* /* dispatcher */) {
75 // See PluginVarSerialization::ReceivePassRef for an example. We don't need 82 // See PluginVarSerialization::ReceivePassRef for an example. We don't need
76 // to do anything here. 83 // to do anything here.
77 } 84 }
78 85
79 void HostVarSerializationRules::VarToString(const PP_Var& var, 86 void HostVarSerializationRules::VarToStringPtr(
80 std::string* str) { 87 const PP_Var& var,
88 const std::string** str_ptr_out) {
81 DCHECK(var.type == PP_VARTYPE_STRING); 89 DCHECK(var.type == PP_VARTYPE_STRING);
82 90 *str_ptr_out = NULL;
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
85 // a std::string.
86 StringVar* string_var = StringVar::FromPPVar(var); 91 StringVar* string_var = StringVar::FromPPVar(var);
87 if (string_var) 92 if (string_var)
88 *str = string_var->value(); 93 *str_ptr_out = string_var->ptr();
89 } 94 }
90 95
91 void HostVarSerializationRules::ReleaseObjectRef(const PP_Var& var) { 96 void HostVarSerializationRules::ReleaseObjectRef(const PP_Var& var) {
92 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var); 97 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var);
93 } 98 }
94 99
95 } // namespace proxy 100 } // namespace proxy
96 } // namespace ppapi 101 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/host_var_serialization_rules.h ('k') | ppapi/proxy/plugin_var_serialization_rules.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698