| OLD | NEW |
| 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 Loading... |
| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 // is accepting SRPCs won't get dropped. | 442 // is accepting SRPCs won't get dropped. |
| 468 translate_thread_.reset(new PnaclStreamingTranslateThread()); | 443 translate_thread_.reset(new PnaclStreamingTranslateThread()); |
| 469 if (translate_thread_ == NULL) { | 444 if (translate_thread_ == NULL) { |
| 470 ReportNonPpapiError("could not allocate translation thread."); | 445 ReportNonPpapiError("could not allocate translation thread."); |
| 471 return; | 446 return; |
| 472 } | 447 } |
| 473 // In the streaming case we also want to open the object file now so the | 448 // 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. | 449 // translator can start writing to it during streaming translation. |
| 475 // In the non-streaming case this can wait until the bitcode download is | 450 // In the non-streaming case this can wait until the bitcode download is |
| 476 // finished. | 451 // finished. |
| 477 obj_file_.reset(new LocalTempFile(plugin_, file_system_.get(), | 452 obj_file_.reset(new TempFile(plugin_)); |
| 478 nacl::string(kPnaclTempDir))); | |
| 479 pp::CompletionCallback obj_cb = | 453 pp::CompletionCallback obj_cb = |
| 480 callback_factory_.NewCallback(&PnaclCoordinator::ObjectWriteDidOpen); | 454 callback_factory_.NewCallback(&PnaclCoordinator::ObjectFileDidOpen); |
| 481 obj_file_->OpenWrite(obj_cb); | 455 obj_file_->Open(obj_cb); |
| 482 | 456 |
| 483 streaming_downloader_.reset(new FileDownloader()); | 457 streaming_downloader_.reset(new FileDownloader()); |
| 484 streaming_downloader_->Initialize(plugin_); | 458 streaming_downloader_->Initialize(plugin_); |
| 485 pp::CompletionCallback cb = | 459 pp::CompletionCallback cb = |
| 486 callback_factory_.NewCallback( | 460 callback_factory_.NewCallback( |
| 487 &PnaclCoordinator::BitcodeStreamDidFinish); | 461 &PnaclCoordinator::BitcodeStreamDidFinish); |
| 488 | 462 |
| 489 // TODO(dschuff): need to use url_util_->ResolveRelativeToURL? | 463 // TODO(dschuff): need to use url_util_->ResolveRelativeToURL? |
| 490 if (!streaming_downloader_->OpenStream(pexe_url_, cb, this)) { | 464 if (!streaming_downloader_->OpenStream(pexe_url_, cb, this)) { |
| 491 ReportNonPpapiError(nacl::string("failed to open stream ") + pexe_url_); | 465 ReportNonPpapiError(nacl::string("failed to open stream ") + pexe_url_); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 514 static_cast<PnaclStreamingTranslateThread*>(translate_thread_.get()); | 488 static_cast<PnaclStreamingTranslateThread*>(translate_thread_.get()); |
| 515 DCHECK(thread); | 489 DCHECK(thread); |
| 516 thread->PutBytes(data, pp_error); | 490 thread->PutBytes(data, pp_error); |
| 517 } | 491 } |
| 518 | 492 |
| 519 StreamCallback PnaclCoordinator::GetCallback() { | 493 StreamCallback PnaclCoordinator::GetCallback() { |
| 520 return callback_factory_.NewCallbackWithOutput( | 494 return callback_factory_.NewCallbackWithOutput( |
| 521 &PnaclCoordinator::BitcodeStreamGotData); | 495 &PnaclCoordinator::BitcodeStreamGotData); |
| 522 } | 496 } |
| 523 | 497 |
| 524 void PnaclCoordinator::ObjectWriteDidOpen(int32_t pp_error) { | 498 void PnaclCoordinator::ObjectFileDidOpen(int32_t pp_error) { |
| 525 PLUGIN_PRINTF(("PnaclCoordinator::ObjectWriteDidOpen (pp_error=%" | 499 PLUGIN_PRINTF(("PnaclCoordinator::ObjectFileDidOpen (pp_error=%" |
| 526 NACL_PRId32")\n", pp_error)); | 500 NACL_PRId32")\n", pp_error)); |
| 527 if (pp_error != PP_OK) { | 501 if (pp_error != PP_OK) { |
| 528 ReportPpapiError(pp_error); | 502 ReportPpapiError(pp_error); |
| 529 return; | 503 return; |
| 530 } | 504 } |
| 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. | 505 // Create the nexe file for connecting ld and sel_ldr. |
| 544 // Start translation when done with this last step of setup! | 506 // Start translation when done with this last step of setup! |
| 545 nexe_file_.reset(new LocalTempFile(plugin_, file_system_.get(), | 507 nexe_file_.reset(new LocalTempFile(plugin_, file_system_.get(), |
| 546 nacl::string(kPnaclTempDir))); | 508 nacl::string(kPnaclTempDir))); |
| 547 pp::CompletionCallback cb = | 509 pp::CompletionCallback cb = |
| 548 callback_factory_.NewCallback(&PnaclCoordinator::RunTranslate); | 510 callback_factory_.NewCallback(&PnaclCoordinator::RunTranslate); |
| 549 nexe_file_->OpenWrite(cb); | 511 nexe_file_->OpenWrite(cb); |
| 550 } | 512 } |
| 551 | 513 |
| 552 void PnaclCoordinator::RunTranslate(int32_t pp_error) { | 514 void PnaclCoordinator::RunTranslate(int32_t pp_error) { |
| 553 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" | 515 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" |
| 554 NACL_PRId32")\n", pp_error)); | 516 NACL_PRId32")\n", pp_error)); |
| 555 // Invoke llc followed by ld off the main thread. This allows use of | 517 // Invoke llc followed by ld off the main thread. This allows use of |
| 556 // blocking RPCs that would otherwise block the JavaScript main thread. | 518 // blocking RPCs that would otherwise block the JavaScript main thread. |
| 557 pp::CompletionCallback report_translate_finished = | 519 pp::CompletionCallback report_translate_finished = |
| 558 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); | 520 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); |
| 559 | 521 |
| 560 CHECK(translate_thread_ != NULL); | 522 CHECK(translate_thread_ != NULL); |
| 561 translate_thread_->RunTranslate(report_translate_finished, | 523 translate_thread_->RunTranslate(report_translate_finished, |
| 562 manifest_.get(), | 524 manifest_.get(), |
| 563 ld_manifest_.get(), | 525 ld_manifest_.get(), |
| 564 obj_file_.get(), | 526 obj_file_.get(), |
| 565 nexe_file_.get(), | 527 nexe_file_.get(), |
| 566 &error_info_, | 528 &error_info_, |
| 567 resources_.get(), | 529 resources_.get(), |
| 568 plugin_); | 530 plugin_); |
| 569 } | 531 } |
| 570 | 532 |
| 571 } // namespace plugin | 533 } // namespace plugin |
| OLD | NEW |