OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CONTENT_COMMON_MOJO_EMBEDDED_APPLICATION_RUNNER_H_ | 5 #ifndef CONTENT_COMMON_MOJO_EMBEDDED_APPLICATION_RUNNER_H_ |
6 #define CONTENT_COMMON_MOJO_EMBEDDED_APPLICATION_RUNNER_H_ | 6 #define CONTENT_COMMON_MOJO_EMBEDDED_APPLICATION_RUNNER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "services/shell/public/cpp/shell_client.h" | 14 #include "services/shell/public/cpp/shell_client.h" |
15 #include "services/shell/public/interfaces/shell_client.mojom.h" | 15 #include "services/shell/public/interfaces/shell_client.mojom.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 // Hosts an in-process application instance that supports multiple ShellClient | 19 // Hosts an in-process application instance that supports multiple ShellClient |
20 // connections. The first incoming connection will invoke a provided factory | 20 // connections. The first incoming connection will invoke a provided factory |
21 // function to instantiate the application, and the application will | 21 // function to instantiate the application, and the application will |
22 // automatically be torn down when its last connection is lost. The application | 22 // automatically be torn down when its last connection is lost. The application |
23 // may be launched and torn down multiple times by a single | 23 // may be launched and torn down multiple times by a single |
24 // EmbeddedApplicationRunner instance. | 24 // EmbeddedApplicationRunner instance. |
25 class EmbeddedApplicationRunner { | 25 class EmbeddedApplicationRunner { |
26 public: | 26 public: |
27 using FactoryCallback = | 27 using FactoryCallback = base::Callback<std::unique_ptr<shell::ShellClient>()>; |
28 base::Callback<std::unique_ptr<mojo::ShellClient>()>; | |
29 | 28 |
30 // Constructs a runner which hosts the application on |task_runner|'s thread. | 29 // Constructs a runner which hosts the application on |task_runner|'s thread. |
31 // If an existing instance of the app is not running when an incoming | 30 // If an existing instance of the app is not running when an incoming |
32 // connection is made, |callback| will be run on |task_runner|'s thread to | 31 // connection is made, |callback| will be run on |task_runner|'s thread to |
33 // create a new instance which will live on that thread. | 32 // create a new instance which will live on that thread. |
34 EmbeddedApplicationRunner( | 33 EmbeddedApplicationRunner( |
35 const FactoryCallback& callback, | 34 const FactoryCallback& callback, |
36 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
37 | 36 |
38 ~EmbeddedApplicationRunner(); | 37 ~EmbeddedApplicationRunner(); |
39 | 38 |
40 // Binds an incoming ShellClientRequest for this application. If the | 39 // Binds an incoming ShellClientRequest for this application. If the |
41 // application isn't already running, it's started. Otherwise the request is | 40 // application isn't already running, it's started. Otherwise the request is |
42 // bound to the running instance. | 41 // bound to the running instance. |
43 void BindShellClientRequest(mojo::shell::mojom::ShellClientRequest request); | 42 void BindShellClientRequest(shell::mojom::ShellClientRequest request); |
44 | 43 |
45 private: | 44 private: |
46 class Instance; | 45 class Instance; |
47 | 46 |
48 // The TaskRunner on which the factory callback will be run. The | 47 // The TaskRunner on which the factory callback will be run. The |
49 // mojo::ShellClient it returns will live and die on this TaskRunner's thread. | 48 // shell::ShellClient it returns will live and die on this TaskRunner's |
| 49 // thread. |
50 const scoped_refptr<base::SingleThreadTaskRunner> application_task_runner_; | 50 const scoped_refptr<base::SingleThreadTaskRunner> application_task_runner_; |
51 | 51 |
52 // A reference to the application instance which may operate on the | 52 // A reference to the application instance which may operate on the |
53 // |application_task_runner_|'s thread. | 53 // |application_task_runner_|'s thread. |
54 scoped_refptr<Instance> instance_; | 54 scoped_refptr<Instance> instance_; |
55 | 55 |
56 DISALLOW_COPY_AND_ASSIGN(EmbeddedApplicationRunner); | 56 DISALLOW_COPY_AND_ASSIGN(EmbeddedApplicationRunner); |
57 }; | 57 }; |
58 | 58 |
59 } // namespace content | 59 } // namespace content |
60 | 60 |
61 #endif // CONTENT_COMMON_MOJO_EMBEDDED_APPLICATION_RUNNER_H_ | 61 #endif // CONTENT_COMMON_MOJO_EMBEDDED_APPLICATION_RUNNER_H_ |
OLD | NEW |