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..9e65d6974d4e90e2155c3ddf0509c23ef1839fe1 100644 |
--- a/components/nacl/renderer/plugin/pnacl_resources.cc |
+++ b/components/nacl/renderer/plugin/pnacl_resources.cc |
@@ -4,6 +4,8 @@ |
#include "components/nacl/renderer/plugin/pnacl_resources.h" |
+#include <vector> |
+ |
#include "components/nacl/renderer/plugin/plugin.h" |
#include "components/nacl/renderer/plugin/utility.h" |
#include "native_client/src/include/portability_io.h" |
@@ -24,57 +26,82 @@ 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 (PnaclResourceEntry& entry : resources_) { |
+ entry.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 (PnaclResourceEntry& entry : resources_) { |
+ if (entry.file_info.handle != PP_kInvalidFileHandle) |
+ CloseFileHandle(entry.file_info.handle); |
+ } |
+} |
+ |
+const std::string& PnaclResources::GetUrl(ResourceType type) const { |
+ size_t index = static_cast<size_t>(type); |
+ if (index < NUM_TYPES) { |
+ return resources_[index].tool_name; |
+ } |
+ // TODO(jvoung): Use NOTREACHED() from base/logging.h once |
+ // we are able to use base/logging.h without conflicting |
+ // with NaCl macros. |
+ DCHECK(false && "Index out of bounds"); |
+ // Return a dummy tool name. |
+ return resources_[index].tool_name; |
+} |
+ |
+PP_NaClFileInfo PnaclResources::TakeFileInfo(ResourceType type) { |
+ size_t index = static_cast<size_t>(type); |
+ if (index >= NUM_TYPES) { |
+ DCHECK(false && "Index out of bounds"); |
+ return kInvalidNaClFileInfo; |
+ } |
+ PP_NaClFileInfo to_return = resources_[index].file_info; |
+ resources_[index].file_info = kInvalidNaClFileInfo; |
+ return to_return; |
} |
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_[LLC].tool_name = GetFullUrl(llc_tool_name.AsString()); |
+ resources_[LD].tool_name = GetFullUrl(ld_tool_name.AsString()); |
+ resources_[SUBZERO].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(SUBZERO); |
+ } else { |
+ to_load.push_back(LLC); |
+ } |
+ to_load.push_back(LD); |
+ 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 |