| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(). | 63 // All resource URLs are relative to the coordinator's resource_base_url(). |
| 64 nacl::string resource_base_url = coordinator_->resource_base_url(); | 64 nacl::string resource_base_url = coordinator_->resource_base_url(); |
| 65 | 65 |
| 66 // Schedule the downloads. | 66 // Schedule the downloads. |
| 67 CHECK(resource_urls_.size() > 0); | 67 CHECK(resource_urls_.size() > 0); |
| 68 for (size_t i = 0; i < resource_urls_.size(); ++i) { | 68 for (size_t i = 0; i < resource_urls_.size(); ++i) { |
| 69 const nacl::string& full_url = resource_base_url + resource_urls_[i]; | 69 const nacl::string& full_url = resource_base_url + resource_urls_[i]; |
| 70 PLUGIN_PRINTF(("PnaclResources::StartDownloads === creating callback\n")); |
| 70 pp::CompletionCallback ready_callback = | 71 pp::CompletionCallback ready_callback = |
| 71 callback_factory_.NewCallback(&PnaclResources::ResourceReady, | 72 callback_factory_.NewCallback(&PnaclResources::ResourceReady, |
| 72 resource_urls_[i], | 73 resource_urls_[i], |
| 73 full_url); | 74 full_url); |
| 75 PLUGIN_PRINTF(("PnaclResources::StartDownloads === created callback\n")); |
| 74 if (!plugin_->StreamAsFile(full_url, | 76 if (!plugin_->StreamAsFile(full_url, |
| 75 ready_callback.pp_completion_callback())) { | 77 ready_callback.pp_completion_callback())) { |
| 76 ErrorInfo error_info; | 78 coordinator_->ReportNonPpapiError( |
| 77 error_info.SetReport(ERROR_UNKNOWN, | 79 "PnaclCoordinator: Failed to download file: " + |
| 78 "PnaclCoordinator: Failed to download file: " + | 80 resource_urls_[i] + "\n"); |
| 79 resource_urls_[i] + "\n"); | |
| 80 coordinator_->ReportLoadError(error_info); | |
| 81 coordinator_->PnaclNonPpapiError(); | |
| 82 break; | 81 break; |
| 83 } | 82 } |
| 83 PLUGIN_PRINTF(("PnaclResources::StartDownloads === invoked SAF\n")); |
| 84 } | 84 } |
| 85 resource_urls_.clear(); | 85 resource_urls_.clear(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void PnaclResources::ResourceReady(int32_t pp_error, | 88 void PnaclResources::ResourceReady(int32_t pp_error, |
| 89 const nacl::string& url, | 89 const nacl::string& url, |
| 90 const nacl::string& full_url) { | 90 const nacl::string& full_url) { |
| 91 PLUGIN_PRINTF(("PnaclResources::ResourceReady (pp_error=%" | 91 PLUGIN_PRINTF(("PnaclResources::ResourceReady (pp_error=%" |
| 92 NACL_PRId32", url=%s)\n", pp_error, url.c_str())); | 92 NACL_PRId32", url=%s)\n", pp_error, url.c_str())); |
| 93 // pp_error is checked by GetLoadedFileDesc. | 93 // pp_error is checked by GetLoadedFileDesc. |
| 94 int32_t fd = coordinator_->GetLoadedFileDesc(pp_error, | 94 int32_t fd = coordinator_->GetLoadedFileDesc(pp_error, |
| 95 full_url, | 95 full_url, |
| 96 "resource " + url); | 96 "resource " + url); |
| 97 if (fd < 0) { | 97 if (fd < 0) { |
| 98 coordinator_->PnaclPpapiError(pp_error); | 98 coordinator_->ReportPpapiError(pp_error, |
| 99 "PnaclResources: get fd failed.\n"); |
| 99 } else { | 100 } else { |
| 100 resource_wrappers_[url] = | 101 resource_wrappers_[url] = |
| 101 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY); | 102 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY); |
| 102 delayed_callback_->RunIfTime(); | 103 delayed_callback_->RunIfTime(); |
| 103 } | 104 } |
| 104 } | 105 } |
| 105 | 106 |
| 106 void PnaclResources::AllLoaded(int32_t pp_error) { | 107 void PnaclResources::AllLoaded(int32_t pp_error) { |
| 107 PLUGIN_PRINTF(("PnaclResources::AllLoaded (pp_error=%"NACL_PRId32")\n", | 108 PLUGIN_PRINTF(("PnaclResources::AllLoaded (pp_error=%"NACL_PRId32")\n", |
| 108 pp_error)); | 109 pp_error)); |
| 109 all_loaded_ = true; | 110 all_loaded_ = true; |
| 110 // Run the client-specified callback if one was set. | 111 // Run the client-specified callback if one was set. |
| 111 if (client_callback_is_valid_) { | 112 if (client_callback_is_valid_) { |
| 112 pp::Core* core = pp::Module::Get()->core(); | 113 pp::Core* core = pp::Module::Get()->core(); |
| 113 core->CallOnMainThread(0, client_callback_, PP_OK); | 114 core->CallOnMainThread(0, client_callback_, PP_OK); |
| 114 } | 115 } |
| 115 } | 116 } |
| 116 | 117 |
| 117 void PnaclResources::RunWhenAllLoaded(pp::CompletionCallback& client_callback) { | 118 void PnaclResources::RunWhenAllLoaded(pp::CompletionCallback& client_callback) { |
| 118 if (all_loaded_) { | 119 if (all_loaded_) { |
| 119 pp::Core* core = pp::Module::Get()->core(); | 120 pp::Core* core = pp::Module::Get()->core(); |
| 120 core->CallOnMainThread(0, client_callback, PP_OK); | 121 core->CallOnMainThread(0, client_callback, PP_OK); |
| 121 } | 122 } |
| 122 client_callback_ = client_callback; | 123 client_callback_ = client_callback; |
| 123 client_callback_is_valid_ = true; | 124 client_callback_is_valid_ = true; |
| 124 } | 125 } |
| 125 | 126 |
| 126 } // namespace plugin | 127 } // namespace plugin |
| OLD | NEW |