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

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

Issue 6282007: First pass at making the proxy handle multiple renderers. This associates the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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/var_serialization_rules.h » ('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) 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"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 : inner_(new Inner(serialization_rules, var)) { 218 : inner_(new Inner(serialization_rules, var)) {
219 } 219 }
220 220
221 SerializedVar::~SerializedVar() { 221 SerializedVar::~SerializedVar() {
222 } 222 }
223 223
224 // SerializedVarSendInput ------------------------------------------------------ 224 // SerializedVarSendInput ------------------------------------------------------
225 225
226 SerializedVarSendInput::SerializedVarSendInput(Dispatcher* dispatcher, 226 SerializedVarSendInput::SerializedVarSendInput(Dispatcher* dispatcher,
227 const PP_Var& var) 227 const PP_Var& var)
228 : SerializedVar(dispatcher->serialization_rules(), var) { 228 : SerializedVar(dispatcher->serialization_rules()) {
229 dispatcher->serialization_rules()->SendCallerOwned(var, 229 inner_->SetVar(dispatcher->serialization_rules()->SendCallerOwned(
230 inner_->GetStringPtr()); 230 var, inner_->GetStringPtr()));
231 } 231 }
232 232
233 // static 233 // static
234 void SerializedVarSendInput::ConvertVector(Dispatcher* dispatcher, 234 void SerializedVarSendInput::ConvertVector(Dispatcher* dispatcher,
235 const PP_Var* input, 235 const PP_Var* input,
236 size_t input_count, 236 size_t input_count,
237 std::vector<SerializedVar>* output) { 237 std::vector<SerializedVar>* output) {
238 output->resize(input_count); 238 output->resize(input_count);
239 for (size_t i = 0; i < input_count; i++) { 239 for (size_t i = 0; i < input_count; i++) {
240 (*output)[i] = SerializedVar(dispatcher->serialization_rules(), input[i]); 240 SerializedVar& cur = (*output)[i];
241 dispatcher->serialization_rules()->SendCallerOwned( 241 cur = SerializedVar(dispatcher->serialization_rules());
242 input[i], (*output)[i].inner_->GetStringPtr()); 242 cur.inner_->SetVar(dispatcher->serialization_rules()->SendCallerOwned(
243 input[i], cur.inner_->GetStringPtr()));
243 } 244 }
244 } 245 }
245 246
246 // ReceiveSerializedVarReturnValue --------------------------------------------- 247 // ReceiveSerializedVarReturnValue ---------------------------------------------
247 248
248 ReceiveSerializedVarReturnValue::ReceiveSerializedVarReturnValue() { 249 ReceiveSerializedVarReturnValue::ReceiveSerializedVarReturnValue() {
249 } 250 }
250 251
251 PP_Var ReceiveSerializedVarReturnValue::Return(Dispatcher* dispatcher) { 252 PP_Var ReceiveSerializedVarReturnValue::Return(Dispatcher* dispatcher) {
252 inner_->set_serialization_rules(dispatcher->serialization_rules()); 253 inner_->set_serialization_rules(dispatcher->serialization_rules());
253 inner_->SetVar(inner_->serialization_rules()->ReceivePassRef( 254 inner_->SetVar(inner_->serialization_rules()->ReceivePassRef(
254 inner_->GetIncompleteVar(), inner_->GetString())); 255 inner_->GetIncompleteVar(), inner_->GetString(), dispatcher));
255 return inner_->GetVar(); 256 return inner_->GetVar();
256 } 257 }
257 258
258 // ReceiveSerializedException -------------------------------------------------- 259 // ReceiveSerializedException --------------------------------------------------
259 260
260 ReceiveSerializedException::ReceiveSerializedException(Dispatcher* dispatcher, 261 ReceiveSerializedException::ReceiveSerializedException(Dispatcher* dispatcher,
261 PP_Var* exception) 262 PP_Var* exception)
262 : SerializedVar(dispatcher->serialization_rules()), 263 : SerializedVar(dispatcher->serialization_rules()),
264 dispatcher_(dispatcher),
263 exception_(exception) { 265 exception_(exception) {
264 } 266 }
265 267
266 ReceiveSerializedException::~ReceiveSerializedException() { 268 ReceiveSerializedException::~ReceiveSerializedException() {
267 if (exception_) { 269 if (exception_) {
268 // 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
269 // reference. 271 // reference.
270 inner_->SetVar(inner_->serialization_rules()->ReceivePassRef( 272 inner_->SetVar(inner_->serialization_rules()->ReceivePassRef(
271 inner_->GetIncompleteVar(), inner_->GetString())); 273 inner_->GetIncompleteVar(), inner_->GetString(), dispatcher_));
272 *exception_ = inner_->GetVar(); 274 *exception_ = inner_->GetVar();
273 } else { 275 } else {
274 // When no output exception is specified, the browser thinks we have a ref 276 // When no output exception is specified, the browser thinks we have a ref
275 // to an object that we don't want (this will happen only in the plugin 277 // to an object that we don't want (this will happen only in the plugin
276 // since the browser will always specify an out exception for the plugin to 278 // since the browser will always specify an out exception for the plugin to
277 // write into). 279 // write into).
278 // 280 //
279 // Strings don't need this handling since we can just avoid creating a 281 // Strings don't need this handling since we can just avoid creating a
280 // Var from the std::string in the first place. 282 // Var from the std::string in the first place.
281 if (inner_->GetVar().type == PP_VARTYPE_OBJECT) 283 if (inner_->GetVar().type == PP_VARTYPE_OBJECT)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 serialized_.inner_->set_serialization_rules( 337 serialized_.inner_->set_serialization_rules(
336 dispatcher->serialization_rules()); 338 dispatcher->serialization_rules());
337 339
338 // Ensure that when the serialized var goes out of scope it cleans up the 340 // Ensure that when the serialized var goes out of scope it cleans up the
339 // stuff we're making in BeginReceiveCallerOwned. 341 // stuff we're making in BeginReceiveCallerOwned.
340 serialized_.inner_->set_cleanup_mode(SerializedVar::END_RECEIVE_CALLER_OWNED); 342 serialized_.inner_->set_cleanup_mode(SerializedVar::END_RECEIVE_CALLER_OWNED);
341 343
342 serialized_.inner_->SetVar( 344 serialized_.inner_->SetVar(
343 serialized_.inner_->serialization_rules()->BeginReceiveCallerOwned( 345 serialized_.inner_->serialization_rules()->BeginReceiveCallerOwned(
344 serialized_.inner_->GetIncompleteVar(), 346 serialized_.inner_->GetIncompleteVar(),
345 serialized_.inner_->GetStringPtr())); 347 serialized_.inner_->GetStringPtr(),
348 dispatcher));
346 return serialized_.inner_->GetVar(); 349 return serialized_.inner_->GetVar();
347 } 350 }
348 351
349 // SerializedVarVectorReceiveInput --------------------------------------------- 352 // SerializedVarVectorReceiveInput ---------------------------------------------
350 353
351 SerializedVarVectorReceiveInput::SerializedVarVectorReceiveInput( 354 SerializedVarVectorReceiveInput::SerializedVarVectorReceiveInput(
352 const std::vector<SerializedVar>& serialized) 355 const std::vector<SerializedVar>& serialized)
353 : serialized_(serialized) { 356 : serialized_(serialized) {
354 } 357 }
355 358
356 SerializedVarVectorReceiveInput::~SerializedVarVectorReceiveInput() { 359 SerializedVarVectorReceiveInput::~SerializedVarVectorReceiveInput() {
357 for (size_t i = 0; i < deserialized_.size(); i++) { 360 for (size_t i = 0; i < deserialized_.size(); i++) {
358 serialized_[i].inner_->serialization_rules()->EndReceiveCallerOwned( 361 serialized_[i].inner_->serialization_rules()->EndReceiveCallerOwned(
359 deserialized_[i]); 362 deserialized_[i]);
360 } 363 }
361 } 364 }
362 365
363 PP_Var* SerializedVarVectorReceiveInput::Get(Dispatcher* dispatcher, 366 PP_Var* SerializedVarVectorReceiveInput::Get(Dispatcher* dispatcher,
364 uint32_t* array_size) { 367 uint32_t* array_size) {
365 deserialized_.resize(serialized_.size()); 368 deserialized_.resize(serialized_.size());
366 for (size_t i = 0; i < serialized_.size(); i++) { 369 for (size_t i = 0; i < serialized_.size(); i++) {
367 // The vector must be able to clean themselves up after this call is 370 // The vector must be able to clean themselves up after this call is
368 // torn down. 371 // torn down.
369 serialized_[i].inner_->set_serialization_rules( 372 serialized_[i].inner_->set_serialization_rules(
370 dispatcher->serialization_rules()); 373 dispatcher->serialization_rules());
371 374
372 serialized_[i].inner_->SetVar( 375 serialized_[i].inner_->SetVar(
373 serialized_[i].inner_->serialization_rules()->BeginReceiveCallerOwned( 376 serialized_[i].inner_->serialization_rules()->BeginReceiveCallerOwned(
374 serialized_[i].inner_->GetIncompleteVar(), 377 serialized_[i].inner_->GetIncompleteVar(),
375 serialized_[i].inner_->GetStringPtr())); 378 serialized_[i].inner_->GetStringPtr(),
379 dispatcher));
376 deserialized_[i] = serialized_[i].inner_->GetVar(); 380 deserialized_[i] = serialized_[i].inner_->GetVar();
377 } 381 }
378 382
379 *array_size = static_cast<uint32_t>(serialized_.size()); 383 *array_size = static_cast<uint32_t>(serialized_.size());
380 return deserialized_.size() > 0 ? &deserialized_[0] : NULL; 384 return deserialized_.size() > 0 ? &deserialized_[0] : NULL;
381 } 385 }
382 386
383 // SerializedVarReturnValue ---------------------------------------------------- 387 // SerializedVarReturnValue ----------------------------------------------------
384 388
385 SerializedVarReturnValue::SerializedVarReturnValue(SerializedVar* serialized) 389 SerializedVarReturnValue::SerializedVarReturnValue(SerializedVar* serialized)
386 : serialized_(serialized) { 390 : serialized_(serialized) {
387 } 391 }
388 392
389 void SerializedVarReturnValue::Return(Dispatcher* dispatcher, 393 void SerializedVarReturnValue::Return(Dispatcher* dispatcher,
390 const PP_Var& var) { 394 const PP_Var& var) {
391 serialized_->inner_->set_serialization_rules( 395 serialized_->inner_->set_serialization_rules(
392 dispatcher->serialization_rules()); 396 dispatcher->serialization_rules());
393 serialized_->inner_->SetVar(var);
394 397
395 // Var must clean up after our BeginSendPassRef call. 398 // Var must clean up after our BeginSendPassRef call.
396 serialized_->inner_->set_cleanup_mode(SerializedVar::END_SEND_PASS_REF); 399 serialized_->inner_->set_cleanup_mode(SerializedVar::END_SEND_PASS_REF);
397 400
398 dispatcher->serialization_rules()->BeginSendPassRef( 401 serialized_->inner_->SetVar(
399 serialized_->inner_->GetIncompleteVar(), 402 dispatcher->serialization_rules()->BeginSendPassRef(
400 serialized_->inner_->GetStringPtr()); 403 var,
404 serialized_->inner_->GetStringPtr()));
401 } 405 }
402 406
403 // SerializedVarOutParam ------------------------------------------------------- 407 // SerializedVarOutParam -------------------------------------------------------
404 408
405 SerializedVarOutParam::SerializedVarOutParam(SerializedVar* serialized) 409 SerializedVarOutParam::SerializedVarOutParam(SerializedVar* serialized)
406 : serialized_(serialized), 410 : serialized_(serialized),
407 writable_var_(PP_MakeUndefined()) { 411 writable_var_(PP_MakeUndefined()) {
408 } 412 }
409 413
410 SerializedVarOutParam::~SerializedVarOutParam() { 414 SerializedVarOutParam::~SerializedVarOutParam() {
411 if (serialized_->inner_->serialization_rules()) { 415 if (serialized_->inner_->serialization_rules()) {
412 // When unset, OutParam wasn't called. We'll just leave the var untouched 416 // When unset, OutParam wasn't called. We'll just leave the var untouched
413 // in that case. 417 // in that case.
414 serialized_->inner_->SetVar(writable_var_); 418 serialized_->inner_->SetVar(
415 serialized_->inner_->serialization_rules()->BeginSendPassRef( 419 serialized_->inner_->serialization_rules()->BeginSendPassRef(
416 writable_var_, serialized_->inner_->GetStringPtr()); 420 writable_var_, serialized_->inner_->GetStringPtr()));
417 421
418 // Normally the current object will be created on the stack to wrap a 422 // Normally the current object will be created on the stack to wrap a
419 // SerializedVar and won't have a scope around the actual IPC send. So we 423 // SerializedVar and won't have a scope around the actual IPC send. So we
420 // need to tell the SerializedVar to do the begin/end send pass ref calls. 424 // need to tell the SerializedVar to do the begin/end send pass ref calls.
421 serialized_->inner_->set_cleanup_mode(SerializedVar::END_SEND_PASS_REF); 425 serialized_->inner_->set_cleanup_mode(SerializedVar::END_SEND_PASS_REF);
422 } 426 }
423 } 427 }
424 428
425 PP_Var* SerializedVarOutParam::OutParam(Dispatcher* dispatcher) { 429 PP_Var* SerializedVarOutParam::OutParam(Dispatcher* dispatcher) {
426 serialized_->inner_->set_serialization_rules( 430 serialized_->inner_->set_serialization_rules(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 464
461 PP_Var** SerializedVarVectorOutParam::ArrayOutParam(Dispatcher* dispatcher) { 465 PP_Var** SerializedVarVectorOutParam::ArrayOutParam(Dispatcher* dispatcher) {
462 DCHECK(!dispatcher_); // Should only be called once. 466 DCHECK(!dispatcher_); // Should only be called once.
463 dispatcher_ = dispatcher; 467 dispatcher_ = dispatcher;
464 return &array_; 468 return &array_;
465 } 469 }
466 470
467 } // namespace proxy 471 } // namespace proxy
468 } // namespace pp 472 } // namespace pp
469 473
OLDNEW
« no previous file with comments | « ppapi/proxy/serialized_var.h ('k') | ppapi/proxy/var_serialization_rules.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698