| Index: components/nacl/renderer/plugin/pnacl_resources.cc
|
| diff --git a/components/nacl/renderer/plugin/pnacl_resources.cc b/components/nacl/renderer/plugin/pnacl_resources.cc
|
| index 51df48d0239602e704aa4da25f03adf8cdb6f6d2..6c1e54b452bfdb4bc3b3abe988568e0561942bfd 100644
|
| --- a/components/nacl/renderer/plugin/pnacl_resources.cc
|
| +++ b/components/nacl/renderer/plugin/pnacl_resources.cc
|
| @@ -4,6 +4,9 @@
|
|
|
| #include "components/nacl/renderer/plugin/pnacl_resources.h"
|
|
|
| +#include <vector>
|
| +
|
| +#include "base/macros.h"
|
| #include "components/nacl/renderer/plugin/plugin.h"
|
| #include "components/nacl/renderer/plugin/utility.h"
|
| #include "native_client/src/include/portability_io.h"
|
| @@ -24,57 +27,77 @@ std::string GetFullUrl(const std::string& partial_url) {
|
|
|
| } // namespace
|
|
|
| -PnaclResources::PnaclResources(Plugin* plugin)
|
| - : plugin_(plugin) {
|
| - llc_file_info_ = kInvalidNaClFileInfo;
|
| - ld_file_info_ = kInvalidNaClFileInfo;
|
| +PnaclResources::PnaclResources(Plugin* plugin, bool use_subzero)
|
| + : plugin_(plugin), use_subzero_(use_subzero) {
|
| + for (size_t i = 0; i < arraysize(resources_); ++i) {
|
| + resources_[i].file_info = kInvalidNaClFileInfo;
|
| + }
|
| }
|
|
|
| PnaclResources::~PnaclResources() {
|
| - if (llc_file_info_.handle != PP_kInvalidFileHandle)
|
| - CloseFileHandle(llc_file_info_.handle);
|
| - if (ld_file_info_.handle != PP_kInvalidFileHandle)
|
| - CloseFileHandle(ld_file_info_.handle);
|
| + for (size_t i = 0; i < arraysize(resources_); ++i) {
|
| + if (resources_[i].file_info.handle != PP_kInvalidFileHandle)
|
| + CloseFileHandle(resources_[i].file_info.handle);
|
| + }
|
| +}
|
| +
|
| +const std::string& PnaclResources::GetUrl(ResourceType type) const {
|
| + size_t index = static_cast<size_t>(type);
|
| + if (index < kNumTypes) {
|
| + return resources_[index].tool_name;
|
| + }
|
| + DCHECK(false && "Index out of bounds");
|
| + // Return a dummy URL.
|
| + return resources_[kNumTypes].tool_name;
|
| +}
|
| +
|
| +PP_NaClFileInfo PnaclResources::TakeFileInfo(ResourceType type) {
|
| + size_t index = static_cast<size_t>(type);
|
| + if (index >= kNumTypes) {
|
| + DCHECK(false && "Index out of bounds");
|
| + return kInvalidNaClFileInfo;
|
| + }
|
| + return resources_[index].file_info;
|
| }
|
|
|
| bool PnaclResources::ReadResourceInfo() {
|
| PP_Var pp_llc_tool_name_var;
|
| PP_Var pp_ld_tool_name_var;
|
| + PP_Var pp_subzero_tool_name_var;
|
| if (!plugin_->nacl_interface()->GetPnaclResourceInfo(
|
| - plugin_->pp_instance(),
|
| - &pp_llc_tool_name_var,
|
| - &pp_ld_tool_name_var)) {
|
| + plugin_->pp_instance(), &pp_llc_tool_name_var, &pp_ld_tool_name_var,
|
| + &pp_subzero_tool_name_var)) {
|
| return false;
|
| }
|
| pp::Var llc_tool_name(pp::PASS_REF, pp_llc_tool_name_var);
|
| pp::Var ld_tool_name(pp::PASS_REF, pp_ld_tool_name_var);
|
| - llc_tool_name_ = GetFullUrl(llc_tool_name.AsString());
|
| - ld_tool_name_ = GetFullUrl(ld_tool_name.AsString());
|
| + pp::Var subzero_tool_name(pp::PASS_REF, pp_subzero_tool_name_var);
|
| + resources_[kLLC].tool_name = GetFullUrl(llc_tool_name.AsString());
|
| + resources_[kLD].tool_name = GetFullUrl(ld_tool_name.AsString());
|
| + resources_[kSubzero].tool_name = GetFullUrl(subzero_tool_name.AsString());
|
| return true;
|
| }
|
|
|
| -PP_NaClFileInfo PnaclResources::TakeLlcFileInfo() {
|
| - PP_NaClFileInfo to_return = llc_file_info_;
|
| - llc_file_info_ = kInvalidNaClFileInfo;
|
| - return to_return;
|
| -}
|
| -
|
| -PP_NaClFileInfo PnaclResources::TakeLdFileInfo() {
|
| - PP_NaClFileInfo to_return = ld_file_info_;
|
| - ld_file_info_ = kInvalidNaClFileInfo;
|
| - return to_return;
|
| -}
|
|
|
| bool PnaclResources::StartLoad() {
|
| PLUGIN_PRINTF(("PnaclResources::StartLoad\n"));
|
|
|
| // Do a blocking load of each of the resources.
|
| - plugin_->nacl_interface()->GetReadExecPnaclFd(llc_tool_name_.c_str(),
|
| - &llc_file_info_);
|
| - plugin_->nacl_interface()->GetReadExecPnaclFd(ld_tool_name_.c_str(),
|
| - &ld_file_info_);
|
| - return (llc_file_info_.handle != PP_kInvalidFileHandle &&
|
| - ld_file_info_.handle != PP_kInvalidFileHandle);
|
| + std::vector<ResourceType> to_load;
|
| + if (use_subzero_) {
|
| + to_load.push_back(kSubzero);
|
| + } else {
|
| + to_load.push_back(kLLC);
|
| + }
|
| + to_load.push_back(kLD);
|
| + bool all_valid = true;
|
| + for (ResourceType t : to_load) {
|
| + plugin_->nacl_interface()->GetReadExecPnaclFd(
|
| + resources_[t].tool_name.c_str(), &resources_[t].file_info);
|
| + all_valid =
|
| + all_valid && resources_[t].file_info.handle != PP_kInvalidFileHandle;
|
| + }
|
| + return all_valid;
|
| }
|
|
|
| } // namespace plugin
|
|
|