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 <numeric> | 7 #include <numeric> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/containers/scoped_ptr_hash_map.h" | 14 #include "base/containers/scoped_ptr_hash_map.h" |
15 #include "base/cpu.h" | 15 #include "base/cpu.h" |
16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
19 #include "components/nacl/common/nacl_host_messages.h" | 19 #include "components/nacl/common/nacl_host_messages.h" |
20 #include "components/nacl/common/nacl_messages.h" | 20 #include "components/nacl/common/nacl_messages.h" |
21 #include "components/nacl/common/nacl_switches.h" | 21 #include "components/nacl/common/nacl_switches.h" |
22 #include "components/nacl/common/nacl_types.h" | 22 #include "components/nacl/common/nacl_types.h" |
23 #include "components/nacl/renderer/histogram.h" | 23 #include "components/nacl/renderer/histogram.h" |
24 #include "components/nacl/renderer/json_manifest.h" | 24 #include "components/nacl/renderer/json_manifest.h" |
25 #include "components/nacl/renderer/manifest_downloader.h" | 25 #include "components/nacl/renderer/manifest_downloader.h" |
26 #include "components/nacl/renderer/manifest_service_channel.h" | 26 #include "components/nacl/renderer/manifest_service_channel.h" |
27 #include "components/nacl/renderer/nexe_load_manager.h" | 27 #include "components/nacl/renderer/nexe_load_manager.h" |
28 #include "components/nacl/renderer/pnacl_translation_resource_host.h" | 28 #include "components/nacl/renderer/pnacl_translation_resource_host.h" |
| 29 #include "components/nacl/renderer/progress_event.h" |
29 #include "components/nacl/renderer/sandbox_arch.h" | 30 #include "components/nacl/renderer/sandbox_arch.h" |
30 #include "components/nacl/renderer/trusted_plugin_channel.h" | 31 #include "components/nacl/renderer/trusted_plugin_channel.h" |
31 #include "content/public/common/content_client.h" | 32 #include "content/public/common/content_client.h" |
32 #include "content/public/common/content_switches.h" | 33 #include "content/public/common/content_switches.h" |
33 #include "content/public/common/sandbox_init.h" | 34 #include "content/public/common/sandbox_init.h" |
34 #include "content/public/renderer/pepper_plugin_instance.h" | 35 #include "content/public/renderer/pepper_plugin_instance.h" |
35 #include "content/public/renderer/render_thread.h" | 36 #include "content/public/renderer/render_thread.h" |
36 #include "content/public/renderer/render_view.h" | 37 #include "content/public/renderer/render_view.h" |
37 #include "content/public/renderer/renderer_ppapi_host.h" | 38 #include "content/public/renderer/renderer_ppapi_host.h" |
38 #include "net/base/data_url.h" | 39 #include "net/base/data_url.h" |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 | 648 |
648 if (out_fd == IPC::InvalidPlatformFileForTransit()) { | 649 if (out_fd == IPC::InvalidPlatformFileForTransit()) { |
649 return base::kInvalidPlatformFileValue; | 650 return base::kInvalidPlatformFileValue; |
650 } | 651 } |
651 | 652 |
652 base::PlatformFile handle = | 653 base::PlatformFile handle = |
653 IPC::PlatformFileForTransitToPlatformFile(out_fd); | 654 IPC::PlatformFileForTransitToPlatformFile(out_fd); |
654 return handle; | 655 return handle; |
655 } | 656 } |
656 | 657 |
657 void DispatchEventOnMainThread(PP_Instance instance, | |
658 PP_NaClEventType event_type, | |
659 const std::string& resource_url, | |
660 PP_Bool length_is_computable, | |
661 uint64_t loaded_bytes, | |
662 uint64_t total_bytes); | |
663 | |
664 void DispatchEvent(PP_Instance instance, | 658 void DispatchEvent(PP_Instance instance, |
665 PP_NaClEventType event_type, | 659 PP_NaClEventType event_type, |
666 const char *resource_url, | 660 const char *resource_url, |
667 PP_Bool length_is_computable, | 661 PP_Bool length_is_computable, |
668 uint64_t loaded_bytes, | 662 uint64_t loaded_bytes, |
669 uint64_t total_bytes) { | 663 uint64_t total_bytes) { |
670 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 664 ProgressEvent event(event_type, |
671 FROM_HERE, | 665 resource_url, |
672 base::Bind(&DispatchEventOnMainThread, | 666 PP_ToBool(length_is_computable), |
673 instance, | 667 loaded_bytes, |
674 event_type, | 668 total_bytes); |
675 std::string(resource_url), | 669 DispatchProgressEvent(instance, event); |
676 length_is_computable, | |
677 loaded_bytes, | |
678 total_bytes)); | |
679 } | |
680 | |
681 void DispatchEventOnMainThread(PP_Instance instance, | |
682 PP_NaClEventType event_type, | |
683 const std::string& resource_url, | |
684 PP_Bool length_is_computable, | |
685 uint64_t loaded_bytes, | |
686 uint64_t total_bytes) { | |
687 NexeLoadManager* load_manager = | |
688 GetNexeLoadManager(instance); | |
689 // The instance may have been destroyed after we were scheduled, so do | |
690 // nothing if it's gone. | |
691 if (load_manager) { | |
692 NexeLoadManager::ProgressEvent event(event_type); | |
693 event.resource_url = resource_url; | |
694 event.length_is_computable = PP_ToBool(length_is_computable); | |
695 event.loaded_bytes = loaded_bytes; | |
696 event.total_bytes = total_bytes; | |
697 load_manager->DispatchEvent(event); | |
698 } | |
699 } | 670 } |
700 | 671 |
701 void NexeFileDidOpen(PP_Instance instance, | 672 void NexeFileDidOpen(PP_Instance instance, |
702 int32_t pp_error, | 673 int32_t pp_error, |
703 int32_t fd, | 674 int32_t fd, |
704 int32_t http_status, | 675 int32_t http_status, |
705 int64_t nexe_bytes_read, | 676 int64_t nexe_bytes_read, |
706 const char* url, | 677 const char* url, |
707 int64_t time_since_open) { | 678 int64_t time_since_open) { |
708 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 679 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 &PostMessageToJavaScript | 1279 &PostMessageToJavaScript |
1309 }; | 1280 }; |
1310 | 1281 |
1311 } // namespace | 1282 } // namespace |
1312 | 1283 |
1313 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1284 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
1314 return &nacl_interface; | 1285 return &nacl_interface; |
1315 } | 1286 } |
1316 | 1287 |
1317 } // namespace nacl | 1288 } // namespace nacl |
OLD | NEW |