| OLD | NEW |
| (Empty) |
| 1 /* -*- c++ -*- */ | |
| 2 /* | |
| 3 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 // A class containing information regarding a socket connection to a | |
| 9 // service runtime instance. | |
| 10 | |
| 11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SERVICE_RUNTIME_H_ | |
| 12 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SERVICE_RUNTIME_H_ | |
| 13 | |
| 14 #include "native_client/src/include/nacl_macros.h" | |
| 15 #include "native_client/src/include/nacl_scoped_ptr.h" | |
| 16 #include "native_client/src/public/imc_types.h" | |
| 17 #include "native_client/src/shared/platform/nacl_sync.h" | |
| 18 #include "native_client/src/shared/srpc/nacl_srpc.h" | |
| 19 | |
| 20 #include "ppapi/cpp/completion_callback.h" | |
| 21 #include "ppapi/native_client/src/trusted/plugin/utility.h" | |
| 22 | |
| 23 struct NaClFileInfo; | |
| 24 | |
| 25 namespace plugin { | |
| 26 | |
| 27 class ErrorInfo; | |
| 28 class Plugin; | |
| 29 class SelLdrLauncherChrome; | |
| 30 class SrpcClient; | |
| 31 class ServiceRuntime; | |
| 32 | |
| 33 // Struct of params used by StartSelLdr. Use a struct so that callback | |
| 34 // creation templates aren't overwhelmed with too many parameters. | |
| 35 struct SelLdrStartParams { | |
| 36 SelLdrStartParams(const std::string& url, | |
| 37 const PP_NaClFileInfo& file_info, | |
| 38 PP_NaClAppProcessType process_type) | |
| 39 : url(url), | |
| 40 file_info(file_info), | |
| 41 process_type(process_type) { | |
| 42 } | |
| 43 std::string url; | |
| 44 PP_NaClFileInfo file_info; | |
| 45 PP_NaClAppProcessType process_type; | |
| 46 }; | |
| 47 | |
| 48 // ServiceRuntime abstracts a NativeClient sel_ldr instance. | |
| 49 class ServiceRuntime { | |
| 50 public: | |
| 51 ServiceRuntime(Plugin* plugin, | |
| 52 PP_Instance pp_instance, | |
| 53 bool main_service_runtime, | |
| 54 bool uses_nonsfi_mode); | |
| 55 // The destructor terminates the sel_ldr process. | |
| 56 ~ServiceRuntime(); | |
| 57 | |
| 58 // Spawn the sel_ldr instance. | |
| 59 void StartSelLdr(const SelLdrStartParams& params, | |
| 60 pp::CompletionCallback callback); | |
| 61 | |
| 62 // If starting sel_ldr from a background thread, wait for sel_ldr to | |
| 63 // actually start. Returns |false| if timed out waiting for the process | |
| 64 // to start. Otherwise, returns |true| if StartSelLdr is complete | |
| 65 // (either successfully or unsuccessfully). | |
| 66 bool WaitForSelLdrStart(); | |
| 67 | |
| 68 // Signal to waiting threads that StartSelLdr is complete (either | |
| 69 // successfully or unsuccessfully). | |
| 70 void SignalStartSelLdrDone(); | |
| 71 | |
| 72 // If starting the nexe from a background thread, wait for the nexe to | |
| 73 // actually start. Returns |true| is the nexe started successfully. | |
| 74 bool WaitForNexeStart(); | |
| 75 | |
| 76 // Returns |true| if WaitForSelLdrStart() timed out. | |
| 77 bool SelLdrWaitTimedOut(); | |
| 78 | |
| 79 // Signal to waiting threads that LoadNexeAndStart is complete (either | |
| 80 // successfully or unsuccessfully). | |
| 81 void SignalNexeStarted(bool ok); | |
| 82 | |
| 83 // Establish an SrpcClient to the sel_ldr instance and start the nexe. | |
| 84 // This function must be called on the main thread. | |
| 85 // This function must only be called once. | |
| 86 void StartNexe(); | |
| 87 | |
| 88 // Starts the application channel to the nexe. | |
| 89 SrpcClient* SetupAppChannel(); | |
| 90 | |
| 91 bool RemoteLog(int severity, const std::string& msg); | |
| 92 Plugin* plugin() const { return plugin_; } | |
| 93 void Shutdown(); | |
| 94 | |
| 95 bool main_service_runtime() const { return main_service_runtime_; } | |
| 96 | |
| 97 private: | |
| 98 NACL_DISALLOW_COPY_AND_ASSIGN(ServiceRuntime); | |
| 99 bool StartNexeInternal(); | |
| 100 | |
| 101 bool SetupCommandChannel(); | |
| 102 bool StartModule(); | |
| 103 void ReapLogs(); | |
| 104 | |
| 105 void ReportLoadError(const ErrorInfo& error_info); | |
| 106 | |
| 107 NaClSrpcChannel command_channel_; | |
| 108 Plugin* plugin_; | |
| 109 PP_Instance pp_instance_; | |
| 110 bool main_service_runtime_; | |
| 111 bool uses_nonsfi_mode_; | |
| 112 nacl::scoped_ptr<SelLdrLauncherChrome> subprocess_; | |
| 113 | |
| 114 // Mutex and CondVar to protect start_sel_ldr_done_ and nexe_started_. | |
| 115 NaClMutex mu_; | |
| 116 NaClCondVar cond_; | |
| 117 bool start_sel_ldr_done_; | |
| 118 bool sel_ldr_wait_timed_out_; | |
| 119 bool start_nexe_done_; | |
| 120 bool nexe_started_ok_; | |
| 121 | |
| 122 NaClHandle bootstrap_channel_; | |
| 123 }; | |
| 124 | |
| 125 } // namespace plugin | |
| 126 | |
| 127 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SERVICE_RUNTIME_H_ | |
| OLD | NEW |