| 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 // Instances of NaCl modules spun up within the plugin as a subprocess. | 5 // Instances of NaCl modules spun up within the plugin as a subprocess. |
| 6 // This may represent the "main" nacl module, or it may represent helpers | 6 // This may represent the "main" nacl module, or it may represent helpers |
| 7 // that perform various tasks within the plugin, for example, | 7 // that perform various tasks within the plugin, for example, |
| 8 // a NaCl module for a compiler could be loaded to translate LLVM bitcode | 8 // a NaCl module for a compiler could be loaded to translate LLVM bitcode |
| 9 // into native code. | 9 // into native code. |
| 10 | 10 |
| 11 #ifndef COMPONENTS_NACL_RENDERER_PLUGIN_NACL_SUBPROCESS_H_ | 11 #ifndef COMPONENTS_NACL_RENDERER_PLUGIN_NACL_SUBPROCESS_H_ |
| 12 #define COMPONENTS_NACL_RENDERER_PLUGIN_NACL_SUBPROCESS_H_ | 12 #define COMPONENTS_NACL_RENDERER_PLUGIN_NACL_SUBPROCESS_H_ |
| 13 | 13 |
| 14 #include <stdarg.h> | 14 #include <stdarg.h> |
| 15 | 15 |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "components/nacl/renderer/plugin/service_runtime.h" | 17 #include "components/nacl/renderer/plugin/service_runtime.h" |
| 18 #include "components/nacl/renderer/plugin/srpc_client.h" | |
| 19 #include "native_client/src/include/nacl_macros.h" | 18 #include "native_client/src/include/nacl_macros.h" |
| 20 #include "native_client/src/include/portability.h" | 19 #include "native_client/src/include/portability.h" |
| 21 | 20 |
| 22 namespace plugin { | 21 namespace plugin { |
| 23 | 22 |
| 24 class Plugin; | 23 class Plugin; |
| 25 class ServiceRuntime; | 24 class ServiceRuntime; |
| 26 class SrpcParams; | |
| 27 | 25 |
| 28 | 26 |
| 29 // A class representing an instance of a NaCl module, loaded by the plugin. | 27 // A class representing an instance of a NaCl module, loaded by the plugin. |
| 30 class NaClSubprocess { | 28 class NaClSubprocess { |
| 31 public: | 29 public: |
| 32 NaClSubprocess(const std::string& description, | 30 NaClSubprocess(const std::string& description, |
| 33 ServiceRuntime* service_runtime, | 31 ServiceRuntime* service_runtime); |
| 34 SrpcClient* srpc_client); | |
| 35 virtual ~NaClSubprocess(); | 32 virtual ~NaClSubprocess(); |
| 36 | 33 |
| 37 ServiceRuntime* service_runtime() const { return service_runtime_.get(); } | 34 ServiceRuntime* service_runtime() const { return service_runtime_.get(); } |
| 38 void set_service_runtime(ServiceRuntime* service_runtime) { | 35 void set_service_runtime(ServiceRuntime* service_runtime) { |
| 39 service_runtime_.reset(service_runtime); | 36 service_runtime_.reset(service_runtime); |
| 40 } | 37 } |
| 41 | 38 |
| 42 // The socket used for communicating w/ the NaCl module. | |
| 43 SrpcClient* srpc_client() const { return srpc_client_.get(); } | |
| 44 | |
| 45 // A basic description of the subprocess. | 39 // A basic description of the subprocess. |
| 46 std::string description() const { return description_; } | 40 std::string description() const { return description_; } |
| 47 | 41 |
| 48 // A detailed description of the subprocess that may contain addresses. | 42 // A detailed description of the subprocess that may contain addresses. |
| 49 // Only use for debugging, but do not expose this to untrusted webapps. | 43 // Only use for debugging, but do not expose this to untrusted webapps. |
| 50 std::string detailed_description() const; | 44 std::string detailed_description() const; |
| 51 | 45 |
| 52 // Start up interfaces. | |
| 53 bool StartSrpcServices(); | |
| 54 | |
| 55 // Invoke an Srpc Method. |out_params| must be allocated and cleaned up | |
| 56 // outside of this function, but it will be initialized by this function, and | |
| 57 // on success any out-params (if any) will be placed in |out_params|. | |
| 58 // Input types must be listed in |input_signature|, with the actual | |
| 59 // arguments passed in as var-args. Returns |true| on success. | |
| 60 bool InvokeSrpcMethod(const std::string& method_name, | |
| 61 const std::string& input_signature, | |
| 62 SrpcParams* out_params, | |
| 63 ...); | |
| 64 | |
| 65 // Fully shut down the subprocess. | 46 // Fully shut down the subprocess. |
| 66 void Shutdown(); | 47 void Shutdown(); |
| 67 | 48 |
| 68 private: | 49 private: |
| 69 NACL_DISALLOW_COPY_AND_ASSIGN(NaClSubprocess); | 50 NACL_DISALLOW_COPY_AND_ASSIGN(NaClSubprocess); |
| 70 | 51 |
| 71 bool VInvokeSrpcMethod(const std::string& method_name, | |
| 72 const std::string& signature, | |
| 73 SrpcParams* params, | |
| 74 va_list vl); | |
| 75 | |
| 76 std::string description_; | 52 std::string description_; |
| 77 | 53 |
| 78 // The service runtime representing the NaCl module instance. | 54 // The service runtime representing the NaCl module instance. |
| 79 nacl::scoped_ptr<ServiceRuntime> service_runtime_; | 55 nacl::scoped_ptr<ServiceRuntime> service_runtime_; |
| 80 // Ownership of srpc_client taken from the service runtime. | |
| 81 nacl::scoped_ptr<SrpcClient> srpc_client_; | |
| 82 }; | 56 }; |
| 83 | 57 |
| 84 } // namespace plugin | 58 } // namespace plugin |
| 85 | 59 |
| 86 #endif // COMPONENTS_NACL_RENDERER_PLUGIN_NACL_SUBPROCESS_H_ | 60 #endif // COMPONENTS_NACL_RENDERER_PLUGIN_NACL_SUBPROCESS_H_ |
| OLD | NEW |