| 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_resources.h" | 5 #include "native_client/src/trusted/plugin/pnacl_resources.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "native_client/src/include/portability_io.h" | 10 #include "native_client/src/include/portability_io.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // Create a counter (barrier) callback to track when all of the resources | 38 // Create a counter (barrier) callback to track when all of the resources |
| 39 // are loaded. | 39 // are loaded. |
| 40 uint32_t resource_count = static_cast<uint32_t>(resource_urls_.size()); | 40 uint32_t resource_count = static_cast<uint32_t>(resource_urls_.size()); |
| 41 delayed_callback_.reset( | 41 delayed_callback_.reset( |
| 42 new DelayedCallback(all_loaded_callback_, resource_count)); | 42 new DelayedCallback(all_loaded_callback_, resource_count)); |
| 43 | 43 |
| 44 // Schedule the downloads. | 44 // Schedule the downloads. |
| 45 CHECK(resource_urls_.size() > 0); | 45 CHECK(resource_urls_.size() > 0); |
| 46 for (size_t i = 0; i < resource_urls_.size(); ++i) { | 46 for (size_t i = 0; i < resource_urls_.size(); ++i) { |
| 47 nacl::string full_url; | 47 nacl::string full_url; |
| 48 bool permit_extension_url = false; | |
| 49 ErrorInfo error_info; | 48 ErrorInfo error_info; |
| 50 if (!manifest_->ResolveURL(resource_urls_[i], &full_url, | 49 if (!manifest_->ResolveURL(resource_urls_[i], &full_url, &error_info)) { |
| 51 &permit_extension_url, &error_info)) { | |
| 52 coordinator_->ReportNonPpapiError(nacl::string("failed to resolve ") + | 50 coordinator_->ReportNonPpapiError(nacl::string("failed to resolve ") + |
| 53 resource_urls_[i] + ": " + | 51 resource_urls_[i] + ": " + |
| 54 error_info.message() + "."); | 52 error_info.message() + "."); |
| 55 break; | 53 break; |
| 56 } | 54 } |
| 57 pp::CompletionCallback ready_callback = | 55 pp::CompletionCallback ready_callback = |
| 58 callback_factory_.NewCallback(&PnaclResources::ResourceReady, | 56 callback_factory_.NewCallback(&PnaclResources::ResourceReady, |
| 59 resource_urls_[i], | 57 resource_urls_[i], |
| 60 full_url); | 58 full_url); |
| 61 if (!plugin_->StreamAsFile(full_url, | 59 if (!plugin_->StreamAsFile(full_url, |
| 62 permit_extension_url, | |
| 63 ready_callback.pp_completion_callback())) { | 60 ready_callback.pp_completion_callback())) { |
| 64 coordinator_->ReportNonPpapiError(nacl::string("failed to download ") + | 61 coordinator_->ReportNonPpapiError(nacl::string("failed to download ") + |
| 65 resource_urls_[i] + "."); | 62 resource_urls_[i] + "."); |
| 66 break; | 63 break; |
| 67 } | 64 } |
| 68 } | 65 } |
| 69 } | 66 } |
| 70 | 67 |
| 71 void PnaclResources::ResourceReady(int32_t pp_error, | 68 void PnaclResources::ResourceReady(int32_t pp_error, |
| 72 const nacl::string& url, | 69 const nacl::string& url, |
| 73 const nacl::string& full_url) { | 70 const nacl::string& full_url) { |
| 74 PLUGIN_PRINTF(("PnaclResources::ResourceReady (pp_error=%" | 71 PLUGIN_PRINTF(("PnaclResources::ResourceReady (pp_error=%" |
| 75 NACL_PRId32", url=%s)\n", pp_error, url.c_str())); | 72 NACL_PRId32", url=%s)\n", pp_error, url.c_str())); |
| 76 // pp_error is checked by GetLoadedFileDesc. | 73 // pp_error is checked by GetLoadedFileDesc. |
| 77 int32_t fd = coordinator_->GetLoadedFileDesc(pp_error, | 74 int32_t fd = coordinator_->GetLoadedFileDesc(pp_error, |
| 78 full_url, | 75 full_url, |
| 79 "resource " + url); | 76 "resource " + url); |
| 80 if (fd < 0) { | 77 if (fd < 0) { |
| 81 coordinator_->ReportPpapiError(pp_error, | 78 coordinator_->ReportPpapiError(pp_error, |
| 82 "PnaclResources::ResourceReady failed."); | 79 "PnaclResources::ResourceReady failed."); |
| 83 } else { | 80 } else { |
| 84 resource_wrappers_[url] = | 81 resource_wrappers_[url] = |
| 85 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY); | 82 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY); |
| 86 delayed_callback_->RunIfTime(); | 83 delayed_callback_->RunIfTime(); |
| 87 } | 84 } |
| 88 } | 85 } |
| 89 | 86 |
| 90 } // namespace plugin | 87 } // namespace plugin |
| OLD | NEW |