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

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

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
« no previous file with comments | « ppapi/proxy/ppp_messaging_proxy_perftest.cc ('k') | ppapi/proxy/serialized_var.cc » ('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) 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_SERIALIZED_VAR_H_ 5 #ifndef PPAPI_PROXY_SERIALIZED_VAR_H_
6 #define PPAPI_PROXY_SERIALIZED_VAR_H_ 6 #define PPAPI_PROXY_SERIALIZED_VAR_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
13 #include "ppapi/c/pp_var.h" 14 #include "ppapi/c/pp_var.h"
14 #include "ppapi/proxy/ppapi_proxy_export.h" 15 #include "ppapi/proxy/ppapi_proxy_export.h"
15 16
16 namespace IPC { 17 namespace IPC {
17 class Message; 18 class Message;
18 } 19 }
19 20
20 namespace ppapi { 21 namespace ppapi {
21 namespace proxy { 22 namespace proxy {
22 23
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 friend class SerializedVarReturnValue; 81 friend class SerializedVarReturnValue;
81 friend class SerializedVarOutParam; 82 friend class SerializedVarOutParam;
82 friend class SerializedVarSendInput; 83 friend class SerializedVarSendInput;
83 friend class SerializedVarTestConstructor; 84 friend class SerializedVarTestConstructor;
84 friend class SerializedVarVectorReceiveInput; 85 friend class SerializedVarVectorReceiveInput;
85 86
86 class PPAPI_PROXY_EXPORT Inner : public base::RefCounted<Inner> { 87 class PPAPI_PROXY_EXPORT Inner : public base::RefCounted<Inner> {
87 public: 88 public:
88 Inner(); 89 Inner();
89 Inner(VarSerializationRules* serialization_rules); 90 Inner(VarSerializationRules* serialization_rules);
90 Inner(VarSerializationRules* serialization_rules, const PP_Var& var);
91 ~Inner(); 91 ~Inner();
92 92
93 VarSerializationRules* serialization_rules() { 93 VarSerializationRules* serialization_rules() {
94 return serialization_rules_; 94 return serialization_rules_;
95 } 95 }
96 void set_serialization_rules(VarSerializationRules* serialization_rules) { 96 void set_serialization_rules(VarSerializationRules* serialization_rules) {
97 serialization_rules_ = serialization_rules; 97 serialization_rules_ = serialization_rules;
98 } 98 }
99 99
100 // See outer class's declarations above. 100 // See outer class's declarations above.
101 PP_Var GetVar() const; 101 PP_Var GetVar() const;
102 PP_Var GetIncompleteVar() const; 102 PP_Var GetIncompleteVar() const;
103 void SetVar(PP_Var var); 103 void SetVar(PP_Var var);
104 const std::string& GetString() const; 104 void SetString(scoped_ptr<std::string> str);
105 std::string* GetStringPtr(); 105 // Return a new string with the contents of the string referenced by Inner.
106 // The string referenced by the Inner will be empty after this.
107 scoped_ptr<std::string> GetStringDestructive();
108 // Return a pointer to our internal string pointer. This is so that the
109 // caller will be able to make this Inner point to a string that's owned
110 // elsewhere (i.e., in the tracker).
111 const std::string** GetStringPtrPtr();
106 112
107 // For the SerializedVarTestConstructor, this writes the Var value as if 113 // For the SerializedVarTestConstructor, this writes the Var value as if
108 // it was just received off the wire, without any serialization rules. 114 // it was just received off the wire, without any serialization rules.
109 void ForceSetVarValueForTest(PP_Var value); 115 void ForceSetVarValueForTest(PP_Var value);
110 void ForceSetStringValueForTest(const std::string& str); 116 void ForceSetStringValueForTest(const std::string& str);
111 117
112 void WriteToMessage(IPC::Message* m) const; 118 void WriteToMessage(IPC::Message* m) const;
113 bool ReadFromMessage(const IPC::Message* m, void** iter); 119 bool ReadFromMessage(const IPC::Message* m, void** iter);
114 120
115 // Sets the cleanup mode. See the CleanupMode enum below. These functions 121 // Sets the cleanup mode. See the CleanupMode enum below. These functions
(...skipping 14 matching lines...) Expand all
130 // The serialized var will call EndReceiveCallerOwned in the destructor. 136 // The serialized var will call EndReceiveCallerOwned in the destructor.
131 END_RECEIVE_CALLER_OWNED 137 END_RECEIVE_CALLER_OWNED
132 }; 138 };
133 139
134 // Rules for serializing and deserializing vars for this process type. 140 // Rules for serializing and deserializing vars for this process type.
135 // This may be NULL, but must be set before trying to serialize to IPC when 141 // This may be NULL, but must be set before trying to serialize to IPC when
136 // sending, or before converting back to a PP_Var when receiving. 142 // sending, or before converting back to a PP_Var when receiving.
137 VarSerializationRules* serialization_rules_; 143 VarSerializationRules* serialization_rules_;
138 144
139 // If this is set to VARTYPE_STRING and the 'value.id' is 0, then the 145 // If this is set to VARTYPE_STRING and the 'value.id' is 0, then the
140 // string_value_ contains the string. This means that the caller hasn't 146 // string_from_ipc_ holds the string. This means that the caller hasn't
141 // called Deserialize with a valid Dispatcher yet, which is how we can 147 // called Deserialize with a valid Dispatcher yet, which is how we can
142 // convert the serialized string value to a PP_Var string ID. 148 // convert the serialized string value to a PP_Var string ID.
143 // 149 //
144 // This var may not be complete until the serialization rules are set when 150 // This var may not be complete until the serialization rules are set when
145 // reading from IPC since we'll need that to convert the string_value to 151 // reading from IPC since we'll need that to convert the string_value to
146 // a string ID. Before this, the as_id will be 0 for VARTYPE_STRING. 152 // a string ID. Before this, the as_id will be 0 for VARTYPE_STRING.
147 PP_Var var_; 153 PP_Var var_;
148 154
149 // Holds the literal string value to/from IPC. This will be valid if the 155 // If valid, this is a pointer to a string owned by the VarTracker. When our
150 // var_ is VARTYPE_STRING. 156 // outer SerializedVar gets serialized, it will write the string directly
151 std::string string_value_; 157 // from the tracker so we do not need to make any unnecessary copies. This
158 // should only be valid on the sender side.
159 const std::string* tracker_string_ptr_;
160
161 // If valid, this is a string received from IPC which needs to be inserted
162 // in to the var tracker. When we provide it to the tracker, we pass
163 // ownership so that there are no unnecessary copies. This should only ever
164 // be valid on the receiver side.
165 scoped_ptr<std::string> string_from_ipc_;
152 166
153 CleanupMode cleanup_mode_; 167 CleanupMode cleanup_mode_;
154 168
155 // The dispatcher saved for the call to EndSendPassRef for the cleanup. 169 // The dispatcher saved for the call to EndSendPassRef for the cleanup.
156 // This is only valid when cleanup_mode == END_SEND_PASS_REF. 170 // This is only valid when cleanup_mode == END_SEND_PASS_REF.
157 Dispatcher* dispatcher_for_end_send_pass_ref_; 171 Dispatcher* dispatcher_for_end_send_pass_ref_;
158 172
159 #ifndef NDEBUG 173 #ifndef NDEBUG
160 // When being sent or received over IPC, we should only be serialized or 174 // When being sent or received over IPC, we should only be serialized or
161 // deserialized once. These flags help us assert this is true. 175 // deserialized once. These flags help us assert this is true.
162 mutable bool has_been_serialized_; 176 mutable bool has_been_serialized_;
163 mutable bool has_been_deserialized_; 177 mutable bool has_been_deserialized_;
164 #endif 178 #endif
165 179
166 DISALLOW_COPY_AND_ASSIGN(Inner); 180 DISALLOW_COPY_AND_ASSIGN(Inner);
167 }; 181 };
168 182
169 SerializedVar(VarSerializationRules* serialization_rules); 183 SerializedVar(VarSerializationRules* serialization_rules);
170 SerializedVar(VarSerializationRules* serialization, const PP_Var& var);
171 184
172 mutable scoped_refptr<Inner> inner_; 185 mutable scoped_refptr<Inner> inner_;
173 }; 186 };
174 187
175 // Helpers for message sending side -------------------------------------------- 188 // Helpers for message sending side --------------------------------------------
176 189
177 // For sending a value to the remote side. 190 // For sending a value to the remote side.
178 // 191 //
179 // Example for API: 192 // Example for API:
180 // void MyFunction(PP_Var) 193 // void MyFunction(PP_Var)
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 // For tests that want to read what's in a SerializedVar. 459 // For tests that want to read what's in a SerializedVar.
447 class PPAPI_PROXY_EXPORT SerializedVarTestReader : public SerializedVar { 460 class PPAPI_PROXY_EXPORT SerializedVarTestReader : public SerializedVar {
448 public: 461 public:
449 explicit SerializedVarTestReader(const SerializedVar& var); 462 explicit SerializedVarTestReader(const SerializedVar& var);
450 463
451 // The "incomplete" var is the one sent over the wire. Strings and object 464 // The "incomplete" var is the one sent over the wire. Strings and object
452 // IDs have not yet been converted, so this is the thing that tests will 465 // IDs have not yet been converted, so this is the thing that tests will
453 // actually want to check. 466 // actually want to check.
454 PP_Var GetIncompleteVar() const { return inner_->GetIncompleteVar(); } 467 PP_Var GetIncompleteVar() const { return inner_->GetIncompleteVar(); }
455 468
456 const std::string& GetString() const { return inner_->GetString(); } 469 const std::string* GetTrackerStringPtr() const {
470 return *inner_->GetStringPtrPtr();
471 }
457 }; 472 };
458 473
459 } // namespace proxy 474 } // namespace proxy
460 } // namespace ppapi 475 } // namespace ppapi
461 476
462 #endif // PPAPI_PROXY_SERIALIZED_VAR_H_ 477 #endif // PPAPI_PROXY_SERIALIZED_VAR_H_
463 478
OLDNEW
« no previous file with comments | « ppapi/proxy/ppp_messaging_proxy_perftest.cc ('k') | ppapi/proxy/serialized_var.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698