diff options
author | teravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-05 18:27:58 +0000 |
---|---|---|
committer | teravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-05 18:27:58 +0000 |
commit | 566255d701f1e40f1a75901946a44329f1cd75f5 (patch) | |
tree | dafd1a4d7635ea0caf11bdd934b2c05ad9483b47 | |
parent | 2930722efc7e54eafb86ee09ed076245fdb013a7 (diff) | |
download | chromium_src-566255d701f1e40f1a75901946a44329f1cd75f5.zip chromium_src-566255d701f1e40f1a75901946a44329f1cd75f5.tar.gz chromium_src-566255d701f1e40f1a75901946a44329f1cd75f5.tar.bz2 |
Pepper: Preparation for async LoadAndStartNexe.
This is a preperatory change for moving nexe loading and starting from SRPC to
Chrome IPC. It's much simpler from an IPC and threading perspective if the new
IPC traffic is asynchronous. This change updates Plugin::LoadAndStartNexe() to
prepare for having an asynchronous interface in ServiceRuntime.
BUG=333950
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=275097
R=dmichael@chromium.org
Review URL: https://codereview.chromium.org/316013005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275196 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 62 insertions, 25 deletions
diff --git a/ppapi/native_client/src/trusted/plugin/plugin.cc b/ppapi/native_client/src/trusted/plugin/plugin.cc index b70468b..58276d4 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.cc +++ b/ppapi/native_client/src/trusted/plugin/plugin.cc @@ -116,12 +116,16 @@ bool Plugin::LoadNaClModuleFromBackgroundThread( info.token_hi = 0; // Now actually load the nexe, which can happen on a background thread. - bool nexe_loaded = service_runtime->LoadNexeAndStart( - info, pp::BlockUntilComplete()); - PLUGIN_PRINTF(("Plugin::LoadNaClModuleFromBackgroundThread " - "(nexe_loaded=%d)\n", - nexe_loaded)); - return nexe_loaded; + // + // We can't use pp::BlockUntilComplete() inside an in-process plugin, so we + // have to roll our own blocking logic, similar to WaitForSelLdrStart() + // above, except without timeout logic. + bool nexe_started = false; + pp::CompletionCallback started_cb = callback_factory_.NewCallback( + &Plugin::SignalNexeStarted, &nexe_started, service_runtime); + service_runtime->LoadNexeAndStart(info, started_cb, pp::CompletionCallback()); + service_runtime->WaitForNexeStart(); + return nexe_started; } void Plugin::StartSelLdrOnMainThread(int32_t pp_error, @@ -144,6 +148,13 @@ void Plugin::SignalStartSelLdrDone(int32_t pp_error, service_runtime->SignalStartSelLdrDone(); } +void Plugin::SignalNexeStarted(int32_t pp_error, + bool* started, + ServiceRuntime* service_runtime) { + *started = (pp_error == PP_OK); + service_runtime->SignalNexeStarted(); +} + void Plugin::LoadNaClModule(PP_NaClFileInfo file_info, bool uses_nonsfi_mode, bool enable_dyncode_syscalls, @@ -186,8 +197,7 @@ void Plugin::LoadNaClModule(PP_NaClFileInfo file_info, } pp::CompletionCallback callback = callback_factory_.NewCallback( - &Plugin::LoadNexeAndStart, file_info, service_runtime, - crash_cb); + &Plugin::LoadNexeAndStart, file_info, service_runtime, crash_cb); StartSelLdrOnMainThread( static_cast<int32_t>(PP_OK), service_runtime, params, callback); } @@ -199,14 +209,10 @@ void Plugin::LoadNexeAndStart(int32_t pp_error, if (pp_error != PP_OK) return; - // Now actually load the nexe, which can happen on a background thread. - bool nexe_loaded = service_runtime->LoadNexeAndStart(file_info, crash_cb); - PLUGIN_PRINTF(("Plugin::LoadNaClModule (nexe_loaded=%d)\n", - nexe_loaded)); - if (nexe_loaded) { - PLUGIN_PRINTF(("Plugin::LoadNaClModule (%s)\n", - main_subprocess_.detailed_description().c_str())); - } + // We don't take any action once nexe loading has completed, so pass an empty + // callback here for |loaded_cb|. + service_runtime->LoadNexeAndStart(file_info, pp::CompletionCallback(), + crash_cb); } bool Plugin::LoadNaClModuleContinuationIntern() { diff --git a/ppapi/native_client/src/trusted/plugin/plugin.h b/ppapi/native_client/src/trusted/plugin/plugin.h index c10e0e9..54aa4dd 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.h +++ b/ppapi/native_client/src/trusted/plugin/plugin.h @@ -159,10 +159,17 @@ class Plugin : public pp::Instance { pp::CompletionCallback callback); // Signals that StartSelLdr has finished. + // This is invoked on the main thread. void SignalStartSelLdrDone(int32_t pp_error, bool* started, ServiceRuntime* service_runtime); + // Signals that the nexe is started. + // This is invoked on the main thread. + void SignalNexeStarted(int32_t pp_error, + bool* started, + ServiceRuntime* service_runtime); + void LoadNexeAndStart(int32_t pp_error, PP_NaClFileInfo file_info, ServiceRuntime* service_runtime, diff --git a/ppapi/native_client/src/trusted/plugin/service_runtime.cc b/ppapi/native_client/src/trusted/plugin/service_runtime.cc index 75ccb1c..b186832 100644 --- a/ppapi/native_client/src/trusted/plugin/service_runtime.cc +++ b/ppapi/native_client/src/trusted/plugin/service_runtime.cc @@ -446,7 +446,8 @@ ServiceRuntime::ServiceRuntime(Plugin* plugin, anchor_(new nacl::WeakRefAnchor()), rev_interface_(new PluginReverseInterface(anchor_, plugin, this, init_done_cb, crash_cb)), - start_sel_ldr_done_(false) { + start_sel_ldr_done_(false), + nexe_started_(false) { NaClSrpcChannelInitialize(&command_channel_); NaClXMutexCtor(&mu_); NaClXCondVarCtor(&cond_); @@ -664,7 +665,22 @@ void ServiceRuntime::SignalStartSelLdrDone() { NaClXCondVarSignal(&cond_); } -bool ServiceRuntime::LoadNexeAndStart(PP_NaClFileInfo file_info, +void ServiceRuntime::WaitForNexeStart() { + nacl::MutexLocker take(&mu_); + while (!nexe_started_) + NaClXCondVarWait(&cond_, &mu_); + // Reset nexe_started_ here in case we run again. + nexe_started_ = false; +} + +void ServiceRuntime::SignalNexeStarted() { + nacl::MutexLocker take(&mu_); + nexe_started_ = true; + NaClXCondVarSignal(&cond_); +} + +void ServiceRuntime::LoadNexeAndStart(PP_NaClFileInfo file_info, + const pp::CompletionCallback& started_cb, const pp::CompletionCallback& crash_cb) { NaClLog(4, "ServiceRuntime::LoadNexeAndStart (handle_valid=%d " "token_lo=%" NACL_PRIu64 " token_hi=%" NACL_PRIu64 ")\n", @@ -693,11 +709,12 @@ bool ServiceRuntime::LoadNexeAndStart(PP_NaClFileInfo file_info, } else { NaClLog(LOG_ERROR, "Reverse service thread will pick up crash log\n"); } - return false; + pp::Module::Get()->core()->CallOnMainThread(0, started_cb, PP_ERROR_FAILED); + return; } NaClLog(4, "ServiceRuntime::LoadNexeAndStart (return 1)\n"); - return true; + pp::Module::Get()->core()->CallOnMainThread(0, started_cb, PP_OK); } SrpcClient* ServiceRuntime::SetupAppChannel() { diff --git a/ppapi/native_client/src/trusted/plugin/service_runtime.h b/ppapi/native_client/src/trusted/plugin/service_runtime.h index 7f37c92..52d22b1 100644 --- a/ppapi/native_client/src/trusted/plugin/service_runtime.h +++ b/ppapi/native_client/src/trusted/plugin/service_runtime.h @@ -183,14 +183,20 @@ class ServiceRuntime { // Signal to waiting threads that StartSelLdr is complete (either // successfully or unsuccessfully). - // Done externally, in case external users want to write to shared - // memory that is yet to be fenced. void SignalStartSelLdrDone(); + // If starting the nexe from a background thread, wait for the nexe to + // actually start. + void WaitForNexeStart(); + + // Signal to waiting threads that LoadNexeAndStart is complete (either + // successfully or unsuccessfully). + void SignalNexeStarted(); + // Establish an SrpcClient to the sel_ldr instance and load the nexe. // The nexe to be started is passed through |file_info|. - // On success, returns true. On failure, returns false. - bool LoadNexeAndStart(PP_NaClFileInfo file_info, + void LoadNexeAndStart(PP_NaClFileInfo file_info, + const pp::CompletionCallback& started_cb, const pp::CompletionCallback& crash_cb); // Starts the application channel to the nexe. @@ -229,10 +235,11 @@ class ServiceRuntime { PluginReverseInterface* rev_interface_; - // Mutex and CondVar to protect start_sel_ldr_done_. + // Mutex and CondVar to protect start_sel_ldr_done_ and nexe_started_. NaClMutex mu_; NaClCondVar cond_; bool start_sel_ldr_done_; + bool nexe_started_; }; } // namespace plugin |