Commit eecc60c0 authored by sehr@google.com's avatar sehr@google.com

Get all the resources relative to a single base. Currently the same base

URL used for the link resources.  In the future that base will be the pnacl
manifest file.
BUG= none
TEST= none
Review URL: http://codereview.chromium.org/8525014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109659 0039d316-1c4b-4281-b951-d872f2087c98
parent 46e297a4
...@@ -60,10 +60,6 @@ const char* const kUrlKey = "url"; ...@@ -60,10 +60,6 @@ const char* const kUrlKey = "url";
// } // }
// } // }
// TODO(jvoung): Remove these when we find a better way to store/install them.
const char* const kPnaclLlcKey = "pnacl-llc";
const char* const kPnaclLdKey = "pnacl-ld";
// Looks up |property_name| in the vector |valid_names| with length // Looks up |property_name| in the vector |valid_names| with length
// |valid_name_count|. Returns true if |property_name| is found. // |valid_name_count|. Returns true if |property_name| is found.
bool FindMatchingProperty(nacl::string property_name, bool FindMatchingProperty(nacl::string property_name,
...@@ -434,67 +430,4 @@ bool Manifest::ResolveKey(const nacl::string& key, ...@@ -434,67 +430,4 @@ bool Manifest::ResolveKey(const nacl::string& key,
full_url, error_info, is_portable, this); full_url, error_info, is_portable, this);
} }
// TODO(jvoung): We won't need these if we figure out how to install llc and ld.
bool Manifest::GetLLCURL(nacl::string* full_url, ErrorInfo* error_info) {
if (full_url == NULL || error_info == NULL)
return false;
Json::Value pnacl_llc = dictionary_[kPnaclLlcKey];
nacl::string nexe_url;
nacl::string error_string;
bool is_portable;
if (!GetURLFromISADictionary(pnacl_llc,
sandbox_isa_,
&nexe_url,
&error_string,
&is_portable)) {
error_info->SetReport(ERROR_MANIFEST_GET_NEXE_URL,
nacl::string(kPnaclLlcKey) + ":" + sandbox_isa_ +
error_string);
return false;
}
if (is_portable) {
// Bootstrap problem -- we need this to translate portable programs!
error_info->SetReport(ERROR_MANIFEST_GET_NEXE_URL,
nacl::string(kPnaclLlcKey) +
" must be pre-translated for " + sandbox_isa_ + "!");
return false;
}
return ResolveURL(nexe_url, full_url, error_info);
}
bool Manifest::GetLDURL(nacl::string* full_url, ErrorInfo* error_info) {
if (full_url == NULL || error_info == NULL)
return false;
Json::Value pnacl_ld = dictionary_[kPnaclLdKey];
nacl::string nexe_url;
nacl::string error_string;
bool is_portable;
if (!GetURLFromISADictionary(pnacl_ld,
sandbox_isa_,
&nexe_url,
&error_string,
&is_portable)) {
error_info->SetReport(ERROR_MANIFEST_GET_NEXE_URL,
nacl::string(kPnaclLdKey) + ":" + sandbox_isa_ +
error_string);
return false;
}
if (is_portable) {
// Bootstrap problem -- we need this to translate portable programs!
error_info->SetReport(ERROR_MANIFEST_GET_NEXE_URL,
nacl::string(kPnaclLdKey) +
" must be pre-translated for " + sandbox_isa_ + "!");
return false;
}
return ResolveURL(nexe_url, full_url, error_info);
}
} // namespace plugin } // namespace plugin
...@@ -51,15 +51,6 @@ class Manifest { ...@@ -51,15 +51,6 @@ class Manifest {
ErrorInfo* error_info, ErrorInfo* error_info,
bool* is_portable); bool* is_portable);
// TODO(jvoung): Get rid of these when we find a better way to
// store / install these.
// Gets the full nexe URL for the LLC nexe from the manifest file.
bool GetLLCURL(nacl::string* full_url, ErrorInfo* error_info);
// Gets the full nexe URL for the LD nexe from the manifest file.
bool GetLDURL(nacl::string* full_url, ErrorInfo* error_info);
// end TODO(jvoung)
// Resolves a URL relative to the manifest base URL // Resolves a URL relative to the manifest base URL
bool ResolveURL(const nacl::string& relative_url, bool ResolveURL(const nacl::string& relative_url,
nacl::string* full_url, nacl::string* full_url,
......
...@@ -1607,20 +1607,11 @@ void Plugin::ProcessNaClManifest(const nacl::string& manifest_json) { ...@@ -1607,20 +1607,11 @@ void Plugin::ProcessNaClManifest(const nacl::string& manifest_json) {
// Inform JavaScript that we found a nexe URL to load. // Inform JavaScript that we found a nexe URL to load.
EnqueueProgressEvent(kProgressEventProgress); EnqueueProgressEvent(kProgressEventProgress);
if (is_portable) { if (is_portable) {
// TODO(jvoung): Do we want to check an ENV var if pnacl is enabled first? pp::CompletionCallback translate_callback =
nacl::string llc_url; callback_factory_.NewCallback(&Plugin::BitcodeDidTranslate);
nacl::string ld_url; // Will always call the callback on success or failure.
if (SelectLLCURLFromManifest(&llc_url, &error_info) && pnacl_.BitcodeToNative(program_url, translate_callback);
SelectLDURLFromManifest(&ld_url, &error_info)) { return;
pp::CompletionCallback translate_callback =
callback_factory_.NewCallback(&Plugin::BitcodeDidTranslate);
// Will always call the callback on success or failure.
pnacl_.BitcodeToNative(program_url,
llc_url,
ld_url,
translate_callback);
return;
}
} else { } else {
pp::CompletionCallback open_callback = pp::CompletionCallback open_callback =
callback_factory_.NewRequiredCallback(&Plugin::NexeFileDidOpen); callback_factory_.NewRequiredCallback(&Plugin::NexeFileDidOpen);
...@@ -1708,26 +1699,6 @@ bool Plugin::SelectProgramURLFromManifest(nacl::string* result, ...@@ -1708,26 +1699,6 @@ bool Plugin::SelectProgramURLFromManifest(nacl::string* result,
return manifest_->GetProgramURL(result, error_info, is_portable); return manifest_->GetProgramURL(result, error_info, is_portable);
} }
// TODO(jvoung): get rid of these when we have a better hosting solution
// for PNaCl's nexes.
bool Plugin::SelectLLCURLFromManifest(nacl::string* result,
ErrorInfo* error_info) {
PLUGIN_PRINTF(("Plugin::SelectLLCURLFromManifest()\n"));
if (result == NULL || error_info == NULL || manifest_ == NULL)
return false;
return manifest_->GetLLCURL(result, error_info);
}
bool Plugin::SelectLDURLFromManifest(nacl::string* result,
ErrorInfo* error_info) {
PLUGIN_PRINTF(("Plugin::SelectLDURLFromManifest()\n"));
if (result == NULL || error_info == NULL || manifest_ == NULL)
return false;
return manifest_->GetLDURL(result, error_info);
}
// end TODO(jvoung)
void Plugin::UrlDidOpenForStreamAsFile(int32_t pp_error, void Plugin::UrlDidOpenForStreamAsFile(int32_t pp_error,
FileDownloader*& url_downloader, FileDownloader*& url_downloader,
PP_CompletionCallback callback) { PP_CompletionCallback callback) {
......
...@@ -442,13 +442,6 @@ class Plugin : public pp::InstancePrivate { ...@@ -442,13 +442,6 @@ class Plugin : public pp::InstancePrivate {
ErrorInfo* error_info, ErrorInfo* error_info,
bool* is_portable); bool* is_portable);
// TODO(jvoung): get rid of these once we find a better way to store / install
// the pnacl translator nexes.
bool SelectLLCURLFromManifest(nacl::string* result,
ErrorInfo* error_info);
bool SelectLDURLFromManifest(nacl::string* result,
ErrorInfo* error_info);
// Logs timing information to a UMA histogram, and also logs the same timing // Logs timing information to a UMA histogram, and also logs the same timing
// information divided by the size of the nexe to another histogram. // information divided by the size of the nexe to another histogram.
void HistogramStartupTimeSmall(const std::string& name, float dt); void HistogramStartupTimeSmall(const std::string& name, float dt);
......
...@@ -348,20 +348,23 @@ nacl::string GeneratedObjectFileName() { ...@@ -348,20 +348,23 @@ nacl::string GeneratedObjectFileName() {
return nacl::string("___PNACL_GENERATED"); return nacl::string("___PNACL_GENERATED");
} }
string_vector LinkResources(const nacl::string& sandbox_isa, nacl::string ResourceBaseUrl() {
bool withGenerated) { nacl::string sandbox_isa = GetSandboxISA();
string_vector results; nacl::string base_url = "pnacl_support/" + sandbox_isa + "/";
nacl::string base_dir = "pnacl_support/" + sandbox_isa; return base_url;
}
string_vector LinkResources(bool withGenerated) {
string_vector results;
// NOTE: order of items == link order. // NOTE: order of items == link order.
results.push_back(base_dir + "/crtbegin.o"); results.push_back("crtbegin.o");
if (withGenerated) { if (withGenerated) {
results.push_back(GeneratedObjectFileName()); results.push_back(GeneratedObjectFileName());
} }
results.push_back(base_dir + "/libcrt_platform.a"); results.push_back("libcrt_platform.a");
results.push_back(base_dir + "/libgcc.a"); results.push_back("libgcc.a");
results.push_back(base_dir + "/libgcc_eh.a"); results.push_back("libgcc_eh.a");
results.push_back(base_dir + "/crtend.o"); results.push_back("crtend.o");
return results; return results;
} }
...@@ -429,7 +432,7 @@ void WINAPI DoLinkThread(void* arg) { ...@@ -429,7 +432,7 @@ void WINAPI DoLinkThread(void* arg) {
} }
//// Files. //// Files.
string_vector files = LinkResources(sandbox_isa, true); string_vector files = LinkResources(true);
PnaclResources* resources = coordinator->resources(); PnaclResources* resources = coordinator->resources();
for (string_vector::iterator i = files.begin(), e = files.end(); for (string_vector::iterator i = files.begin(), e = files.end();
i != e; ++i) { i != e; ++i) {
...@@ -585,15 +588,16 @@ void PnaclCoordinator::ResourcesDidLoad(int32_t pp_error, ...@@ -585,15 +588,16 @@ void PnaclCoordinator::ResourcesDidLoad(int32_t pp_error,
void PnaclCoordinator::BitcodeToNative( void PnaclCoordinator::BitcodeToNative(
const nacl::string& pexe_url, const nacl::string& pexe_url,
const nacl::string& llc_url,
const nacl::string& ld_url,
const pp::CompletionCallback& finish_callback) { const pp::CompletionCallback& finish_callback) {
PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (pexe=%s, llc=%s, ld=%s)\n", PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (pexe=%s)\n",
pexe_url.c_str(), pexe_url.c_str()));
llc_url.c_str(), // The base URL for finding all the resources will be obtained from the
ld_url.c_str())); // PNaCl manifest file.
llc_url_ = llc_url; // Also, the llc and ld pathnames should be read from the manifest.
ld_url_ = ld_url; // TODO(sehr): change to use the manifest file when ready.
resource_base_url_ = ResourceBaseUrl();
llc_url_ = "llc";
ld_url_ = "ld";
translate_notify_callback_ = finish_callback; translate_notify_callback_ = finish_callback;
// Steps: // Steps:
...@@ -613,9 +617,9 @@ void PnaclCoordinator::BitcodeToNative( ...@@ -613,9 +617,9 @@ void PnaclCoordinator::BitcodeToNative(
callback_factory_.NewCallback(&PnaclCoordinator::ResourcesDidLoad, callback_factory_.NewCallback(&PnaclCoordinator::ResourcesDidLoad,
pexe_url, pexe_url,
translation_unit_.get()); translation_unit_.get());
resources_->AddResourceUrl(llc_url); resources_->AddResourceUrl(llc_url_);
resources_->AddResourceUrl(ld_url); resources_->AddResourceUrl(ld_url_);
string_vector link_resources = LinkResources(GetSandboxISA(), false); string_vector link_resources = LinkResources(false);
for (string_vector::iterator for (string_vector::iterator
i = link_resources.begin(), e = link_resources.end(); i = link_resources.begin(), e = link_resources.end();
i != e; i != e;
......
...@@ -90,8 +90,6 @@ class PnaclCoordinator { ...@@ -90,8 +90,6 @@ class PnaclCoordinator {
void Initialize(Plugin* instance); void Initialize(Plugin* instance);
void BitcodeToNative(const nacl::string& pexe_url, void BitcodeToNative(const nacl::string& pexe_url,
const nacl::string& llc_url,
const nacl::string& ld_url,
const pp::CompletionCallback& finish_callback); const pp::CompletionCallback& finish_callback);
// Call this to take ownership of the FD of the translated nexe after // Call this to take ownership of the FD of the translated nexe after
...@@ -115,9 +113,8 @@ class PnaclCoordinator { ...@@ -115,9 +113,8 @@ class PnaclCoordinator {
// Wrapper for Plugin ReportLoadError. // Wrapper for Plugin ReportLoadError.
void ReportLoadError(const ErrorInfo& error); void ReportLoadError(const ErrorInfo& error);
// Accessors for use by helper threads. // Accessors for use by helper threads.
nacl::string resource_base_url() const { return resource_base_url_; }
Plugin* plugin() const { return plugin_; } Plugin* plugin() const { return plugin_; }
nacl::string llc_url() const { return llc_url_; } nacl::string llc_url() const { return llc_url_; }
NaClSubprocess* llc_subprocess() const { return llc_subprocess_; } NaClSubprocess* llc_subprocess() const { return llc_subprocess_; }
...@@ -153,6 +150,7 @@ class PnaclCoordinator { ...@@ -153,6 +150,7 @@ class PnaclCoordinator {
pp::CompletionCallbackFactory<PnaclCoordinator> callback_factory_; pp::CompletionCallbackFactory<PnaclCoordinator> callback_factory_;
// URLs used to lookup downloaded resources. // URLs used to lookup downloaded resources.
nacl::string resource_base_url_;
nacl::string llc_url_; nacl::string llc_url_;
nacl::string ld_url_; nacl::string ld_url_;
......
...@@ -60,17 +60,23 @@ void PnaclResources::StartDownloads() { ...@@ -60,17 +60,23 @@ void PnaclResources::StartDownloads() {
delayed_callback_.reset( delayed_callback_.reset(
new DelayedCallback(all_loaded_callback, resource_count)); new DelayedCallback(all_loaded_callback, resource_count));
// All resource URLs are relative to the coordinator's resource_base_url().
nacl::string resource_base_url = coordinator_->resource_base_url();
// Schedule the downloads. // Schedule the downloads.
CHECK(resource_urls_.size() > 0); CHECK(resource_urls_.size() > 0);
for (size_t i = 0; i < resource_urls_.size(); ++i) { for (size_t i = 0; i < resource_urls_.size(); ++i) {
const nacl::string& url = resource_urls_[i]; const nacl::string& full_url = resource_base_url + resource_urls_[i];
pp::CompletionCallback ready_callback = pp::CompletionCallback ready_callback =
callback_factory_.NewCallback(&PnaclResources::ResourceReady, url); callback_factory_.NewCallback(&PnaclResources::ResourceReady,
if (!plugin_->StreamAsFile(url, ready_callback.pp_completion_callback())) { resource_urls_[i],
full_url);
if (!plugin_->StreamAsFile(full_url,
ready_callback.pp_completion_callback())) {
ErrorInfo error_info; ErrorInfo error_info;
error_info.SetReport(ERROR_UNKNOWN, error_info.SetReport(ERROR_UNKNOWN,
"PnaclCoordinator: Failed to download file: " + "PnaclCoordinator: Failed to download file: " +
url + "\n"); resource_urls_[i] + "\n");
coordinator_->ReportLoadError(error_info); coordinator_->ReportLoadError(error_info);
coordinator_->PnaclNonPpapiError(); coordinator_->PnaclNonPpapiError();
break; break;
...@@ -80,12 +86,13 @@ void PnaclResources::StartDownloads() { ...@@ -80,12 +86,13 @@ void PnaclResources::StartDownloads() {
} }
void PnaclResources::ResourceReady(int32_t pp_error, void PnaclResources::ResourceReady(int32_t pp_error,
const nacl::string& url) { const nacl::string& url,
const nacl::string& full_url) {
PLUGIN_PRINTF(("PnaclResources::ResourceReady (pp_error=%" PLUGIN_PRINTF(("PnaclResources::ResourceReady (pp_error=%"
NACL_PRId32", url=%s)\n", pp_error, url.c_str())); NACL_PRId32", url=%s)\n", pp_error, url.c_str()));
// pp_error is checked by GetLoadedFileDesc. // pp_error is checked by GetLoadedFileDesc.
int32_t fd = coordinator_->GetLoadedFileDesc(pp_error, int32_t fd = coordinator_->GetLoadedFileDesc(pp_error,
url, full_url,
"resource " + url); "resource " + url);
if (fd < 0) { if (fd < 0) {
coordinator_->PnaclPpapiError(pp_error); coordinator_->PnaclPpapiError(pp_error);
......
...@@ -35,6 +35,9 @@ class PnaclResources { ...@@ -35,6 +35,9 @@ class PnaclResources {
void Initialize(); void Initialize();
// URLs are all relative to the coordinator's resource_base_url().
// Get the wrapper for the downloaded resource.
nacl::DescWrapper* WrapperForUrl(const nacl::string& url) { nacl::DescWrapper* WrapperForUrl(const nacl::string& url) {
return resource_wrappers_[url]; return resource_wrappers_[url];
} }
...@@ -50,7 +53,9 @@ class PnaclResources { ...@@ -50,7 +53,9 @@ class PnaclResources {
NACL_DISALLOW_COPY_AND_ASSIGN(PnaclResources); NACL_DISALLOW_COPY_AND_ASSIGN(PnaclResources);
// Callback invoked each time one resource has been loaded. // Callback invoked each time one resource has been loaded.
void ResourceReady(int32_t pp_error, const nacl::string& url); void ResourceReady(int32_t pp_error,
const nacl::string& url,
const nacl::string& full_url);
// Callback invoked when all resources have been loaded. // Callback invoked when all resources have been loaded.
void AllLoaded(int32_t pp_error); void AllLoaded(int32_t pp_error);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment