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

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

Issue 20182002: Make inttypes.h and similar macro usage C++11-friendly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: line Created 7 years, 4 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 "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" 5 #include "ppapi/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/checked_cast.h" 10 #include "native_client/src/include/checked_cast.h"
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 translate_notify_callback_.Run(PP_ERROR_FAILED); 334 translate_notify_callback_.Run(PP_ERROR_FAILED);
335 } else { 335 } else {
336 PLUGIN_PRINTF(("PnaclCoordinator::ExitWithError an earlier error was " 336 PLUGIN_PRINTF(("PnaclCoordinator::ExitWithError an earlier error was "
337 "already reported -- Skipping.\n")); 337 "already reported -- Skipping.\n"));
338 } 338 }
339 } 339 }
340 340
341 // Signal that Pnacl translation completed normally. 341 // Signal that Pnacl translation completed normally.
342 void PnaclCoordinator::TranslateFinished(int32_t pp_error) { 342 void PnaclCoordinator::TranslateFinished(int32_t pp_error) {
343 PLUGIN_PRINTF(("PnaclCoordinator::TranslateFinished (pp_error=%" 343 PLUGIN_PRINTF(("PnaclCoordinator::TranslateFinished (pp_error=%"
344 NACL_PRId32")\n", pp_error)); 344 NACL_PRId32 ")\n", pp_error));
345 // Bail out if there was an earlier error (e.g., pexe load failure). 345 // Bail out if there was an earlier error (e.g., pexe load failure).
346 if (translate_finish_error_ != PP_OK) { 346 if (translate_finish_error_ != PP_OK) {
347 ExitWithError(); 347 ExitWithError();
348 return; 348 return;
349 } 349 }
350 // Bail out if there is an error from the translation thread. 350 // Bail out if there is an error from the translation thread.
351 if (pp_error != PP_OK) { 351 if (pp_error != PP_OK) {
352 ExitWithError(); 352 ExitWithError();
353 return; 353 return;
354 } 354 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 char buf[kCopyBufSize]; 468 char buf[kCopyBufSize];
469 int32_t num_read = 469 int32_t num_read =
470 nacl::assert_cast<int32_t>(read_wrapper->Read(buf, sizeof buf)); 470 nacl::assert_cast<int32_t>(read_wrapper->Read(buf, sizeof buf));
471 // Hit EOF or something. 471 // Hit EOF or something.
472 if (num_read == 0) { 472 if (num_read == 0) {
473 NexeWasCopiedToCache(PP_OK); 473 NexeWasCopiedToCache(PP_OK);
474 return; 474 return;
475 } 475 }
476 if (num_read < 0) { 476 if (num_read < 0) {
477 PLUGIN_PRINTF(("PnaclCoordinator::CachedNexeOpenedForWrite read failed " 477 PLUGIN_PRINTF(("PnaclCoordinator::CachedNexeOpenedForWrite read failed "
478 "(error=%"NACL_PRId32")\n", num_read)); 478 "(error=%" NACL_PRId32 ")\n", num_read));
479 NexeWasCopiedToCache(PP_ERROR_FAILED); 479 NexeWasCopiedToCache(PP_ERROR_FAILED);
480 return; 480 return;
481 } 481 }
482 pp::CompletionCallback cb = callback_factory_.NewCallback( 482 pp::CompletionCallback cb = callback_factory_.NewCallback(
483 &PnaclCoordinator::DidCopyNexeToCachePartial, num_read, cur_offset); 483 &PnaclCoordinator::DidCopyNexeToCachePartial, num_read, cur_offset);
484 cached_nexe_file_->write_file_io()->Write(cur_offset, buf, num_read, cb); 484 cached_nexe_file_->write_file_io()->Write(cur_offset, buf, num_read, cb);
485 } 485 }
486 486
487 void PnaclCoordinator::DidCopyNexeToCachePartial(int32_t pp_error, 487 void PnaclCoordinator::DidCopyNexeToCachePartial(int32_t pp_error,
488 int32_t num_read_prev, 488 int32_t num_read_prev,
489 int64_t cur_offset) { 489 int64_t cur_offset) {
490 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial " 490 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial "
491 "(pp_error=%"NACL_PRId32", num_read_prev=%"NACL_PRId32"" 491 "(pp_error=%" NACL_PRId32 ", num_read_prev=%" NACL_PRId32
492 ", cur_offset=%"NACL_PRId64").\n", 492 ", cur_offset=%" NACL_PRId64 ").\n",
493 pp_error, num_read_prev, cur_offset)); 493 pp_error, num_read_prev, cur_offset));
494 // Assume we are done. 494 // Assume we are done.
495 if (pp_error == PP_OK) { 495 if (pp_error == PP_OK) {
496 NexeWasCopiedToCache(PP_OK); 496 NexeWasCopiedToCache(PP_OK);
497 return; 497 return;
498 } 498 }
499 if (pp_error < PP_OK) { 499 if (pp_error < PP_OK) {
500 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial failed (err=%" 500 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial failed (err=%"
501 NACL_PRId32")\n", pp_error)); 501 NACL_PRId32 ")\n", pp_error));
502 NexeWasCopiedToCache(pp_error); 502 NexeWasCopiedToCache(pp_error);
503 return; 503 return;
504 } 504 }
505 505
506 // Check if we wrote as much as we read. 506 // Check if we wrote as much as we read.
507 nacl::DescWrapper* read_wrapper = temp_nexe_file_->read_wrapper(); 507 nacl::DescWrapper* read_wrapper = temp_nexe_file_->read_wrapper();
508 if (pp_error != num_read_prev) { 508 if (pp_error != num_read_prev) {
509 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial partial " 509 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial partial "
510 "write (bytes_written=%"NACL_PRId32" vs " 510 "write (bytes_written=%" NACL_PRId32 " vs "
511 "read=%"NACL_PRId32")\n", pp_error, num_read_prev)); 511 "read=%" NACL_PRId32 ")\n", pp_error, num_read_prev));
512 CHECK(pp_error < num_read_prev); 512 CHECK(pp_error < num_read_prev);
513 // Seek back to re-read the bytes that were not written. 513 // Seek back to re-read the bytes that were not written.
514 nacl_off64_t seek_result = 514 nacl_off64_t seek_result =
515 read_wrapper->Seek(pp_error - num_read_prev, SEEK_CUR); 515 read_wrapper->Seek(pp_error - num_read_prev, SEEK_CUR);
516 if (seek_result < 0) { 516 if (seek_result < 0) {
517 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial seek failed " 517 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial seek failed "
518 "(err=%"NACL_PRId64")\n", seek_result)); 518 "(err=%" NACL_PRId64 ")\n", seek_result));
519 NexeWasCopiedToCache(PP_ERROR_FAILED); 519 NexeWasCopiedToCache(PP_ERROR_FAILED);
520 return; 520 return;
521 } 521 }
522 } 522 }
523 523
524 int64_t next_offset = cur_offset + pp_error; 524 int64_t next_offset = cur_offset + pp_error;
525 char buf[kCopyBufSize]; 525 char buf[kCopyBufSize];
526 int32_t num_read = 526 int32_t num_read =
527 nacl::assert_cast<int32_t>(read_wrapper->Read(buf, sizeof buf)); 527 nacl::assert_cast<int32_t>(read_wrapper->Read(buf, sizeof buf));
528 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial read (bytes=%" 528 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial read (bytes=%"
529 NACL_PRId32")\n", num_read)); 529 NACL_PRId32 ")\n", num_read));
530 // Hit EOF or something. 530 // Hit EOF or something.
531 if (num_read == 0) { 531 if (num_read == 0) {
532 NexeWasCopiedToCache(PP_OK); 532 NexeWasCopiedToCache(PP_OK);
533 return; 533 return;
534 } 534 }
535 if (num_read < 0) { 535 if (num_read < 0) {
536 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial read failed " 536 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial read failed "
537 "(error=%"NACL_PRId32")\n", num_read)); 537 "(error=%" NACL_PRId32 ")\n", num_read));
538 NexeWasCopiedToCache(PP_ERROR_FAILED); 538 NexeWasCopiedToCache(PP_ERROR_FAILED);
539 return; 539 return;
540 } 540 }
541 pp::CompletionCallback cb = callback_factory_.NewCallback( 541 pp::CompletionCallback cb = callback_factory_.NewCallback(
542 &PnaclCoordinator::DidCopyNexeToCachePartial, num_read, next_offset); 542 &PnaclCoordinator::DidCopyNexeToCachePartial, num_read, next_offset);
543 PLUGIN_PRINTF(("PnaclCoordinator::CopyNexeToCache Writing (" 543 PLUGIN_PRINTF(("PnaclCoordinator::CopyNexeToCache Writing ("
544 "bytes=%"NACL_PRId32", buf=%p, file_io=%p)\n", num_read, buf, 544 "bytes=%" NACL_PRId32 ", buf=%p, file_io=%p)\n", num_read, buf,
545 cached_nexe_file_->write_file_io())); 545 cached_nexe_file_->write_file_io()));
546 cached_nexe_file_->write_file_io()->Write(next_offset, buf, num_read, cb); 546 cached_nexe_file_->write_file_io()->Write(next_offset, buf, num_read, cb);
547 } 547 }
548 548
549 void PnaclCoordinator::NexeWasCopiedToCache(int32_t pp_error) { 549 void PnaclCoordinator::NexeWasCopiedToCache(int32_t pp_error) {
550 if (pp_error != PP_OK) { 550 if (pp_error != PP_OK) {
551 // Try to delete the partially written not-yet-committed cache file before 551 // Try to delete the partially written not-yet-committed cache file before
552 // returning. We pass the current pp_error along so that it can be reported 552 // returning. We pass the current pp_error along so that it can be reported
553 // before returning. 553 // before returning.
554 pp::CompletionCallback cb = callback_factory_.NewCallback( 554 pp::CompletionCallback cb = callback_factory_.NewCallback(
555 &PnaclCoordinator::CorruptCacheFileWasDeleted, pp_error); 555 &PnaclCoordinator::CorruptCacheFileWasDeleted, pp_error);
556 cached_nexe_file_->Delete(cb); 556 cached_nexe_file_->Delete(cb);
557 return; 557 return;
558 } 558 }
559 // Rename the cached_nexe_file_ file to the cache id, to finalize. 559 // Rename the cached_nexe_file_ file to the cache id, to finalize.
560 pp::CompletionCallback cb = 560 pp::CompletionCallback cb =
561 callback_factory_.NewCallback(&PnaclCoordinator::NexeFileWasRenamed); 561 callback_factory_.NewCallback(&PnaclCoordinator::NexeFileWasRenamed);
562 cached_nexe_file_->Rename(pnacl_options_.GetCacheKey(), cb); 562 cached_nexe_file_->Rename(pnacl_options_.GetCacheKey(), cb);
563 } 563 }
564 564
565 void PnaclCoordinator::CorruptCacheFileWasDeleted(int32_t delete_pp_error, 565 void PnaclCoordinator::CorruptCacheFileWasDeleted(int32_t delete_pp_error,
566 int32_t orig_pp_error) { 566 int32_t orig_pp_error) {
567 if (delete_pp_error != PP_OK) { 567 if (delete_pp_error != PP_OK) {
568 // The cache file was certainly already opened by the time we tried 568 // The cache file was certainly already opened by the time we tried
569 // to write to it, so it should certainly be deletable. 569 // to write to it, so it should certainly be deletable.
570 PLUGIN_PRINTF(("PnaclCoordinator::CorruptCacheFileWasDeleted " 570 PLUGIN_PRINTF(("PnaclCoordinator::CorruptCacheFileWasDeleted "
571 "delete failed with pp_error=%"NACL_PRId32"\n", 571 "delete failed with pp_error=%" NACL_PRId32 "\n",
572 delete_pp_error)); 572 delete_pp_error));
573 // fall through and report the original error. 573 // fall through and report the original error.
574 } 574 }
575 // Report the original error that caused us to consider the 575 // Report the original error that caused us to consider the
576 // cache file corrupted. 576 // cache file corrupted.
577 if (orig_pp_error == PP_ERROR_NOQUOTA) { 577 if (orig_pp_error == PP_ERROR_NOQUOTA) {
578 ReportPpapiError(ERROR_PNACL_CACHE_FINALIZE_COPY_NOQUOTA, 578 ReportPpapiError(ERROR_PNACL_CACHE_FINALIZE_COPY_NOQUOTA,
579 orig_pp_error, 579 orig_pp_error,
580 "Failed to copy translated nexe to cache (no quota)."); 580 "Failed to copy translated nexe to cache (no quota).");
581 return; 581 return;
582 } 582 }
583 if (orig_pp_error == PP_ERROR_NOSPACE) { 583 if (orig_pp_error == PP_ERROR_NOSPACE) {
584 ReportPpapiError(ERROR_PNACL_CACHE_FINALIZE_COPY_NOSPACE, 584 ReportPpapiError(ERROR_PNACL_CACHE_FINALIZE_COPY_NOSPACE,
585 orig_pp_error, 585 orig_pp_error,
586 "Failed to copy translated nexe to cache (no space)."); 586 "Failed to copy translated nexe to cache (no space).");
587 return; 587 return;
588 } 588 }
589 ReportPpapiError(ERROR_PNACL_CACHE_FINALIZE_COPY_OTHER, 589 ReportPpapiError(ERROR_PNACL_CACHE_FINALIZE_COPY_OTHER,
590 orig_pp_error, 590 orig_pp_error,
591 "Failed to copy translated nexe to cache."); 591 "Failed to copy translated nexe to cache.");
592 return; 592 return;
593 } 593 }
594 594
595 void PnaclCoordinator::NexeFileWasRenamed(int32_t pp_error) { 595 void PnaclCoordinator::NexeFileWasRenamed(int32_t pp_error) {
596 PLUGIN_PRINTF(("PnaclCoordinator::NexeFileWasRenamed (pp_error=%" 596 PLUGIN_PRINTF(("PnaclCoordinator::NexeFileWasRenamed (pp_error=%"
597 NACL_PRId32")\n", pp_error)); 597 NACL_PRId32 ")\n", pp_error));
598 if (pp_error != PP_OK) { 598 if (pp_error != PP_OK) {
599 if (pp_error == PP_ERROR_NOACCESS) { 599 if (pp_error == PP_ERROR_NOACCESS) {
600 ReportPpapiError(ERROR_PNACL_CACHE_FINALIZE_RENAME_NOACCESS, 600 ReportPpapiError(ERROR_PNACL_CACHE_FINALIZE_RENAME_NOACCESS,
601 pp_error, 601 pp_error,
602 "Failed to finalize cached translation (no access)."); 602 "Failed to finalize cached translation (no access).");
603 return; 603 return;
604 } else if (pp_error != PP_ERROR_FILEEXISTS) { 604 } else if (pp_error != PP_ERROR_FILEEXISTS) {
605 ReportPpapiError(ERROR_PNACL_CACHE_FINALIZE_RENAME_OTHER, 605 ReportPpapiError(ERROR_PNACL_CACHE_FINALIZE_RENAME_OTHER,
606 pp_error, 606 pp_error,
607 "Failed to finalize cached translation."); 607 "Failed to finalize cached translation.");
(...skipping 20 matching lines...) Expand all
628 total_time / 1000000.0); 628 total_time / 1000000.0);
629 629
630 // Open the cache file for reading. 630 // Open the cache file for reading.
631 pp::CompletionCallback cb = 631 pp::CompletionCallback cb =
632 callback_factory_.NewCallback(&PnaclCoordinator::NexeReadDidOpen); 632 callback_factory_.NewCallback(&PnaclCoordinator::NexeReadDidOpen);
633 cached_nexe_file_->OpenRead(cb); 633 cached_nexe_file_->OpenRead(cb);
634 } 634 }
635 635
636 void PnaclCoordinator::NexeReadDidOpen(int32_t pp_error) { 636 void PnaclCoordinator::NexeReadDidOpen(int32_t pp_error) {
637 PLUGIN_PRINTF(("PnaclCoordinator::NexeReadDidOpen (pp_error=%" 637 PLUGIN_PRINTF(("PnaclCoordinator::NexeReadDidOpen (pp_error=%"
638 NACL_PRId32")\n", pp_error)); 638 NACL_PRId32 ")\n", pp_error));
639 if (pp_error != PP_OK) { 639 if (pp_error != PP_OK) {
640 if (pp_error == PP_ERROR_FILENOTFOUND) { 640 if (pp_error == PP_ERROR_FILENOTFOUND) {
641 ReportPpapiError(ERROR_PNACL_CACHE_FETCH_NOTFOUND, 641 ReportPpapiError(ERROR_PNACL_CACHE_FETCH_NOTFOUND,
642 pp_error, 642 pp_error,
643 "Failed to open translated nexe (not found)."); 643 "Failed to open translated nexe (not found).");
644 return; 644 return;
645 } 645 }
646 if (pp_error == PP_ERROR_NOACCESS) { 646 if (pp_error == PP_ERROR_NOACCESS) {
647 ReportPpapiError(ERROR_PNACL_CACHE_FETCH_NOACCESS, 647 ReportPpapiError(ERROR_PNACL_CACHE_FETCH_NOACCESS,
648 pp_error, 648 pp_error,
(...skipping 10 matching lines...) Expand all
659 if (cached_nexe_file_ != NULL) { 659 if (cached_nexe_file_ != NULL) {
660 translated_fd_.reset(cached_nexe_file_->release_read_wrapper()); 660 translated_fd_.reset(cached_nexe_file_->release_read_wrapper());
661 } else { 661 } else {
662 translated_fd_.reset(temp_nexe_file_->release_read_wrapper()); 662 translated_fd_.reset(temp_nexe_file_->release_read_wrapper());
663 } 663 }
664 translate_notify_callback_.Run(pp_error); 664 translate_notify_callback_.Run(pp_error);
665 } 665 }
666 666
667 void PnaclCoordinator::ResourceInfoWasRead(int32_t pp_error) { 667 void PnaclCoordinator::ResourceInfoWasRead(int32_t pp_error) {
668 PLUGIN_PRINTF(("PluginCoordinator::ResourceInfoWasRead (pp_error=%" 668 PLUGIN_PRINTF(("PluginCoordinator::ResourceInfoWasRead (pp_error=%"
669 NACL_PRId32")\n", pp_error)); 669 NACL_PRId32 ")\n", pp_error));
670 // Second step of loading resources: call StartLoad. 670 // Second step of loading resources: call StartLoad.
671 pp::CompletionCallback resources_cb = 671 pp::CompletionCallback resources_cb =
672 callback_factory_.NewCallback(&PnaclCoordinator::ResourcesDidLoad); 672 callback_factory_.NewCallback(&PnaclCoordinator::ResourcesDidLoad);
673 resources_->StartLoad(resources_cb); 673 resources_->StartLoad(resources_cb);
674 } 674 }
675 675
676 void PnaclCoordinator::ResourcesDidLoad(int32_t pp_error) { 676 void PnaclCoordinator::ResourcesDidLoad(int32_t pp_error) {
677 PLUGIN_PRINTF(("PnaclCoordinator::ResourcesDidLoad (pp_error=%" 677 PLUGIN_PRINTF(("PnaclCoordinator::ResourcesDidLoad (pp_error=%"
678 NACL_PRId32")\n", pp_error)); 678 NACL_PRId32 ")\n", pp_error));
679 if (pp_error != PP_OK) { 679 if (pp_error != PP_OK) {
680 // Finer-grained error code should have already been reported by 680 // Finer-grained error code should have already been reported by
681 // the PnaclResources class. 681 // the PnaclResources class.
682 return; 682 return;
683 } 683 }
684 684
685 if (!off_the_record_) { 685 if (!off_the_record_) {
686 if (use_new_cache_) { 686 if (use_new_cache_) {
687 OpenBitcodeStream(); 687 OpenBitcodeStream();
688 } else { 688 } else {
(...skipping 21 matching lines...) Expand all
710 } 710 }
711 } 711 }
712 } else { 712 } else {
713 // We don't have a cache, so do the non-cached codepath. 713 // We don't have a cache, so do the non-cached codepath.
714 OpenBitcodeStream(); 714 OpenBitcodeStream();
715 } 715 }
716 } 716 }
717 717
718 void PnaclCoordinator::FileSystemDidOpen(int32_t pp_error) { 718 void PnaclCoordinator::FileSystemDidOpen(int32_t pp_error) {
719 PLUGIN_PRINTF(("PnaclCoordinator::FileSystemDidOpen (pp_error=%" 719 PLUGIN_PRINTF(("PnaclCoordinator::FileSystemDidOpen (pp_error=%"
720 NACL_PRId32")\n", pp_error)); 720 NACL_PRId32 ")\n", pp_error));
721 if (pp_error != PP_OK) { 721 if (pp_error != PP_OK) {
722 if (pp_error == PP_ERROR_NOACCESS) { 722 if (pp_error == PP_ERROR_NOACCESS) {
723 ReportPpapiError( 723 ReportPpapiError(
724 ERROR_PNACL_CACHE_OPEN_NOACCESS, 724 ERROR_PNACL_CACHE_OPEN_NOACCESS,
725 pp_error, 725 pp_error,
726 "File system for PNaCl translation cache failed to open " 726 "File system for PNaCl translation cache failed to open "
727 "(no access)."); 727 "(no access).");
728 return; 728 return;
729 } 729 }
730 if (pp_error == PP_ERROR_NOQUOTA) { 730 if (pp_error == PP_ERROR_NOQUOTA) {
(...skipping 18 matching lines...) Expand all
749 } 749 }
750 dir_ref_.reset(new pp::FileRef(*file_system_, kPnaclTempDir)); 750 dir_ref_.reset(new pp::FileRef(*file_system_, kPnaclTempDir));
751 // Attempt to create the directory. 751 // Attempt to create the directory.
752 pp::CompletionCallback cb = 752 pp::CompletionCallback cb =
753 callback_factory_.NewCallback(&PnaclCoordinator::DirectoryWasCreated); 753 callback_factory_.NewCallback(&PnaclCoordinator::DirectoryWasCreated);
754 dir_ref_->MakeDirectory(cb); 754 dir_ref_->MakeDirectory(cb);
755 } 755 }
756 756
757 void PnaclCoordinator::DirectoryWasCreated(int32_t pp_error) { 757 void PnaclCoordinator::DirectoryWasCreated(int32_t pp_error) {
758 PLUGIN_PRINTF(("PnaclCoordinator::DirectoryWasCreated (pp_error=%" 758 PLUGIN_PRINTF(("PnaclCoordinator::DirectoryWasCreated (pp_error=%"
759 NACL_PRId32")\n", pp_error)); 759 NACL_PRId32 ")\n", pp_error));
760 if (pp_error != PP_ERROR_FILEEXISTS && pp_error != PP_OK) { 760 if (pp_error != PP_ERROR_FILEEXISTS && pp_error != PP_OK) {
761 // Directory did not exist and could not be created. 761 // Directory did not exist and could not be created.
762 if (pp_error == PP_ERROR_NOACCESS) { 762 if (pp_error == PP_ERROR_NOACCESS) {
763 ReportPpapiError( 763 ReportPpapiError(
764 ERROR_PNACL_CACHE_DIRECTORY_CREATE, 764 ERROR_PNACL_CACHE_DIRECTORY_CREATE,
765 pp_error, 765 pp_error,
766 "PNaCl translation cache directory creation/check failed " 766 "PNaCl translation cache directory creation/check failed "
767 "(no access)."); 767 "(no access).");
768 return; 768 return;
769 } 769 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 cached_nexe_file_->OpenRead(cb); 871 cached_nexe_file_->OpenRead(cb);
872 } 872 }
873 } else { 873 } else {
874 // No cache case. 874 // No cache case.
875 CachedFileDidOpen(PP_ERROR_FAILED); 875 CachedFileDidOpen(PP_ERROR_FAILED);
876 } 876 }
877 } 877 }
878 878
879 void PnaclCoordinator::NexeFdDidOpen(int32_t pp_error) { 879 void PnaclCoordinator::NexeFdDidOpen(int32_t pp_error) {
880 PLUGIN_PRINTF(("PnaclCoordinator::NexeFdDidOpen (pp_error=%" 880 PLUGIN_PRINTF(("PnaclCoordinator::NexeFdDidOpen (pp_error=%"
881 NACL_PRId32", hit=%d, handle=%d)\n", pp_error, 881 NACL_PRId32 ", hit=%d, handle=%d)\n", pp_error,
882 is_cache_hit_ == PP_TRUE, 882 is_cache_hit_ == PP_TRUE,
883 nexe_handle_)); 883 nexe_handle_));
884 if (pp_error < PP_OK) { 884 if (pp_error < PP_OK) {
885 ReportPpapiError(ERROR_PNACL_CREATE_TEMP, pp_error, 885 ReportPpapiError(ERROR_PNACL_CREATE_TEMP, pp_error,
886 nacl::string("GetNexeFd failed")); 886 nacl::string("GetNexeFd failed"));
887 return; 887 return;
888 } 888 }
889 temp_nexe_file_.reset(new TempFile(plugin_)); 889 temp_nexe_file_.reset(new TempFile(plugin_));
890 if (!temp_nexe_file_->SetExistingFd(nexe_handle_)) { 890 if (!temp_nexe_file_->SetExistingFd(nexe_handle_)) {
891 ReportNonPpapiError( 891 ReportNonPpapiError(
(...skipping 24 matching lines...) Expand all
916 // will begin handing data to the coordinator, which is safe any time after 916 // will begin handing data to the coordinator, which is safe any time after
917 // the translate_thread_ object has been initialized). 917 // the translate_thread_ object has been initialized).
918 pp::CompletionCallback finish_cb = callback_factory_.NewCallback( 918 pp::CompletionCallback finish_cb = callback_factory_.NewCallback(
919 &PnaclCoordinator::BitcodeStreamDidFinish); 919 &PnaclCoordinator::BitcodeStreamDidFinish);
920 streaming_downloader_->FinishStreaming(finish_cb); 920 streaming_downloader_->FinishStreaming(finish_cb);
921 } 921 }
922 } 922 }
923 923
924 void PnaclCoordinator::CachedFileDidOpen(int32_t pp_error) { 924 void PnaclCoordinator::CachedFileDidOpen(int32_t pp_error) {
925 PLUGIN_PRINTF(("PnaclCoordinator::CachedFileDidOpen (pp_error=%" 925 PLUGIN_PRINTF(("PnaclCoordinator::CachedFileDidOpen (pp_error=%"
926 NACL_PRId32")\n", pp_error)); 926 NACL_PRId32 ")\n", pp_error));
927 if (pp_error == PP_OK) { 927 if (pp_error == PP_OK) {
928 // Cache hit -- no need to stream the rest of the file. 928 // Cache hit -- no need to stream the rest of the file.
929 streaming_downloader_.reset(NULL); 929 streaming_downloader_.reset(NULL);
930 HistogramEnumerateTranslationCache(true); 930 HistogramEnumerateTranslationCache(true);
931 NexeReadDidOpen(PP_OK); 931 NexeReadDidOpen(PP_OK);
932 return; 932 return;
933 } 933 }
934 // Otherwise, the cache file is missing so we must translate. 934 // Otherwise, the cache file is missing so we must translate.
935 HistogramEnumerateTranslationCache(false); 935 HistogramEnumerateTranslationCache(false);
936 936
937 // Continue streaming. 937 // Continue streaming.
938 pp::CompletionCallback cb = 938 pp::CompletionCallback cb =
939 callback_factory_.NewCallback(&PnaclCoordinator::BitcodeStreamDidFinish); 939 callback_factory_.NewCallback(&PnaclCoordinator::BitcodeStreamDidFinish);
940 streaming_downloader_->FinishStreaming(cb); 940 streaming_downloader_->FinishStreaming(cb);
941 } 941 }
942 942
943 void PnaclCoordinator::BitcodeStreamDidFinish(int32_t pp_error) { 943 void PnaclCoordinator::BitcodeStreamDidFinish(int32_t pp_error) {
944 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamDidFinish (pp_error=%" 944 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamDidFinish (pp_error=%"
945 NACL_PRId32")\n", pp_error)); 945 NACL_PRId32 ")\n", pp_error));
946 if (pp_error != PP_OK) { 946 if (pp_error != PP_OK) {
947 // Defer reporting the error and cleanup until after the translation 947 // Defer reporting the error and cleanup until after the translation
948 // thread returns, because it may be accessing the coordinator's 948 // thread returns, because it may be accessing the coordinator's
949 // objects or writing to the files. 949 // objects or writing to the files.
950 translate_finish_error_ = pp_error; 950 translate_finish_error_ = pp_error;
951 if (pp_error == PP_ERROR_ABORTED) { 951 if (pp_error == PP_ERROR_ABORTED) {
952 error_info_.SetReport(ERROR_PNACL_PEXE_FETCH_ABORTED, 952 error_info_.SetReport(ERROR_PNACL_PEXE_FETCH_ABORTED,
953 "PnaclCoordinator: pexe load failed (aborted)."); 953 "PnaclCoordinator: pexe load failed (aborted).");
954 } 954 }
955 if (pp_error == PP_ERROR_NOACCESS) { 955 if (pp_error == PP_ERROR_NOACCESS) {
956 error_info_.SetReport(ERROR_PNACL_PEXE_FETCH_NOACCESS, 956 error_info_.SetReport(ERROR_PNACL_PEXE_FETCH_NOACCESS,
957 "PnaclCoordinator: pexe load failed (no access)."); 957 "PnaclCoordinator: pexe load failed (no access).");
958 } else { 958 } else {
959 nacl::stringstream ss; 959 nacl::stringstream ss;
960 ss << "PnaclCoordinator: pexe load failed (pp_error=" << pp_error << ")."; 960 ss << "PnaclCoordinator: pexe load failed (pp_error=" << pp_error << ").";
961 error_info_.SetReport(ERROR_PNACL_PEXE_FETCH_OTHER, ss.str()); 961 error_info_.SetReport(ERROR_PNACL_PEXE_FETCH_OTHER, ss.str());
962 } 962 }
963 translate_thread_->AbortSubprocesses(); 963 translate_thread_->AbortSubprocesses();
964 } else { 964 } else {
965 // Compare download completion pct (100% now), to compile completion pct. 965 // Compare download completion pct (100% now), to compile completion pct.
966 HistogramRatio("NaCl.Perf.PNaClLoadTime.PctCompiledWhenFullyDownloaded", 966 HistogramRatio("NaCl.Perf.PNaClLoadTime.PctCompiledWhenFullyDownloaded",
967 pexe_bytes_compiled_, pexe_size_); 967 pexe_bytes_compiled_, pexe_size_);
968 } 968 }
969 } 969 }
970 970
971 void PnaclCoordinator::BitcodeStreamGotData(int32_t pp_error, 971 void PnaclCoordinator::BitcodeStreamGotData(int32_t pp_error,
972 FileStreamData data) { 972 FileStreamData data) {
973 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamGotData (pp_error=%" 973 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamGotData (pp_error=%"
974 NACL_PRId32", data=%p)\n", pp_error, data ? &(*data)[0] : 0)); 974 NACL_PRId32 ", data=%p)\n", pp_error, data ? &(*data)[0] : 0));
975 DCHECK(translate_thread_.get()); 975 DCHECK(translate_thread_.get());
976 976
977 translate_thread_->PutBytes(data, pp_error); 977 translate_thread_->PutBytes(data, pp_error);
978 // If pp_error > 0, then it represents the number of bytes received. 978 // If pp_error > 0, then it represents the number of bytes received.
979 if (data && pp_error > 0) { 979 if (data && pp_error > 0) {
980 pexe_size_ += pp_error; 980 pexe_size_ += pp_error;
981 } 981 }
982 } 982 }
983 983
984 StreamCallback PnaclCoordinator::GetCallback() { 984 StreamCallback PnaclCoordinator::GetCallback() {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 } 1022 }
1023 1023
1024 void PnaclCoordinator::GetCurrentProgress(int64_t* bytes_loaded, 1024 void PnaclCoordinator::GetCurrentProgress(int64_t* bytes_loaded,
1025 int64_t* bytes_total) { 1025 int64_t* bytes_total) {
1026 *bytes_loaded = pexe_bytes_compiled_; 1026 *bytes_loaded = pexe_bytes_compiled_;
1027 *bytes_total = expected_pexe_size_; 1027 *bytes_total = expected_pexe_size_;
1028 } 1028 }
1029 1029
1030 void PnaclCoordinator::ObjectFileDidOpen(int32_t pp_error) { 1030 void PnaclCoordinator::ObjectFileDidOpen(int32_t pp_error) {
1031 PLUGIN_PRINTF(("PnaclCoordinator::ObjectFileDidOpen (pp_error=%" 1031 PLUGIN_PRINTF(("PnaclCoordinator::ObjectFileDidOpen (pp_error=%"
1032 NACL_PRId32")\n", pp_error)); 1032 NACL_PRId32 ")\n", pp_error));
1033 if (pp_error != PP_OK) { 1033 if (pp_error != PP_OK) {
1034 ReportPpapiError(ERROR_PNACL_CREATE_TEMP, 1034 ReportPpapiError(ERROR_PNACL_CREATE_TEMP,
1035 pp_error, 1035 pp_error,
1036 "Failed to open scratch object file."); 1036 "Failed to open scratch object file.");
1037 return; 1037 return;
1038 } 1038 }
1039 // Open the nexe file for connecting ld and sel_ldr. 1039 // Open the nexe file for connecting ld and sel_ldr.
1040 // Start translation when done with this last step of setup! 1040 // Start translation when done with this last step of setup!
1041 if (!use_new_cache_) 1041 if (!use_new_cache_)
1042 // In the new cache case, the TempFile has already been created. 1042 // In the new cache case, the TempFile has already been created.
1043 temp_nexe_file_.reset(new TempFile(plugin_)); 1043 temp_nexe_file_.reset(new TempFile(plugin_));
1044 1044
1045 pp::CompletionCallback cb = 1045 pp::CompletionCallback cb =
1046 callback_factory_.NewCallback(&PnaclCoordinator::RunTranslate); 1046 callback_factory_.NewCallback(&PnaclCoordinator::RunTranslate);
1047 temp_nexe_file_->Open(cb, true); 1047 temp_nexe_file_->Open(cb, true);
1048 } 1048 }
1049 1049
1050 void PnaclCoordinator::RunTranslate(int32_t pp_error) { 1050 void PnaclCoordinator::RunTranslate(int32_t pp_error) {
1051 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" 1051 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%"
1052 NACL_PRId32")\n", pp_error)); 1052 NACL_PRId32 ")\n", pp_error));
1053 // Invoke llc followed by ld off the main thread. This allows use of 1053 // Invoke llc followed by ld off the main thread. This allows use of
1054 // blocking RPCs that would otherwise block the JavaScript main thread. 1054 // blocking RPCs that would otherwise block the JavaScript main thread.
1055 pp::CompletionCallback report_translate_finished = 1055 pp::CompletionCallback report_translate_finished =
1056 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); 1056 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished);
1057 1057
1058 CHECK(translate_thread_ != NULL); 1058 CHECK(translate_thread_ != NULL);
1059 translate_thread_->RunTranslate(report_translate_finished, 1059 translate_thread_->RunTranslate(report_translate_finished,
1060 manifest_.get(), 1060 manifest_.get(),
1061 obj_file_.get(), 1061 obj_file_.get(),
1062 temp_nexe_file_.get(), 1062 temp_nexe_file_.get(),
1063 &error_info_, 1063 &error_info_,
1064 resources_.get(), 1064 resources_.get(),
1065 &pnacl_options_, 1065 &pnacl_options_,
1066 this, 1066 this,
1067 plugin_); 1067 plugin_);
1068 } 1068 }
1069 1069
1070 } // namespace plugin 1070 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/plugin.cc ('k') | ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698