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

Side by Side Diff: ppapi/proxy/serialized_var.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
« no previous file with comments | « ppapi/proxy/serialized_var.h ('k') | ppapi/proxy/serialized_var_unittest.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 #include "ppapi/proxy/serialized_var.h" 5 #include "ppapi/proxy/serialized_var.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ipc/ipc_message_utils.h" 8 #include "ipc/ipc_message_utils.h"
9 #include "ppapi/proxy/dispatcher.h" 9 #include "ppapi/proxy/dispatcher.h"
10 #include "ppapi/proxy/interface_proxy.h" 10 #include "ppapi/proxy/interface_proxy.h"
11 #include "ppapi/proxy/ppapi_param_traits.h" 11 #include "ppapi/proxy/ppapi_param_traits.h"
12 #include "ppapi/proxy/var_serialization_rules.h" 12 #include "ppapi/proxy/var_serialization_rules.h"
13 13
14 namespace ppapi { 14 namespace ppapi {
15 namespace proxy { 15 namespace proxy {
16 16
17 // SerializedVar::Inner -------------------------------------------------------- 17 // SerializedVar::Inner --------------------------------------------------------
18 18
19 SerializedVar::Inner::Inner() 19 SerializedVar::Inner::Inner()
20 : serialization_rules_(NULL), 20 : serialization_rules_(NULL),
21 var_(PP_MakeUndefined()), 21 var_(PP_MakeUndefined()),
22 tracker_string_ptr_(NULL),
22 cleanup_mode_(CLEANUP_NONE), 23 cleanup_mode_(CLEANUP_NONE),
23 dispatcher_for_end_send_pass_ref_(NULL) { 24 dispatcher_for_end_send_pass_ref_(NULL) {
24 #ifndef NDEBUG 25 #ifndef NDEBUG
25 has_been_serialized_ = false; 26 has_been_serialized_ = false;
26 has_been_deserialized_ = false; 27 has_been_deserialized_ = false;
27 #endif 28 #endif
28 } 29 }
29 30
30 SerializedVar::Inner::Inner(VarSerializationRules* serialization_rules) 31 SerializedVar::Inner::Inner(VarSerializationRules* serialization_rules)
31 : serialization_rules_(serialization_rules), 32 : serialization_rules_(serialization_rules),
32 var_(PP_MakeUndefined()), 33 var_(PP_MakeUndefined()),
34 tracker_string_ptr_(NULL),
33 cleanup_mode_(CLEANUP_NONE), 35 cleanup_mode_(CLEANUP_NONE),
34 dispatcher_for_end_send_pass_ref_(NULL) { 36 dispatcher_for_end_send_pass_ref_(NULL) {
35 #ifndef NDEBUG 37 #ifndef NDEBUG
36 has_been_serialized_ = false;
37 has_been_deserialized_ = false;
38 #endif
39 }
40
41 SerializedVar::Inner::Inner(VarSerializationRules* serialization_rules,
42 const PP_Var& var)
43 : serialization_rules_(serialization_rules),
44 var_(var),
45 cleanup_mode_(CLEANUP_NONE),
46 dispatcher_for_end_send_pass_ref_(NULL) {
47 #ifndef NDEBUG
48 has_been_serialized_ = false; 38 has_been_serialized_ = false;
49 has_been_deserialized_ = false; 39 has_been_deserialized_ = false;
50 #endif 40 #endif
51 } 41 }
52 42
53 SerializedVar::Inner::~Inner() { 43 SerializedVar::Inner::~Inner() {
54 switch (cleanup_mode_) { 44 switch (cleanup_mode_) {
55 case END_SEND_PASS_REF: 45 case END_SEND_PASS_REF:
56 DCHECK(dispatcher_for_end_send_pass_ref_); 46 DCHECK(dispatcher_for_end_send_pass_ref_);
57 serialization_rules_->EndSendPassRef(var_, 47 serialization_rules_->EndSendPassRef(var_,
(...skipping 21 matching lines...) Expand all
79 return var_; 69 return var_;
80 } 70 }
81 71
82 void SerializedVar::Inner::SetVar(PP_Var var) { 72 void SerializedVar::Inner::SetVar(PP_Var var) {
83 // Sanity check, when updating the var we should have received a 73 // Sanity check, when updating the var we should have received a
84 // serialization rules pointer already. 74 // serialization rules pointer already.
85 DCHECK(serialization_rules_); 75 DCHECK(serialization_rules_);
86 var_ = var; 76 var_ = var;
87 } 77 }
88 78
89 const std::string& SerializedVar::Inner::GetString() const { 79 scoped_ptr<std::string> SerializedVar::Inner::GetStringDestructive() {
90 DCHECK(serialization_rules_); 80 DCHECK(serialization_rules_);
91 return string_value_; 81 return string_from_ipc_.Pass();
92 } 82 }
93 83
94 std::string* SerializedVar::Inner::GetStringPtr() { 84 const std::string** SerializedVar::Inner::GetStringPtrPtr() {
95 DCHECK(serialization_rules_); 85 DCHECK(serialization_rules_);
96 return &string_value_; 86 // The caller will set our string pointer, and we promise not to change it.
87 // This path is taken for the "Send" side of SerializedVars, and we will only
88 // read the string in those cases, so it's safe for us to point directly to a
89 // string in the VarTracker.
90 return &tracker_string_ptr_;
97 } 91 }
98 92
99 void SerializedVar::Inner::ForceSetVarValueForTest(PP_Var value) { 93 void SerializedVar::Inner::ForceSetVarValueForTest(PP_Var value) {
100 var_ = value; 94 var_ = value;
101 } 95 }
102 96
103 void SerializedVar::Inner::ForceSetStringValueForTest(const std::string& str) { 97 void SerializedVar::Inner::ForceSetStringValueForTest(const std::string& str) {
104 string_value_ = str; 98 // We don't need to change tracker_string_ptr_, as that is only used for
99 // serializing, and we're emulating a SerializedVar that was received from
100 // IPC.
101 string_from_ipc_.reset(new std::string(str));
105 } 102 }
106 103
107 void SerializedVar::Inner::WriteToMessage(IPC::Message* m) const { 104 void SerializedVar::Inner::WriteToMessage(IPC::Message* m) const {
108 // When writing to the IPC messages, a serization rules handler should 105 // When writing to the IPC messages, a serization rules handler should
109 // always have been set. 106 // always have been set.
110 // 107 //
111 // When sending a message, it should be difficult to trigger this if you're 108 // When sending a message, it should be difficult to trigger this if you're
112 // using the SerializedVarSendInput class and giving a non-NULL dispatcher. 109 // using the SerializedVarSendInput class and giving a non-NULL dispatcher.
113 // Make sure you're using the proper "Send" helper class. 110 // Make sure you're using the proper "Send" helper class.
114 // 111 //
115 // It should be more common to see this when handling an incoming message 112 // It should be more common to see this when handling an incoming message
116 // that returns a var. This means the message handler didn't write to the 113 // that returns a var. This means the message handler didn't write to the
117 // output parameter, or possibly you used the wrong helper class 114 // output parameter, or possibly you used the wrong helper class
118 // (normally SerializedVarReturnValue). 115 // (normally SerializedVarReturnValue).
119 DCHECK(serialization_rules_); 116 DCHECK(serialization_rules_);
120 117
121 #ifndef NDEBUG 118 #ifndef NDEBUG
122 // We should only be serializing something once. 119 // We should only be serializing something once.
123 DCHECK(!has_been_serialized_); 120 DCHECK(!has_been_serialized_);
124 has_been_serialized_ = true; 121 has_been_serialized_ = true;
125 #endif 122 #endif
126 123
127 // If the var is not a string type, we should not have ended up with any 124 // If the var is not a string type, we should not have ended up with any
128 // string data. 125 // string data.
129 DCHECK(var_.type == PP_VARTYPE_STRING || string_value_.empty()); 126 DCHECK(var_.type == PP_VARTYPE_STRING || !tracker_string_ptr_);
130 127
131 m->WriteInt(static_cast<int>(var_.type)); 128 m->WriteInt(static_cast<int>(var_.type));
132 switch (var_.type) { 129 switch (var_.type) {
133 case PP_VARTYPE_UNDEFINED: 130 case PP_VARTYPE_UNDEFINED:
134 case PP_VARTYPE_NULL: 131 case PP_VARTYPE_NULL:
135 // These don't need any data associated with them other than the type we 132 // These don't need any data associated with them other than the type we
136 // just serialized. 133 // just serialized.
137 break; 134 break;
138 case PP_VARTYPE_BOOL: 135 case PP_VARTYPE_BOOL:
139 m->WriteBool(PP_ToBool(var_.value.as_bool)); 136 m->WriteBool(PP_ToBool(var_.value.as_bool));
140 break; 137 break;
141 case PP_VARTYPE_INT32: 138 case PP_VARTYPE_INT32:
142 m->WriteInt(var_.value.as_int); 139 m->WriteInt(var_.value.as_int);
143 break; 140 break;
144 case PP_VARTYPE_DOUBLE: 141 case PP_VARTYPE_DOUBLE:
145 IPC::ParamTraits<double>::Write(m, var_.value.as_double); 142 IPC::ParamTraits<double>::Write(m, var_.value.as_double);
146 break; 143 break;
147 case PP_VARTYPE_STRING: 144 case PP_VARTYPE_STRING:
148 // TODO(brettw) in the case of an invalid string ID, it would be nice 145 // TODO(brettw) in the case of an invalid string ID, it would be nice
149 // to send something to the other side such that a 0 ID would be 146 // to send something to the other side such that a 0 ID would be
150 // generated there. Then the function implementing the interface can 147 // generated there. Then the function implementing the interface can
151 // handle the invalid string as if it was in process rather than seeing 148 // handle the invalid string as if it was in process rather than seeing
152 // what looks like a valid empty string. 149 // what looks like a valid empty string.
153 m->WriteString(string_value_); 150 m->WriteString(tracker_string_ptr_ ? *tracker_string_ptr_
151 : std::string());
154 break; 152 break;
155 case PP_VARTYPE_ARRAY_BUFFER: 153 case PP_VARTYPE_ARRAY_BUFFER:
156 // TODO(dmichael): Proxy ArrayBuffer. 154 // TODO(dmichael): Proxy ArrayBuffer.
157 NOTIMPLEMENTED(); 155 NOTIMPLEMENTED();
158 break; 156 break;
159 case PP_VARTYPE_OBJECT: 157 case PP_VARTYPE_OBJECT:
160 m->WriteInt64(var_.value.as_id); 158 m->WriteInt64(var_.value.as_id);
161 break; 159 break;
162 case PP_VARTYPE_ARRAY: 160 case PP_VARTYPE_ARRAY:
163 case PP_VARTYPE_DICTIONARY: 161 case PP_VARTYPE_DICTIONARY:
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 var_.value.as_bool = PP_FromBool(bool_value); 198 var_.value.as_bool = PP_FromBool(bool_value);
201 break; 199 break;
202 } 200 }
203 case PP_VARTYPE_INT32: 201 case PP_VARTYPE_INT32:
204 success = m->ReadInt(iter, &var_.value.as_int); 202 success = m->ReadInt(iter, &var_.value.as_int);
205 break; 203 break;
206 case PP_VARTYPE_DOUBLE: 204 case PP_VARTYPE_DOUBLE:
207 success = IPC::ParamTraits<double>::Read(m, iter, &var_.value.as_double); 205 success = IPC::ParamTraits<double>::Read(m, iter, &var_.value.as_double);
208 break; 206 break;
209 case PP_VARTYPE_STRING: 207 case PP_VARTYPE_STRING:
210 success = m->ReadString(iter, &string_value_); 208 DCHECK(!tracker_string_ptr_ && !string_from_ipc_.get());
209 string_from_ipc_.reset(new std::string);
210 success = m->ReadString(iter, string_from_ipc_.get());
211 var_.value.as_id = 0; 211 var_.value.as_id = 0;
212 break; 212 break;
213 case PP_VARTYPE_OBJECT: 213 case PP_VARTYPE_OBJECT:
214 success = m->ReadInt64(iter, &var_.value.as_id); 214 success = m->ReadInt64(iter, &var_.value.as_id);
215 break; 215 break;
216 case PP_VARTYPE_ARRAY: 216 case PP_VARTYPE_ARRAY:
217 case PP_VARTYPE_DICTIONARY: 217 case PP_VARTYPE_DICTIONARY:
218 // TODO(brettw) when these types are supported, implement this. 218 // TODO(brettw) when these types are supported, implement this.
219 NOTIMPLEMENTED(); 219 NOTIMPLEMENTED();
220 break; 220 break;
(...skipping 24 matching lines...) Expand all
245 245
246 // SerializedVar --------------------------------------------------------------- 246 // SerializedVar ---------------------------------------------------------------
247 247
248 SerializedVar::SerializedVar() : inner_(new Inner) { 248 SerializedVar::SerializedVar() : inner_(new Inner) {
249 } 249 }
250 250
251 SerializedVar::SerializedVar(VarSerializationRules* serialization_rules) 251 SerializedVar::SerializedVar(VarSerializationRules* serialization_rules)
252 : inner_(new Inner(serialization_rules)) { 252 : inner_(new Inner(serialization_rules)) {
253 } 253 }
254 254
255 SerializedVar::SerializedVar(VarSerializationRules* serialization_rules,
256 const PP_Var& var)
257 : inner_(new Inner(serialization_rules, var)) {
258 }
259
260 SerializedVar::~SerializedVar() { 255 SerializedVar::~SerializedVar() {
261 } 256 }
262 257
263 // SerializedVarSendInput ------------------------------------------------------ 258 // SerializedVarSendInput ------------------------------------------------------
264 259
265 SerializedVarSendInput::SerializedVarSendInput(Dispatcher* dispatcher, 260 SerializedVarSendInput::SerializedVarSendInput(Dispatcher* dispatcher,
266 const PP_Var& var) 261 const PP_Var& var)
267 : SerializedVar(dispatcher->serialization_rules()) { 262 : SerializedVar(dispatcher->serialization_rules()) {
268 inner_->SetVar(dispatcher->serialization_rules()->SendCallerOwned( 263 inner_->SetVar(dispatcher->serialization_rules()->SendCallerOwned(
269 var, inner_->GetStringPtr())); 264 var, inner_->GetStringPtrPtr()));
270 } 265 }
271 266
272 // static 267 // static
273 void SerializedVarSendInput::ConvertVector(Dispatcher* dispatcher, 268 void SerializedVarSendInput::ConvertVector(Dispatcher* dispatcher,
274 const PP_Var* input, 269 const PP_Var* input,
275 size_t input_count, 270 size_t input_count,
276 std::vector<SerializedVar>* output) { 271 std::vector<SerializedVar>* output) {
277 output->resize(input_count); 272 output->reserve(input_count);
278 for (size_t i = 0; i < input_count; i++) { 273 for (size_t i = 0; i < input_count; i++)
279 SerializedVar& cur = (*output)[i]; 274 output->push_back(SerializedVarSendInput(dispatcher, input[i]));
280 cur = SerializedVar(dispatcher->serialization_rules());
281 cur.inner_->SetVar(dispatcher->serialization_rules()->SendCallerOwned(
282 input[i], cur.inner_->GetStringPtr()));
283 }
284 } 275 }
285 276
286 // ReceiveSerializedVarReturnValue --------------------------------------------- 277 // ReceiveSerializedVarReturnValue ---------------------------------------------
287 278
288 ReceiveSerializedVarReturnValue::ReceiveSerializedVarReturnValue() { 279 ReceiveSerializedVarReturnValue::ReceiveSerializedVarReturnValue() {
289 } 280 }
290 281
291 ReceiveSerializedVarReturnValue::ReceiveSerializedVarReturnValue( 282 ReceiveSerializedVarReturnValue::ReceiveSerializedVarReturnValue(
292 const SerializedVar& serialized) 283 const SerializedVar& serialized)
293 : SerializedVar(serialized) { 284 : SerializedVar(serialized) {
294 } 285 }
295 286
296 PP_Var ReceiveSerializedVarReturnValue::Return(Dispatcher* dispatcher) { 287 PP_Var ReceiveSerializedVarReturnValue::Return(Dispatcher* dispatcher) {
297 inner_->set_serialization_rules(dispatcher->serialization_rules()); 288 inner_->set_serialization_rules(dispatcher->serialization_rules());
298 inner_->SetVar(inner_->serialization_rules()->ReceivePassRef( 289 inner_->SetVar(inner_->serialization_rules()->ReceivePassRef(
299 inner_->GetIncompleteVar(), inner_->GetString(), dispatcher)); 290 inner_->GetIncompleteVar(), inner_->GetStringDestructive(), dispatcher));
300 return inner_->GetVar(); 291 return inner_->GetVar();
301 } 292 }
302 293
303 // ReceiveSerializedException -------------------------------------------------- 294 // ReceiveSerializedException --------------------------------------------------
304 295
305 ReceiveSerializedException::ReceiveSerializedException(Dispatcher* dispatcher, 296 ReceiveSerializedException::ReceiveSerializedException(Dispatcher* dispatcher,
306 PP_Var* exception) 297 PP_Var* exception)
307 : SerializedVar(dispatcher->serialization_rules()), 298 : SerializedVar(dispatcher->serialization_rules()),
308 dispatcher_(dispatcher), 299 dispatcher_(dispatcher),
309 exception_(exception) { 300 exception_(exception) {
310 } 301 }
311 302
312 ReceiveSerializedException::~ReceiveSerializedException() { 303 ReceiveSerializedException::~ReceiveSerializedException() {
313 if (exception_) { 304 if (exception_) {
314 // When an output exception is specified, it will take ownership of the 305 // When an output exception is specified, it will take ownership of the
315 // reference. 306 // reference.
316 inner_->SetVar(inner_->serialization_rules()->ReceivePassRef( 307 inner_->SetVar(
317 inner_->GetIncompleteVar(), inner_->GetString(), dispatcher_)); 308 inner_->serialization_rules()->ReceivePassRef(
309 inner_->GetIncompleteVar(),
310 inner_->GetStringDestructive(),
311 dispatcher_));
318 *exception_ = inner_->GetVar(); 312 *exception_ = inner_->GetVar();
319 } else { 313 } else {
320 // When no output exception is specified, the browser thinks we have a ref 314 // When no output exception is specified, the browser thinks we have a ref
321 // to an object that we don't want (this will happen only in the plugin 315 // to an object that we don't want (this will happen only in the plugin
322 // since the browser will always specify an out exception for the plugin to 316 // since the browser will always specify an out exception for the plugin to
323 // write into). 317 // write into).
324 // 318 //
325 // Strings don't need this handling since we can just avoid creating a 319 // Strings don't need this handling since we can just avoid creating a
326 // Var from the std::string in the first place. 320 // Var from the std::string in the first place.
327 if (inner_->GetVar().type == PP_VARTYPE_OBJECT) 321 if (inner_->GetVar().type == PP_VARTYPE_OBJECT)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 serialized_.inner_->set_serialization_rules( 375 serialized_.inner_->set_serialization_rules(
382 dispatcher->serialization_rules()); 376 dispatcher->serialization_rules());
383 377
384 // Ensure that when the serialized var goes out of scope it cleans up the 378 // Ensure that when the serialized var goes out of scope it cleans up the
385 // stuff we're making in BeginReceiveCallerOwned. 379 // stuff we're making in BeginReceiveCallerOwned.
386 serialized_.inner_->SetCleanupModeToEndReceiveCallerOwned(); 380 serialized_.inner_->SetCleanupModeToEndReceiveCallerOwned();
387 381
388 serialized_.inner_->SetVar( 382 serialized_.inner_->SetVar(
389 serialized_.inner_->serialization_rules()->BeginReceiveCallerOwned( 383 serialized_.inner_->serialization_rules()->BeginReceiveCallerOwned(
390 serialized_.inner_->GetIncompleteVar(), 384 serialized_.inner_->GetIncompleteVar(),
391 serialized_.inner_->GetStringPtr(), 385 serialized_.inner_->GetStringDestructive(),
392 dispatcher)); 386 dispatcher));
393 return serialized_.inner_->GetVar(); 387 return serialized_.inner_->GetVar();
394 } 388 }
395 389
396 // SerializedVarVectorReceiveInput --------------------------------------------- 390 // SerializedVarVectorReceiveInput ---------------------------------------------
397 391
398 SerializedVarVectorReceiveInput::SerializedVarVectorReceiveInput( 392 SerializedVarVectorReceiveInput::SerializedVarVectorReceiveInput(
399 const std::vector<SerializedVar>& serialized) 393 const std::vector<SerializedVar>& serialized)
400 : serialized_(serialized) { 394 : serialized_(serialized) {
401 } 395 }
(...skipping 10 matching lines...) Expand all
412 deserialized_.resize(serialized_.size()); 406 deserialized_.resize(serialized_.size());
413 for (size_t i = 0; i < serialized_.size(); i++) { 407 for (size_t i = 0; i < serialized_.size(); i++) {
414 // The vectors must be able to clean themselves up after this call is 408 // The vectors must be able to clean themselves up after this call is
415 // torn down. 409 // torn down.
416 serialized_[i].inner_->set_serialization_rules( 410 serialized_[i].inner_->set_serialization_rules(
417 dispatcher->serialization_rules()); 411 dispatcher->serialization_rules());
418 412
419 serialized_[i].inner_->SetVar( 413 serialized_[i].inner_->SetVar(
420 serialized_[i].inner_->serialization_rules()->BeginReceiveCallerOwned( 414 serialized_[i].inner_->serialization_rules()->BeginReceiveCallerOwned(
421 serialized_[i].inner_->GetIncompleteVar(), 415 serialized_[i].inner_->GetIncompleteVar(),
422 serialized_[i].inner_->GetStringPtr(), 416 serialized_[i].inner_->GetStringDestructive(),
423 dispatcher)); 417 dispatcher));
424 deserialized_[i] = serialized_[i].inner_->GetVar(); 418 deserialized_[i] = serialized_[i].inner_->GetVar();
425 } 419 }
426 420
427 *array_size = static_cast<uint32_t>(serialized_.size()); 421 *array_size = static_cast<uint32_t>(serialized_.size());
428 return deserialized_.empty() ? NULL : &deserialized_[0]; 422 return deserialized_.empty() ? NULL : &deserialized_[0];
429 } 423 }
430 424
431 // SerializedVarReturnValue ---------------------------------------------------- 425 // SerializedVarReturnValue ----------------------------------------------------
432 426
433 SerializedVarReturnValue::SerializedVarReturnValue(SerializedVar* serialized) 427 SerializedVarReturnValue::SerializedVarReturnValue(SerializedVar* serialized)
434 : serialized_(serialized) { 428 : serialized_(serialized) {
435 } 429 }
436 430
437 void SerializedVarReturnValue::Return(Dispatcher* dispatcher, 431 void SerializedVarReturnValue::Return(Dispatcher* dispatcher,
438 const PP_Var& var) { 432 const PP_Var& var) {
439 serialized_->inner_->set_serialization_rules( 433 serialized_->inner_->set_serialization_rules(
440 dispatcher->serialization_rules()); 434 dispatcher->serialization_rules());
441 435
442 // Var must clean up after our BeginSendPassRef call. 436 // Var must clean up after our BeginSendPassRef call.
443 serialized_->inner_->SetCleanupModeToEndSendPassRef(dispatcher); 437 serialized_->inner_->SetCleanupModeToEndSendPassRef(dispatcher);
444 438
445 serialized_->inner_->SetVar( 439 serialized_->inner_->SetVar(
446 dispatcher->serialization_rules()->BeginSendPassRef( 440 dispatcher->serialization_rules()->BeginSendPassRef(
447 var, 441 var,
448 serialized_->inner_->GetStringPtr())); 442 serialized_->inner_->GetStringPtrPtr()));
449 } 443 }
450 444
451 // static 445 // static
452 SerializedVar SerializedVarReturnValue::Convert(Dispatcher* dispatcher, 446 SerializedVar SerializedVarReturnValue::Convert(Dispatcher* dispatcher,
453 const PP_Var& var) { 447 const PP_Var& var) {
454 // Mimic what happens in the normal case. 448 // Mimic what happens in the normal case.
455 SerializedVar result; 449 SerializedVar result;
456 SerializedVarReturnValue retvalue(&result); 450 SerializedVarReturnValue retvalue(&result);
457 retvalue.Return(dispatcher, var); 451 retvalue.Return(dispatcher, var);
458 return result; 452 return result;
459 } 453 }
460 454
461 // SerializedVarOutParam ------------------------------------------------------- 455 // SerializedVarOutParam -------------------------------------------------------
462 456
463 SerializedVarOutParam::SerializedVarOutParam(SerializedVar* serialized) 457 SerializedVarOutParam::SerializedVarOutParam(SerializedVar* serialized)
464 : serialized_(serialized), 458 : serialized_(serialized),
465 writable_var_(PP_MakeUndefined()), 459 writable_var_(PP_MakeUndefined()),
466 dispatcher_(NULL) { 460 dispatcher_(NULL) {
467 } 461 }
468 462
469 SerializedVarOutParam::~SerializedVarOutParam() { 463 SerializedVarOutParam::~SerializedVarOutParam() {
470 if (serialized_->inner_->serialization_rules()) { 464 if (serialized_->inner_->serialization_rules()) {
471 // When unset, OutParam wasn't called. We'll just leave the var untouched 465 // When unset, OutParam wasn't called. We'll just leave the var untouched
472 // in that case. 466 // in that case.
473 serialized_->inner_->SetVar( 467 serialized_->inner_->SetVar(
474 serialized_->inner_->serialization_rules()->BeginSendPassRef( 468 serialized_->inner_->serialization_rules()->BeginSendPassRef(
475 writable_var_, serialized_->inner_->GetStringPtr())); 469 writable_var_, serialized_->inner_->GetStringPtrPtr()));
476 470
477 // Normally the current object will be created on the stack to wrap a 471 // Normally the current object will be created on the stack to wrap a
478 // SerializedVar and won't have a scope around the actual IPC send. So we 472 // SerializedVar and won't have a scope around the actual IPC send. So we
479 // need to tell the SerializedVar to do the begin/end send pass ref calls. 473 // need to tell the SerializedVar to do the begin/end send pass ref calls.
480 serialized_->inner_->SetCleanupModeToEndSendPassRef(dispatcher_); 474 serialized_->inner_->SetCleanupModeToEndSendPassRef(dispatcher_);
481 } 475 }
482 } 476 }
483 477
484 PP_Var* SerializedVarOutParam::OutParam(Dispatcher* dispatcher) { 478 PP_Var* SerializedVarOutParam::OutParam(Dispatcher* dispatcher) {
485 dispatcher_ = dispatcher; 479 dispatcher_ = dispatcher;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 inner_->ForceSetStringValueForTest(str); 533 inner_->ForceSetStringValueForTest(str);
540 } 534 }
541 535
542 SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var) 536 SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var)
543 : SerializedVar(var) { 537 : SerializedVar(var) {
544 } 538 }
545 539
546 } // namespace proxy 540 } // namespace proxy
547 } // namespace ppapi 541 } // namespace ppapi
548 542
OLDNEW
« no previous file with comments | « ppapi/proxy/serialized_var.h ('k') | ppapi/proxy/serialized_var_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698