| OLD | NEW |
| 1 /* -*- c++ -*- */ | 1 /* -*- c++ -*- */ |
| 2 /* | 2 /* |
| 3 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 3 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 // Utility class for launching sel_ldr. | 9 // Utility class for launching sel_ldr. |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 */ | 36 */ |
| 37 class SelLdrLocator { | 37 class SelLdrLocator { |
| 38 public: | 38 public: |
| 39 // Returns a directory with sel_ldr. | 39 // Returns a directory with sel_ldr. |
| 40 virtual void GetDirectory(char* buffer, size_t len) = 0; | 40 virtual void GetDirectory(char* buffer, size_t len) = 0; |
| 41 | 41 |
| 42 SelLdrLocator() {} | 42 SelLdrLocator() {} |
| 43 | 43 |
| 44 virtual ~SelLdrLocator() {} | 44 virtual ~SelLdrLocator() {} |
| 45 | 45 |
| 46 private: |
| 46 DISALLOW_COPY_AND_ASSIGN(SelLdrLocator); | 47 DISALLOW_COPY_AND_ASSIGN(SelLdrLocator); |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 /* | 50 /* |
| 50 * Default implementation of SelLdrLocator which tries to | 51 * Default implementation of SelLdrLocator which tries to |
| 51 * locate a browser plugin. Default constructor of SelLdrLauncher use it. | 52 * locate a browser plugin. Default constructor of SelLdrLauncher use it. |
| 52 */ | 53 */ |
| 53 class PluginSelLdrLocator : public SelLdrLocator { | 54 class PluginSelLdrLocator : public SelLdrLocator { |
| 54 public: | 55 public: |
| 55 // We have different implementations for all platforms. | 56 // We have different implementations for all platforms. |
| 56 virtual void GetDirectory(char* buffer, size_t len); | 57 virtual void GetDirectory(char* buffer, size_t len); |
| 57 | 58 |
| 58 PluginSelLdrLocator() {} | 59 PluginSelLdrLocator() {} |
| 59 | 60 |
| 61 private: |
| 60 DISALLOW_COPY_AND_ASSIGN(PluginSelLdrLocator); | 62 DISALLOW_COPY_AND_ASSIGN(PluginSelLdrLocator); |
| 61 }; | 63 }; |
| 62 | 64 |
| 63 /* | 65 /* |
| 64 * This class encapsulates the process of launching an instance of sel_ldr | 66 * This class encapsulates the process of launching an instance of sel_ldr |
| 65 * to communicate with the NaCl plugin over an IMC channel. | 67 * to communicate with the NaCl plugin over an IMC channel. |
| 66 * | 68 * |
| 67 * The sel_ldr process can be forked directly using a command line of args | 69 * The sel_ldr process can be forked directly using a command line of args |
| 68 * or by sending a message to the (Chrome) browser process. | 70 * or by sending a message to the (Chrome) browser process. |
| 69 */ | 71 */ |
| 70 class SelLdrLauncherBase { | 72 class SelLdrLauncherBase { |
| 71 public: | 73 public: |
| 72 SelLdrLauncherBase(); | 74 SelLdrLauncherBase(); |
| 73 virtual ~SelLdrLauncherBase(); | 75 virtual ~SelLdrLauncherBase(); |
| 74 | 76 |
| 75 ///////////////////////////////////////////////////////////////////////////// | 77 ///////////////////////////////////////////////////////////////////////////// |
| 76 // Browser start-up: (used by the plugin inside or outside of Chrome build.) | 78 // Browser start-up: (used by the plugin inside or outside of Chrome build.) |
| 77 ///////////////////////////////////////////////////////////////////////////// | 79 ///////////////////////////////////////////////////////////////////////////// |
| 78 | 80 |
| 79 virtual bool Start(const char* url) = 0; | 81 virtual bool Start(const char* url) = 0; |
| 80 | 82 |
| 81 ///////////////////////////////////////////////////////////////////////////// | 83 ///////////////////////////////////////////////////////////////////////////// |
| 82 // After starting the sel_ldr process. | 84 // After starting the sel_ldr process. |
| 83 ///////////////////////////////////////////////////////////////////////////// | 85 ///////////////////////////////////////////////////////////////////////////// |
| 84 | 86 |
| 85 // Connects bootstrap socket. | |
| 86 bool ConnectBootstrapSocket(); | |
| 87 | |
| 88 // Retrieves the socket address. | |
| 89 bool RetrieveSockAddr(); | |
| 90 | |
| 91 // Sets up the command channel |command|. | 87 // Sets up the command channel |command|. |
| 92 bool SetupCommand(NaClSrpcChannel* command); | 88 bool SetupCommand(NaClSrpcChannel* command); |
| 93 | 89 |
| 94 // Load |nexe| over the command channel |command|. | 90 // Load |nexe| over the command channel |command|. |
| 95 bool LoadModule(NaClSrpcChannel* command, DescWrapper* nexe); | 91 bool LoadModule(NaClSrpcChannel* command, DescWrapper* nexe); |
| 96 | 92 |
| 97 // Sets up the command channel |command| and sends the SRPC to load |nexe|. | |
| 98 bool SetupCommandAndLoad(NaClSrpcChannel* command, DescWrapper* nexe); | |
| 99 | |
| 100 // Sends the SRPC to start the nexe over |command|. | 93 // Sends the SRPC to start the nexe over |command|. |
| 101 bool StartModule(NaClSrpcChannel* command); | 94 bool StartModule(NaClSrpcChannel* command); |
| 102 | 95 |
| 103 // Sets up the SRPC channel |out_app_chan|. | 96 // Sets up the SRPC channel |out_app_chan|. |
| 104 bool SetupAppChannel(NaClSrpcChannel* out_app_chan); | 97 bool SetupAppChannel(NaClSrpcChannel* out_app_chan); |
| 105 | 98 |
| 106 // Sends the SRPC to start the nexe over |command| and sets up the application | |
| 107 // SRPC chanel |out_app_chan|. | |
| 108 bool StartModuleAndSetupAppChannel(NaClSrpcChannel* command, | |
| 109 NaClSrpcChannel* out_app_chan); | |
| 110 | |
| 111 // Returns the socket address used to connect to the sel_ldr. | |
| 112 DescWrapper* secure_socket_addr() const { return secure_socket_addr_.get(); } | |
| 113 | |
| 114 // Returns the socket address used to connect to the module. | 99 // Returns the socket address used to connect to the module. |
| 115 DescWrapper* socket_addr() const { return socket_addr_.get(); } | 100 DescWrapper* socket_addr() const { return socket_addr_.get(); } |
| 116 | 101 |
| 117 // Wraps a raw NaClDesc descriptor. If NULL is returned, caller retains | |
| 118 // ownership of the reference. | |
| 119 DescWrapper* Wrap(NaClDesc* raw_desc); | |
| 120 | |
| 121 // As above, but raw_desc is Unref'd on failure. | |
| 122 DescWrapper* WrapCleanup(NaClDesc* raw_desc); | |
| 123 | |
| 124 protected: | 102 protected: |
| 125 NaClHandle channel_; | 103 NaClHandle channel_; |
| 126 | 104 |
| 127 private: | 105 private: |
| 106 // Connects bootstrap socket. |
| 107 bool ConnectBootstrapSocket(); |
| 108 |
| 109 // Retrieves the socket address. |
| 110 bool RetrieveSockAddr(); |
| 111 |
| 128 // lifetime of bootstrap_socket_ must be at least that of factory_ | 112 // lifetime of bootstrap_socket_ must be at least that of factory_ |
| 129 scoped_ptr<DescWrapperFactory> factory_; | 113 scoped_ptr<DescWrapperFactory> factory_; |
| 130 scoped_ptr<DescWrapper> bootstrap_socket_; | 114 scoped_ptr<DescWrapper> bootstrap_socket_; |
| 131 // The socket address returned from sel_ldr for connects. | 115 // The socket address returned from sel_ldr for connects. |
| 132 scoped_ptr<DescWrapper> secure_socket_addr_; | 116 scoped_ptr<DescWrapper> secure_socket_addr_; |
| 133 scoped_ptr<DescWrapper> socket_addr_; | 117 scoped_ptr<DescWrapper> socket_addr_; |
| 134 }; | 118 }; |
| 135 | 119 |
| 136 class SelLdrLauncherStandalone : public SelLdrLauncherBase { | 120 class SelLdrLauncherStandalone : public SelLdrLauncherBase { |
| 137 public: | 121 public: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 std::vector<nacl::string> application_argv_; | 192 std::vector<nacl::string> application_argv_; |
| 209 | 193 |
| 210 std::vector<NaClHandle> close_after_launch_; | 194 std::vector<NaClHandle> close_after_launch_; |
| 211 | 195 |
| 212 scoped_ptr<SelLdrLocator> sel_ldr_locator_; | 196 scoped_ptr<SelLdrLocator> sel_ldr_locator_; |
| 213 }; | 197 }; |
| 214 | 198 |
| 215 } // namespace nacl | 199 } // namespace nacl |
| 216 | 200 |
| 217 #endif // NATIVE_CLIENT_SRC_TRUSTED_NONNACL_UTIL_SEL_LDR_LAUNCHER_H_ | 201 #endif // NATIVE_CLIENT_SRC_TRUSTED_NONNACL_UTIL_SEL_LDR_LAUNCHER_H_ |
| OLD | NEW |