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

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

Issue 9158005: RFC: Add an interface for having the browser open a pnacl support file (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add a test, do some tweaks. Created 8 years, 10 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
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/plugin.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 error_info, pnacl_translate); 390 error_info, pnacl_translate);
391 } 391 }
392 392
393 private: 393 private:
394 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclLDManifest); 394 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclLDManifest);
395 395
396 const Manifest* nexe_manifest_; 396 const Manifest* nexe_manifest_;
397 const Manifest* extension_manifest_; 397 const Manifest* extension_manifest_;
398 }; 398 };
399 399
400 static int64_t start_download_time = 0;
401
400 ////////////////////////////////////////////////////////////////////// 402 //////////////////////////////////////////////////////////////////////
401 // The coordinator class. 403 // The coordinator class.
402 ////////////////////////////////////////////////////////////////////// 404 //////////////////////////////////////////////////////////////////////
403 PnaclCoordinator* PnaclCoordinator::BitcodeToNative( 405 PnaclCoordinator* PnaclCoordinator::BitcodeToNative(
404 Plugin* plugin, 406 Plugin* plugin,
405 const nacl::string& pexe_url, 407 const nacl::string& pexe_url,
406 const nacl::string& cache_identity, 408 const nacl::string& cache_identity,
407 const pp::CompletionCallback& translate_notify_callback) { 409 const pp::CompletionCallback& translate_notify_callback) {
408 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n", 410 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n",
409 static_cast<void*>(plugin), pexe_url.c_str())); 411 static_cast<void*>(plugin), pexe_url.c_str()));
410 PnaclCoordinator* coordinator = 412 PnaclCoordinator* coordinator =
411 new PnaclCoordinator(plugin, pexe_url, 413 new PnaclCoordinator(plugin, pexe_url,
412 cache_identity, translate_notify_callback); 414 cache_identity, translate_notify_callback);
413 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest=%p)\n", 415 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest=%p)\n",
414 reinterpret_cast<const void*>(coordinator->manifest_.get()))); 416 reinterpret_cast<const void*>(coordinator->manifest_.get())));
415 // Load llc and ld. 417 // Load llc and ld.
416 std::vector<nacl::string> resource_urls; 418 std::vector<nacl::string> resource_urls;
417 resource_urls.push_back(kLlcUrl); 419 resource_urls.push_back(kLlcUrl);
418 resource_urls.push_back(kLdUrl); 420 resource_urls.push_back(kLdUrl);
419 pp::CompletionCallback resources_cb = 421 pp::CompletionCallback resources_cb =
420 coordinator->callback_factory_.NewCallback( 422 coordinator->callback_factory_.NewCallback(
421 &PnaclCoordinator::ResourcesDidLoad); 423 &PnaclCoordinator::ResourcesDidLoad);
422 coordinator->resources_.reset( 424 coordinator->resources_.reset(
423 new PnaclResources(plugin, 425 new PnaclResources(plugin,
424 coordinator, 426 coordinator,
425 coordinator->manifest_.get(), 427 coordinator->manifest_.get(),
426 resource_urls, 428 resource_urls,
427 resources_cb)); 429 resources_cb));
428 CHECK(coordinator->resources_ != NULL); 430 CHECK(coordinator->resources_ != NULL);
431
432 start_download_time = NaClGetTimeOfDayMicroseconds();
429 coordinator->resources_->StartDownloads(); 433 coordinator->resources_->StartDownloads();
430 // ResourcesDidLoad will be invoked when all resources have been received. 434 // ResourcesDidLoad will be invoked when all resources have been received.
431 return coordinator; 435 return coordinator;
432 } 436 }
433 437
434 int32_t PnaclCoordinator::GetLoadedFileDesc(int32_t pp_error, 438 int32_t PnaclCoordinator::GetLoadedFileDesc(int32_t pp_error,
435 const nacl::string& url, 439 const nacl::string& url,
436 const nacl::string& component) { 440 const nacl::string& component) {
437 PLUGIN_PRINTF(("PnaclCoordinator::GetLoadedFileDesc (pp_error=%" 441 PLUGIN_PRINTF(("PnaclCoordinator::GetLoadedFileDesc (pp_error=%"
438 NACL_PRId32", url=%s, component=%s)\n", pp_error, 442 NACL_PRId32", url=%s, component=%s)\n", pp_error,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 620
617 void PnaclCoordinator::TranslateFailed(const nacl::string& error_string) { 621 void PnaclCoordinator::TranslateFailed(const nacl::string& error_string) {
618 PLUGIN_PRINTF(("PnaclCoordinator::TranslateFailed (error_string=%" 622 PLUGIN_PRINTF(("PnaclCoordinator::TranslateFailed (error_string=%"
619 NACL_PRId32")\n", error_string.c_str())); 623 NACL_PRId32")\n", error_string.c_str()));
620 pp::Core* core = pp::Module::Get()->core(); 624 pp::Core* core = pp::Module::Get()->core();
621 error_info_.SetReport(ERROR_UNKNOWN, 625 error_info_.SetReport(ERROR_UNKNOWN,
622 nacl::string("PnaclCoordinator: ") + error_string); 626 nacl::string("PnaclCoordinator: ") + error_string);
623 core->CallOnMainThread(0, report_translate_finished_, PP_ERROR_FAILED); 627 core->CallOnMainThread(0, report_translate_finished_, PP_ERROR_FAILED);
624 } 628 }
625 629
630
631 // DEBUGGING test junk -- to be removed before checkin and replaced
632 // with something like a test...
633 static void TestPnaclOpenFile(const nacl::string& filename, bool expect_works) {
634 PLUGIN_PRINTF(("JAN calling get_readonly_pnacl_fd: %s\n", filename.c_str()));
635 int fd = get_readonly_pnacl_fd(filename.c_str());
Mark Seaborn 2012/06/20 20:12:55 I don't think get_readonly_pnacl_fd needs to be a
636 const char *expect_success_msg = expect_works ? "YAY!" : "NOO!";
637 const char *expect_fail_msg = expect_works ? "NOO!" : "YAY!";
638
639 if (fd < 0) {
640 PLUGIN_PRINTF(("JAN get %s failed (fd='%d') %s\n",
641 filename.c_str(), fd, expect_fail_msg));
642 } else {
643 PLUGIN_PRINTF(("JAN get %s succeeded (fd='%d') %s\n",
644 filename.c_str(), fd, expect_success_msg));
645 // Try to stat the mofo.
646 struct stat stat_buf;
647 if (0 != fstat(fd, &stat_buf)) {
648 PLUGIN_PRINTF(("JAN stat %s fd failed: %s\n",
649 filename.c_str(), expect_fail_msg));
650 } else {
651 PLUGIN_PRINTF(("JAN stat %s fd (size='%d') succeed: %s\n",
652 filename.c_str(), stat_buf.st_size, expect_success_msg));
653 }
654 close(fd);
655 PLUGIN_PRINTF(("JAN got fd for %s and now closing: %d\n",
656 filename.c_str(), fd));
657 }
658 }
659
660 static void WINAPI DoTestFileOpens(void* arg) {
661 nacl::string sandbox_isa = GetSandboxISA();
662 // We should probably use FilePath.Append() to join these.
663 TestPnaclOpenFile(sandbox_isa + nacl::string("/llc"), true);
664 TestPnaclOpenFile(sandbox_isa + nacl::string("/ld"), true);
665 TestPnaclOpenFile(sandbox_isa + nacl::string("/crtbegin.o"), true);
666
667 // Stuff that shouldn't work.
668 TestPnaclOpenFile("non-existent-file", false);
669 TestPnaclOpenFile("../../chrome_shutdown_ms.txt", false);
670 TestPnaclOpenFile("/bin/ls", false);
671 TestPnaclOpenFile("$HOME/.bashrc", false);
672 }
673 // END DEBUGGING test junk.
674
675
626 void PnaclCoordinator::ResourcesDidLoad(int32_t pp_error) { 676 void PnaclCoordinator::ResourcesDidLoad(int32_t pp_error) {
627 PLUGIN_PRINTF(("PnaclCoordinator::ResourcesDidLoad (pp_error=%" 677 PLUGIN_PRINTF(("PnaclCoordinator::ResourcesDidLoad (pp_error=%"
628 NACL_PRId32")\n", pp_error)); 678 NACL_PRId32")\n", pp_error));
679
680 int64_t end_download_time = NaClGetTimeOfDayMicroseconds();
681 PLUGIN_PRINTF(("PnaclCoordinator:: url load time total=%"NACL_PRId64")\n",
682 end_download_time - start_download_time));
683
684 // BEGIN debugging hack.
685 // On thread accesses work...
686 PLUGIN_PRINTF(("JAN Testing from main thread.\n"));
687 int64_t start_download_time2 = NaClGetTimeOfDayMicroseconds();
688 DoTestFileOpens(NULL);
689 int64_t end_download_time2 = NaClGetTimeOfDayMicroseconds();
690 PLUGIN_PRINTF(("PnaclCoordinator::fd load time total=%"NACL_PRId64")\n",
691 end_download_time2 - start_download_time2));
692
693 // Off thread use doesn't seem to work...
694 // PLUGIN_PRINTF(("JAN Testing from secondary thread.\n"));
695 // static NaClThread *debugging_file_thread = new NaClThread();
696 // if (!NaClThreadCreateJoinable(debugging_file_thread,
697 // DoTestFileOpens,
698 // NULL,
699 // 128 * 1024)) {
700 // PLUGIN_PRINTF(("JAN Failed to creaate test thread\n"));
701 // }
702 PLUGIN_PRINTF(("JAN Testing all done!\n"));
703 // END debugging.
704
629 if (pp_error != PP_OK) { 705 if (pp_error != PP_OK) {
630 ReportPpapiError(pp_error, "resources failed to load."); 706 ReportPpapiError(pp_error, "resources failed to load.");
631 return; 707 return;
632 } 708 }
633 // Open the local temporary file system to create the temporary files 709 // Open the local temporary file system to create the temporary files
634 // for the object and nexe. 710 // for the object and nexe.
635 pp::CompletionCallback cb = 711 pp::CompletionCallback cb =
636 callback_factory_.NewCallback(&PnaclCoordinator::FileSystemDidOpen); 712 callback_factory_.NewCallback(&PnaclCoordinator::FileSystemDidOpen);
637 if (!file_system_->Open(0, cb)) { 713 if (!file_system_->Open(0, cb)) {
638 ReportNonPpapiError("failed to open file system."); 714 ReportNonPpapiError("failed to open file system.");
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 } 805 }
730 } 806 }
731 807
732 void PnaclCoordinator::RunTranslate(int32_t pp_error) { 808 void PnaclCoordinator::RunTranslate(int32_t pp_error) {
733 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" 809 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%"
734 NACL_PRId32")\n", pp_error)); 810 NACL_PRId32")\n", pp_error));
735 int32_t fd = GetLoadedFileDesc(pp_error, pexe_url_, "pexe"); 811 int32_t fd = GetLoadedFileDesc(pp_error, pexe_url_, "pexe");
736 if (fd < 0) { 812 if (fd < 0) {
737 return; 813 return;
738 } 814 }
815
739 pexe_wrapper_.reset(plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY)); 816 pexe_wrapper_.reset(plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY));
740 // Invoke llc followed by ld off the main thread. This allows use of 817 // Invoke llc followed by ld off the main thread. This allows use of
741 // blocking RPCs that would otherwise block the JavaScript main thread. 818 // blocking RPCs that would otherwise block the JavaScript main thread.
742 report_translate_finished_ = 819 report_translate_finished_ =
743 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); 820 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished);
744 translate_thread_.reset(new NaClThread); 821 translate_thread_.reset(new NaClThread);
745 if (translate_thread_ == NULL) { 822 if (translate_thread_ == NULL) {
746 ReportNonPpapiError("could not allocate thread struct."); 823 ReportNonPpapiError("could not allocate thread struct.");
747 return; 824 return;
748 } 825 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 nacl::MutexLocker ml(&subprocess_mu_); 927 nacl::MutexLocker ml(&subprocess_mu_);
851 return subprocesses_should_die_; 928 return subprocesses_should_die_;
852 } 929 }
853 930
854 void PnaclCoordinator::SetSubprocessesShouldDie(bool subprocesses_should_die) { 931 void PnaclCoordinator::SetSubprocessesShouldDie(bool subprocesses_should_die) {
855 nacl::MutexLocker ml(&subprocess_mu_); 932 nacl::MutexLocker ml(&subprocess_mu_);
856 subprocesses_should_die_ = subprocesses_should_die; 933 subprocesses_should_die_ = subprocesses_should_die;
857 } 934 }
858 935
859 } // namespace plugin 936 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/plugin.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698