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

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

Issue 9316123: Remove special handling for strings in var serialization. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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) 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/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 #include "ppapi/shared_impl/var.h"
13 14
14 namespace ppapi { 15 namespace ppapi {
15 namespace proxy { 16 namespace proxy {
16 17
17 // SerializedVar::Inner -------------------------------------------------------- 18 // SerializedVar::Inner --------------------------------------------------------
18 19
19 SerializedVar::Inner::Inner() 20 SerializedVar::Inner::Inner()
20 : serialization_rules_(NULL), 21 : serialization_rules_(NULL),
21 var_(PP_MakeUndefined()), 22 var_(PP_MakeUndefined()),
22 tracker_string_ptr_(NULL),
23 cleanup_mode_(CLEANUP_NONE), 23 cleanup_mode_(CLEANUP_NONE),
24 dispatcher_for_end_send_pass_ref_(NULL) { 24 dispatcher_for_end_send_pass_ref_(NULL) {
25 #ifndef NDEBUG 25 #ifndef NDEBUG
26 has_been_serialized_ = false; 26 has_been_serialized_ = false;
27 has_been_deserialized_ = false; 27 has_been_deserialized_ = false;
28 #endif 28 #endif
29 } 29 }
30 30
31 SerializedVar::Inner::Inner(VarSerializationRules* serialization_rules) 31 SerializedVar::Inner::Inner(VarSerializationRules* serialization_rules)
32 : serialization_rules_(serialization_rules), 32 : serialization_rules_(serialization_rules),
33 var_(PP_MakeUndefined()), 33 var_(PP_MakeUndefined()),
34 tracker_string_ptr_(NULL),
35 cleanup_mode_(CLEANUP_NONE), 34 cleanup_mode_(CLEANUP_NONE),
36 dispatcher_for_end_send_pass_ref_(NULL) { 35 dispatcher_for_end_send_pass_ref_(NULL) {
37 #ifndef NDEBUG 36 #ifndef NDEBUG
38 has_been_serialized_ = false; 37 has_been_serialized_ = false;
39 has_been_deserialized_ = false; 38 has_been_deserialized_ = false;
40 #endif 39 #endif
41 } 40 }
42 41
43 SerializedVar::Inner::~Inner() { 42 SerializedVar::Inner::~Inner() {
44 switch (cleanup_mode_) { 43 switch (cleanup_mode_) {
45 case END_SEND_PASS_REF: 44 case END_SEND_PASS_REF:
46 DCHECK(dispatcher_for_end_send_pass_ref_); 45 DCHECK(dispatcher_for_end_send_pass_ref_);
47 serialization_rules_->EndSendPassRef(var_, 46 serialization_rules_->EndSendPassRef(var_,
48 dispatcher_for_end_send_pass_ref_); 47 dispatcher_for_end_send_pass_ref_);
49 break; 48 break;
50 case END_RECEIVE_CALLER_OWNED: 49 case END_RECEIVE_CALLER_OWNED:
51 serialization_rules_->EndReceiveCallerOwned(var_); 50 serialization_rules_->EndReceiveCallerOwned(var_);
52 break; 51 break;
53 default: 52 default:
54 break; 53 break;
55 } 54 }
56 } 55 }
57 56
58 PP_Var SerializedVar::Inner::GetVar() const { 57 PP_Var SerializedVar::Inner::GetVar() const {
59 DCHECK(serialization_rules_); 58 DCHECK(serialization_rules_);
60
61 // If we're a string var, we should have already converted the string value
62 // to a var ID.
63 DCHECK(var_.type != PP_VARTYPE_STRING || var_.value.as_id != 0);
64 return var_;
65 }
66
67 PP_Var SerializedVar::Inner::GetIncompleteVar() const {
68 DCHECK(serialization_rules_);
69 return var_; 59 return var_;
70 } 60 }
71 61
72 void SerializedVar::Inner::SetVar(PP_Var var) { 62 void SerializedVar::Inner::SetVar(PP_Var var) {
73 // Sanity check, when updating the var we should have received a 63 // Sanity check, when updating the var we should have received a
74 // serialization rules pointer already. 64 // serialization rules pointer already.
75 DCHECK(serialization_rules_); 65 DCHECK(serialization_rules_);
76 var_ = var; 66 var_ = var;
77 } 67 }
78 68
79 scoped_ptr<std::string> SerializedVar::Inner::GetStringDestructive() {
80 DCHECK(serialization_rules_);
81 return string_from_ipc_.Pass();
82 }
83
84 const std::string** SerializedVar::Inner::GetStringPtrPtr() {
85 DCHECK(serialization_rules_);
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_;
91 }
92
93 void SerializedVar::Inner::ForceSetVarValueForTest(PP_Var value) { 69 void SerializedVar::Inner::ForceSetVarValueForTest(PP_Var value) {
94 var_ = value; 70 var_ = value;
95 } 71 }
96 72
97 void SerializedVar::Inner::ForceSetStringValueForTest(const std::string& 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));
102 }
103
104 void SerializedVar::Inner::WriteToMessage(IPC::Message* m) const { 73 void SerializedVar::Inner::WriteToMessage(IPC::Message* m) const {
105 // When writing to the IPC messages, a serization rules handler should 74 // When writing to the IPC messages, a serization rules handler should
106 // always have been set. 75 // always have been set.
107 // 76 //
108 // When sending a message, it should be difficult to trigger this if you're 77 // When sending a message, it should be difficult to trigger this if you're
109 // using the SerializedVarSendInput class and giving a non-NULL dispatcher. 78 // using the SerializedVarSendInput class and giving a non-NULL dispatcher.
110 // Make sure you're using the proper "Send" helper class. 79 // Make sure you're using the proper "Send" helper class.
111 // 80 //
112 // It should be more common to see this when handling an incoming message 81 // It should be more common to see this when handling an incoming message
113 // that returns a var. This means the message handler didn't write to the 82 // that returns a var. This means the message handler didn't write to the
114 // output parameter, or possibly you used the wrong helper class 83 // output parameter, or possibly you used the wrong helper class
115 // (normally SerializedVarReturnValue). 84 // (normally SerializedVarReturnValue).
116 DCHECK(serialization_rules_); 85 DCHECK(serialization_rules_);
117 86
118 #ifndef NDEBUG 87 #ifndef NDEBUG
119 // We should only be serializing something once. 88 // We should only be serializing something once.
120 DCHECK(!has_been_serialized_); 89 DCHECK(!has_been_serialized_);
121 has_been_serialized_ = true; 90 has_been_serialized_ = true;
122 #endif 91 #endif
123 92
124 // If the var is not a string type, we should not have ended up with any
125 // string data.
126 DCHECK(var_.type == PP_VARTYPE_STRING || !tracker_string_ptr_);
127
128 m->WriteInt(static_cast<int>(var_.type)); 93 m->WriteInt(static_cast<int>(var_.type));
129 switch (var_.type) { 94 switch (var_.type) {
130 case PP_VARTYPE_UNDEFINED: 95 case PP_VARTYPE_UNDEFINED:
131 case PP_VARTYPE_NULL: 96 case PP_VARTYPE_NULL:
132 // These don't need any data associated with them other than the type we 97 // These don't need any data associated with them other than the type we
133 // just serialized. 98 // just serialized.
134 break; 99 break;
135 case PP_VARTYPE_BOOL: 100 case PP_VARTYPE_BOOL:
136 m->WriteBool(PP_ToBool(var_.value.as_bool)); 101 m->WriteBool(PP_ToBool(var_.value.as_bool));
137 break; 102 break;
138 case PP_VARTYPE_INT32: 103 case PP_VARTYPE_INT32:
139 m->WriteInt(var_.value.as_int); 104 m->WriteInt(var_.value.as_int);
140 break; 105 break;
141 case PP_VARTYPE_DOUBLE: 106 case PP_VARTYPE_DOUBLE:
142 IPC::ParamTraits<double>::Write(m, var_.value.as_double); 107 IPC::ParamTraits<double>::Write(m, var_.value.as_double);
143 break; 108 break;
144 case PP_VARTYPE_STRING: 109 case PP_VARTYPE_STRING: {
145 // TODO(brettw) in the case of an invalid string ID, it would be nice 110 // TODO(brettw) in the case of an invalid string ID, it would be nice
146 // to send something to the other side such that a 0 ID would be 111 // to send something to the other side such that a 0 ID would be
147 // generated there. Then the function implementing the interface can 112 // generated there. Then the function implementing the interface can
148 // handle the invalid string as if it was in process rather than seeing 113 // handle the invalid string as if it was in process rather than seeing
149 // what looks like a valid empty string. 114 // what looks like a valid empty string.
150 m->WriteString(tracker_string_ptr_ ? *tracker_string_ptr_ 115 StringVar* string_var = StringVar::FromPPVar(var_);
151 : std::string()); 116 m->WriteString(string_var ? *string_var->ptr() : std::string());
152 break; 117 break;
118 }
153 case PP_VARTYPE_ARRAY_BUFFER: 119 case PP_VARTYPE_ARRAY_BUFFER:
154 // TODO(dmichael): Proxy ArrayBuffer. 120 // TODO(dmichael): Proxy ArrayBuffer.
155 NOTIMPLEMENTED(); 121 NOTIMPLEMENTED();
156 break; 122 break;
157 case PP_VARTYPE_OBJECT: 123 case PP_VARTYPE_OBJECT:
158 m->WriteInt64(var_.value.as_id); 124 m->WriteInt64(var_.value.as_id);
159 break; 125 break;
160 case PP_VARTYPE_ARRAY: 126 case PP_VARTYPE_ARRAY:
161 case PP_VARTYPE_DICTIONARY: 127 case PP_VARTYPE_DICTIONARY:
162 // TODO(brettw) when these are supported, implement this. 128 // TODO(brettw) when these are supported, implement this.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 success = m->ReadBool(iter, &bool_value); 163 success = m->ReadBool(iter, &bool_value);
198 var_.value.as_bool = PP_FromBool(bool_value); 164 var_.value.as_bool = PP_FromBool(bool_value);
199 break; 165 break;
200 } 166 }
201 case PP_VARTYPE_INT32: 167 case PP_VARTYPE_INT32:
202 success = m->ReadInt(iter, &var_.value.as_int); 168 success = m->ReadInt(iter, &var_.value.as_int);
203 break; 169 break;
204 case PP_VARTYPE_DOUBLE: 170 case PP_VARTYPE_DOUBLE:
205 success = IPC::ParamTraits<double>::Read(m, iter, &var_.value.as_double); 171 success = IPC::ParamTraits<double>::Read(m, iter, &var_.value.as_double);
206 break; 172 break;
207 case PP_VARTYPE_STRING: 173 case PP_VARTYPE_STRING: {
208 DCHECK(!tracker_string_ptr_ && !string_from_ipc_.get()); 174 std::string string_from_ipc;
209 string_from_ipc_.reset(new std::string); 175 success = m->ReadString(iter, &string_from_ipc);
210 success = m->ReadString(iter, string_from_ipc_.get()); 176 var_ = StringVar::SwapValidatedUTF8StringIntoPPVar(&string_from_ipc);
dmichael (off chromium) 2012/02/07 16:35:31 It just occurred to me that we maybe should still
brettw 2012/02/07 16:56:31 The validating we do is mostly because we wanted t
211 var_.value.as_id = 0;
212 break; 177 break;
178 }
213 case PP_VARTYPE_OBJECT: 179 case PP_VARTYPE_OBJECT:
214 success = m->ReadInt64(iter, &var_.value.as_id); 180 success = m->ReadInt64(iter, &var_.value.as_id);
215 break; 181 break;
216 case PP_VARTYPE_ARRAY: 182 case PP_VARTYPE_ARRAY:
217 case PP_VARTYPE_DICTIONARY: 183 case PP_VARTYPE_DICTIONARY:
218 // TODO(brettw) when these types are supported, implement this. 184 // TODO(brettw) when these types are supported, implement this.
219 NOTIMPLEMENTED(); 185 NOTIMPLEMENTED();
220 break; 186 break;
221 default: 187 default:
222 // Leave success as false. 188 // Leave success as false.
(...skipping 30 matching lines...) Expand all
253 } 219 }
254 220
255 SerializedVar::~SerializedVar() { 221 SerializedVar::~SerializedVar() {
256 } 222 }
257 223
258 // SerializedVarSendInput ------------------------------------------------------ 224 // SerializedVarSendInput ------------------------------------------------------
259 225
260 SerializedVarSendInput::SerializedVarSendInput(Dispatcher* dispatcher, 226 SerializedVarSendInput::SerializedVarSendInput(Dispatcher* dispatcher,
261 const PP_Var& var) 227 const PP_Var& var)
262 : SerializedVar(dispatcher->serialization_rules()) { 228 : SerializedVar(dispatcher->serialization_rules()) {
263 inner_->SetVar(dispatcher->serialization_rules()->SendCallerOwned( 229 inner_->SetVar(dispatcher->serialization_rules()->SendCallerOwned(var));
264 var, inner_->GetStringPtrPtr()));
265 } 230 }
266 231
267 // static 232 // static
268 void SerializedVarSendInput::ConvertVector(Dispatcher* dispatcher, 233 void SerializedVarSendInput::ConvertVector(Dispatcher* dispatcher,
269 const PP_Var* input, 234 const PP_Var* input,
270 size_t input_count, 235 size_t input_count,
271 std::vector<SerializedVar>* output) { 236 std::vector<SerializedVar>* output) {
272 output->reserve(input_count); 237 output->reserve(input_count);
273 for (size_t i = 0; i < input_count; i++) 238 for (size_t i = 0; i < input_count; i++)
274 output->push_back(SerializedVarSendInput(dispatcher, input[i])); 239 output->push_back(SerializedVarSendInput(dispatcher, input[i]));
275 } 240 }
276 241
277 // ReceiveSerializedVarReturnValue --------------------------------------------- 242 // ReceiveSerializedVarReturnValue ---------------------------------------------
278 243
279 ReceiveSerializedVarReturnValue::ReceiveSerializedVarReturnValue() { 244 ReceiveSerializedVarReturnValue::ReceiveSerializedVarReturnValue() {
280 } 245 }
281 246
282 ReceiveSerializedVarReturnValue::ReceiveSerializedVarReturnValue( 247 ReceiveSerializedVarReturnValue::ReceiveSerializedVarReturnValue(
283 const SerializedVar& serialized) 248 const SerializedVar& serialized)
284 : SerializedVar(serialized) { 249 : SerializedVar(serialized) {
285 } 250 }
286 251
287 PP_Var ReceiveSerializedVarReturnValue::Return(Dispatcher* dispatcher) { 252 PP_Var ReceiveSerializedVarReturnValue::Return(Dispatcher* dispatcher) {
288 inner_->set_serialization_rules(dispatcher->serialization_rules()); 253 inner_->set_serialization_rules(dispatcher->serialization_rules());
289 inner_->SetVar(inner_->serialization_rules()->ReceivePassRef( 254 inner_->SetVar(inner_->serialization_rules()->ReceivePassRef(
290 inner_->GetIncompleteVar(), inner_->GetStringDestructive(), dispatcher)); 255 inner_->GetVar(), dispatcher));
291 return inner_->GetVar(); 256 return inner_->GetVar();
292 } 257 }
293 258
294 // ReceiveSerializedException -------------------------------------------------- 259 // ReceiveSerializedException --------------------------------------------------
295 260
296 ReceiveSerializedException::ReceiveSerializedException(Dispatcher* dispatcher, 261 ReceiveSerializedException::ReceiveSerializedException(Dispatcher* dispatcher,
297 PP_Var* exception) 262 PP_Var* exception)
298 : SerializedVar(dispatcher->serialization_rules()), 263 : SerializedVar(dispatcher->serialization_rules()),
299 dispatcher_(dispatcher), 264 dispatcher_(dispatcher),
300 exception_(exception) { 265 exception_(exception) {
301 } 266 }
302 267
303 ReceiveSerializedException::~ReceiveSerializedException() { 268 ReceiveSerializedException::~ReceiveSerializedException() {
304 if (exception_) { 269 if (exception_) {
305 // When an output exception is specified, it will take ownership of the 270 // When an output exception is specified, it will take ownership of the
306 // reference. 271 // reference.
307 inner_->SetVar( 272 inner_->SetVar(
308 inner_->serialization_rules()->ReceivePassRef( 273 inner_->serialization_rules()->ReceivePassRef(inner_->GetVar(),
309 inner_->GetIncompleteVar(), 274 dispatcher_));
310 inner_->GetStringDestructive(),
311 dispatcher_));
312 *exception_ = inner_->GetVar(); 275 *exception_ = inner_->GetVar();
313 } else { 276 } else {
314 // When no output exception is specified, the browser thinks we have a ref 277 // When no output exception is specified, the browser thinks we have a ref
315 // to an object that we don't want (this will happen only in the plugin 278 // to an object that we don't want (this will happen only in the plugin
316 // since the browser will always specify an out exception for the plugin to 279 // since the browser will always specify an out exception for the plugin to
317 // write into). 280 // write into).
318 // 281 //
319 // Strings don't need this handling since we can just avoid creating a 282 // Strings don't need this handling since we can just avoid creating a
320 // Var from the std::string in the first place. 283 // Var from the std::string in the first place.
321 if (inner_->GetVar().type == PP_VARTYPE_OBJECT) 284 if (inner_->GetVar().type == PP_VARTYPE_OBJECT)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 PP_Var SerializedVarReceiveInput::Get(Dispatcher* dispatcher) { 337 PP_Var SerializedVarReceiveInput::Get(Dispatcher* dispatcher) {
375 serialized_.inner_->set_serialization_rules( 338 serialized_.inner_->set_serialization_rules(
376 dispatcher->serialization_rules()); 339 dispatcher->serialization_rules());
377 340
378 // Ensure that when the serialized var goes out of scope it cleans up the 341 // Ensure that when the serialized var goes out of scope it cleans up the
379 // stuff we're making in BeginReceiveCallerOwned. 342 // stuff we're making in BeginReceiveCallerOwned.
380 serialized_.inner_->SetCleanupModeToEndReceiveCallerOwned(); 343 serialized_.inner_->SetCleanupModeToEndReceiveCallerOwned();
381 344
382 serialized_.inner_->SetVar( 345 serialized_.inner_->SetVar(
383 serialized_.inner_->serialization_rules()->BeginReceiveCallerOwned( 346 serialized_.inner_->serialization_rules()->BeginReceiveCallerOwned(
384 serialized_.inner_->GetIncompleteVar(), 347 serialized_.inner_->GetVar(),
385 serialized_.inner_->GetStringDestructive(),
386 dispatcher)); 348 dispatcher));
387 return serialized_.inner_->GetVar(); 349 return serialized_.inner_->GetVar();
388 } 350 }
389 351
390 // SerializedVarVectorReceiveInput --------------------------------------------- 352 // SerializedVarVectorReceiveInput ---------------------------------------------
391 353
392 SerializedVarVectorReceiveInput::SerializedVarVectorReceiveInput( 354 SerializedVarVectorReceiveInput::SerializedVarVectorReceiveInput(
393 const std::vector<SerializedVar>& serialized) 355 const std::vector<SerializedVar>& serialized)
394 : serialized_(serialized) { 356 : serialized_(serialized) {
395 } 357 }
396 358
397 SerializedVarVectorReceiveInput::~SerializedVarVectorReceiveInput() { 359 SerializedVarVectorReceiveInput::~SerializedVarVectorReceiveInput() {
398 for (size_t i = 0; i < deserialized_.size(); i++) { 360 for (size_t i = 0; i < deserialized_.size(); i++) {
399 serialized_[i].inner_->serialization_rules()->EndReceiveCallerOwned( 361 serialized_[i].inner_->serialization_rules()->EndReceiveCallerOwned(
400 deserialized_[i]); 362 deserialized_[i]);
401 } 363 }
402 } 364 }
403 365
404 PP_Var* SerializedVarVectorReceiveInput::Get(Dispatcher* dispatcher, 366 PP_Var* SerializedVarVectorReceiveInput::Get(Dispatcher* dispatcher,
405 uint32_t* array_size) { 367 uint32_t* array_size) {
406 deserialized_.resize(serialized_.size()); 368 deserialized_.resize(serialized_.size());
407 for (size_t i = 0; i < serialized_.size(); i++) { 369 for (size_t i = 0; i < serialized_.size(); i++) {
408 // The vectors must be able to clean themselves up after this call is 370 // The vectors must be able to clean themselves up after this call is
409 // torn down. 371 // torn down.
410 serialized_[i].inner_->set_serialization_rules( 372 serialized_[i].inner_->set_serialization_rules(
411 dispatcher->serialization_rules()); 373 dispatcher->serialization_rules());
412 374
413 serialized_[i].inner_->SetVar( 375 serialized_[i].inner_->SetVar(
414 serialized_[i].inner_->serialization_rules()->BeginReceiveCallerOwned( 376 serialized_[i].inner_->serialization_rules()->BeginReceiveCallerOwned(
415 serialized_[i].inner_->GetIncompleteVar(), 377 serialized_[i].inner_->GetVar(),
416 serialized_[i].inner_->GetStringDestructive(),
417 dispatcher)); 378 dispatcher));
418 deserialized_[i] = serialized_[i].inner_->GetVar(); 379 deserialized_[i] = serialized_[i].inner_->GetVar();
419 } 380 }
420 381
421 *array_size = static_cast<uint32_t>(serialized_.size()); 382 *array_size = static_cast<uint32_t>(serialized_.size());
422 return deserialized_.empty() ? NULL : &deserialized_[0]; 383 return deserialized_.empty() ? NULL : &deserialized_[0];
423 } 384 }
424 385
425 // SerializedVarReturnValue ---------------------------------------------------- 386 // SerializedVarReturnValue ----------------------------------------------------
426 387
427 SerializedVarReturnValue::SerializedVarReturnValue(SerializedVar* serialized) 388 SerializedVarReturnValue::SerializedVarReturnValue(SerializedVar* serialized)
428 : serialized_(serialized) { 389 : serialized_(serialized) {
429 } 390 }
430 391
431 void SerializedVarReturnValue::Return(Dispatcher* dispatcher, 392 void SerializedVarReturnValue::Return(Dispatcher* dispatcher,
432 const PP_Var& var) { 393 const PP_Var& var) {
433 serialized_->inner_->set_serialization_rules( 394 serialized_->inner_->set_serialization_rules(
434 dispatcher->serialization_rules()); 395 dispatcher->serialization_rules());
435 396
436 // Var must clean up after our BeginSendPassRef call. 397 // Var must clean up after our BeginSendPassRef call.
437 serialized_->inner_->SetCleanupModeToEndSendPassRef(dispatcher); 398 serialized_->inner_->SetCleanupModeToEndSendPassRef(dispatcher);
438 399
439 serialized_->inner_->SetVar( 400 serialized_->inner_->SetVar(
440 dispatcher->serialization_rules()->BeginSendPassRef( 401 dispatcher->serialization_rules()->BeginSendPassRef(var));
441 var,
442 serialized_->inner_->GetStringPtrPtr()));
443 } 402 }
444 403
445 // static 404 // static
446 SerializedVar SerializedVarReturnValue::Convert(Dispatcher* dispatcher, 405 SerializedVar SerializedVarReturnValue::Convert(Dispatcher* dispatcher,
447 const PP_Var& var) { 406 const PP_Var& var) {
448 // Mimic what happens in the normal case. 407 // Mimic what happens in the normal case.
449 SerializedVar result; 408 SerializedVar result;
450 SerializedVarReturnValue retvalue(&result); 409 SerializedVarReturnValue retvalue(&result);
451 retvalue.Return(dispatcher, var); 410 retvalue.Return(dispatcher, var);
452 return result; 411 return result;
453 } 412 }
454 413
455 // SerializedVarOutParam ------------------------------------------------------- 414 // SerializedVarOutParam -------------------------------------------------------
456 415
457 SerializedVarOutParam::SerializedVarOutParam(SerializedVar* serialized) 416 SerializedVarOutParam::SerializedVarOutParam(SerializedVar* serialized)
458 : serialized_(serialized), 417 : serialized_(serialized),
459 writable_var_(PP_MakeUndefined()), 418 writable_var_(PP_MakeUndefined()),
460 dispatcher_(NULL) { 419 dispatcher_(NULL) {
461 } 420 }
462 421
463 SerializedVarOutParam::~SerializedVarOutParam() { 422 SerializedVarOutParam::~SerializedVarOutParam() {
464 if (serialized_->inner_->serialization_rules()) { 423 if (serialized_->inner_->serialization_rules()) {
465 // When unset, OutParam wasn't called. We'll just leave the var untouched 424 // When unset, OutParam wasn't called. We'll just leave the var untouched
466 // in that case. 425 // in that case.
467 serialized_->inner_->SetVar( 426 serialized_->inner_->SetVar(
468 serialized_->inner_->serialization_rules()->BeginSendPassRef( 427 serialized_->inner_->serialization_rules()->BeginSendPassRef(
469 writable_var_, serialized_->inner_->GetStringPtrPtr())); 428 writable_var_));
470 429
471 // Normally the current object will be created on the stack to wrap a 430 // Normally the current object will be created on the stack to wrap a
472 // SerializedVar and won't have a scope around the actual IPC send. So we 431 // SerializedVar and won't have a scope around the actual IPC send. So we
473 // need to tell the SerializedVar to do the begin/end send pass ref calls. 432 // need to tell the SerializedVar to do the begin/end send pass ref calls.
474 serialized_->inner_->SetCleanupModeToEndSendPassRef(dispatcher_); 433 serialized_->inner_->SetCleanupModeToEndSendPassRef(dispatcher_);
475 } 434 }
476 } 435 }
477 436
478 PP_Var* SerializedVarOutParam::OutParam(Dispatcher* dispatcher) { 437 PP_Var* SerializedVarOutParam::OutParam(Dispatcher* dispatcher) {
479 dispatcher_ = dispatcher; 438 dispatcher_ = dispatcher;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 } 478 }
520 479
521 SerializedVarTestConstructor::SerializedVarTestConstructor( 480 SerializedVarTestConstructor::SerializedVarTestConstructor(
522 const PP_Var& pod_var) { 481 const PP_Var& pod_var) {
523 DCHECK(pod_var.type != PP_VARTYPE_STRING); 482 DCHECK(pod_var.type != PP_VARTYPE_STRING);
524 inner_->ForceSetVarValueForTest(pod_var); 483 inner_->ForceSetVarValueForTest(pod_var);
525 } 484 }
526 485
527 SerializedVarTestConstructor::SerializedVarTestConstructor( 486 SerializedVarTestConstructor::SerializedVarTestConstructor(
528 const std::string& str) { 487 const std::string& str) {
529 PP_Var string_var = {}; 488 inner_->ForceSetVarValueForTest(StringVar::StringToPPVar(str));
530 string_var.type = PP_VARTYPE_STRING;
531 string_var.value.as_id = 0;
532 inner_->ForceSetVarValueForTest(string_var);
533 inner_->ForceSetStringValueForTest(str);
534 } 489 }
535 490
536 SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var) 491 SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var)
537 : SerializedVar(var) { 492 : SerializedVar(var) {
538 } 493 }
539 494
540 } // namespace proxy 495 } // namespace proxy
541 } // namespace ppapi 496 } // namespace ppapi
542 497
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