| 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& full_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, |
| 69 if (!plugin_->StreamAsFile(url, ready_callback.pp_completion_callback())) { | 72 resource_urls_[i], |
| 73 full_url); |
| 74 if (!plugin_->StreamAsFile(full_url, |
| 75 ready_callback.pp_completion_callback())) { |
| 70 ErrorInfo error_info; | 76 ErrorInfo error_info; |
| 71 error_info.SetReport(ERROR_UNKNOWN, | 77 error_info.SetReport(ERROR_UNKNOWN, |
| 72 "PnaclCoordinator: Failed to download file: " + | 78 "PnaclCoordinator: Failed to download file: " + |
| 73 url + "\n"); | 79 resource_urls_[i] + "\n"); |
| 74 coordinator_->ReportLoadError(error_info); | 80 coordinator_->ReportLoadError(error_info); |
| 75 coordinator_->PnaclNonPpapiError(); | 81 coordinator_->PnaclNonPpapiError(); |
| 76 break; | 82 break; |
| 77 } | 83 } |
| 78 } | 84 } |
| 79 resource_urls_.clear(); | 85 resource_urls_.clear(); |
| 80 } | 86 } |
| 81 | 87 |
| 82 void PnaclResources::ResourceReady(int32_t pp_error, | 88 void PnaclResources::ResourceReady(int32_t pp_error, |
| 83 const nacl::string& url) { | 89 const nacl::string& url, |
| 90 const nacl::string& full_url) { |
| 84 PLUGIN_PRINTF(("PnaclResources::ResourceReady (pp_error=%" | 91 PLUGIN_PRINTF(("PnaclResources::ResourceReady (pp_error=%" |
| 85 NACL_PRId32", url=%s)\n", pp_error, url.c_str())); | 92 NACL_PRId32", url=%s)\n", pp_error, url.c_str())); |
| 86 // pp_error is checked by GetLoadedFileDesc. | 93 // pp_error is checked by GetLoadedFileDesc. |
| 87 int32_t fd = coordinator_->GetLoadedFileDesc(pp_error, | 94 int32_t fd = coordinator_->GetLoadedFileDesc(pp_error, |
| 88 url, | 95 full_url, |
| 89 "resource " + url); | 96 "resource " + url); |
| 90 if (fd < 0) { | 97 if (fd < 0) { |
| 91 coordinator_->PnaclPpapiError(pp_error); | 98 coordinator_->PnaclPpapiError(pp_error); |
| 92 } else { | 99 } else { |
| 93 resource_wrappers_[url] = | 100 resource_wrappers_[url] = |
| 94 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY); | 101 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY); |
| 95 delayed_callback_->RunIfTime(); | 102 delayed_callback_->RunIfTime(); |
| 96 } | 103 } |
| 97 } | 104 } |
| 98 | 105 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 110 void PnaclResources::RunWhenAllLoaded(pp::CompletionCallback& client_callback) { | 117 void PnaclResources::RunWhenAllLoaded(pp::CompletionCallback& client_callback) { |
| 111 if (all_loaded_) { | 118 if (all_loaded_) { |
| 112 pp::Core* core = pp::Module::Get()->core(); | 119 pp::Core* core = pp::Module::Get()->core(); |
| 113 core->CallOnMainThread(0, client_callback, PP_OK); | 120 core->CallOnMainThread(0, client_callback, PP_OK); |
| 114 } | 121 } |
| 115 client_callback_ = client_callback; | 122 client_callback_ = client_callback; |
| 116 client_callback_is_valid_ = true; | 123 client_callback_is_valid_ = true; |
| 117 } | 124 } |
| 118 | 125 |
| 119 } // namespace plugin | 126 } // namespace plugin |
| OLD | NEW |