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

Side by Side Diff: src/trusted/plugin/srpc/srpc.cc

Issue 1092005: Issue 1092005 (Closed) Base URL: http://nativeclient.googlecode.com/svn/trunk/src/native_client/
Patch Set: Created 10 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright 2008 The Native Client Authors. All rights reserved. 2 * Copyright 2008 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can 3 * Use of this source code is governed by a BSD-style license that can
4 * be found in the LICENSE file. 4 * be found in the LICENSE file.
5 */ 5 */
6 6
7 7
8 #include "native_client/src/trusted/plugin/srpc/srpc.h" 8 #include "native_client/src/trusted/plugin/srpc/srpc.h"
9 9
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 stream_buffer = reinterpret_cast<StreamBuffer*>(stream->pdata); 348 stream_buffer = reinterpret_cast<StreamBuffer*>(stream->pdata);
349 } 349 }
350 if (NULL == stream_buffer) { 350 if (NULL == stream_buffer) {
351 return 0; 351 return 0;
352 } 352 }
353 353
354 int32_t written = stream_buffer->write(offset, len, buf); 354 int32_t written = stream_buffer->write(offset, len, buf);
355 if (NULL == stream->notifyData) { 355 if (NULL == stream->notifyData) {
356 // Closures are handled in URLNotify (this is the only way to know 356 // Closures are handled in URLNotify (this is the only way to know
357 // the stream is completed since not all streams have a valid "end" value 357 // the stream is completed since not all streams have a valid "end" value
358 // Here we handle only the default, src=... streams (statically obtained) 358 // Here we handle only the default, nexe=... streams (statically obtained)
359 if (static_cast<int32_t>(stream->end) == offset + len) { 359 if (static_cast<int32_t>(stream->end) == offset + len) {
360 // Stream downloaded - go ahead 360 // Stream downloaded - go ahead
361 dprintf(("default run\n")); 361 dprintf(("default run\n"));
362 nacl_srpc::Plugin* real_plugin = 362 nacl_srpc::Plugin* real_plugin =
363 static_cast<nacl_srpc::Plugin*>(plugin()->get_handle()); 363 static_cast<nacl_srpc::Plugin*>(plugin()->get_handle());
364 real_plugin->Load(stream->url, 364 real_plugin->Load(stream->url,
365 stream->url, 365 stream->url,
366 stream_buffer->get_buffer(), 366 stream_buffer->get_buffer(),
367 stream_buffer->size()); 367 stream_buffer->size());
368 delete(stream_buffer); 368 delete(stream_buffer);
(...skipping 13 matching lines...) Expand all
382 void SRPC_Plugin::StreamAsFile(NPStream* stream, 382 void SRPC_Plugin::StreamAsFile(NPStream* stream,
383 const char* fname) { 383 const char* fname) {
384 dprintf(("SRPC_Plugin::StreamAsFile(%p, %p, %s)\n", 384 dprintf(("SRPC_Plugin::StreamAsFile(%p, %p, %s)\n",
385 static_cast<void*>(this), static_cast<void*>(stream), fname)); 385 static_cast<void*>(this), static_cast<void*>(stream), fname));
386 nacl_srpc::Closure* closure 386 nacl_srpc::Closure* closure
387 = static_cast<nacl_srpc::Closure*>(stream->notifyData); 387 = static_cast<nacl_srpc::Closure*>(stream->notifyData);
388 388
389 if (NULL != closure) { 389 if (NULL != closure) {
390 closure->Run(stream, fname); 390 closure->Run(stream, fname);
391 } else { 391 } else {
392 // default, src=... statically obtained 392 // default, nexe=... statically obtained
393 dprintf(("default run\n")); 393 dprintf(("default run\n"));
394 nacl_srpc::Plugin* real_plugin = 394 nacl_srpc::Plugin* real_plugin =
395 static_cast<nacl_srpc::Plugin*>(plugin_->get_handle()); 395 static_cast<nacl_srpc::Plugin*>(plugin_->get_handle());
396 real_plugin->Load(stream->url, fname); 396 real_plugin->Load(stream->url, fname);
397 } 397 }
398 } 398 }
399 399
400 NPError SRPC_Plugin::DestroyStream(NPStream* stream, 400 NPError SRPC_Plugin::DestroyStream(NPStream* stream,
401 NPReason reason) { 401 NPReason reason) {
402 dprintf(("SRPC_Plugin::DestroyStream(%p, %p, %d)\n", 402 dprintf(("SRPC_Plugin::DestroyStream(%p, %p, %d)\n",
403 static_cast<void*>(this), static_cast<void*>(stream), reason)); 403 static_cast<void*>(this), static_cast<void*>(stream), reason));
404 404
405 return NPERR_NO_ERROR; 405 return NPERR_NO_ERROR;
406 } 406 }
407 407
408 void SRPC_Plugin::URLNotify(const char* url, 408 void SRPC_Plugin::URLNotify(const char* url,
409 NPReason reason, 409 NPReason reason,
410 void* notifyData) { 410 void* notifyData) {
411 dprintf(("SRPC_Plugin::URLNotify(%p, %s, %d, %p)\n", 411 dprintf(("SRPC_Plugin::URLNotify(%p, %s, %d, %p)\n",
412 static_cast<void*>(this), url, reason, notifyData)); 412 static_cast<void*>(this), url, reason, notifyData));
413 413
414 // TODO(sehr): use autoptr to avoid delete. 414 // TODO(sehr): use autoptr to avoid delete.
415 nacl_srpc::Closure* closure 415 nacl_srpc::Closure* closure
416 = static_cast<nacl_srpc::Closure*>(notifyData); 416 = static_cast<nacl_srpc::Closure*>(notifyData);
417 417
418 // FIXME(adonovan): this looks fishy! closure is maybe-null in the
419 // false branch, but assumed non-null in the true branch... yet the
420 // branch condition is not under our control.
sehr (please use chromium) 2010/04/07 03:57:39 I fear this code has changed somewhat due Bennet's
421
418 if (NPRES_DONE == reason) { 422 if (NPRES_DONE == reason) {
419 dprintf(("URLNotify: '%s', rsn NPRES_DONE (%d)\n", url, reason)); 423 dprintf(("URLNotify: '%s', rsn NPRES_DONE (%d)\n", url, reason));
420 StreamBuffer* stream_buffer = closure->buffer(); 424 StreamBuffer* stream_buffer = closure->buffer();
421 if (stream_buffer) { 425 if (stream_buffer) {
422 // NPStream is not valid here since DestroyStream was called earlier 426 // NPStream is not valid here since DestroyStream was called earlier
423 closure->Run(url, 427 closure->Run(url,
424 stream_buffer->get_buffer(), 428 stream_buffer->get_buffer(),
425 stream_buffer->size()); 429 stream_buffer->size());
426 delete(stream_buffer); 430 delete(stream_buffer);
427 closure->set_buffer(NULL); 431 closure->set_buffer(NULL);
428 } 432 }
429 } else { 433 } else {
430 dprintf(("Unable to open: '%s' rsn %d\n", url, reason)); 434 dprintf(("Unable to open: '%s' rsn %d\n", url, reason));
431 if (NULL != closure) { 435 if (NULL != closure) {
432 closure->Run(NULL, NULL); 436 closure->Run(NULL, NULL);
433 } else { 437 } else {
438 // FIXME(adonovan): I don't understand how this can work.
439 // RunOnfailHandler's docstring says "to indicate unsuccessful
440 // loading of a module", but if we're loading a module, then
441 // |closure| is an instance of LoadNaClAppNotify, so it's
442 // non-NULL, and the other branch of the if-statement is taken.
bsy 2010/03/23 21:20:37 plz verify w/ sehr, but i think this distinction i
sehr (please use chromium) 2010/03/23 21:37:16 Bennet got this right. We use the same code to do
adonovan 2010/03/25 00:44:05 Regarding the onfail handler, I can't actually fin
sehr (please use chromium) 2010/04/07 03:57:39 I think this block is because of (3) above. But y
434 plugin()->get_handle()->GetPortablePluginInterface()->RunOnfailHandler( 443 plugin()->get_handle()->GetPortablePluginInterface()->RunOnfailHandler(
435 GetPluginIdentifier()); 444 GetPluginIdentifier());
436 } 445 }
437 } 446 }
438 delete closure; // NB: delete NULL is okay 447 delete closure; // NB: delete NULL is okay
439 } 448 }
440 449
441 } // namespace nacl 450 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698