| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef SHELL_EXTERNAL_APPLICATION_REGISTRAR_CONNECTION_H_ | 5 #ifndef SHELL_EXTERNAL_APPLICATION_REGISTRAR_CONNECTION_H_ |
| 6 #define SHELL_EXTERNAL_APPLICATION_REGISTRAR_CONNECTION_H_ | 6 #define SHELL_EXTERNAL_APPLICATION_REGISTRAR_CONNECTION_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "mojo/common/common_type_converters.h" | 11 #include "mojo/common/common_type_converters.h" |
| 12 #include "mojo/edk/embedder/channel_init.h" | 12 #include "mojo/edk/embedder/channel_init.h" |
| 13 #include "mojo/public/cpp/bindings/error_handler.h" | 13 #include "mojo/public/cpp/bindings/error_handler.h" |
| 14 #include "mojo/public/interfaces/application/application.mojom.h" | 14 #include "mojo/public/interfaces/application/application.mojom.h" |
| 15 #include "mojo/public/interfaces/application/shell.mojom.h" | 15 #include "mojo/public/interfaces/application/shell.mojom.h" |
| 16 #include "shell/domain_socket/socket_descriptor.h" | 16 #include "shell/domain_socket/socket_descriptor.h" |
| 17 #include "shell/domain_socket/unix_domain_client_socket_posix.h" | 17 #include "shell/domain_socket/unix_domain_client_socket_posix.h" |
| 18 #include "shell/external_application_registrar.mojom.h" | 18 #include "shell/external_application_registrar.mojom.h" |
| 19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 20 | 20 |
| 21 namespace mojo { | 21 namespace mojo { |
| 22 |
| 23 class Application; |
| 24 |
| 22 namespace shell { | 25 namespace shell { |
| 23 | 26 |
| 24 // Externally-running applications can use this class to discover and register | 27 // Externally-running applications can use this class to discover and register |
| 25 // with a running mojo_shell instance. | 28 // with a running mojo_shell instance. |
| 26 // MUST be run on an IO thread | 29 // MUST be run on an IO thread |
| 27 class ExternalApplicationRegistrarConnection : public ErrorHandler { | 30 class ExternalApplicationRegistrarConnection : public ErrorHandler { |
| 28 public: | 31 public: |
| 29 // Configures client_socket_ to point at socket_path. | 32 // Configures client_socket_ to point at socket_path. |
| 30 explicit ExternalApplicationRegistrarConnection( | 33 explicit ExternalApplicationRegistrarConnection( |
| 31 const base::FilePath& socket_path); | 34 const base::FilePath& socket_path); |
| 32 ~ExternalApplicationRegistrarConnection() override; | 35 ~ExternalApplicationRegistrarConnection() override; |
| 33 | 36 |
| 34 // Implementation of ErrorHandler | 37 // Implementation of ErrorHandler |
| 35 void OnConnectionError() override; | 38 void OnConnectionError() override; |
| 36 | 39 |
| 37 // Connects the client socket and spins a message loop until the connection is | 40 // Connects the client socket and spins a message loop until the connection is |
| 38 // initiated, returning false if it was unable to do so. | 41 // initiated, returning false if it was unable to do so. |
| 39 bool Connect(); | 42 bool Connect(); |
| 40 | 43 |
| 44 using RegisterCallback = base::Callback<void(InterfaceRequest<Application>)>; |
| 45 |
| 41 // Registers this app with the shell at the provided URL. | 46 // Registers this app with the shell at the provided URL. |
| 42 void Register(const GURL& app_url, | 47 void Register(const GURL& app_url, |
| 43 const std::vector<std::string>& args, | 48 const std::vector<std::string>& args, |
| 44 base::Callback<void(ShellPtr)> register_complete_callback); | 49 const RegisterCallback& callback); |
| 45 | 50 |
| 46 private: | 51 private: |
| 47 // Handles the result of Connect(). If it was successful, promotes the socket | 52 // Handles the result of Connect(). If it was successful, promotes the socket |
| 48 // to a MessagePipe and binds it to registrar_. | 53 // to a MessagePipe and binds it to registrar_. |
| 49 void OnConnect(const base::Closure& cb, int rv); | 54 void OnConnect(const base::Closure& cb, int rv); |
| 50 | 55 |
| 51 scoped_ptr<UnixDomainClientSocket> client_socket_; | 56 scoped_ptr<UnixDomainClientSocket> client_socket_; |
| 52 mojo::embedder::ChannelInit channel_init_; | 57 mojo::embedder::ChannelInit channel_init_; |
| 53 ExternalApplicationRegistrarPtr registrar_; | 58 ExternalApplicationRegistrarPtr registrar_; |
| 54 }; | 59 }; |
| 55 | 60 |
| 56 } // namespace shell | 61 } // namespace shell |
| 57 } // namespace mojo | 62 } // namespace mojo |
| 58 | 63 |
| 59 #endif // SHELL_EXTERNAL_APPLICATION_REGISTRAR_CONNECTION_H_ | 64 #endif // SHELL_EXTERNAL_APPLICATION_REGISTRAR_CONNECTION_H_ |
| OLD | NEW |