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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | |
10 #include <numeric> | 9 #include <numeric> |
11 #include <string> | 10 #include <string> |
| 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/containers/scoped_ptr_hash_map.h" | 17 #include "base/containers/scoped_ptr_hash_map.h" |
18 #include "base/cpu.h" | 18 #include "base/cpu.h" |
19 #include "base/files/file.h" | 19 #include "base/files/file.h" |
20 #include "base/json/json_reader.h" | 20 #include "base/json/json_reader.h" |
21 #include "base/lazy_instance.h" | 21 #include "base/lazy_instance.h" |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 | 530 |
531 // Create the trusted plugin channel. | 531 // Create the trusted plugin channel. |
532 if (IsValidChannelHandle(launch_result.trusted_ipc_channel_handle)) { | 532 if (IsValidChannelHandle(launch_result.trusted_ipc_channel_handle)) { |
533 bool is_helper_nexe = !PP_ToBool(main_service_runtime); | 533 bool is_helper_nexe = !PP_ToBool(main_service_runtime); |
534 scoped_ptr<TrustedPluginChannel> trusted_plugin_channel( | 534 scoped_ptr<TrustedPluginChannel> trusted_plugin_channel( |
535 new TrustedPluginChannel( | 535 new TrustedPluginChannel( |
536 load_manager, | 536 load_manager, |
537 launch_result.trusted_ipc_channel_handle, | 537 launch_result.trusted_ipc_channel_handle, |
538 content::RenderThread::Get()->GetShutdownEvent(), | 538 content::RenderThread::Get()->GetShutdownEvent(), |
539 is_helper_nexe)); | 539 is_helper_nexe)); |
540 load_manager->set_trusted_plugin_channel(trusted_plugin_channel.Pass()); | 540 load_manager->set_trusted_plugin_channel(std::move(trusted_plugin_channel)); |
541 } else { | 541 } else { |
542 PostPPCompletionCallback(callback, PP_ERROR_FAILED); | 542 PostPPCompletionCallback(callback, PP_ERROR_FAILED); |
543 return; | 543 return; |
544 } | 544 } |
545 | 545 |
546 // Create the manifest service handle as well. | 546 // Create the manifest service handle as well. |
547 if (IsValidChannelHandle(launch_result.manifest_service_ipc_channel_handle)) { | 547 if (IsValidChannelHandle(launch_result.manifest_service_ipc_channel_handle)) { |
548 scoped_ptr<ManifestServiceChannel> manifest_service_channel( | 548 scoped_ptr<ManifestServiceChannel> manifest_service_channel( |
549 new ManifestServiceChannel( | 549 new ManifestServiceChannel( |
550 launch_result.manifest_service_ipc_channel_handle, | 550 launch_result.manifest_service_ipc_channel_handle, |
551 base::Bind(&PostPPCompletionCallback, callback), | 551 base::Bind(&PostPPCompletionCallback, callback), |
552 manifest_service_proxy.Pass(), | 552 std::move(manifest_service_proxy), |
553 content::RenderThread::Get()->GetShutdownEvent())); | 553 content::RenderThread::Get()->GetShutdownEvent())); |
554 load_manager->set_manifest_service_channel( | 554 load_manager->set_manifest_service_channel( |
555 manifest_service_channel.Pass()); | 555 std::move(manifest_service_channel)); |
556 } | 556 } |
557 } | 557 } |
558 | 558 |
559 PP_Bool StartPpapiProxy(PP_Instance instance) { | 559 PP_Bool StartPpapiProxy(PP_Instance instance) { |
560 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 560 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
561 DCHECK(load_manager); | 561 DCHECK(load_manager); |
562 if (!load_manager) | 562 if (!load_manager) |
563 return PP_FALSE; | 563 return PP_FALSE; |
564 | 564 |
565 content::PepperPluginInstance* plugin_instance = | 565 content::PepperPluginInstance* plugin_instance = |
566 content::PepperPluginInstance::Get(instance); | 566 content::PepperPluginInstance::Get(instance); |
567 if (!plugin_instance) { | 567 if (!plugin_instance) { |
568 DLOG(ERROR) << "GetInstance() failed"; | 568 DLOG(ERROR) << "GetInstance() failed"; |
569 return PP_FALSE; | 569 return PP_FALSE; |
570 } | 570 } |
571 | 571 |
572 NaClPluginInstance* nacl_plugin_instance = GetNaClPluginInstance(instance); | 572 NaClPluginInstance* nacl_plugin_instance = GetNaClPluginInstance(instance); |
573 if (!nacl_plugin_instance->instance_info) { | 573 if (!nacl_plugin_instance->instance_info) { |
574 DLOG(ERROR) << "Could not find instance ID"; | 574 DLOG(ERROR) << "Could not find instance ID"; |
575 return PP_FALSE; | 575 return PP_FALSE; |
576 } | 576 } |
577 scoped_ptr<InstanceInfo> instance_info = | 577 scoped_ptr<InstanceInfo> instance_info = |
578 nacl_plugin_instance->instance_info.Pass(); | 578 std::move(nacl_plugin_instance->instance_info); |
579 | 579 |
580 PP_ExternalPluginResult result = plugin_instance->SwitchToOutOfProcessProxy( | 580 PP_ExternalPluginResult result = plugin_instance->SwitchToOutOfProcessProxy( |
581 base::FilePath().AppendASCII(instance_info->url.spec()), | 581 base::FilePath().AppendASCII(instance_info->url.spec()), |
582 instance_info->permissions, | 582 instance_info->permissions, |
583 instance_info->channel_handle, | 583 instance_info->channel_handle, |
584 instance_info->plugin_pid, | 584 instance_info->plugin_pid, |
585 instance_info->plugin_child_id); | 585 instance_info->plugin_child_id); |
586 | 586 |
587 if (result == PP_EXTERNAL_PLUGIN_OK) { | 587 if (result == PP_EXTERNAL_PLUGIN_OK) { |
588 // Log the amound of time that has passed between the trusted plugin being | 588 // Log the amound of time that has passed between the trusted plugin being |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 const char* error_message) { | 856 const char* error_message) { |
857 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 857 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
858 if (load_manager) | 858 if (load_manager) |
859 load_manager->ReportLoadError(error, error_message); | 859 load_manager->ReportLoadError(error, error_message); |
860 } | 860 } |
861 | 861 |
862 void InstanceCreated(PP_Instance instance) { | 862 void InstanceCreated(PP_Instance instance) { |
863 InstanceMap& map = g_instance_map.Get(); | 863 InstanceMap& map = g_instance_map.Get(); |
864 CHECK(map.find(instance) == map.end()); // Sanity check. | 864 CHECK(map.find(instance) == map.end()); // Sanity check. |
865 scoped_ptr<NaClPluginInstance> new_instance(new NaClPluginInstance(instance)); | 865 scoped_ptr<NaClPluginInstance> new_instance(new NaClPluginInstance(instance)); |
866 map.add(instance, new_instance.Pass()); | 866 map.add(instance, std::move(new_instance)); |
867 } | 867 } |
868 | 868 |
869 void InstanceDestroyed(PP_Instance instance) { | 869 void InstanceDestroyed(PP_Instance instance) { |
870 InstanceMap& map = g_instance_map.Get(); | 870 InstanceMap& map = g_instance_map.Get(); |
871 InstanceMap::iterator iter = map.find(instance); | 871 InstanceMap::iterator iter = map.find(instance); |
872 CHECK(iter != map.end()); | 872 CHECK(iter != map.end()); |
873 // The erase may call NexeLoadManager's destructor prior to removing it from | 873 // The erase may call NexeLoadManager's destructor prior to removing it from |
874 // the map. In that case, it is possible for the trusted Plugin to re-enter | 874 // the map. In that case, it is possible for the trusted Plugin to re-enter |
875 // the NexeLoadManager (e.g., by calling ReportLoadError). Passing out the | 875 // the NexeLoadManager (e.g., by calling ReportLoadError). Passing out the |
876 // NexeLoadManager to a local scoped_ptr just ensures that its entry is gone | 876 // NexeLoadManager to a local scoped_ptr just ensures that its entry is gone |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 const blink::WebDocument& document = | 999 const blink::WebDocument& document = |
1000 plugin_instance->GetContainer()->element().document(); | 1000 plugin_instance->GetContainer()->element().document(); |
1001 | 1001 |
1002 const GURL& gurl = load_manager->manifest_base_url(); | 1002 const GURL& gurl = load_manager->manifest_base_url(); |
1003 scoped_ptr<blink::WebURLLoader> url_loader( | 1003 scoped_ptr<blink::WebURLLoader> url_loader( |
1004 CreateWebURLLoader(document, gurl)); | 1004 CreateWebURLLoader(document, gurl)); |
1005 blink::WebURLRequest request = CreateWebURLRequest(document, gurl); | 1005 blink::WebURLRequest request = CreateWebURLRequest(document, gurl); |
1006 | 1006 |
1007 // ManifestDownloader deletes itself after invoking the callback. | 1007 // ManifestDownloader deletes itself after invoking the callback. |
1008 ManifestDownloader* manifest_downloader = new ManifestDownloader( | 1008 ManifestDownloader* manifest_downloader = new ManifestDownloader( |
1009 url_loader.Pass(), | 1009 std::move(url_loader), load_manager->is_installed(), |
1010 load_manager->is_installed(), | 1010 base::Bind(DownloadManifestToBufferCompletion, instance, callback, |
1011 base::Bind(DownloadManifestToBufferCompletion, | 1011 base::Time::Now())); |
1012 instance, callback, base::Time::Now())); | |
1013 manifest_downloader->Load(request); | 1012 manifest_downloader->Load(request); |
1014 } | 1013 } |
1015 | 1014 |
1016 void DownloadManifestToBufferCompletion(PP_Instance instance, | 1015 void DownloadManifestToBufferCompletion(PP_Instance instance, |
1017 struct PP_CompletionCallback callback, | 1016 struct PP_CompletionCallback callback, |
1018 base::Time start_time, | 1017 base::Time start_time, |
1019 PP_NaClError pp_nacl_error, | 1018 PP_NaClError pp_nacl_error, |
1020 const std::string& data) { | 1019 const std::string& data) { |
1021 base::TimeDelta download_time = base::Time::Now() - start_time; | 1020 base::TimeDelta download_time = base::Time::Now() - start_time; |
1022 HistogramTimeSmall("NaCl.Perf.StartupTime.ManifestDownload", | 1021 HistogramTimeSmall("NaCl.Perf.StartupTime.ManifestDownload", |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 const blink::WebDocument& document = | 1340 const blink::WebDocument& document = |
1342 plugin_instance->GetContainer()->element().document(); | 1341 plugin_instance->GetContainer()->element().document(); |
1343 scoped_ptr<blink::WebURLLoader> url_loader( | 1342 scoped_ptr<blink::WebURLLoader> url_loader( |
1344 CreateWebURLLoader(document, gurl)); | 1343 CreateWebURLLoader(document, gurl)); |
1345 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); | 1344 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); |
1346 | 1345 |
1347 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); | 1346 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); |
1348 | 1347 |
1349 // FileDownloader deletes itself after invoking DownloadNexeCompletion. | 1348 // FileDownloader deletes itself after invoking DownloadNexeCompletion. |
1350 FileDownloader* file_downloader = new FileDownloader( | 1349 FileDownloader* file_downloader = new FileDownloader( |
1351 url_loader.Pass(), | 1350 std::move(url_loader), std::move(target_file), |
1352 target_file.Pass(), | |
1353 base::Bind(&DownloadNexeCompletion, request, out_file_info), | 1351 base::Bind(&DownloadNexeCompletion, request, out_file_info), |
1354 base::Bind(&ProgressEventRateLimiter::ReportProgress, | 1352 base::Bind(&ProgressEventRateLimiter::ReportProgress, |
1355 base::Owned(tracker), std::string(url))); | 1353 base::Owned(tracker), std::string(url))); |
1356 file_downloader->Load(url_request); | 1354 file_downloader->Load(url_request); |
1357 } | 1355 } |
1358 | 1356 |
1359 void DownloadNexeCompletion(const DownloadNexeRequest& request, | 1357 void DownloadNexeCompletion(const DownloadNexeRequest& request, |
1360 PP_NaClFileInfo* out_file_info, | 1358 PP_NaClFileInfo* out_file_info, |
1361 FileDownloader::Status status, | 1359 FileDownloader::Status status, |
1362 base::File target_file, | 1360 base::File target_file, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1490 } | 1488 } |
1491 const blink::WebDocument& document = | 1489 const blink::WebDocument& document = |
1492 plugin_instance->GetContainer()->element().document(); | 1490 plugin_instance->GetContainer()->element().document(); |
1493 scoped_ptr<blink::WebURLLoader> url_loader( | 1491 scoped_ptr<blink::WebURLLoader> url_loader( |
1494 CreateWebURLLoader(document, gurl)); | 1492 CreateWebURLLoader(document, gurl)); |
1495 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); | 1493 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); |
1496 | 1494 |
1497 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); | 1495 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); |
1498 | 1496 |
1499 // FileDownloader deletes itself after invoking DownloadNexeCompletion. | 1497 // FileDownloader deletes itself after invoking DownloadNexeCompletion. |
1500 FileDownloader* file_downloader = new FileDownloader( | 1498 FileDownloader* file_downloader = |
1501 url_loader.Pass(), | 1499 new FileDownloader(std::move(url_loader), std::move(target_file), |
1502 target_file.Pass(), | 1500 base::Bind(&DownloadFileCompletion, callback), |
1503 base::Bind(&DownloadFileCompletion, callback), | 1501 base::Bind(&ProgressEventRateLimiter::ReportProgress, |
1504 base::Bind(&ProgressEventRateLimiter::ReportProgress, | 1502 base::Owned(tracker), std::string(url))); |
1505 base::Owned(tracker), std::string(url))); | |
1506 file_downloader->Load(url_request); | 1503 file_downloader->Load(url_request); |
1507 } | 1504 } |
1508 | 1505 |
1509 void LogTranslateTime(const char* histogram_name, | 1506 void LogTranslateTime(const char* histogram_name, |
1510 int64_t time_in_us) { | 1507 int64_t time_in_us) { |
1511 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1508 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
1512 FROM_HERE, | 1509 FROM_HERE, |
1513 base::Bind(&HistogramTimeTranslation, | 1510 base::Bind(&HistogramTimeTranslation, |
1514 std::string(histogram_name), | 1511 std::string(histogram_name), |
1515 time_in_us / 1000)); | 1512 time_in_us / 1000)); |
(...skipping 22 matching lines...) Expand all Loading... |
1538 class PexeDownloader : public blink::WebURLLoaderClient { | 1535 class PexeDownloader : public blink::WebURLLoaderClient { |
1539 public: | 1536 public: |
1540 PexeDownloader(PP_Instance instance, | 1537 PexeDownloader(PP_Instance instance, |
1541 scoped_ptr<blink::WebURLLoader> url_loader, | 1538 scoped_ptr<blink::WebURLLoader> url_loader, |
1542 const std::string& pexe_url, | 1539 const std::string& pexe_url, |
1543 int32_t pexe_opt_level, | 1540 int32_t pexe_opt_level, |
1544 bool use_subzero, | 1541 bool use_subzero, |
1545 const PPP_PexeStreamHandler* stream_handler, | 1542 const PPP_PexeStreamHandler* stream_handler, |
1546 void* stream_handler_user_data) | 1543 void* stream_handler_user_data) |
1547 : instance_(instance), | 1544 : instance_(instance), |
1548 url_loader_(url_loader.Pass()), | 1545 url_loader_(std::move(url_loader)), |
1549 pexe_url_(pexe_url), | 1546 pexe_url_(pexe_url), |
1550 pexe_opt_level_(pexe_opt_level), | 1547 pexe_opt_level_(pexe_opt_level), |
1551 use_subzero_(use_subzero), | 1548 use_subzero_(use_subzero), |
1552 stream_handler_(stream_handler), | 1549 stream_handler_(stream_handler), |
1553 stream_handler_user_data_(stream_handler_user_data), | 1550 stream_handler_user_data_(stream_handler_user_data), |
1554 success_(false), | 1551 success_(false), |
1555 expected_content_length_(-1), | 1552 expected_content_length_(-1), |
1556 weak_factory_(this) {} | 1553 weak_factory_(this) {} |
1557 | 1554 |
1558 void Load(const blink::WebURLRequest& request) { | 1555 void Load(const blink::WebURLRequest& request) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1679 static_cast<int32_t>(PP_ERROR_FAILED))); | 1676 static_cast<int32_t>(PP_ERROR_FAILED))); |
1680 return; | 1677 return; |
1681 } | 1678 } |
1682 | 1679 |
1683 GURL gurl(pexe_url); | 1680 GURL gurl(pexe_url); |
1684 const blink::WebDocument& document = | 1681 const blink::WebDocument& document = |
1685 plugin_instance->GetContainer()->element().document(); | 1682 plugin_instance->GetContainer()->element().document(); |
1686 scoped_ptr<blink::WebURLLoader> url_loader( | 1683 scoped_ptr<blink::WebURLLoader> url_loader( |
1687 CreateWebURLLoader(document, gurl)); | 1684 CreateWebURLLoader(document, gurl)); |
1688 PexeDownloader* downloader = | 1685 PexeDownloader* downloader = |
1689 new PexeDownloader(instance, url_loader.Pass(), pexe_url, opt_level, | 1686 new PexeDownloader(instance, std::move(url_loader), pexe_url, opt_level, |
1690 PP_ToBool(use_subzero), handler, handler_user_data); | 1687 PP_ToBool(use_subzero), handler, handler_user_data); |
1691 | 1688 |
1692 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); | 1689 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); |
1693 // Mark the request as requesting a PNaCl bitcode file, | 1690 // Mark the request as requesting a PNaCl bitcode file, |
1694 // so that component updater can detect this user action. | 1691 // so that component updater can detect this user action. |
1695 url_request.addHTTPHeaderField( | 1692 url_request.addHTTPHeaderField( |
1696 blink::WebString::fromUTF8("Accept"), | 1693 blink::WebString::fromUTF8("Accept"), |
1697 blink::WebString::fromUTF8("application/x-pnacl, */*")); | 1694 blink::WebString::fromUTF8("application/x-pnacl, */*")); |
1698 url_request.setRequestContext(blink::WebURLRequest::RequestContextObject); | 1695 url_request.setRequestContext(blink::WebURLRequest::RequestContextObject); |
1699 downloader->Load(url_request); | 1696 downloader->Load(url_request); |
(...skipping 27 matching lines...) Expand all Loading... |
1727 &StreamPexe | 1724 &StreamPexe |
1728 }; | 1725 }; |
1729 | 1726 |
1730 } // namespace | 1727 } // namespace |
1731 | 1728 |
1732 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1729 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
1733 return &nacl_interface; | 1730 return &nacl_interface; |
1734 } | 1731 } |
1735 | 1732 |
1736 } // namespace nacl | 1733 } // namespace nacl |
OLD | NEW |