OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "native_client/src/trusted/plugin/pnacl_coordinator.h" | 5 #include "native_client/src/trusted/plugin/pnacl_coordinator.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "native_client/src/include/checked_cast.h" | 10 #include "native_client/src/include/checked_cast.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // All of the component files are native (do not require pnacl translate). | 83 // All of the component files are native (do not require pnacl translate). |
84 pnacl_options->set_translate(false); | 84 pnacl_options->set_translate(false); |
85 // We can only resolve keys in the files/ namespace. | 85 // We can only resolve keys in the files/ namespace. |
86 const nacl::string kFilesPrefix = "files/"; | 86 const nacl::string kFilesPrefix = "files/"; |
87 size_t files_prefix_pos = key.find(kFilesPrefix); | 87 size_t files_prefix_pos = key.find(kFilesPrefix); |
88 if (files_prefix_pos == nacl::string::npos) { | 88 if (files_prefix_pos == nacl::string::npos) { |
89 error_info->SetReport(ERROR_MANIFEST_RESOLVE_URL, | 89 error_info->SetReport(ERROR_MANIFEST_RESOLVE_URL, |
90 "key did not start with files/"); | 90 "key did not start with files/"); |
91 return false; | 91 return false; |
92 } | 92 } |
93 // Append what follows files to the pnacl URL prefix. | 93 // Resolve the full URL to the file. Provide it with a platform-specific |
| 94 // prefix. |
94 nacl::string key_basename = key.substr(kFilesPrefix.length()); | 95 nacl::string key_basename = key.substr(kFilesPrefix.length()); |
95 return ResolveURL(key_basename, full_url, error_info); | 96 return ResolveURL(PnaclUrls::PrependPlatformPrefix(key_basename), |
| 97 full_url, error_info); |
96 } | 98 } |
97 | 99 |
98 private: | 100 private: |
99 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclManifest); | 101 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclManifest); |
100 | 102 |
101 nacl::string manifest_base_url_; | 103 nacl::string manifest_base_url_; |
102 }; | 104 }; |
103 | 105 |
104 ////////////////////////////////////////////////////////////////////// | 106 ////////////////////////////////////////////////////////////////////// |
105 // UMA stat helpers. | 107 // UMA stat helpers. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 pnacl_options, | 232 pnacl_options, |
231 translate_notify_callback); | 233 translate_notify_callback); |
232 coordinator->pnacl_init_time_ = NaClGetTimeOfDayMicroseconds(); | 234 coordinator->pnacl_init_time_ = NaClGetTimeOfDayMicroseconds(); |
233 coordinator->off_the_record_ = | 235 coordinator->off_the_record_ = |
234 plugin->nacl_interface()->IsOffTheRecord(); | 236 plugin->nacl_interface()->IsOffTheRecord(); |
235 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest=%p, " | 237 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest=%p, " |
236 "off_the_record=%d)\n", | 238 "off_the_record=%d)\n", |
237 reinterpret_cast<const void*>(coordinator->manifest_.get()), | 239 reinterpret_cast<const void*>(coordinator->manifest_.get()), |
238 coordinator->off_the_record_)); | 240 coordinator->off_the_record_)); |
239 | 241 |
240 // Load llc and ld. | 242 // Loading resources (e.g. llc and ld nexes) is done with PnaclResources. |
241 std::vector<nacl::string> resource_urls; | |
242 resource_urls.push_back(PnaclUrls::GetLlcUrl()); | |
243 resource_urls.push_back(PnaclUrls::GetLdUrl()); | |
244 pp::CompletionCallback resources_cb = | |
245 coordinator->callback_factory_.NewCallback( | |
246 &PnaclCoordinator::ResourcesDidLoad); | |
247 coordinator->resources_.reset( | 243 coordinator->resources_.reset( |
248 new PnaclResources(plugin, | 244 new PnaclResources(plugin, |
249 coordinator, | 245 coordinator, |
250 coordinator->manifest_.get(), | 246 coordinator->manifest_.get())); |
251 resource_urls, | |
252 resources_cb)); | |
253 CHECK(coordinator->resources_ != NULL); | 247 CHECK(coordinator->resources_ != NULL); |
254 coordinator->resources_->StartLoad(); | 248 |
255 // ResourcesDidLoad will be invoked when all resources have been received. | 249 // The first step of loading resources: read the resource info file. |
| 250 pp::CompletionCallback resource_info_read_cb = |
| 251 coordinator->callback_factory_.NewCallback( |
| 252 &PnaclCoordinator::ResourceInfoWasRead); |
| 253 coordinator->resources_->ReadResourceInfo(PnaclUrls::GetResourceInfoUrl(), |
| 254 resource_info_read_cb); |
256 return coordinator; | 255 return coordinator; |
257 } | 256 } |
258 | 257 |
259 PnaclCoordinator::PnaclCoordinator( | 258 PnaclCoordinator::PnaclCoordinator( |
260 Plugin* plugin, | 259 Plugin* plugin, |
261 const nacl::string& pexe_url, | 260 const nacl::string& pexe_url, |
262 const PnaclOptions& pnacl_options, | 261 const PnaclOptions& pnacl_options, |
263 const pp::CompletionCallback& translate_notify_callback) | 262 const pp::CompletionCallback& translate_notify_callback) |
264 : translate_finish_error_(PP_OK), | 263 : translate_finish_error_(PP_OK), |
265 plugin_(plugin), | 264 plugin_(plugin), |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 | 641 |
643 // Transfer ownership of cache/temp file's wrapper to the coordinator. | 642 // Transfer ownership of cache/temp file's wrapper to the coordinator. |
644 if (cached_nexe_file_ != NULL) { | 643 if (cached_nexe_file_ != NULL) { |
645 translated_fd_.reset(cached_nexe_file_->release_read_wrapper()); | 644 translated_fd_.reset(cached_nexe_file_->release_read_wrapper()); |
646 } else { | 645 } else { |
647 translated_fd_.reset(temp_nexe_file_->release_read_wrapper()); | 646 translated_fd_.reset(temp_nexe_file_->release_read_wrapper()); |
648 } | 647 } |
649 translate_notify_callback_.Run(pp_error); | 648 translate_notify_callback_.Run(pp_error); |
650 } | 649 } |
651 | 650 |
| 651 void PnaclCoordinator::ResourceInfoWasRead(int32_t pp_error) { |
| 652 PLUGIN_PRINTF(("PluginCoordinator::ResourceInfoWasRead (pp_error=%" |
| 653 NACL_PRId32")\n", pp_error)); |
| 654 // Second step of loading resources: call StartLoad. |
| 655 pp::CompletionCallback resources_cb = |
| 656 callback_factory_.NewCallback(&PnaclCoordinator::ResourcesDidLoad); |
| 657 resources_->StartLoad(resources_cb); |
| 658 } |
| 659 |
652 void PnaclCoordinator::ResourcesDidLoad(int32_t pp_error) { | 660 void PnaclCoordinator::ResourcesDidLoad(int32_t pp_error) { |
653 PLUGIN_PRINTF(("PnaclCoordinator::ResourcesDidLoad (pp_error=%" | 661 PLUGIN_PRINTF(("PnaclCoordinator::ResourcesDidLoad (pp_error=%" |
654 NACL_PRId32")\n", pp_error)); | 662 NACL_PRId32")\n", pp_error)); |
655 if (pp_error != PP_OK) { | 663 if (pp_error != PP_OK) { |
656 // Finer-grained error code should have already been reported by | 664 // Finer-grained error code should have already been reported by |
657 // the PnaclResources class. | 665 // the PnaclResources class. |
658 return; | 666 return; |
659 } | 667 } |
660 | 668 |
661 if (!off_the_record_) { | 669 if (!off_the_record_) { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 obj_file_.get(), | 924 obj_file_.get(), |
917 temp_nexe_file_.get(), | 925 temp_nexe_file_.get(), |
918 &error_info_, | 926 &error_info_, |
919 resources_.get(), | 927 resources_.get(), |
920 &pnacl_options_, | 928 &pnacl_options_, |
921 this, | 929 this, |
922 plugin_); | 930 plugin_); |
923 } | 931 } |
924 | 932 |
925 } // namespace plugin | 933 } // namespace plugin |
OLD | NEW |