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" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 PnaclCoordinator::~PnaclCoordinator() { | 244 PnaclCoordinator::~PnaclCoordinator() { |
245 PLUGIN_PRINTF(("PnaclCoordinator::~PnaclCoordinator (this=%p, " | 245 PLUGIN_PRINTF(("PnaclCoordinator::~PnaclCoordinator (this=%p, " |
246 "translate_thread=%p\n", | 246 "translate_thread=%p\n", |
247 static_cast<void*>(this), translate_thread_.get())); | 247 static_cast<void*>(this), translate_thread_.get())); |
248 // Stopping the translate thread will cause the translate thread to try to | 248 // Stopping the translate thread will cause the translate thread to try to |
249 // run translation_complete_callback_ on the main thread. This destructor is | 249 // run translation_complete_callback_ on the main thread. This destructor is |
250 // running from the main thread, and by the time it exits, callback_factory_ | 250 // running from the main thread, and by the time it exits, callback_factory_ |
251 // will have been destroyed. This will result in the cancellation of | 251 // will have been destroyed. This will result in the cancellation of |
252 // translation_complete_callback_, so no notification will be delivered. | 252 // translation_complete_callback_, so no notification will be delivered. |
253 if (translate_thread_.get() != NULL) { | 253 if (translate_thread_.get() != NULL) { |
254 translate_thread_->SetSubprocessesShouldDie(); | 254 translate_thread_->AbortSubprocesses(); |
255 } | 255 } |
256 } | 256 } |
257 | 257 |
258 void PnaclCoordinator::ReportNonPpapiError(const nacl::string& message) { | 258 void PnaclCoordinator::ReportNonPpapiError(const nacl::string& message) { |
259 error_info_.SetReport(ERROR_UNKNOWN, | 259 error_info_.SetReport(ERROR_UNKNOWN, |
260 nacl::string("PnaclCoordinator: ") + message); | 260 nacl::string("PnaclCoordinator: ") + message); |
261 ReportPpapiError(PP_ERROR_FAILED); | 261 ReportPpapiError(PP_ERROR_FAILED); |
262 } | 262 } |
263 | 263 |
264 void PnaclCoordinator::ReportPpapiError(int32_t pp_error, | 264 void PnaclCoordinator::ReportPpapiError(int32_t pp_error, |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 } | 437 } |
438 | 438 |
439 // Create the translation thread object immediately. This ensures that any | 439 // Create the translation thread object immediately. This ensures that any |
440 // pieces of the file that get downloaded before the compilation thread | 440 // pieces of the file that get downloaded before the compilation thread |
441 // is accepting SRPCs won't get dropped. | 441 // is accepting SRPCs won't get dropped. |
442 translate_thread_.reset(new PnaclTranslateThread()); | 442 translate_thread_.reset(new PnaclTranslateThread()); |
443 if (translate_thread_ == NULL) { | 443 if (translate_thread_ == NULL) { |
444 ReportNonPpapiError("could not allocate translation thread."); | 444 ReportNonPpapiError("could not allocate translation thread."); |
445 return; | 445 return; |
446 } | 446 } |
447 // In the streaming case we also want to open the object file now so the | 447 // We also want to open the object file now so the |
448 // translator can start writing to it during streaming translation. | 448 // translator can start writing to it during streaming translation. |
449 // In the non-streaming case this can wait until the bitcode download is | |
450 // finished. | |
451 obj_file_.reset(new TempFile(plugin_)); | 449 obj_file_.reset(new TempFile(plugin_)); |
452 pp::CompletionCallback obj_cb = | 450 pp::CompletionCallback obj_cb = |
453 callback_factory_.NewCallback(&PnaclCoordinator::ObjectFileDidOpen); | 451 callback_factory_.NewCallback(&PnaclCoordinator::ObjectFileDidOpen); |
454 obj_file_->Open(obj_cb); | 452 obj_file_->Open(obj_cb); |
455 | 453 |
456 streaming_downloader_.reset(new FileDownloader()); | 454 streaming_downloader_.reset(new FileDownloader()); |
457 streaming_downloader_->Initialize(plugin_); | 455 streaming_downloader_->Initialize(plugin_); |
458 pp::CompletionCallback cb = | 456 pp::CompletionCallback cb = |
459 callback_factory_.NewCallback( | 457 callback_factory_.NewCallback( |
460 &PnaclCoordinator::BitcodeStreamDidFinish); | 458 &PnaclCoordinator::BitcodeStreamDidFinish); |
461 | 459 |
462 // TODO(dschuff): need to use url_util_->ResolveRelativeToURL? | 460 // TODO(dschuff): need to use url_util_->ResolveRelativeToURL? |
463 if (!streaming_downloader_->OpenStream(pexe_url_, cb, this)) { | 461 if (!streaming_downloader_->OpenStream(pexe_url_, cb, this)) { |
464 ReportNonPpapiError(nacl::string("failed to open stream ") + pexe_url_); | 462 ReportNonPpapiError(nacl::string("failed to open stream ") + pexe_url_); |
465 } | 463 } |
466 } | 464 } |
467 | 465 |
468 void PnaclCoordinator::BitcodeStreamDidFinish(int32_t pp_error) { | 466 void PnaclCoordinator::BitcodeStreamDidFinish(int32_t pp_error) { |
469 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamDidFinish (pp_error=%" | 467 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamDidFinish (pp_error=%" |
470 NACL_PRId32")\n", pp_error)); | 468 NACL_PRId32")\n", pp_error)); |
471 if (pp_error != PP_OK) { | 469 if (pp_error != PP_OK) { |
472 // Defer reporting the error and obj_file/nexe_file cleanup until after | 470 // Defer reporting the error and obj_file/nexe_file cleanup until after |
473 // the translation thread returns, because it may be accessing the | 471 // the translation thread returns, because it may be accessing the |
474 // coordinator's objects or writing to the files. | 472 // coordinator's objects or writing to the files. |
475 translate_finish_error_ = pp_error; | 473 translate_finish_error_ = pp_error; |
476 error_info_.SetReport(ERROR_UNKNOWN, | 474 error_info_.SetReport(ERROR_UNKNOWN, |
477 nacl::string("PnaclCoordinator: pexe load failed.")); | 475 nacl::string("PnaclCoordinator: pexe load failed.")); |
478 translate_thread_->SetSubprocessesShouldDie(); | 476 translate_thread_->AbortSubprocesses(); |
479 } | 477 } |
480 } | 478 } |
481 | 479 |
482 void PnaclCoordinator::BitcodeStreamGotData(int32_t pp_error, | 480 void PnaclCoordinator::BitcodeStreamGotData(int32_t pp_error, |
483 FileStreamData data) { | 481 FileStreamData data) { |
484 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamGotData (pp_error=%" | 482 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamGotData (pp_error=%" |
485 NACL_PRId32", data=%p)\n", pp_error, data ? &(*data)[0] : 0)); | 483 NACL_PRId32", data=%p)\n", pp_error, data ? &(*data)[0] : 0)); |
486 DCHECK(translate_thread_.get()); | 484 DCHECK(translate_thread_.get()); |
487 translate_thread_->PutBytes(data, pp_error); | 485 translate_thread_->PutBytes(data, pp_error); |
488 } | 486 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 manifest_.get(), | 519 manifest_.get(), |
522 ld_manifest_.get(), | 520 ld_manifest_.get(), |
523 obj_file_.get(), | 521 obj_file_.get(), |
524 nexe_file_.get(), | 522 nexe_file_.get(), |
525 &error_info_, | 523 &error_info_, |
526 resources_.get(), | 524 resources_.get(), |
527 plugin_); | 525 plugin_); |
528 } | 526 } |
529 | 527 |
530 } // namespace plugin | 528 } // namespace plugin |
OLD | NEW |