OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/nacl/renderer/ppb_nacl_private_impl.h" | 5 #include "components/nacl/renderer/ppb_nacl_private_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/containers/scoped_ptr_hash_map.h" | 8 #include "base/containers/scoped_ptr_hash_map.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 if (load_manager) { | 469 if (load_manager) { |
470 nacl::NexeLoadManager::ProgressEvent event(event_type); | 470 nacl::NexeLoadManager::ProgressEvent event(event_type); |
471 event.resource_url = resource_url; | 471 event.resource_url = resource_url; |
472 event.length_is_computable = PP_ToBool(length_is_computable); | 472 event.length_is_computable = PP_ToBool(length_is_computable); |
473 event.loaded_bytes = loaded_bytes; | 473 event.loaded_bytes = loaded_bytes; |
474 event.total_bytes = total_bytes; | 474 event.total_bytes = total_bytes; |
475 load_manager->DispatchEvent(event); | 475 load_manager->DispatchEvent(event); |
476 } | 476 } |
477 } | 477 } |
478 | 478 |
| 479 void NexeFileDidOpen(PP_Instance instance, |
| 480 int32_t pp_error, |
| 481 int32_t fd, |
| 482 int32_t http_status, |
| 483 int64_t nexe_bytes_read, |
| 484 const char* url) { |
| 485 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
| 486 if (load_manager) { |
| 487 load_manager->NexeFileDidOpen(pp_error, |
| 488 fd, |
| 489 http_status, |
| 490 nexe_bytes_read, |
| 491 url); |
| 492 } |
| 493 } |
| 494 |
479 void ReportLoadSuccess(PP_Instance instance, | 495 void ReportLoadSuccess(PP_Instance instance, |
480 const char* url, | 496 const char* url, |
481 uint64_t loaded_bytes, | 497 uint64_t loaded_bytes, |
482 uint64_t total_bytes) { | 498 uint64_t total_bytes) { |
483 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 499 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
484 if (load_manager) | 500 if (load_manager) |
485 load_manager->ReportLoadSuccess(url, loaded_bytes, total_bytes); | 501 load_manager->ReportLoadSuccess(url, loaded_bytes, total_bytes); |
486 } | 502 } |
487 | 503 |
488 void ReportLoadError(PP_Instance instance, | 504 void ReportLoadError(PP_Instance instance, |
(...skipping 21 matching lines...) Expand all Loading... |
510 scoped_ptr<nacl::NexeLoadManager> new_load_manager( | 526 scoped_ptr<nacl::NexeLoadManager> new_load_manager( |
511 new nacl::NexeLoadManager(instance)); | 527 new nacl::NexeLoadManager(instance)); |
512 NexeLoadManagerMap& map = g_load_manager_map.Get(); | 528 NexeLoadManagerMap& map = g_load_manager_map.Get(); |
513 DLOG_IF(ERROR, map.count(instance) != 0) << "Instance count should be 0"; | 529 DLOG_IF(ERROR, map.count(instance) != 0) << "Instance count should be 0"; |
514 map.add(instance, new_load_manager.Pass()); | 530 map.add(instance, new_load_manager.Pass()); |
515 } | 531 } |
516 | 532 |
517 void InstanceDestroyed(PP_Instance instance) { | 533 void InstanceDestroyed(PP_Instance instance) { |
518 NexeLoadManagerMap& map = g_load_manager_map.Get(); | 534 NexeLoadManagerMap& map = g_load_manager_map.Get(); |
519 DLOG_IF(ERROR, map.count(instance) == 0) << "Could not find instance ID"; | 535 DLOG_IF(ERROR, map.count(instance) == 0) << "Could not find instance ID"; |
| 536 // The erase may call NexeLoadManager's destructor prior to removing it from |
| 537 // the map. In that case, it is possible for the trusted Plugin to re-enter |
| 538 // the NexeLoadManager (e.g., by calling ReportLoadError). Passing out the |
| 539 // NexeLoadManager to a local scoped_ptr just ensures that its entry is gone |
| 540 // from the map prior to the destructor being invoked. |
| 541 scoped_ptr<nacl::NexeLoadManager> temp(map.take(instance)); |
520 map.erase(instance); | 542 map.erase(instance); |
521 } | 543 } |
522 | 544 |
523 PP_Bool NaClDebugEnabledForURL(const char* alleged_nmf_url) { | 545 PP_Bool NaClDebugEnabledForURL(const char* alleged_nmf_url) { |
524 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaClDebug)) | 546 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaClDebug)) |
525 return PP_FALSE; | 547 return PP_FALSE; |
526 bool should_debug; | 548 bool should_debug; |
527 IPC::Sender* sender = content::RenderThread::Get(); | 549 IPC::Sender* sender = content::RenderThread::Get(); |
528 DCHECK(sender); | 550 DCHECK(sender); |
529 if(!sender->Send(new NaClHostMsg_NaClDebugEnabledForURL( | 551 if(!sender->Send(new NaClHostMsg_NaClDebugEnabledForURL( |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 } | 644 } |
623 | 645 |
624 int64_t GetNexeSize(PP_Instance instance) { | 646 int64_t GetNexeSize(PP_Instance instance) { |
625 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 647 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
626 DCHECK(load_manager); | 648 DCHECK(load_manager); |
627 if (load_manager) | 649 if (load_manager) |
628 return load_manager->nexe_size(); | 650 return load_manager->nexe_size(); |
629 return 0; | 651 return 0; |
630 } | 652 } |
631 | 653 |
632 void SetNexeSize(PP_Instance instance, int64_t nexe_size) { | |
633 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); | |
634 DCHECK(load_manager); | |
635 if (load_manager) | |
636 return load_manager->set_nexe_size(nexe_size); | |
637 } | |
638 | |
639 const PPB_NaCl_Private nacl_interface = { | 654 const PPB_NaCl_Private nacl_interface = { |
640 &LaunchSelLdr, | 655 &LaunchSelLdr, |
641 &StartPpapiProxy, | 656 &StartPpapiProxy, |
642 &UrandomFD, | 657 &UrandomFD, |
643 &Are3DInterfacesDisabled, | 658 &Are3DInterfacesDisabled, |
644 &BrokerDuplicateHandle, | 659 &BrokerDuplicateHandle, |
645 &GetReadonlyPnaclFD, | 660 &GetReadonlyPnaclFD, |
646 &CreateTemporaryFile, | 661 &CreateTemporaryFile, |
647 &GetNumberOfProcessors, | 662 &GetNumberOfProcessors, |
648 &IsNonSFIModeEnabled, | 663 &IsNonSFIModeEnabled, |
649 &GetNexeFd, | 664 &GetNexeFd, |
650 &ReportTranslationFinished, | 665 &ReportTranslationFinished, |
651 &OpenNaClExecutable, | 666 &OpenNaClExecutable, |
652 &DispatchEvent, | 667 &DispatchEvent, |
| 668 &NexeFileDidOpen, |
653 &ReportLoadSuccess, | 669 &ReportLoadSuccess, |
654 &ReportLoadError, | 670 &ReportLoadError, |
655 &ReportLoadAbort, | 671 &ReportLoadAbort, |
656 &NexeDidCrash, | 672 &NexeDidCrash, |
657 &InstanceCreated, | 673 &InstanceCreated, |
658 &InstanceDestroyed, | 674 &InstanceDestroyed, |
659 &NaClDebugEnabledForURL, | 675 &NaClDebugEnabledForURL, |
660 &GetSandboxArch, | 676 &GetSandboxArch, |
661 &GetUrlScheme, | 677 &GetUrlScheme, |
662 &LogToConsole, | 678 &LogToConsole, |
663 &GetNaClReadyState, | 679 &GetNaClReadyState, |
664 &SetNaClReadyState, | 680 &SetNaClReadyState, |
665 &GetIsInstalled, | 681 &GetIsInstalled, |
666 &SetIsInstalled, | 682 &SetIsInstalled, |
667 &SetReadyTime, | 683 &SetReadyTime, |
668 &GetExitStatus, | 684 &GetExitStatus, |
669 &SetExitStatus, | 685 &SetExitStatus, |
670 &Vlog, | 686 &Vlog, |
671 &SetInitTime, | 687 &SetInitTime, |
672 &GetNexeSize, | 688 &GetNexeSize |
673 &SetNexeSize | |
674 }; | 689 }; |
675 | 690 |
676 } // namespace | 691 } // namespace |
677 | 692 |
678 namespace nacl { | 693 namespace nacl { |
679 | 694 |
680 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 695 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
681 return &nacl_interface; | 696 return &nacl_interface; |
682 } | 697 } |
683 | 698 |
684 } // namespace nacl | 699 } // namespace nacl |
OLD | NEW |