| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 return; | 53 return; |
| 54 } | 54 } |
| 55 pp::CompletionCallback all_loaded_callback = | 55 pp::CompletionCallback all_loaded_callback = |
| 56 callback_factory_.NewCallback(&PnaclResources::AllLoaded); | 56 callback_factory_.NewCallback(&PnaclResources::AllLoaded); |
| 57 // Create a counter (barrier) callback to track when all of the resources | 57 // Create a counter (barrier) callback to track when all of the resources |
| 58 // are loaded. | 58 // are loaded. |
| 59 uint32_t resource_count = static_cast<uint32_t>(resource_urls_.size()); | 59 uint32_t resource_count = static_cast<uint32_t>(resource_urls_.size()); |
| 60 delayed_callback_.reset( | 60 delayed_callback_.reset( |
| 61 new DelayedCallback(all_loaded_callback, resource_count)); | 61 new DelayedCallback(all_loaded_callback, resource_count)); |
| 62 | 62 |
| 63 // All resource URLs are relative to the coordinator's resource_base_url(). |
| 64 nacl::string resource_base_url = coordinator_->resource_base_url(); |
| 65 |
| 63 // Schedule the downloads. | 66 // Schedule the downloads. |
| 64 CHECK(resource_urls_.size() > 0); | 67 CHECK(resource_urls_.size() > 0); |
| 65 for (size_t i = 0; i < resource_urls_.size(); ++i) { | 68 for (size_t i = 0; i < resource_urls_.size(); ++i) { |
| 66 const nacl::string& url = resource_urls_[i]; | 69 const nacl::string& url = resource_base_url + resource_urls_[i]; |
| 67 pp::CompletionCallback ready_callback = | 70 pp::CompletionCallback ready_callback = |
| 68 callback_factory_.NewCallback(&PnaclResources::ResourceReady, url); | 71 callback_factory_.NewCallback(&PnaclResources::ResourceReady, |
| 72 resource_urls_[i]); |
| 69 if (!plugin_->StreamAsFile(url, ready_callback.pp_completion_callback())) { | 73 if (!plugin_->StreamAsFile(url, ready_callback.pp_completion_callback())) { |
| 70 ErrorInfo error_info; | 74 ErrorInfo error_info; |
| 71 error_info.SetReport(ERROR_UNKNOWN, | 75 error_info.SetReport(ERROR_UNKNOWN, |
| 72 "PnaclCoordinator: Failed to download file: " + | 76 "PnaclCoordinator: Failed to download file: " + |
| 73 url + "\n"); | 77 url + "\n"); |
| 74 coordinator_->ReportLoadError(error_info); | 78 coordinator_->ReportLoadError(error_info); |
| 75 coordinator_->PnaclNonPpapiError(); | 79 coordinator_->PnaclNonPpapiError(); |
| 76 break; | 80 break; |
| 77 } | 81 } |
| 78 } | 82 } |
| 79 resource_urls_.clear(); | 83 resource_urls_.clear(); |
| 80 } | 84 } |
| 81 | 85 |
| 82 void PnaclResources::ResourceReady(int32_t pp_error, | 86 void PnaclResources::ResourceReady(int32_t pp_error, |
| 83 const nacl::string& url) { | 87 const nacl::string& url) { |
| 84 PLUGIN_PRINTF(("PnaclResources::ResourceReady (pp_error=%" | 88 PLUGIN_PRINTF(("PnaclResources::ResourceReady (pp_error=%" |
| 85 NACL_PRId32", url=%s)\n", pp_error, url.c_str())); | 89 NACL_PRId32", url=%s)\n", pp_error, url.c_str())); |
| 86 // pp_error is checked by GetLoadedFileDesc. | 90 // pp_error is checked by GetLoadedFileDesc. |
| 91 nacl::string full_url = coordinator_->resource_base_url() + url; |
| 87 int32_t fd = coordinator_->GetLoadedFileDesc(pp_error, | 92 int32_t fd = coordinator_->GetLoadedFileDesc(pp_error, |
| 88 url, | 93 full_url, |
| 89 "resource " + url); | 94 "resource " + url); |
| 90 if (fd < 0) { | 95 if (fd < 0) { |
| 91 coordinator_->PnaclPpapiError(pp_error); | 96 coordinator_->PnaclPpapiError(pp_error); |
| 92 } else { | 97 } else { |
| 93 resource_wrappers_[url] = | 98 resource_wrappers_[url] = |
| 94 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY); | 99 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY); |
| 95 delayed_callback_->RunIfTime(); | 100 delayed_callback_->RunIfTime(); |
| 96 } | 101 } |
| 97 } | 102 } |
| 98 | 103 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 110 void PnaclResources::RunWhenAllLoaded(pp::CompletionCallback& client_callback) { | 115 void PnaclResources::RunWhenAllLoaded(pp::CompletionCallback& client_callback) { |
| 111 if (all_loaded_) { | 116 if (all_loaded_) { |
| 112 pp::Core* core = pp::Module::Get()->core(); | 117 pp::Core* core = pp::Module::Get()->core(); |
| 113 core->CallOnMainThread(0, client_callback, PP_OK); | 118 core->CallOnMainThread(0, client_callback, PP_OK); |
| 114 } | 119 } |
| 115 client_callback_ = client_callback; | 120 client_callback_ = client_callback; |
| 116 client_callback_is_valid_ = true; | 121 client_callback_is_valid_ = true; |
| 117 } | 122 } |
| 118 | 123 |
| 119 } // namespace plugin | 124 } // namespace plugin |
| OLD | NEW |