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" | |
30 #include "components/nacl/renderer/sandbox_arch.h" | 29 #include "components/nacl/renderer/sandbox_arch.h" |
31 #include "components/nacl/renderer/trusted_plugin_channel.h" | 30 #include "components/nacl/renderer/trusted_plugin_channel.h" |
32 #include "content/public/common/content_client.h" | 31 #include "content/public/common/content_client.h" |
33 #include "content/public/common/content_switches.h" | 32 #include "content/public/common/content_switches.h" |
34 #include "content/public/common/sandbox_init.h" | 33 #include "content/public/common/sandbox_init.h" |
35 #include "content/public/renderer/pepper_plugin_instance.h" | 34 #include "content/public/renderer/pepper_plugin_instance.h" |
36 #include "content/public/renderer/render_thread.h" | 35 #include "content/public/renderer/render_thread.h" |
37 #include "content/public/renderer/render_view.h" | 36 #include "content/public/renderer/render_view.h" |
38 #include "content/public/renderer/renderer_ppapi_host.h" | 37 #include "content/public/renderer/renderer_ppapi_host.h" |
39 #include "net/base/data_url.h" | 38 #include "net/base/data_url.h" |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 | 640 |
642 if (out_fd == IPC::InvalidPlatformFileForTransit()) { | 641 if (out_fd == IPC::InvalidPlatformFileForTransit()) { |
643 return base::kInvalidPlatformFileValue; | 642 return base::kInvalidPlatformFileValue; |
644 } | 643 } |
645 | 644 |
646 base::PlatformFile handle = | 645 base::PlatformFile handle = |
647 IPC::PlatformFileForTransitToPlatformFile(out_fd); | 646 IPC::PlatformFileForTransitToPlatformFile(out_fd); |
648 return handle; | 647 return handle; |
649 } | 648 } |
650 | 649 |
| 650 void DispatchEventOnMainThread(PP_Instance instance, |
| 651 PP_NaClEventType event_type, |
| 652 const std::string& resource_url, |
| 653 PP_Bool length_is_computable, |
| 654 uint64_t loaded_bytes, |
| 655 uint64_t total_bytes); |
| 656 |
651 void DispatchEvent(PP_Instance instance, | 657 void DispatchEvent(PP_Instance instance, |
652 PP_NaClEventType event_type, | 658 PP_NaClEventType event_type, |
653 const char *resource_url, | 659 const char *resource_url, |
654 PP_Bool length_is_computable, | 660 PP_Bool length_is_computable, |
655 uint64_t loaded_bytes, | 661 uint64_t loaded_bytes, |
656 uint64_t total_bytes) { | 662 uint64_t total_bytes) { |
657 ProgressEvent event(event_type, | 663 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
658 resource_url, | 664 FROM_HERE, |
659 PP_ToBool(length_is_computable), | 665 base::Bind(&DispatchEventOnMainThread, |
660 loaded_bytes, | 666 instance, |
661 total_bytes); | 667 event_type, |
662 DispatchProgressEvent(instance, event); | 668 std::string(resource_url), |
| 669 length_is_computable, |
| 670 loaded_bytes, |
| 671 total_bytes)); |
| 672 } |
| 673 |
| 674 void DispatchEventOnMainThread(PP_Instance instance, |
| 675 PP_NaClEventType event_type, |
| 676 const std::string& resource_url, |
| 677 PP_Bool length_is_computable, |
| 678 uint64_t loaded_bytes, |
| 679 uint64_t total_bytes) { |
| 680 NexeLoadManager* load_manager = |
| 681 GetNexeLoadManager(instance); |
| 682 // The instance may have been destroyed after we were scheduled, so do |
| 683 // nothing if it's gone. |
| 684 if (load_manager) { |
| 685 NexeLoadManager::ProgressEvent event(event_type); |
| 686 event.resource_url = resource_url; |
| 687 event.length_is_computable = PP_ToBool(length_is_computable); |
| 688 event.loaded_bytes = loaded_bytes; |
| 689 event.total_bytes = total_bytes; |
| 690 load_manager->DispatchEvent(event); |
| 691 } |
663 } | 692 } |
664 | 693 |
665 void NexeFileDidOpen(PP_Instance instance, | 694 void NexeFileDidOpen(PP_Instance instance, |
666 int32_t pp_error, | 695 int32_t pp_error, |
667 int32_t fd, | 696 int32_t fd, |
668 int32_t http_status, | 697 int32_t http_status, |
669 int64_t nexe_bytes_read, | 698 int64_t nexe_bytes_read, |
670 const char* url, | 699 const char* url, |
671 int64_t time_since_open) { | 700 int64_t time_since_open) { |
672 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 701 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 &GetCpuFeatureAttrs | 1281 &GetCpuFeatureAttrs |
1253 }; | 1282 }; |
1254 | 1283 |
1255 } // namespace | 1284 } // namespace |
1256 | 1285 |
1257 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1286 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
1258 return &nacl_interface; | 1287 return &nacl_interface; |
1259 } | 1288 } |
1260 | 1289 |
1261 } // namespace nacl | 1290 } // namespace nacl |
OLD | NEW |