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

Side by Side Diff: ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc

Issue 10815080: Add an interface for nacl to create delete-on-close temp files, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 // 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 "native_client/src/trusted/plugin/pnacl_coordinator.h" 5 #include "native_client/src/trusted/plugin/pnacl_coordinator.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "native_client/src/include/portability_io.h" 10 #include "native_client/src/include/portability_io.h"
11 #include "native_client/src/shared/platform/nacl_check.h" 11 #include "native_client/src/shared/platform/nacl_check.h"
12 #include "native_client/src/trusted/plugin/local_temp_file.h" 12 #include "native_client/src/trusted/plugin/local_temp_file.h"
13 #include "native_client/src/trusted/plugin/manifest.h" 13 #include "native_client/src/trusted/plugin/manifest.h"
14 #include "native_client/src/trusted/plugin/plugin.h" 14 #include "native_client/src/trusted/plugin/plugin.h"
15 #include "native_client/src/trusted/plugin/plugin_error.h" 15 #include "native_client/src/trusted/plugin/plugin_error.h"
16 #include "native_client/src/trusted/plugin/pnacl_streaming_translate_thread.h" 16 #include "native_client/src/trusted/plugin/pnacl_streaming_translate_thread.h"
17 #include "native_client/src/trusted/plugin/pnacl_translate_thread.h" 17 #include "native_client/src/trusted/plugin/pnacl_translate_thread.h"
18 #include "native_client/src/trusted/plugin/service_runtime.h" 18 #include "native_client/src/trusted/plugin/service_runtime.h"
19 #include "native_client/src/trusted/plugin/temporary_file.h"
19 #include "native_client/src/trusted/service_runtime/include/sys/stat.h" 20 #include "native_client/src/trusted/service_runtime/include/sys/stat.h"
20 21
21 #include "ppapi/c/pp_errors.h" 22 #include "ppapi/c/pp_errors.h"
22 #include "ppapi/c/ppb_file_io.h" 23 #include "ppapi/c/ppb_file_io.h"
23 #include "ppapi/cpp/file_io.h" 24 #include "ppapi/cpp/file_io.h"
24 25
25 namespace { 26 namespace {
26 const char kPnaclTempDir[] = "/.pnacl"; 27 const char kPnaclTempDir[] = "/.pnacl";
27 } 28 }
28 29
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 // Save the translate error code, and inspect after cleaning up junk files. 298 // Save the translate error code, and inspect after cleaning up junk files.
298 // Note: If there was a surfaway and the file objects were actually 299 // Note: If there was a surfaway and the file objects were actually
299 // destroyed, then we are in trouble since the obj_file_, nexe_file_, 300 // destroyed, then we are in trouble since the obj_file_, nexe_file_,
300 // etc. may have been destroyed. 301 // etc. may have been destroyed.
301 // TODO(jvoung,sehr): Fix. 302 // TODO(jvoung,sehr): Fix.
302 // If there was an error already set (e.g. pexe load failure) then we want 303 // If there was an error already set (e.g. pexe load failure) then we want
303 // to use the first one, (which might be something useful) rather than 304 // to use the first one, (which might be something useful) rather than
304 // the one from the compiler, (which is always just PP_ERROR_FAILED) 305 // the one from the compiler, (which is always just PP_ERROR_FAILED)
305 if (translate_finish_error_ == PP_OK) translate_finish_error_ = pp_error; 306 if (translate_finish_error_ == PP_OK) translate_finish_error_ = pp_error;
306 307
307 // Close the object temporary file (regardless of error code).
308 pp::CompletionCallback cb =
309 callback_factory_.NewCallback(&PnaclCoordinator::ObjectFileWasClosed);
310 obj_file_->Close(cb);
311 }
312
313 void PnaclCoordinator::ObjectFileWasClosed(int32_t pp_error) {
314 PLUGIN_PRINTF(("PnaclCoordinator::ObjectFileWasClosed (pp_error=%"
315 NACL_PRId32")\n", pp_error));
316 if (pp_error != PP_OK) {
317 ReportPpapiError(pp_error);
318 return;
319 }
320 // Delete the object temporary file.
321 pp::CompletionCallback cb =
322 callback_factory_.NewCallback(&PnaclCoordinator::ObjectFileWasDeleted);
323 obj_file_->Delete(cb);
324 }
325
326 void PnaclCoordinator::ObjectFileWasDeleted(int32_t pp_error) {
327 PLUGIN_PRINTF(("PnaclCoordinator::ObjectFileWasDeleted (pp_error=%"
328 NACL_PRId32")\n", pp_error));
329 if (pp_error != PP_OK) {
330 ReportPpapiError(pp_error);
331 return;
332 }
333 // Close the nexe temporary file. 308 // Close the nexe temporary file.
334 if (nexe_file_ != NULL) { 309 if (nexe_file_ != NULL) {
335 pp::CompletionCallback cb = 310 pp::CompletionCallback cb =
336 callback_factory_.NewCallback(&PnaclCoordinator::NexeFileWasClosed); 311 callback_factory_.NewCallback(&PnaclCoordinator::NexeFileWasClosed);
337 nexe_file_->Close(cb); 312 nexe_file_->Close(cb);
338 } 313 }
339 } 314 }
340 315
341 void PnaclCoordinator::NexeFileWasClosed(int32_t pp_error) { 316 void PnaclCoordinator::NexeFileWasClosed(int32_t pp_error) {
342 PLUGIN_PRINTF(("PnaclCoordinator::NexeFileWasClosed (pp_error=%" 317 PLUGIN_PRINTF(("PnaclCoordinator::NexeFileWasClosed (pp_error=%"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 } 429 }
455 } 430 }
456 431
457 void PnaclCoordinator::CachedFileDidOpen(int32_t pp_error) { 432 void PnaclCoordinator::CachedFileDidOpen(int32_t pp_error) {
458 PLUGIN_PRINTF(("PnaclCoordinator::CachedFileDidOpen (pp_error=%" 433 PLUGIN_PRINTF(("PnaclCoordinator::CachedFileDidOpen (pp_error=%"
459 NACL_PRId32")\n", pp_error)); 434 NACL_PRId32")\n", pp_error));
460 if (pp_error == PP_OK) { 435 if (pp_error == PP_OK) {
461 NexeReadDidOpen(PP_OK); 436 NexeReadDidOpen(PP_OK);
462 return; 437 return;
463 } 438 }
464
465 // Create the translation thread object immediately. This ensures that any 439 // Create the translation thread object immediately. This ensures that any
466 // pieces of the file that get downloaded before the compilation thread 440 // pieces of the file that get downloaded before the compilation thread
467 // is accepting SRPCs won't get dropped. 441 // is accepting SRPCs won't get dropped.
468 translate_thread_.reset(new PnaclStreamingTranslateThread()); 442 translate_thread_.reset(new PnaclStreamingTranslateThread());
469 if (translate_thread_ == NULL) { 443 if (translate_thread_ == NULL) {
470 ReportNonPpapiError("could not allocate translation thread."); 444 ReportNonPpapiError("could not allocate translation thread.");
471 return; 445 return;
472 } 446 }
473 // In the streaming case we also want to open the object file now so the 447 // In the streaming case we also want to open the object file now so the
474 // translator can start writing to it during streaming translation. 448 // translator can start writing to it during streaming translation.
475 // In the non-streaming case this can wait until the bitcode download is 449 // In the non-streaming case this can wait until the bitcode download is
476 // finished. 450 // finished.
477 obj_file_.reset(new LocalTempFile(plugin_, file_system_.get(), 451 obj_file_.reset(new TempFile(plugin_));
478 nacl::string(kPnaclTempDir)));
479 pp::CompletionCallback obj_cb = 452 pp::CompletionCallback obj_cb =
480 callback_factory_.NewCallback(&PnaclCoordinator::ObjectWriteDidOpen); 453 callback_factory_.NewCallback(&PnaclCoordinator::ObjectFileDidOpen);
481 obj_file_->OpenWrite(obj_cb); 454 obj_file_->Open(obj_cb);
482 455
483 streaming_downloader_.reset(new FileDownloader()); 456 streaming_downloader_.reset(new FileDownloader());
484 streaming_downloader_->Initialize(plugin_); 457 streaming_downloader_->Initialize(plugin_);
485 pp::CompletionCallback cb = 458 pp::CompletionCallback cb =
486 callback_factory_.NewCallback( 459 callback_factory_.NewCallback(
487 &PnaclCoordinator::BitcodeStreamDidFinish); 460 &PnaclCoordinator::BitcodeStreamDidFinish);
488 461
489 // TODO(dschuff): need to use url_util_->ResolveRelativeToURL? 462 // TODO(dschuff): need to use url_util_->ResolveRelativeToURL?
490 if (!streaming_downloader_->OpenStream(pexe_url_, cb, this)) { 463 if (!streaming_downloader_->OpenStream(pexe_url_, cb, this)) {
491 ReportNonPpapiError(nacl::string("failed to open stream ") + pexe_url_); 464 ReportNonPpapiError(nacl::string("failed to open stream ") + pexe_url_);
(...skipping 22 matching lines...) Expand all
514 static_cast<PnaclStreamingTranslateThread*>(translate_thread_.get()); 487 static_cast<PnaclStreamingTranslateThread*>(translate_thread_.get());
515 DCHECK(thread); 488 DCHECK(thread);
516 thread->PutBytes(data, pp_error); 489 thread->PutBytes(data, pp_error);
517 } 490 }
518 491
519 StreamCallback PnaclCoordinator::GetCallback() { 492 StreamCallback PnaclCoordinator::GetCallback() {
520 return callback_factory_.NewCallbackWithOutput( 493 return callback_factory_.NewCallbackWithOutput(
521 &PnaclCoordinator::BitcodeStreamGotData); 494 &PnaclCoordinator::BitcodeStreamGotData);
522 } 495 }
523 496
524 void PnaclCoordinator::ObjectWriteDidOpen(int32_t pp_error) { 497 void PnaclCoordinator::ObjectFileDidOpen(int32_t pp_error) {
525 PLUGIN_PRINTF(("PnaclCoordinator::ObjectWriteDidOpen (pp_error=%" 498 PLUGIN_PRINTF(("PnaclCoordinator::ObjectFileDidOpen (pp_error=%"
526 NACL_PRId32")\n", pp_error)); 499 NACL_PRId32")\n", pp_error));
527 if (pp_error != PP_OK) { 500 if (pp_error != PP_OK) {
528 ReportPpapiError(pp_error); 501 ReportPpapiError(pp_error);
529 return; 502 return;
530 } 503 }
531 pp::CompletionCallback cb =
532 callback_factory_.NewCallback(&PnaclCoordinator::ObjectReadDidOpen);
533 obj_file_->OpenRead(cb);
534 }
535
536 void PnaclCoordinator::ObjectReadDidOpen(int32_t pp_error) {
537 PLUGIN_PRINTF(("PnaclCoordinator::ObjectReadDidOpen (pp_error=%"
538 NACL_PRId32")\n", pp_error));
539 if (pp_error != PP_OK) {
540 ReportPpapiError(pp_error);
541 return;
542 }
543 // Create the nexe file for connecting ld and sel_ldr. 504 // Create the nexe file for connecting ld and sel_ldr.
544 // Start translation when done with this last step of setup! 505 // Start translation when done with this last step of setup!
545 nexe_file_.reset(new LocalTempFile(plugin_, file_system_.get(), 506 nexe_file_.reset(new LocalTempFile(plugin_, file_system_.get(),
546 nacl::string(kPnaclTempDir))); 507 nacl::string(kPnaclTempDir)));
547 pp::CompletionCallback cb = 508 pp::CompletionCallback cb =
548 callback_factory_.NewCallback(&PnaclCoordinator::RunTranslate); 509 callback_factory_.NewCallback(&PnaclCoordinator::RunTranslate);
549 nexe_file_->OpenWrite(cb); 510 nexe_file_->OpenWrite(cb);
550 } 511 }
551 512
552 void PnaclCoordinator::RunTranslate(int32_t pp_error) { 513 void PnaclCoordinator::RunTranslate(int32_t pp_error) {
553 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" 514 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%"
554 NACL_PRId32")\n", pp_error)); 515 NACL_PRId32")\n", pp_error));
555 // Invoke llc followed by ld off the main thread. This allows use of 516 // Invoke llc followed by ld off the main thread. This allows use of
556 // blocking RPCs that would otherwise block the JavaScript main thread. 517 // blocking RPCs that would otherwise block the JavaScript main thread.
557 pp::CompletionCallback report_translate_finished = 518 pp::CompletionCallback report_translate_finished =
558 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); 519 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished);
559 520
560 CHECK(translate_thread_ != NULL); 521 CHECK(translate_thread_ != NULL);
561 translate_thread_->RunTranslate(report_translate_finished, 522 translate_thread_->RunTranslate(report_translate_finished,
562 manifest_.get(), 523 manifest_.get(),
563 ld_manifest_.get(), 524 ld_manifest_.get(),
564 obj_file_.get(), 525 obj_file_.get(),
565 nexe_file_.get(), 526 nexe_file_.get(),
566 &error_info_, 527 &error_info_,
567 resources_.get(), 528 resources_.get(),
568 plugin_); 529 plugin_);
569 } 530 }
570 531
571 } // namespace plugin 532 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698