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_LISTENER_H_ | 5 #ifndef SHELL_EXTERNAL_APPLICATION_LISTENER_H_ |
6 #define SHELL_EXTERNAL_APPLICATION_LISTENER_H_ | 6 #define SHELL_EXTERNAL_APPLICATION_LISTENER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
16 #include "mojo/edk/embedder/channel_init.h" | 16 #include "mojo/edk/embedder/channel_init.h" |
17 #include "mojo/public/interfaces/application/shell.mojom.h" | 17 #include "mojo/public/interfaces/application/application.mojom.h" |
18 #include "shell/domain_socket/socket_descriptor.h" | 18 #include "shell/domain_socket/socket_descriptor.h" |
19 #include "shell/external_application_registrar.mojom.h" | 19 #include "shell/external_application_registrar.mojom.h" |
20 #include "shell/incoming_connection_listener.h" | 20 #include "shell/incoming_connection_listener.h" |
21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
22 | 22 |
23 namespace mojo { | 23 namespace mojo { |
24 namespace shell { | 24 namespace shell { |
25 | 25 |
26 // In order to support Mojo apps whose lifetime is managed by | 26 // In order to support Mojo apps whose lifetime is managed by something other |
27 // something other than mojo_shell, mojo_shell needs to support a | 27 // than mojo_shell, mojo_shell needs to support a mechanism by which such an |
28 // mechanism by which such an application can discover a running shell | 28 // application can discover a running shell instance, connect to it, and ask to |
29 // instance, connect to it, and ask to be "registered" at a given | 29 // be "registered" at a given URL. Registration implies that the app can be |
30 // URL. Registration implies that the app can be connected to at that | 30 // connected to at that URL from then on out, and that the app has a connection |
31 // URL from then on out, and that the app has received a usable ShellPtr. | 31 // to the shell. Once registered the shell will treat the external application |
| 32 // as if it was started from the shell and make a mojo.Application.Initialize() |
| 33 // call on it, passing it a handle to the mojo.Shell interface. |
32 // | 34 // |
33 // This class implements most of the mojo_shell side of external application | 35 // This class implements most of the mojo_shell side of external application |
34 // registration. It handles: | 36 // registration. It handles: |
35 // 1) discoverability - sets up a unix domain socket at a well-known location, | 37 // 1) discoverability - sets up a unix domain socket at a well-known location, |
36 // 2) incoming connections - listens for and accepts incoming connections on | 38 // 2) incoming connections - listens for and accepts incoming connections on |
37 // that socket, and | 39 // that socket, and |
38 // 3) registration requests - forwarded to a RegisterCallback that implements | 40 // 3) registration requests - forwarded to a RegisterCallback that implements |
39 // the actual registration logic. | 41 // the actual registration logic. |
40 // | 42 // |
41 // External applications can connect to the shell using the | 43 // External applications can connect to the shell using the |
42 // ExternalApplicationRegistrarConnection class. | 44 // ExternalApplicationRegistrarConnection class. |
43 class ExternalApplicationListener | 45 class ExternalApplicationListener |
44 : public IncomingConnectionListener::Delegate { | 46 : public IncomingConnectionListener::Delegate { |
45 public: | 47 public: |
46 // When run, a RegisterCallback should note that an app has asked to be | 48 // When run, a RegisterCallback should note that an app has asked to be |
47 // registered at app_url and Bind the provided pipe handle to a ShellImpl. | 49 // registered at app_url and Bind the provided pipe handle to an |
| 50 // ApplicationPtr to be initialized. |
48 using RegisterCallback = | 51 using RegisterCallback = |
49 base::Callback<void(const GURL& app_url, | 52 base::Callback<void(const GURL& app_url, |
50 const std::vector<std::string>& args, | 53 const std::vector<std::string>& args, |
51 ScopedMessagePipeHandle shell)>; | 54 ApplicationPtr application)>; |
52 using ErrorCallback = base::Callback<void(int rv)>; | 55 using ErrorCallback = base::Callback<void(int rv)>; |
53 | 56 |
54 static base::FilePath ConstructDefaultSocketPath(); | 57 static base::FilePath ConstructDefaultSocketPath(); |
55 | 58 |
56 // This class uses two threads, an IO thread for listening and accepting | 59 // This class uses two threads, an IO thread for listening and accepting |
57 // incoming sockets, and a "main" thread where all Mojo traffic is processed | 60 // incoming sockets, and a "main" thread where all Mojo traffic is processed |
58 // and provided callbacks are run. | 61 // and provided callbacks are run. |
59 ExternalApplicationListener( | 62 ExternalApplicationListener( |
60 const scoped_refptr<base::SequencedTaskRunner>& shell_runner, | 63 const scoped_refptr<base::SequencedTaskRunner>& shell_runner, |
61 const scoped_refptr<base::SequencedTaskRunner>& io_runner); | 64 const scoped_refptr<base::SequencedTaskRunner>& io_runner); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 base::ThreadChecker register_thread_checker_; | 130 base::ThreadChecker register_thread_checker_; |
128 | 131 |
129 // Used on shell_runner_. | 132 // Used on shell_runner_. |
130 base::WeakPtrFactory<ExternalApplicationListener> weak_ptr_factory_; | 133 base::WeakPtrFactory<ExternalApplicationListener> weak_ptr_factory_; |
131 }; | 134 }; |
132 | 135 |
133 } // namespace shell | 136 } // namespace shell |
134 } // namespace mojo | 137 } // namespace mojo |
135 | 138 |
136 #endif // SHELL_EXTERNAL_APPLICATION_LISTENER_H_ | 139 #endif // SHELL_EXTERNAL_APPLICATION_LISTENER_H_ |
OLD | NEW |