OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 pp { | 14 namespace pp { |
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 cleanup_mode_(CLEANUP_NONE) { | 22 cleanup_mode_(CLEANUP_NONE), |
| 23 dispatcher_for_end_send_pass_ref_(NULL) { |
23 #ifndef NDEBUG | 24 #ifndef NDEBUG |
24 has_been_serialized_ = false; | 25 has_been_serialized_ = false; |
25 has_been_deserialized_ = false; | 26 has_been_deserialized_ = false; |
26 #endif | 27 #endif |
27 } | 28 } |
28 | 29 |
29 SerializedVar::Inner::Inner(VarSerializationRules* serialization_rules) | 30 SerializedVar::Inner::Inner(VarSerializationRules* serialization_rules) |
30 : serialization_rules_(serialization_rules), | 31 : serialization_rules_(serialization_rules), |
31 var_(PP_MakeUndefined()), | 32 var_(PP_MakeUndefined()), |
32 cleanup_mode_(CLEANUP_NONE) { | 33 cleanup_mode_(CLEANUP_NONE), |
| 34 dispatcher_for_end_send_pass_ref_(NULL) { |
33 #ifndef NDEBUG | 35 #ifndef NDEBUG |
34 has_been_serialized_ = false; | 36 has_been_serialized_ = false; |
35 has_been_deserialized_ = false; | 37 has_been_deserialized_ = false; |
36 #endif | 38 #endif |
37 } | 39 } |
38 | 40 |
39 SerializedVar::Inner::Inner(VarSerializationRules* serialization_rules, | 41 SerializedVar::Inner::Inner(VarSerializationRules* serialization_rules, |
40 const PP_Var& var) | 42 const PP_Var& var) |
41 : serialization_rules_(serialization_rules), | 43 : serialization_rules_(serialization_rules), |
42 var_(var), | 44 var_(var), |
43 cleanup_mode_(CLEANUP_NONE) { | 45 cleanup_mode_(CLEANUP_NONE), |
| 46 dispatcher_for_end_send_pass_ref_(NULL) { |
44 #ifndef NDEBUG | 47 #ifndef NDEBUG |
45 has_been_serialized_ = false; | 48 has_been_serialized_ = false; |
46 has_been_deserialized_ = false; | 49 has_been_deserialized_ = false; |
47 #endif | 50 #endif |
48 } | 51 } |
49 | 52 |
50 SerializedVar::Inner::~Inner() { | 53 SerializedVar::Inner::~Inner() { |
51 switch (cleanup_mode_) { | 54 switch (cleanup_mode_) { |
52 case END_SEND_PASS_REF: | 55 case END_SEND_PASS_REF: |
53 serialization_rules_->EndSendPassRef(var_); | 56 DCHECK(dispatcher_for_end_send_pass_ref_); |
| 57 serialization_rules_->EndSendPassRef(var_, |
| 58 dispatcher_for_end_send_pass_ref_); |
54 break; | 59 break; |
55 case END_RECEIVE_CALLER_OWNED: | 60 case END_RECEIVE_CALLER_OWNED: |
56 serialization_rules_->EndReceiveCallerOwned(var_); | 61 serialization_rules_->EndReceiveCallerOwned(var_); |
57 break; | 62 break; |
58 default: | 63 default: |
59 break; | 64 break; |
60 } | 65 } |
61 } | 66 } |
62 | 67 |
63 PP_Var SerializedVar::Inner::GetVar() const { | 68 PP_Var SerializedVar::Inner::GetVar() const { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 202 } |
198 | 203 |
199 // All success cases get here. We avoid writing the type above so that the | 204 // All success cases get here. We avoid writing the type above so that the |
200 // output param is untouched (defaults to VARTYPE_UNDEFINED) even in the | 205 // output param is untouched (defaults to VARTYPE_UNDEFINED) even in the |
201 // failure case. | 206 // failure case. |
202 if (success) | 207 if (success) |
203 var_.type = static_cast<PP_VarType>(type); | 208 var_.type = static_cast<PP_VarType>(type); |
204 return success; | 209 return success; |
205 } | 210 } |
206 | 211 |
| 212 void SerializedVar::Inner::SetCleanupModeToEndSendPassRef( |
| 213 Dispatcher* dispatcher) { |
| 214 DCHECK(dispatcher); |
| 215 DCHECK(!dispatcher_for_end_send_pass_ref_); |
| 216 dispatcher_for_end_send_pass_ref_ = dispatcher; |
| 217 cleanup_mode_ = END_SEND_PASS_REF; |
| 218 } |
| 219 |
| 220 void SerializedVar::Inner::SetCleanupModeToEndReceiveCallerOwned() { |
| 221 cleanup_mode_ = END_RECEIVE_CALLER_OWNED; |
| 222 } |
| 223 |
207 // SerializedVar --------------------------------------------------------------- | 224 // SerializedVar --------------------------------------------------------------- |
208 | 225 |
209 SerializedVar::SerializedVar() : inner_(new Inner) { | 226 SerializedVar::SerializedVar() : inner_(new Inner) { |
210 } | 227 } |
211 | 228 |
212 SerializedVar::SerializedVar(VarSerializationRules* serialization_rules) | 229 SerializedVar::SerializedVar(VarSerializationRules* serialization_rules) |
213 : inner_(new Inner(serialization_rules)) { | 230 : inner_(new Inner(serialization_rules)) { |
214 } | 231 } |
215 | 232 |
216 SerializedVar::SerializedVar(VarSerializationRules* serialization_rules, | 233 SerializedVar::SerializedVar(VarSerializationRules* serialization_rules, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 | 349 |
333 SerializedVarReceiveInput::~SerializedVarReceiveInput() { | 350 SerializedVarReceiveInput::~SerializedVarReceiveInput() { |
334 } | 351 } |
335 | 352 |
336 PP_Var SerializedVarReceiveInput::Get(Dispatcher* dispatcher) { | 353 PP_Var SerializedVarReceiveInput::Get(Dispatcher* dispatcher) { |
337 serialized_.inner_->set_serialization_rules( | 354 serialized_.inner_->set_serialization_rules( |
338 dispatcher->serialization_rules()); | 355 dispatcher->serialization_rules()); |
339 | 356 |
340 // Ensure that when the serialized var goes out of scope it cleans up the | 357 // Ensure that when the serialized var goes out of scope it cleans up the |
341 // stuff we're making in BeginReceiveCallerOwned. | 358 // stuff we're making in BeginReceiveCallerOwned. |
342 serialized_.inner_->set_cleanup_mode(SerializedVar::END_RECEIVE_CALLER_OWNED); | 359 serialized_.inner_->SetCleanupModeToEndReceiveCallerOwned(); |
343 | 360 |
344 serialized_.inner_->SetVar( | 361 serialized_.inner_->SetVar( |
345 serialized_.inner_->serialization_rules()->BeginReceiveCallerOwned( | 362 serialized_.inner_->serialization_rules()->BeginReceiveCallerOwned( |
346 serialized_.inner_->GetIncompleteVar(), | 363 serialized_.inner_->GetIncompleteVar(), |
347 serialized_.inner_->GetStringPtr(), | 364 serialized_.inner_->GetStringPtr(), |
348 dispatcher)); | 365 dispatcher)); |
349 return serialized_.inner_->GetVar(); | 366 return serialized_.inner_->GetVar(); |
350 } | 367 } |
351 | 368 |
352 // SerializedVarVectorReceiveInput --------------------------------------------- | 369 // SerializedVarVectorReceiveInput --------------------------------------------- |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 SerializedVarReturnValue::SerializedVarReturnValue(SerializedVar* serialized) | 406 SerializedVarReturnValue::SerializedVarReturnValue(SerializedVar* serialized) |
390 : serialized_(serialized) { | 407 : serialized_(serialized) { |
391 } | 408 } |
392 | 409 |
393 void SerializedVarReturnValue::Return(Dispatcher* dispatcher, | 410 void SerializedVarReturnValue::Return(Dispatcher* dispatcher, |
394 const PP_Var& var) { | 411 const PP_Var& var) { |
395 serialized_->inner_->set_serialization_rules( | 412 serialized_->inner_->set_serialization_rules( |
396 dispatcher->serialization_rules()); | 413 dispatcher->serialization_rules()); |
397 | 414 |
398 // Var must clean up after our BeginSendPassRef call. | 415 // Var must clean up after our BeginSendPassRef call. |
399 serialized_->inner_->set_cleanup_mode(SerializedVar::END_SEND_PASS_REF); | 416 serialized_->inner_->SetCleanupModeToEndSendPassRef(dispatcher); |
400 | 417 |
401 serialized_->inner_->SetVar( | 418 serialized_->inner_->SetVar( |
402 dispatcher->serialization_rules()->BeginSendPassRef( | 419 dispatcher->serialization_rules()->BeginSendPassRef( |
403 var, | 420 var, |
404 serialized_->inner_->GetStringPtr())); | 421 serialized_->inner_->GetStringPtr())); |
405 } | 422 } |
406 | 423 |
407 // SerializedVarOutParam ------------------------------------------------------- | 424 // SerializedVarOutParam ------------------------------------------------------- |
408 | 425 |
409 SerializedVarOutParam::SerializedVarOutParam(SerializedVar* serialized) | 426 SerializedVarOutParam::SerializedVarOutParam(SerializedVar* serialized) |
410 : serialized_(serialized), | 427 : serialized_(serialized), |
411 writable_var_(PP_MakeUndefined()) { | 428 writable_var_(PP_MakeUndefined()), |
| 429 dispatcher_(NULL) { |
412 } | 430 } |
413 | 431 |
414 SerializedVarOutParam::~SerializedVarOutParam() { | 432 SerializedVarOutParam::~SerializedVarOutParam() { |
415 if (serialized_->inner_->serialization_rules()) { | 433 if (serialized_->inner_->serialization_rules()) { |
416 // When unset, OutParam wasn't called. We'll just leave the var untouched | 434 // When unset, OutParam wasn't called. We'll just leave the var untouched |
417 // in that case. | 435 // in that case. |
418 serialized_->inner_->SetVar( | 436 serialized_->inner_->SetVar( |
419 serialized_->inner_->serialization_rules()->BeginSendPassRef( | 437 serialized_->inner_->serialization_rules()->BeginSendPassRef( |
420 writable_var_, serialized_->inner_->GetStringPtr())); | 438 writable_var_, serialized_->inner_->GetStringPtr())); |
421 | 439 |
422 // Normally the current object will be created on the stack to wrap a | 440 // Normally the current object will be created on the stack to wrap a |
423 // SerializedVar and won't have a scope around the actual IPC send. So we | 441 // SerializedVar and won't have a scope around the actual IPC send. So we |
424 // need to tell the SerializedVar to do the begin/end send pass ref calls. | 442 // need to tell the SerializedVar to do the begin/end send pass ref calls. |
425 serialized_->inner_->set_cleanup_mode(SerializedVar::END_SEND_PASS_REF); | 443 serialized_->inner_->SetCleanupModeToEndSendPassRef(dispatcher_); |
426 } | 444 } |
427 } | 445 } |
428 | 446 |
429 PP_Var* SerializedVarOutParam::OutParam(Dispatcher* dispatcher) { | 447 PP_Var* SerializedVarOutParam::OutParam(Dispatcher* dispatcher) { |
| 448 dispatcher_ = dispatcher; |
430 serialized_->inner_->set_serialization_rules( | 449 serialized_->inner_->set_serialization_rules( |
431 dispatcher->serialization_rules()); | 450 dispatcher->serialization_rules()); |
432 return &writable_var_; | 451 return &writable_var_; |
433 } | 452 } |
434 | 453 |
435 // SerializedVarVectorOutParam ------------------------------------------------- | 454 // SerializedVarVectorOutParam ------------------------------------------------- |
436 | 455 |
437 SerializedVarVectorOutParam::SerializedVarVectorOutParam( | 456 SerializedVarVectorOutParam::SerializedVarVectorOutParam( |
438 std::vector<SerializedVar>* serialized) | 457 std::vector<SerializedVar>* serialized) |
439 : dispatcher_(NULL), | 458 : dispatcher_(NULL), |
(...skipping 21 matching lines...) Expand all Loading... |
461 // ownership of the array. | 480 // ownership of the array. |
462 free(array_); | 481 free(array_); |
463 } | 482 } |
464 | 483 |
465 PP_Var** SerializedVarVectorOutParam::ArrayOutParam(Dispatcher* dispatcher) { | 484 PP_Var** SerializedVarVectorOutParam::ArrayOutParam(Dispatcher* dispatcher) { |
466 DCHECK(!dispatcher_); // Should only be called once. | 485 DCHECK(!dispatcher_); // Should only be called once. |
467 dispatcher_ = dispatcher; | 486 dispatcher_ = dispatcher; |
468 return &array_; | 487 return &array_; |
469 } | 488 } |
470 | 489 |
| 490 SerializedVarTestConstructor::SerializedVarTestConstructor( |
| 491 const PP_Var& pod_var) { |
| 492 DCHECK(pod_var.type != PP_VARTYPE_STRING); |
| 493 inner_->SetVar(pod_var); |
| 494 } |
| 495 |
| 496 SerializedVarTestConstructor::SerializedVarTestConstructor( |
| 497 const std::string& str) { |
| 498 PP_Var string_var; |
| 499 string_var.type = PP_VARTYPE_STRING; |
| 500 string_var.value.as_id = 0; |
| 501 inner_->SetVar(string_var); |
| 502 *inner_->GetStringPtr() = str; |
| 503 } |
| 504 |
| 505 SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var) |
| 506 : SerializedVar(var) { |
| 507 } |
| 508 |
471 } // namespace proxy | 509 } // namespace proxy |
472 } // namespace pp | 510 } // namespace pp |
473 | 511 |
OLD | NEW |