| 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, pp::CompletionCallback()); | 118 |
| 119 pp::Module::Get()->core()->CallOnMainThread( |
| 120 0, |
| 121 callback_factory_.NewCallback( |
| 122 &Plugin::LoadNexeAndStart, |
| 123 service_runtime, info, nexe_started_callback)); |
| 119 service_runtime->WaitForNexeStart(); | 124 service_runtime->WaitForNexeStart(); |
| 125 |
| 120 return nexe_started; | 126 return nexe_started; |
| 121 } | 127 } |
| 122 | 128 |
| 123 void Plugin::StartSelLdrOnMainThread(int32_t pp_error, | 129 void Plugin::StartSelLdrOnMainThread(int32_t pp_error, |
| 124 ServiceRuntime* service_runtime, | 130 ServiceRuntime* service_runtime, |
| 125 const SelLdrStartParams& params, | 131 const SelLdrStartParams& params, |
| 126 pp::CompletionCallback callback) { | 132 pp::CompletionCallback callback) { |
| 127 if (pp_error != PP_OK) { | 133 if (pp_error != PP_OK) { |
| 128 PLUGIN_PRINTF(("Plugin::StartSelLdrOnMainThread: non-PP_OK arg " | 134 PLUGIN_PRINTF(("Plugin::StartSelLdrOnMainThread: non-PP_OK arg " |
| 129 "-- SHOULD NOT HAPPEN\n")); | 135 "-- 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", | 184 PLUGIN_PRINTF(("Plugin::LoadNaClModule (service_runtime=%p)\n", |
| 179 static_cast<void*>(service_runtime))); | 185 static_cast<void*>(service_runtime))); |
| 180 if (NULL == service_runtime) { | 186 if (NULL == service_runtime) { |
| 181 error_info.SetReport( | 187 error_info.SetReport( |
| 182 PP_NACL_ERROR_SEL_LDR_INIT, | 188 PP_NACL_ERROR_SEL_LDR_INIT, |
| 183 "sel_ldr init failure " + main_subprocess_.description()); | 189 "sel_ldr init failure " + main_subprocess_.description()); |
| 184 ReportLoadError(error_info); | 190 ReportLoadError(error_info); |
| 185 return; | 191 return; |
| 186 } | 192 } |
| 187 | 193 |
| 194 // We don't take any action once nexe loading has completed, so pass an empty |
| 195 // callback here for |callback|. |
| 188 pp::CompletionCallback callback = callback_factory_.NewCallback( | 196 pp::CompletionCallback callback = callback_factory_.NewCallback( |
| 189 &Plugin::LoadNexeAndStart, file_info, service_runtime, crash_cb); | 197 &Plugin::LoadNexeAndStart, |
| 198 service_runtime, file_info, pp::CompletionCallback()); |
| 190 StartSelLdrOnMainThread( | 199 StartSelLdrOnMainThread( |
| 191 static_cast<int32_t>(PP_OK), service_runtime, params, callback); | 200 static_cast<int32_t>(PP_OK), service_runtime, params, callback); |
| 192 } | 201 } |
| 193 | 202 |
| 194 void Plugin::LoadNexeAndStart(int32_t pp_error, | 203 void Plugin::LoadNexeAndStart(int32_t pp_error, |
| 204 ServiceRuntime* service_runtime, |
| 195 PP_NaClFileInfo file_info, | 205 PP_NaClFileInfo file_info, |
| 196 ServiceRuntime* service_runtime, | 206 const pp::CompletionCallback& callback) { |
| 197 const pp::CompletionCallback& crash_cb) { | 207 CHECK(pp::Module::Get()->core()->IsMainThread()); |
| 198 if (pp_error != PP_OK) | 208 if (pp_error != PP_OK) |
| 199 return; | 209 return; |
| 200 | 210 service_runtime->LoadNexeAndStart(file_info, callback); |
| 201 // We don't take any action once nexe loading has completed, so pass an empty | |
| 202 // callback here for |loaded_cb|. | |
| 203 service_runtime->LoadNexeAndStart(file_info, pp::CompletionCallback(), | |
| 204 crash_cb); | |
| 205 } | 211 } |
| 206 | 212 |
| 207 bool Plugin::LoadNaClModuleContinuationIntern() { | 213 bool Plugin::LoadNaClModuleContinuationIntern() { |
| 208 ErrorInfo error_info; | 214 ErrorInfo error_info; |
| 209 if (!uses_nonsfi_mode_) { | 215 if (!uses_nonsfi_mode_) { |
| 210 if (!main_subprocess_.StartSrpcServices()) { | 216 if (!main_subprocess_.StartSrpcServices()) { |
| 211 // The NaCl process probably crashed. On Linux, a crash causes this | 217 // The NaCl process probably crashed. On Linux, a crash causes this |
| 212 // error, while on other platforms, the error is detected below, when we | 218 // error, while on other platforms, the error is detected below, when we |
| 213 // attempt to start the proxy. Report a module initialization error here, | 219 // attempt to start the proxy. Report a module initialization error here, |
| 214 // to make it less confusing for developers. | 220 // to make it less confusing for developers. |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 | 531 |
| 526 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, | 532 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, |
| 527 int exit_status) { | 533 int exit_status) { |
| 528 DCHECK(pp::Module::Get()->core()->IsMainThread()); | 534 DCHECK(pp::Module::Get()->core()->IsMainThread()); |
| 529 DCHECK(nacl_interface_); | 535 DCHECK(nacl_interface_); |
| 530 nacl_interface_->SetExitStatus(pp_instance(), exit_status); | 536 nacl_interface_->SetExitStatus(pp_instance(), exit_status); |
| 531 } | 537 } |
| 532 | 538 |
| 533 | 539 |
| 534 } // namespace plugin | 540 } // namespace plugin |
| OLD | NEW |