| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MOJO_SHELL_EXTERNAL_APPLICATION_LISTENER_H_ | |
| 6 #define MOJO_SHELL_EXTERNAL_APPLICATION_LISTENER_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/sequenced_task_runner.h" | |
| 13 #include "mojo/public/cpp/system/message_pipe.h" | |
| 14 #include "mojo/shell/domain_socket/socket_descriptor.h" | |
| 15 #include "url/gurl.h" | |
| 16 | |
| 17 namespace mojo { | |
| 18 namespace shell { | |
| 19 | |
| 20 // In order to support Mojo apps whose lifetime is managed by | |
| 21 // something other than mojo_shell, mojo_shell needs to support a | |
| 22 // mechanism by which such an application can discover a running shell | |
| 23 // instance, connect to it, and ask to be "registered" at a given | |
| 24 // URL. Registration implies that the app can be connected to at that | |
| 25 // URL from then on out, and that the app has received a usable ShellPtr. | |
| 26 // | |
| 27 // External applications can connect to the shell using the | |
| 28 // ExternalApplicationRegistrarConnection class. | |
| 29 class ExternalApplicationListener { | |
| 30 public: | |
| 31 // When run, a RegisterCallback should note that an app has asked to be | |
| 32 // registered at app_url and Bind the provided pipe handle to a ShellImpl. | |
| 33 typedef base::Callback<void(const GURL& app_url, | |
| 34 ScopedMessagePipeHandle shell)> RegisterCallback; | |
| 35 typedef base::Callback<void(int rv)> ErrorCallback; | |
| 36 | |
| 37 virtual ~ExternalApplicationListener() {} | |
| 38 | |
| 39 // Implementations of this class may use two threads, an IO thread for | |
| 40 // listening and accepting incoming sockets, and a "main" thread | |
| 41 // where all Mojo traffic is processed and provided callbacks are run. | |
| 42 static scoped_ptr<ExternalApplicationListener> Create( | |
| 43 const scoped_refptr<base::SequencedTaskRunner>& shell_runner, | |
| 44 const scoped_refptr<base::SequencedTaskRunner>& io_runner); | |
| 45 | |
| 46 static base::FilePath ConstructDefaultSocketPath(); | |
| 47 | |
| 48 // Begin listening (on io_runner) to a socket at listen_socket_path. | |
| 49 // Incoming registration requests will be forwarded to register_callback. | |
| 50 // Errors are ignored. | |
| 51 virtual void ListenInBackground( | |
| 52 const base::FilePath& listen_socket_path, | |
| 53 const RegisterCallback& register_callback) = 0; | |
| 54 | |
| 55 // Begin listening (on io_runner) to a socket at listen_socket_path. | |
| 56 // Incoming registration requests will be forwarded to register_callback. | |
| 57 // Errors are reported via error_callback. | |
| 58 virtual void ListenInBackgroundWithErrorCallback( | |
| 59 const base::FilePath& listen_socket_path, | |
| 60 const RegisterCallback& register_callback, | |
| 61 const ErrorCallback& error_callback) = 0; | |
| 62 | |
| 63 // Block the current thread until listening has started on io_runner. | |
| 64 // If listening has already started, returns immediately. | |
| 65 virtual void WaitForListening() = 0; | |
| 66 }; | |
| 67 | |
| 68 } // namespace shell | |
| 69 } // namespace mojo | |
| 70 | |
| 71 #endif // MOJO_SHELL_EXTERNAL_APPLICATION_LISTENER_H_ | |
| OLD | NEW |