| 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 "ppapi/native_client/src/trusted/plugin/plugin.h" | 5 #include "ppapi/native_client/src/trusted/plugin/plugin.h" |
| 6 | 6 |
| 7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
| 8 #include <sys/types.h> | 8 #include <sys/types.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 info.handle = file_handle; | 106 info.handle = file_handle; |
| 107 info.token_lo = 0; | 107 info.token_lo = 0; |
| 108 info.token_hi = 0; | 108 info.token_hi = 0; |
| 109 | 109 |
| 110 // Now actually load the nexe, which can happen on a background thread. | 110 // Now actually load the nexe, which can happen on a background thread. |
| 111 // | 111 // |
| 112 // We can't use pp::BlockUntilComplete() inside an in-process plugin, so we | 112 // We can't use pp::BlockUntilComplete() inside an in-process plugin, so we |
| 113 // have to roll our own blocking logic, similar to WaitForSelLdrStart() | 113 // have to roll our own blocking logic, similar to WaitForSelLdrStart() |
| 114 // above, except without timeout logic. | 114 // above, except without timeout logic. |
| 115 bool nexe_started = false; | 115 bool nexe_started = false; |
| 116 pp::CompletionCallback started_cb = callback_factory_.NewCallback( | 116 pp::CompletionCallback nexe_started_callback = callback_factory_.NewCallback( |
| 117 &Plugin::SignalNexeStarted, &nexe_started, service_runtime); | 117 &Plugin::SignalNexeStarted, &nexe_started, service_runtime); |
| 118 service_runtime->LoadNexeAndStart(info, started_cb); | 118 pp::Module::Get()->core()->CallOnMainThread( |
| 119 0, |
| 120 callback_factory_.NewCallback( |
| 121 &Plugin::LoadNexeAndStart, |
| 122 service_runtime, info, nexe_started_callback)); |
| 119 service_runtime->WaitForNexeStart(); | 123 service_runtime->WaitForNexeStart(); |
| 124 |
| 120 return nexe_started; | 125 return nexe_started; |
| 121 } | 126 } |
| 122 | 127 |
| 123 void Plugin::StartSelLdrOnMainThread(int32_t pp_error, | 128 void Plugin::StartSelLdrOnMainThread(int32_t pp_error, |
| 124 ServiceRuntime* service_runtime, | 129 ServiceRuntime* service_runtime, |
| 125 const SelLdrStartParams& params, | 130 const SelLdrStartParams& params, |
| 126 pp::CompletionCallback callback) { | 131 pp::CompletionCallback callback) { |
| 127 if (pp_error != PP_OK) { | 132 if (pp_error != PP_OK) { |
| 128 PLUGIN_PRINTF(("Plugin::StartSelLdrOnMainThread: non-PP_OK arg " | 133 PLUGIN_PRINTF(("Plugin::StartSelLdrOnMainThread: non-PP_OK arg " |
| 129 "-- SHOULD NOT HAPPEN\n")); | 134 "-- SHOULD NOT HAPPEN\n")); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 PLUGIN_PRINTF(("Plugin::LoadNaClModule (service_runtime=%p)\n", | 183 PLUGIN_PRINTF(("Plugin::LoadNaClModule (service_runtime=%p)\n", |
| 179 static_cast<void*>(service_runtime))); | 184 static_cast<void*>(service_runtime))); |
| 180 if (NULL == service_runtime) { | 185 if (NULL == service_runtime) { |
| 181 error_info.SetReport( | 186 error_info.SetReport( |
| 182 PP_NACL_ERROR_SEL_LDR_INIT, | 187 PP_NACL_ERROR_SEL_LDR_INIT, |
| 183 "sel_ldr init failure " + main_subprocess_.description()); | 188 "sel_ldr init failure " + main_subprocess_.description()); |
| 184 ReportLoadError(error_info); | 189 ReportLoadError(error_info); |
| 185 return; | 190 return; |
| 186 } | 191 } |
| 187 | 192 |
| 193 // We don't take any action once nexe loading has completed, so pass an empty |
| 194 // callback here for |callback|. |
| 188 pp::CompletionCallback callback = callback_factory_.NewCallback( | 195 pp::CompletionCallback callback = callback_factory_.NewCallback( |
| 189 &Plugin::LoadNexeAndStart, file_info, service_runtime); | 196 &Plugin::LoadNexeAndStart, |
| 197 service_runtime, file_info, pp::CompletionCallback()); |
| 190 StartSelLdrOnMainThread( | 198 StartSelLdrOnMainThread( |
| 191 static_cast<int32_t>(PP_OK), service_runtime, params, callback); | 199 static_cast<int32_t>(PP_OK), service_runtime, params, callback); |
| 192 } | 200 } |
| 193 | 201 |
| 194 void Plugin::LoadNexeAndStart(int32_t pp_error, | 202 void Plugin::LoadNexeAndStart(int32_t pp_error, |
| 203 ServiceRuntime* service_runtime, |
| 195 PP_NaClFileInfo file_info, | 204 PP_NaClFileInfo file_info, |
| 196 ServiceRuntime* service_runtime) { | 205 const pp::CompletionCallback& callback) { |
| 206 CHECK(pp::Module::Get()->core()->IsMainThread()); |
| 197 if (pp_error != PP_OK) | 207 if (pp_error != PP_OK) |
| 198 return; | 208 return; |
| 199 | 209 service_runtime->LoadNexeAndStart(file_info, callback); |
| 200 // We don't take any action once nexe loading has completed, so pass an empty | |
| 201 // callback here for |loaded_cb|. | |
| 202 service_runtime->LoadNexeAndStart(file_info, pp::CompletionCallback()); | |
| 203 } | 210 } |
| 204 | 211 |
| 205 bool Plugin::LoadNaClModuleContinuationIntern() { | 212 bool Plugin::LoadNaClModuleContinuationIntern() { |
| 206 ErrorInfo error_info; | 213 ErrorInfo error_info; |
| 207 if (!uses_nonsfi_mode_) { | 214 if (!uses_nonsfi_mode_) { |
| 208 if (!main_subprocess_.StartSrpcServices()) { | 215 if (!main_subprocess_.StartSrpcServices()) { |
| 209 // The NaCl process probably crashed. On Linux, a crash causes this | 216 // The NaCl process probably crashed. On Linux, a crash causes this |
| 210 // error, while on other platforms, the error is detected below, when we | 217 // error, while on other platforms, the error is detected below, when we |
| 211 // attempt to start the proxy. Report a module initialization error here, | 218 // attempt to start the proxy. Report a module initialization error here, |
| 212 // to make it less confusing for developers. | 219 // to make it less confusing for developers. |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 530 |
| 524 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, | 531 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, |
| 525 int exit_status) { | 532 int exit_status) { |
| 526 DCHECK(pp::Module::Get()->core()->IsMainThread()); | 533 DCHECK(pp::Module::Get()->core()->IsMainThread()); |
| 527 DCHECK(nacl_interface_); | 534 DCHECK(nacl_interface_); |
| 528 nacl_interface_->SetExitStatus(pp_instance(), exit_status); | 535 nacl_interface_->SetExitStatus(pp_instance(), exit_status); |
| 529 } | 536 } |
| 530 | 537 |
| 531 | 538 |
| 532 } // namespace plugin | 539 } // namespace plugin |
| OLD | NEW |